Problem in sample rate conversion with AudioConverterFillComplexBuffer
Problem in sample rate conversion with AudioConverterFillComplexBuffer
- Subject: Problem in sample rate conversion with AudioConverterFillComplexBuffer
- From: p_j_r_m <email@hidden>
- Date: Mon, 9 Jun 2008 07:33:16 -0700 (PDT)
Hello:
I have modified the ConvertFile sample in impleSDK samples to change sample rate in a raw audio file I recorded at 22050 Hz LPCM / 32-bit float mono.
By "raw" file I mean it has no structure. Simply, I took CAPlayThrough sample and dumped to a file each mic input sample I receive in its AudioInputProc.
I can open this file with Audacity and confirm is LPCM/32Bit float at 22Khz.
So, I modified the ConvertFile sample replacing AudioFileRead/write calls by simple fread/fwrite. This are the stream format structs I use to set AudioConverter:
inputFormat.mSampleRate = 22050;
inputFormat.mFormatID = kAudioFormatLinearPCM;
inputFormat.mFormatFlags = kLinearPCMFormatFlagIsFloat
//| kLinearPCMFormatFlagIsBigEndian
| kLinearPCMFormatFlagIsPacked
| kAudioFormatFlagIsNonInterleaved;
inputFormat.mBytesPerPacket = 4;
inputFormat.mFramesPerPacket = 1;
inputFormat.mBytesPerFrame = 4;
inputFormat.mChannelsPerFrame = 1;
inputFormat.mBitsPerChannel = 32;
outputFormat = inputFormat;
outputFormat.mSampleRate = 8000;
outputFormat.mFormatID = kAudioFormatLinearPCM;
outputFormat.mFormatFlags = /*kLinearPCMFormatFlagIsSignedInteger*/
kLinearPCMFormatFlagIsFloat | kLinearPCMFormatFlagIsPacked | kAudioFormatFlagIsNonInterleaved;
outputFormat.mChannelsPerFrame = 1;
outputFormat.mBytesPerPacket = 4;
outputFormat.mFramesPerPacket = 1;
outputFormat.mBytesPerFrame = 4;
outputFormat.mBitsPerChannel = 32; //16;
and this is how I set my callback for AudioConverterFillComplexBuffer:
OSStatus EncoderDataProc( ...)
{
// get pointer to struct describing audio data
AudioFileIO* afio = (AudioFileIO*)inUserData;
UInt32 maxPackets = afio->srcBufferSize / afio->srcSizePerPacket;
if (*ioNumberDataPackets > maxPackets)
*ioNumberDataPackets = maxPackets;
// read from the file (afio->afid is a FILE *)
size_t outNumBytes;
FILE *pf = afio->afid;
fseek(pf,afio->pos,SEEK_SET);
// In real app, we will take this data from microphone
outNumBytes = fread(afio->srcBuffer,4,*ioNumberDataPackets,pf);
// advance input file packet position
afio->pos += *ioNumberDataPackets;
ioData->mBuffers[0].mData = afio->srcBuffer;
ioData->mBuffers[0].mDataByteSize = outNumBytes;
ioData->mBuffers[0].mNumberChannels = 1;
OSStatus err = (outNumBytes<0);
return err;
}
With this, AudioConverterFillComplexBuffer returns the "famous" insz error,
i donĀ“t know why. I call it with:
AudioBufferList fillBufList;
fillBufList.mNumberBuffers = 1;
fillBufList.mBuffers[0].mNumberChannels = inputFormat.mChannelsPerFrame;
fillBufList.mBuffers[0].mDataByteSize = theOutputBufSize;
fillBufList.mBuffers[0].mData = outputBuffer;
UInt32 ioOutputDataPackets = 8192
err = AudioConverterFillComplexBuffer(converter, EncoderDataProc, &afio, &ioOutputDataPackets, &fillBufList, NULL);
ioOutputDataPackets is set to zero after return with insz error. What's the reason for that?
Final goal is to do sample rate conversion on the fly from 22Khz 32bit float LPCM stream to 8Khz 16bit-Signed LPCM. Where should i do float32->int16 conversion?
Thanks
_______________________________________________
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