Re: Reduce Audio Time Latency
Re: Reduce Audio Time Latency
- Subject: Re: Reduce Audio Time Latency
- From: Jeff Moore <email@hidden>
- Date: Mon, 22 Jun 2009 13:02:40 -0700
You should get no differences in terms of IO latency when using AUHAL
versus when using the HAL directly. AUHAL does not induce any
additional latency at all. So, I'm not sure I follow what you mean
when you say that "the Callback method was having an offset which
varied between 1ms-200 ms".
At any rate, the output time stamp that you get in your Render
callback or your IOProc is the time at which the audio stack will be
finished getting the first sample frame of the data to the hardware.
So to get the time at which the first sample frame will hit the
speaker, all you need to do is add the device's latency. The latency
figure can be gotten from adding together the HAL with the properties,
kAudioDevicePropertyLatency and kAudioStreamPropertyLatency for the
device and stream combination you are interested in.
--
Jeff Moore
Core Audio
Apple
On Jun 22, 2009, at 11:17 AM, Ravneet Kaur wrote:
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