1 /* PROJECT: ReactOS sndrec32
2 * LICENSE: GPL - See COPYING in the top level directory
3 * FILE: base/applications/sndrec32/audio_format.hpp
4 * PURPOSE: Audio format abstraction
5 * PROGRAMMERS: Marco Pagliaricci (irc: rendar)
10 #ifndef _AUDIOFORMAT__H_
11 #define _AUDIOFORMAT__H_
15 #include "audio_def.hpp"
20 _AUDIO_NAMESPACE_START_
33 unsigned int samples_psec;
34 unsigned short int bits_psample;
35 unsigned short int chan;
45 audio_format( unsigned int samples_per_second,
46 unsigned short int bits_per_sample, unsigned short int channels )
48 : samples_psec( samples_per_second ), bits_psample( bits_per_sample ),
63 virtual ~audio_format( void )
76 bool operator==( audio_format & eq ) const
79 // The same audio format is when samples per second,
80 // bit per sample, and channels mono/stereo are equal.
83 return (( samples_psec == eq.samples_psec )
84 && ( bits_psample == eq.bits_psample ) && ( chan == eq.chan ));
98 unsigned int sample_rate( void ) const
99 { return samples_psec; }
102 unsigned short int bits( void ) const
103 { return bits_psample; }
106 unsigned short int channels( void ) const
110 unsigned int byte_rate( void ) const
111 { return ( samples_psec * chan * ( bits_psample / 8 )); }
114 unsigned int block_align( void ) const
115 { return ( chan * ( bits_psample / 8 )); }
119 unsigned int samples_in_seconds( float seconds ) const
122 return ( unsigned int )
123 ((( float )samples_psec * ( float ) chan ) * seconds );
127 unsigned int samples_in_bytes ( unsigned int bytes ) const
130 return ( bytes / (( bits_psample / 8 ) * chan ));
134 unsigned int bytes_in_samples( unsigned int samples ) const
137 return ( samples * (( bits_psample / 8 ) * chan ));
146 extern audio_format UNKNOWN_FORMAT;
147 extern audio_format A44100_16BIT_STEREO;
148 extern audio_format A44100_16BIT_MONO;
155 _AUDIO_NAMESPACE_END_
163 #endif //ifdef _AUDIOFORMAT__H_