- Merge from trunk up to r45543
[reactos.git] / base / applications / sndrec32 / audio_format.hpp
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)
6 */
7
8
9
10 #ifndef _AUDIOFORMAT__H_
11 #define _AUDIOFORMAT__H_
12
13
14
15 #include "audio_def.hpp"
16
17
18
19
20 _AUDIO_NAMESPACE_START_
21
22
23
24
25
26
27
28 class audio_format
29 {
30 protected:
31
32
33 unsigned int samples_psec;
34 unsigned short int bits_psample;
35 unsigned short int chan;
36
37
38 public:
39
40
41 //
42 // Ctors
43 //
44
45 audio_format( unsigned int samples_per_second,
46 unsigned short int bits_per_sample, unsigned short int channels )
47
48 : samples_psec( samples_per_second ), bits_psample( bits_per_sample ),
49 chan( channels )
50
51 { }
52
53
54
55
56
57
58
59 //
60 // Dtor
61 //
62
63 virtual ~audio_format( void )
64 { }
65
66
67
68
69
70
71
72 //
73 // Operators
74 //
75
76 bool operator==( audio_format & eq ) const
77 {
78 //
79 // The same audio format is when samples per second,
80 // bit per sample, and channels mono/stereo are equal.
81 //
82
83 return (( samples_psec == eq.samples_psec )
84 && ( bits_psample == eq.bits_psample ) && ( chan == eq.chan ));
85 }
86
87
88
89
90
91
92
93
94 //
95 // Public Functions
96 //
97
98 unsigned int sample_rate( void ) const
99 { return samples_psec; }
100
101
102 unsigned short int bits( void ) const
103 { return bits_psample; }
104
105
106 unsigned short int channels( void ) const
107 { return chan; }
108
109
110 unsigned int byte_rate( void ) const
111 { return ( samples_psec * chan * ( bits_psample / 8 )); }
112
113
114 unsigned int block_align( void ) const
115 { return ( chan * ( bits_psample / 8 )); }
116
117
118
119 unsigned int samples_in_seconds( float seconds ) const
120 {
121
122 return ( unsigned int )
123 ((( float )samples_psec * ( float ) chan ) * seconds );
124
125 }
126
127 unsigned int samples_in_bytes ( unsigned int bytes ) const
128 {
129
130 return ( bytes / (( bits_psample / 8 ) * chan ));
131
132 }
133
134 unsigned int bytes_in_samples( unsigned int samples ) const
135 {
136
137 return ( samples * (( bits_psample / 8 ) * chan ));
138
139 }
140
141 };
142
143
144
145
146 extern audio_format UNKNOWN_FORMAT;
147 extern audio_format A44100_16BIT_STEREO;
148 extern audio_format A44100_16BIT_MONO;
149
150
151
152
153
154
155 _AUDIO_NAMESPACE_END_
156
157
158
159
160
161
162
163 #endif //ifdef _AUDIOFORMAT__H_