comparison src/audio/baudio/SDL_beaudio.cc @ 3851:405a192b68e7 SDL-1.2

Backport from 1.3: most of the audio drivers can now handle data conversion at a higher level when they can't open the hardware in the exact format requested.
author Ryan C. Gordon <icculus@icculus.org>
date Fri, 01 Sep 2006 22:50:24 +0000
parents 376665398b25
children 5b5e549382b3
comparison
equal deleted inserted replaced
3850:28db418c7573 3851:405a192b68e7
150 SDL_QuitBeApp(); 150 SDL_QuitBeApp();
151 } 151 }
152 152
153 int BE_OpenAudio(_THIS, SDL_AudioSpec *spec) 153 int BE_OpenAudio(_THIS, SDL_AudioSpec *spec)
154 { 154 {
155 media_raw_audio_format format; 155 int valid_datatype = 0;
156 156 media_raw_audio_format format;
157 /* Initialize the Be Application, if it's not already started */ 157 SDL_AudioFormat test_format = SDL_FirstAudioFormat(spec->format);
158 if ( SDL_InitBeApp() < 0 ) { 158
159 return(-1); 159 /* Parse the audio format and fill the Be raw audio format */
160 } 160 memset(&format, '\0', sizeof (media_raw_audio_format));
161 161 format.byte_order = B_MEDIA_LITTLE_ENDIAN;
162 /* Parse the audio format and fill the Be raw audio format */ 162 format.frame_rate = (float) spec->freq;
163 format.frame_rate = (float)spec->freq; 163 format.channel_count = spec->channels; /* !!! FIXME: support > 2? */
164 format.channel_count = spec->channels; 164 while ((!valid_datatype) && (test_format)) {
165 switch (spec->format&~0x1000) { 165 valid_datatype = 1;
166 case AUDIO_S8: 166 spec->format = test_format;
167 /* Signed 8-bit audio unsupported, convert to U8 */ 167 switch (test_format) {
168 spec->format = AUDIO_U8; 168 case AUDIO_S8:
169 case AUDIO_U8: 169 format.format = media_raw_audio_format::B_AUDIO_CHAR;
170 format.format = media_raw_audio_format::B_AUDIO_UCHAR; 170 break;
171 format.byte_order = 0; 171
172 break; 172 case AUDIO_U8:
173 case AUDIO_U16: 173 format.format = media_raw_audio_format::B_AUDIO_UCHAR;
174 /* Unsigned 16-bit audio unsupported, convert to S16 */ 174 break;
175 spec->format ^= 0x8000; 175
176 case AUDIO_S16: 176 case AUDIO_S16LSB:
177 format.format = media_raw_audio_format::B_AUDIO_SHORT; 177 format.format = media_raw_audio_format::B_AUDIO_SHORT;
178 if ( spec->format & 0x1000 ) { 178 break;
179 format.byte_order = 1; /* Big endian */ 179
180 } else { 180 case AUDIO_S16MSB:
181 format.byte_order = 2; /* Little endian */ 181 format.format = media_raw_audio_format::B_AUDIO_SHORT;
182 } 182 format.byte_order = B_MEDIA_BIG_ENDIAN;
183 break; 183 break;
184 } 184
185 format.buffer_size = spec->samples; 185 default:
186 186 valid_datatype = 0;
187 test_format = SDL_NextAudioFormat();
188 break;
189 }
190 }
191
192 if (!valid_datatype) { /* shouldn't happen, but just in case... */
193 SDL_SetError("Unsupported audio format");
194 return (-1);
195 }
196
197 /* Initialize the Be Application, if it's not already started */
198 if (SDL_InitBeApp() < 0) {
199 return (-1);
200 }
201
202 format.buffer_size = spec->samples;
203
187 /* Calculate the final parameters for this audio specification */ 204 /* Calculate the final parameters for this audio specification */
188 SDL_CalculateAudioSpec(spec); 205 SDL_CalculateAudioSpec(spec);
189 206
190 /* Subscribe to the audio stream (creates a new thread) */ 207 /* Subscribe to the audio stream (creates a new thread) */
191 { sigset_t omask; 208 { sigset_t omask;