AudioQueueServices AudioInputCallBack inPacketDescs copy problems
AudioQueueServices AudioInputCallBack inPacketDescs copy problems
- Subject: AudioQueueServices AudioInputCallBack inPacketDescs copy problems
- From: Peter de Kraker <email@hidden>
- Date: Sun, 08 Jan 2012 14:22:22 +0100
Hi,
I am using Audio Queue Services on iOS to record audio. The purpose of my app is to record to a circular buffer (the last 15 buffers are kept in memory). Therefor the writing to an audio file is not done directly in the AudioInputCallBack, but later.
The AudioInputCallBack is used to copy all the incoming information into one of my buffers.
This works great, and the AudioFileWritePackets using the buffered data works ok when I use a LinearPCM format and AIF filetype.
Problems arise when I use a format with variable packets like M4A. II get error 561211770 which is bad size error?
I narrowed it down to the const AudioStreamPacketDescription *inPacketDescs variable that gets passed to the AudioInputCallBack. When I copy this variable's data to another instance of it, and supply that instance to AudioFileWritePackets it immediately errors out. When checking the data in the debugger and using printf it shows that it's data fields are identical and have the same values. Still AudioFileWritePackets won't use it.
This problem is easily reproducable when just using the AudioInputCallBack to record there immediately with AudioFileWritePackets. The only thing to do is copy the inPacketsDescs to another variable and supply that.
I am a bit of a noob in C/C++ so maybe it's my fault with the copying, but I couldn't find an error with it.
Copy code:
item.inPacketDescs = (AudioStreamPacketDescription *)(malloc(sizeof(AudioStreamPacketDescription)));
item.inPacketDescs->mDataByteSize = inPacketDescs->mDataByteSize;
item.inPacketDescs->mStartOffset = inPacketDescs->mStartOffset;
item.inPacketDescs->mVariableFramesInPacket = inPacketDescs->mVariableFramesInPacket;
item.InPacketDescs is of type AudioStreamPacketDescription *.
Check:
printf("inPacketDescs:\n");
printf(" mDataByteSize. Orig: %ld Copy:%ld\n", inPacketDescs->mDataByteSize, item.inPacketDescs->mDataByteSize);
printf(" mStartOffset. Orig: %lld Copy:%lld\n", inPacketDescs->mStartOffset, item.inPacketDescs->mStartOffset);
printf(" mVariableFramesInPacket. Orig: %ld Copy:%ld\n", inPacketDescs->mVariableFramesInPacket, item.inPacketDescs->mVariableFramesInPacket);
printf("\n");
OSStatus status = AudioFileWritePackets(recordState->audioFile,
false,
item.mAudioDataByteSize,
item.inPacketDescs, //This one is erring
recordState->currentPacket,
&item.inNumberPacketDescriptions,
item.mAudioData);
if(status == 0)
{
recordState->currentPacket += item.inNumberPacketDescriptions;
printf("Saving buffer succeeded\n");
}
else
{
printf("Saving buffer failed: %ld\n", status);
}
Got buffer 1: length:8362
inPacketDescs:
mDataByteSize. Orig: 185 Copy:185
mStartOffset. Orig: 0 Copy:0
mVariableFramesInPacket. Orig: 0 Copy:0
Saving buffer failed: 561211770
I don't get why AudioFileWritePackets won't take my variable?
Kind regards,
Peter
_______________________________________________
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