Mercurial > sdl-ios-xcode
comparison src/audio/baudio/SDL_beaudio.cc @ 1997:46319c67b3d7
Added int32 and float32 support (and some others!) to BeOS audio backend.
Untested: No BeOS system here for compiling!
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Thu, 31 Aug 2006 22:15:07 +0000 |
parents | c121d94672cb |
children | cbac0f77a799 |
comparison
equal
deleted
inserted
replaced
1996:f25d771fe6f2 | 1997:46319c67b3d7 |
---|---|
154 } | 154 } |
155 | 155 |
156 int BE_OpenAudio(_THIS, SDL_AudioSpec * spec) | 156 int BE_OpenAudio(_THIS, SDL_AudioSpec * spec) |
157 { | 157 { |
158 media_raw_audio_format format; | 158 media_raw_audio_format format; |
159 SDL_AudioFormat test_format = SDL_FirstAudioFormat(spec->format); | |
160 int valid_datatype = 0; | |
161 | |
162 /* Parse the audio format and fill the Be raw audio format */ | |
163 memset(&format, '\0', sizeof (media_raw_audio_format)); | |
164 format.byte_order = B_MEDIA_LITTLE_ENDIAN; | |
165 format.frame_rate = (float) spec->freq; | |
166 format.channel_count = spec->channels; /* !!! FIXME: support > 2? */ | |
167 while ((!valid_datatype) && (test_format)) { | |
168 spec->format = test_format; | |
169 switch (test_format) { | |
170 case AUDIO_S8: | |
171 valid_datatype = 1; | |
172 format.format = media_raw_audio_format::B_AUDIO_CHAR; | |
173 break; | |
174 | |
175 case AUDIO_U8: | |
176 valid_datatype = 1; | |
177 format.format = media_raw_audio_format::B_AUDIO_UCHAR; | |
178 break; | |
179 | |
180 case AUDIO_S16LSB: | |
181 valid_datatype = 1; | |
182 format.format = media_raw_audio_format::B_AUDIO_SHORT; | |
183 break; | |
184 | |
185 case AUDIO_S16MSB: | |
186 valid_datatype = 1; | |
187 format.format = media_raw_audio_format::B_AUDIO_SHORT; | |
188 format.byte_order = B_MEDIA_BIG_ENDIAN; | |
189 break; | |
190 | |
191 case AUDIO_S32LSB: | |
192 valid_datatype = 1; | |
193 format.format = media_raw_audio_format::B_AUDIO_INT; | |
194 break; | |
195 | |
196 case AUDIO_S32MSB: | |
197 valid_datatype = 1; | |
198 format.format = media_raw_audio_format::B_AUDIO_INT; | |
199 format.byte_order = B_MEDIA_BIG_ENDIAN; | |
200 break; | |
201 | |
202 case AUDIO_F32LSB: | |
203 valid_datatype = 1; | |
204 format.format = media_raw_audio_format::B_AUDIO_FLOAT; | |
205 break; | |
206 | |
207 case AUDIO_F32MSB: | |
208 valid_datatype = 1; | |
209 format.format = media_raw_audio_format::B_AUDIO_FLOAT; | |
210 format.byte_order = B_MEDIA_BIG_ENDIAN; | |
211 break; | |
212 | |
213 default: | |
214 test_format = SDL_NextAudioFormat(); | |
215 break; | |
216 } | |
217 } | |
218 | |
219 format.buffer_size = spec->samples; | |
220 | |
221 if (!valid_datatype) { /* shouldn't happen, but just in case... */ | |
222 SDL_SetError("Unsupported audio format"); | |
223 return (-1); | |
224 } | |
159 | 225 |
160 /* Initialize the Be Application, if it's not already started */ | 226 /* Initialize the Be Application, if it's not already started */ |
161 if (SDL_InitBeApp() < 0) { | 227 if (SDL_InitBeApp() < 0) { |
162 return (-1); | 228 return (-1); |
163 } | 229 } |
164 | |
165 /* Parse the audio format and fill the Be raw audio format */ | |
166 format.frame_rate = (float) spec->freq; | |
167 format.channel_count = spec->channels; | |
168 switch (spec->format & ~0x1000) { | |
169 case AUDIO_S8: | |
170 /* Signed 8-bit audio unsupported, convert to U8 */ | |
171 spec->format = AUDIO_U8; | |
172 case AUDIO_U8: | |
173 format.format = media_raw_audio_format::B_AUDIO_UCHAR; | |
174 format.byte_order = 0; | |
175 break; | |
176 case AUDIO_U16: | |
177 /* Unsigned 16-bit audio unsupported, convert to S16 */ | |
178 spec->format ^= 0x8000; | |
179 case AUDIO_S16: | |
180 format.format = media_raw_audio_format::B_AUDIO_SHORT; | |
181 if (spec->format & 0x1000) { | |
182 format.byte_order = 1; /* Big endian */ | |
183 } else { | |
184 format.byte_order = 2; /* Little endian */ | |
185 } | |
186 break; | |
187 } | |
188 format.buffer_size = spec->samples; | |
189 | 230 |
190 /* Calculate the final parameters for this audio specification */ | 231 /* Calculate the final parameters for this audio specification */ |
191 SDL_CalculateAudioSpec(spec); | 232 SDL_CalculateAudioSpec(spec); |
192 | 233 |
193 /* Subscribe to the audio stream (creates a new thread) */ | 234 /* Subscribe to the audio stream (creates a new thread) */ |