problem with AudioConverterFillComplexBuffer
problem with AudioConverterFillComplexBuffer
- Subject: problem with AudioConverterFillComplexBuffer
- From: john <email@hidden>
- Date: Tue, 11 Oct 2005 12:56:49 -0400
Hi,
I'm having a problem using AudioConverterFillComplexBuffer.
I am having no problems converting audio of the same sample rate, but
audio with different sample rates the following happens:
- Although my custom return code is returned every time, every other
call does not convert audio data - outOutputData.mDataByteSize and
ioOutputDataPacketSize are 0.
- When data is converted (every other call), it is exactly twice the
size it is supposed to be - for example, my
AudioBufferList.mDataByteSize before the call is 512K, after the call
it is 1024K. This is obviously bad since it overwrites memory.
Any thoughts to what I'm doing wrong (or a bug?). Here's the code:
- (unsigned long)readData: (NSMutableData*)theAudioData range:
(NSRange)range
{
unsigned long lengthRead
= range.length;
unsigned long
lengthConverted = 0;
unsigned long size =
sizeof(lengthConverted);
OSStatus theStatus;
readPosition = range.location;
if (!AudioConverterGetProperty(theConverterWrite,
kAudioConverterPropertyCalculateOutputBufferSize, &size, &lengthRead))
{
[intermediateReadBuffer setLength: lengthRead];
theStatus = AudioFileReadBytes(theAudioFileID, NO,
readPosition, &lengthRead, [intermediateReadBuffer mutableBytes]);
if (theStatus == eofErr)
endOfFile = YES;
else if (theStatus != noErr)
NSLog(@"readData - error <%d> reading", theStatus);
else
{
unsigned long packetCount =
(range.length / theAudioFileStreamDescription.mBytesPerFrame);
AudioBufferList theReadABL = { 1,
{ 2, range.length, [theAudioData mutableBytes] } };
while ('done' != AudioConverterFillComplexBuffer
(theConverterRead, readFillBufferProc, self, &packetCount,
&theReadABL, NULL))
lengthConverted += theReadABL.mBuffers
[0].mDataByteSize;
lengthConverted += theReadABL.mBuffers[0].mDataByteSize;
}
}
return lengthConverted;
}
- (OSStatus)readFillBuffer: (UInt32*)ioNumDataPkts bufferList:
(AudioBufferList*)ioData
{
OSStatus theResult = noErr;
if (bufferFed != YES)
{
ioData->mBuffers[0].mNumberChannels = 2;
ioData->mBuffers[0].mDataByteSize = [intermediateReadBuffer
length];
ioData->mBuffers[0].mData = [intermediateReadBuffer
mutableBytes];
*ioNumDataPkts = ioData->mBuffers[0].mDataByteSize /
theAudioFileStreamDescription.mBytesPerPacket;
bufferFed = YES;
}
else
{
ioData->mBuffers[0].mDataByteSize = 0;
*ioNumDataPkts = 0;
theResult = 'done';
}
return theResult;
}
-- John
_______________________________________________
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