views:

165

answers:

0

How to do audio latency test in iphone os ? I don't have a clear idea about that. Now am reading a caf file like this .

NSString *soundPath = [[NSBundle mainBundle] pathForResource:@"tick" ofType:@"caf"];   UInt64 gTotalPacketCount=0;
UInt64 gFileByteCount =0;
UInt32 gMaxPacketSize =0;
UInt32 size;
OSStatus err = noErr;
AudioFileID fileID = [self openAudioFile:soundPath];
size = sizeof(gTotalPacketCount); //type is UInt64
err = AudioFileGetProperty(fileID,kAudioFilePropertyAudioDataPacketCount,&size,&gTotalPacketCount);   

size = sizeof(gFileByteCount); //type is UInt64
err = AudioFileGetProperty(fileID, kAudioFilePropertyAudioDataByteCount, &size, &gFileByteCount);

size = sizeof(gMaxPacketSize); //type is UInt32
err = AudioFileGetProperty(fileID, kAudioFilePropertyMaximumPacketSize, &size, &gMaxPacketSize);

ilbc_beep_packet =
malloc(gFileByteCount); 
memset(ilbc_beep_packet, 0,
gFileByteCount); 
ilbc_beep_packet_size=gFileByteCount; 
OSStatus result = noErr;
UInt32 packets =gTotalPacketCount;
UInt32  bytesReturned = 0;

//Read in the ENTIRE file into a memory buffer
result = AudioFileReadPackets (fileID,
           false,
           &bytesReturned,
           NULL,
           0,
           &packets,
           ilbc_beep_packet);


AudioFileClose(fileID); //close the audio file

I am confused whether this is the way to read a file . How i can write this data into another file. I welcome any help for audio latency test. Thanks in advance.