Reduce Audio Time Latency
Reduce Audio Time Latency
- Subject: Reduce Audio Time Latency
- From: Ravneet Kaur <email@hidden>
- Date: Mon, 22 Jun 2009 23:47:31 +0530
Hello All,
I am working on CoreAudio API to play an audio file and get exact time of audio playback. I have used following structure
A) Get Components
ComponentDescription desc;
err = OpenAComponent(comp, theOutputUnit); //gains access to the services provided by the component
B) Get The Audio Unit
verify_noerr(AudioUnitInitialize(*theOutputUnit));
C)Set Output Unit Properties
//Set the stream format of the output to match the input
result = AudioUnitSetProperty (*theUnit,kAudioUnitProperty_StreamFormat,kAudioUnitScope_Input,theInputBus,theDesc,size);
result = AudioUnitSetParameter(*theUnit, kAudioUnitParameterUnit_LinearGain, kAudioUnitScope_Output, 0, (Float32)volume, 0);
D) Read File Information
FSPathMakeRef ((const UInt8 *)fileName, fileRef, 0); //Obtain filesystem reference to the file
err = AudioFileOpen(fileRef, fsRdPerm,0,fileID); //Obtain AudioFileID
E)Make Converter
err = AudioConverterNew( inASBD,outASBD , conv);
F)Setup Callback
//Sets the callback for the Audio Unit
err = AudioUnitSetProperty (*theOutputUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, 0,renderCallback, sizeof(AURenderCallbackStruct));
G)Start the Audio Unit
Now the time I get in the Callback method was having an offset which varied between 1ms-200 ms in worst cases. So I decided to get more low level and binded callback method with HAL layer. I binded a simple Proc with my default device
OSStatus mySimpleIOProc ( AudioDeviceID inDevice,const AudioTimeStamp* inNow,const AudioBufferList* inInputData,const AudioTimeStamp* inInputTime, AudioBufferList* outOutputData, const AudioTimeStamp* inOutputTime, void* inClientData)
{
if(rendererFlag==1)
{
rendererFlag++;
UInt32 propSize;
propSize = sizeof(UInt32);
AudioDeviceGetProperty(inDevice, 0, 0, kAudioDevicePropertyLatency, &propSize, &frameLatency);
struct timeval timeOfDay;
gettimeofday(&timeOfDay, NULL);
uint64_t nowTimeOfMachine = (timeOfDay.tv_sec) * 1E+6 + timeOfDay.tv_usec;
NSLog(@"<======================= frameLatency 111 ===================== %ld \n", frameLatency);
}
return 0;
}
I used MTCoreAudio as I have limited familiarity with HAL layer and its c libraries.
myDevice = [MTCoreAudioDevice defaultOutputDevice];
[myDevice setIOProc:mySimpleIOProc withClientData:nil];
[myDevice deviceStart];
Now as soon as I start my Audio Unit, my callback method gets called and then my HAL device Proc "mySimpleIOProc" (as shown above) gets called. I was assuming that mySimpleIOProc will have better timing accuracy in terms of inNow or if I take current time inside this proc.
Can someone please help me in finding the exact playback time? I read that HAL does provide synchronization capability but could not find any samples for the same. The sample in CoreAudio SDK is too difficult for a beginner like me.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden