comparison src/audio/macosx/SDL_coreaudio.c @ 2003:506851d3efa4

Mac OS X audio backend now supports int32/float32.
author Ryan C. Gordon <icculus@icculus.org>
date Fri, 01 Sep 2006 05:31:36 +0000
parents c121d94672cb
children 72fa74928062
comparison
equal deleted inserted replaced
2002:7590aaf89a60 2003:506851d3efa4
205 { 205 {
206 OSStatus result = noErr; 206 OSStatus result = noErr;
207 Component comp; 207 Component comp;
208 ComponentDescription desc; 208 ComponentDescription desc;
209 struct AudioUnitInputCallback callback; 209 struct AudioUnitInputCallback callback;
210 AudioStreamBasicDescription requestedDesc; 210 AudioStreamBasicDescription desc;
211 SDL_AudioFormat test_format = SDL_FirstAudioFormat(spec->format);
212 int valid_datatype = 0;
211 213
212 /* Setup a AudioStreamBasicDescription with the requested format */ 214 /* Setup a AudioStreamBasicDescription with the requested format */
213 requestedDesc.mFormatID = kAudioFormatLinearPCM; 215 memset(&desc, '\0', sizeof (AudioStreamBasicDescription));
214 requestedDesc.mFormatFlags = kLinearPCMFormatFlagIsPacked; 216 desc.mFormatID = kAudioFormatLinearPCM;
215 requestedDesc.mChannelsPerFrame = spec->channels; 217 desc.mFormatFlags = kLinearPCMFormatFlagIsPacked;
216 requestedDesc.mSampleRate = spec->freq; 218 desc.mChannelsPerFrame = spec->channels;
217 219 desc.mSampleRate = spec->freq;
218 requestedDesc.mBitsPerChannel = spec->format & 0xFF; 220 desc.mFramesPerPacket = 1;
219 if (spec->format & 0x8000) 221
220 requestedDesc.mFormatFlags |= kLinearPCMFormatFlagIsSignedInteger; 222 while ((!valid_datatype) && (test_format)) {
221 if (spec->format & 0x1000) 223 spec->format = test_format;
222 requestedDesc.mFormatFlags |= kLinearPCMFormatFlagIsBigEndian; 224 desc.mFormatFlags = 0;
223 225 /* Just a list of valid SDL formats, so people don't pass junk here. */
224 requestedDesc.mFramesPerPacket = 1; 226 switch (test_format) {
225 requestedDesc.mBytesPerFrame = 227 case AUDIO_U8:
226 requestedDesc.mBitsPerChannel * requestedDesc.mChannelsPerFrame / 8; 228 case AUDIO_S8:
227 requestedDesc.mBytesPerPacket = 229 case AUDIO_U16LSB:
228 requestedDesc.mBytesPerFrame * requestedDesc.mFramesPerPacket; 230 case AUDIO_S16LSB:
231 case AUDIO_U16MSB:
232 case AUDIO_S16MSB:
233 case AUDIO_S32LSB:
234 case AUDIO_S32MSB:
235 case AUDIO_F32LSB:
236 case AUDIO_F32MSB:
237 valid_datatype = 1;
238 desc.mBitsPerChannel = SDL_AUDIO_BITSIZE(spec->format);
239
240 if (SDL_AUDIO_ISFLOAT(spec->format))
241 desc.mFormatFlags |= kLinearPCMFormatFlagIsFloat;
242 else if (SDL_AUDIO_ISSIGNED(spec->format))
243 desc.mFormatFlags |= kLinearPCMFormatFlagIsSignedInteger;
244
245 if (SDL_AUDIO_ISBIGENDIAN(spec->format))
246 desc.mFormatFlags |= kLinearPCMFormatFlagIsBigEndian;
247 break;
248 }
249 }
250
251 if (!valid_datatype) { /* shouldn't happen, but just in case... */
252 SDL_SetError("Unsupported audio format");
253 return (-1);
254 }
255
256 desc.mBytesPerFrame =
257 desc.mBitsPerChannel * desc.mChannelsPerFrame / 8;
258 desc.mBytesPerPacket =
259 desc.mBytesPerFrame * desc.mFramesPerPacket;
229 260
230 261
231 /* Locate the default output audio unit */ 262 /* Locate the default output audio unit */
232 desc.componentType = kAudioUnitComponentType; 263 desc.componentType = kAudioUnitComponentType;
233 desc.componentSubType = kAudioUnitSubType_Output; 264 desc.componentSubType = kAudioUnitSubType_Output;
250 /* Set the input format of the audio unit. */ 281 /* Set the input format of the audio unit. */
251 result = AudioUnitSetProperty(outputAudioUnit, 282 result = AudioUnitSetProperty(outputAudioUnit,
252 kAudioUnitProperty_StreamFormat, 283 kAudioUnitProperty_StreamFormat,
253 kAudioUnitScope_Input, 284 kAudioUnitScope_Input,
254 0, 285 0,
255 &requestedDesc, sizeof(requestedDesc)); 286 &desc, sizeof (desc));
256 CHECK_RESULT("AudioUnitSetProperty (kAudioUnitProperty_StreamFormat)") 287 CHECK_RESULT("AudioUnitSetProperty (kAudioUnitProperty_StreamFormat)")
257 /* Set the audio callback */ 288 /* Set the audio callback */
258 callback.inputProc = audioCallback; 289 callback.inputProc = audioCallback;
259 callback.inputProcRefCon = this; 290 callback.inputProcRefCon = this;
260 result = AudioUnitSetProperty(outputAudioUnit, 291 result = AudioUnitSetProperty(outputAudioUnit,