comparison libao2/ao_macosx.c @ 16014:67266a949b51

remove delay when setting audio volume
author nplourde
date Tue, 19 Jul 2005 14:36:13 +0000
parents 6e994905f77b
children 5c8acc972551
comparison
equal deleted inserted replaced
16013:4ee24ec6ac16 16014:67266a949b51
222 int aoIsCreated = ao != NULL; 222 int aoIsCreated = ao != NULL;
223 223
224 if (!aoIsCreated) ao = (ao_macosx_t *)malloc(sizeof(ao_macosx_t)); 224 if (!aoIsCreated) ao = (ao_macosx_t *)malloc(sizeof(ao_macosx_t));
225 225
226 // Build Description for the input format 226 // Build Description for the input format
227 memset(&inDesc, 0, sizeof(AudioStreamBasicDescription));
228 inDesc.mSampleRate=rate; 227 inDesc.mSampleRate=rate;
229 inDesc.mFormatID=kAudioFormatLinearPCM; 228 inDesc.mFormatID=kAudioFormatLinearPCM;
230 inDesc.mChannelsPerFrame=channels; 229 inDesc.mChannelsPerFrame=channels;
231 switch(format&AF_FORMAT_BITS_MASK){ 230 switch(format&AF_FORMAT_BITS_MASK){
232 case AF_FORMAT_8BIT: 231 case AF_FORMAT_8BIT:
300 if (err) { 299 if (err) {
301 ao_msg(MSGT_AO, MSGL_WARN, "Unable to set the input format (err=%d)\n", err); 300 ao_msg(MSGT_AO, MSGL_WARN, "Unable to set the input format (err=%d)\n", err);
302 return CONTROL_FALSE; 301 return CONTROL_FALSE;
303 } 302 }
304 303
305 size=sizeof(UInt32); 304 size = sizeof(UInt32);
306 maxFrames=8192; // This was calculated empirically. On MY system almost everything works more or less the same... 305 err = AudioUnitGetProperty(ao->theOutputUnit, kAudioDevicePropertyBufferSize, kAudioUnitScope_Input, 0, &maxFrames, &size);
307 err = AudioUnitSetProperty(ao->theOutputUnit, kAudioUnitProperty_MaximumFramesPerSlice, kAudioUnitScope_Input, 0, &maxFrames, size);
308 306
309 if(err) { 307 if (err)
310 ao_msg(MSGT_AO, MSGL_WARN, "Unable to set the maximum number of frames per slice!! (err=%d)\n", err); 308 {
311 return CONTROL_FALSE; 309 ao_msg(MSGT_AO,MSGL_WARN, "AudioUnitGetProperty returned %d when getting kAudioDevicePropertyBufferSize\n", (int)err);
312 } 310 return CONTROL_FALSE;
313 311 }
314 ao_msg(MSGT_AO, MSGL_DBG2, "Maximum number of frames per request %d (that is %d bytes)", err, maxFrames, maxFrames*inDesc.mBytesPerFrame); 312
315 313 ao->chunk_size = maxFrames;//*inDesc.mBytesPerFrame;
316 ao->chunk_size = maxFrames*inDesc.mBytesPerFrame; 314 ao_msg(MSGT_AO,MSGL_V, "%5d chunk size\n", (int)ao->chunk_size);
317 ao->num_chunks = NUM_BUFS; 315
316 ao->num_chunks = NUM_BUFS;
318 ao->buffer_len = (ao->num_chunks + 1) * ao->chunk_size; 317 ao->buffer_len = (ao->num_chunks + 1) * ao->chunk_size;
319 ao->buffer = aoIsCreated ? (unsigned char *)realloc(ao->buffer,(ao->num_chunks + 1)*ao->chunk_size) 318 ao->buffer = aoIsCreated ? (unsigned char *)realloc(ao->buffer,(ao->num_chunks + 1)*ao->chunk_size)
320 : (unsigned char *)calloc(ao->num_chunks + 1, ao->chunk_size); 319 : (unsigned char *)calloc(ao->num_chunks + 1, ao->chunk_size);
321 320
322 ao_data.samplerate = inDesc.mSampleRate; 321 ao_data.samplerate = inDesc.mSampleRate;
323 ao_data.channels = inDesc.mChannelsPerFrame; 322 ao_data.channels = inDesc.mChannelsPerFrame;
324 ao_data.outburst = ao_data.buffersize = ao->chunk_size; 323 ao_data.outburst = ao_data.buffersize = ao->chunk_size;
325 ao_data.bps = ao_data.samplerate * inDesc.mBytesPerFrame; 324 ao_data.bps = ao_data.samplerate * inDesc.mBytesPerFrame;
326 325
327 memset(&renderCallback, 0, sizeof(AURenderCallbackStruct));
328 renderCallback.inputProc = theRenderProc; 326 renderCallback.inputProc = theRenderProc;
329 renderCallback.inputProcRefCon = 0; 327 renderCallback.inputProcRefCon = 0;
330 err = AudioUnitSetProperty(ao->theOutputUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, 0, &renderCallback, sizeof(AURenderCallbackStruct)); 328 err = AudioUnitSetProperty(ao->theOutputUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, 0, &renderCallback, sizeof(AURenderCallbackStruct));
331 if (err) { 329 if (err) {
332 ao_msg(MSGT_AO, MSGL_WARN, "Unable to set the render callback (err=%d)\n", err); 330 ao_msg(MSGT_AO, MSGL_WARN, "Unable to set the render callback (err=%d)\n", err);