Re: Reduce Audio Time Latency
Re: Reduce Audio Time Latency
- Subject: Re: Reduce Audio Time Latency
- From: Ravneet Kaur <email@hidden>
- Date: Mon, 6 Jul 2009 09:41:44 +0530
Hello Jeff
Thanks , following your approach I took all my code into Objective C and was able to extract exact Callback time. Now I am facing an issue , if I am playing my stimulus using audio units , it crashes after playing the audio files roughly after 2500 times.
I have tried on multiple Mac OSX 10.5 systems and they all crash after around 2500 times. Below is the error message in console
Sound assertion ""( kRequestStateCORB == fCodecRequest->state ) = CORB engine stuck or response was missing"" failed in "/SourceCache/AppleHDA/AppleHDA-157.1.24/AppleHDAController/AppleHDAController.cpp" at line 1492 goto handler
Jul 6 00:58:53
ravneet-kaurs-macbook kernel[0]: Sound assertion "0 != err" failed in "/SourceCache/AppleHDA/AppleHDA-157.1.24/IOHDAFamily/IOHDACodecDevice.cpp" at line 131 goto Exit
Jul 6 00:58:53 ravneet-kaurs-macbook kernel[0]: Sound assertion "0 != result" failed in "/SourceCache/AppleHDA/AppleHDA-157.1.24/AppleHDA/AppleHDANode.cpp" at line 376 goto Exit
Jul 6 00:58:53 ravneet-kaurs-macbook kernel[0]: Sound assertion "0 != audioFunctionGroup->powerState ( &restorePowerState )" failed in "/SourceCache/AppleHDA/AppleHDA-157.1.24/AppleHDA/AppleHDADriver.cpp" at line 232 goto handler
Please let me know if it is a known bug/limitation.Below is my code
for(i=0;i<4000;i++){
[nsAudio play:"/freq.wav":100:nil:500];
usleep(500000);
}
- (uint64_t) play:(char *) fileNameIn:(int) volumeValue:(id)listObject:(int)duration {
volume = volumeValue;
fileName = fileNameIn;
[NSThread detachNewThreadSelector:@selector(playObjectiveCThread:) toTarget:self withObject:listObject];
sleep(duration/1000.0);
cleanUpFlag = FALSE;
return 1;
}
-(void) playObjectiveCThread:(id) param{
gIsPlaying=TRUE;
NetScopeAudio* nsAudio = [[NetScopeAudio alloc]init];
MTCoreAudioDevice* myDevice = [MTCoreAudioDevice defaultOutputDevice];
[myDevice setIOProc:mySimpleIOProc withClientData:nil];
[myDevice deviceStart];
[nsAudio playThread];
while(gIsPlaying || rendererFlag<2)
{
usleep(2000);
}
uint64_t audioSTime = ((audioTimeOfDay.tv_sec) * 1E+6 + audioTimeOfDay.tv_usec);
int duration = [[param objectAtIndex:1] intValue];
if([param count] > 2){
[param replaceObjectAtIndex:0 withObject:[@"" stringByAppendingFormat:@"%lld", audioSTime]];
[nsSync postEvent:param];
}
usleep(duration*1000);
[nsAudio CleanUp:&musicFileID];
[myDevice deviceStop];
}
-(void) playThread{
AURenderCallbackStruct renderCallback;
OSStatus err = noErr;
AudioStreamBasicDescription fileASBD, outputASBD;
FSRef fileRef;
err = setupAudioUnit(&theOutputUnit);
checkStatus(err);
err = MatchAUFormats(&theOutputUnit,&outputASBD, 0);
checkStatus(err);
err = [self getFileInfo:&fileRef:&musicFileID:&fileASBD:fileName];
checkStatus(err);
err = MakeAUConverter(&musicFileID, &converter,&fileASBD, &outputASBD );
checkStatus(err);
err = [self setupCallbacks:&theOutputUnit:&renderCallback];
checkStatus(err);
err =AudioOutputUnitStart(theOutputUnit);
checkStatus(err);
}
OSStatus setupAudioUnit(AudioUnit *theOutputUnit){
OSStatus err;
ComponentDescription desc;
desc.componentType = kAudioUnitType_Output;
desc.componentSubType = kAudioUnitSubType_DefaultOutput;
desc.componentManufacturer = kAudioUnitManufacturer_Apple;
desc.componentFlags = 0;
desc.componentFlagsMask = 0;
Component comp = FindNextComponent(NULL, &desc);
if (comp == NULL) exit (-1);
err = OpenAComponent(comp, theOutputUnit);
if (err) exit (-1);
verify_noerr(AudioUnitInitialize(*theOutputUnit));
return err;
}
-(void) CleanUp:(AudioFileID*) fileID{
AudioFileClose(*fileID);
if (gSourceBuffer != NULL) {
free(gSourceBuffer);
gSourceBuffer = NULL;
}
if (gSourceAudioFileID != NULL) {
gSourceAudioFileID = NULL;
}
gTotalPacketCount=0;
gFileByteCount =0;
gMaxPacketSize =0;
gPacketOffset=0;
AudioConverterDispose(converter);
AudioOutputUnitStop(theOutputUnit);
AudioUnitUninitialize (theOutputUnit);
CloseComponent(theOutputUnit);
rendererFlag = 0;
nowPlayTime = 0;
cleanUpFlag = TRUE;
gIsPlaying=TRUE;}
Regards
Ravneet
_______________________________________________
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