Using AudioConverter
Using AudioConverter
- Subject: Using AudioConverter
- From: Patrick Machielse <email@hidden>
- Date: Sat, 16 Oct 2004 15:06:47 +0200
Hi,
I'm trying to use an AudioConverter to convert some 16 bit signed integer
data to the cannonical format. However, I can't seem to make it work.
Whatever I try, the result is always error -50, (which isn't an error listed
for AudioConverter.
Since Apple doesn't seem to have _any_ documentation for the
AudioConverterConvertBuffer() function (!) (which is what I'm using) I hope
someone else can help me debug this.
The following function shows what I'm trying to do.
void convertTest(void)
{
AudioConverterRef conv = NULL;
UInt32 outBufSize = 1024;
OSStatus err;
//
// set up the audio converter to convert
// 16bit signed int --> 32bit float
//
AudioStreamBasicDescription srcFmt, destFmt;
srcFmt.mFormatID = kAudioFormatLinearPCM;
srcFmt.mFormatFlags = (kLinearPCMFormatFlagIsBigEndian |
kLinearPCMFormatFlagIsSignedInteger);
srcFmt.mSampleRate = 44100;
srcFmt.mBitsPerChannel = 16;
srcFmt.mChannelsPerFrame = 2;
srcFmt.mBytesPerFrame = 4;
srcFmt.mFramesPerPacket = 1;
srcFmt.mBytesPerPacket = 4;
destFmt.mFormatID = kAudioFormatLinearPCM;
destFmt.mFormatFlags = (kLinearPCMFormatFlagIsBigEndian |
kLinearPCMFormatFlagIsFloat);
destFmt.mSampleRate = 44100;
destFmt.mBitsPerChannel = 32;
destFmt.mChannelsPerFrame = 2;
destFmt.mBytesPerFrame = 8;
destFmt.mFramesPerPacket = 1;
destFmt.mBytesPerPacket = 8;
err = AudioConverterNew(&srcFmt, &destFmt, &conv);
if (err != kAudioHardwareNoError) {
printf("AudioConverterNew() returned error: %ld\n", err);
}
//
// ask the converter to calculate the size of the input buffer
//
UInt32 inBufSize = outBufSize;
UInt32 dataSize = sizeof inBufSize;
err = AudioConverterGetProperty(
converter,
kAudioConverterPropertyCalculateInputBufferSize,
&dataSize,
(void*)&inBufSize);
if (err != kAudioHardwareNoError) {
printConverterError(err);
}
printf("in size: %lu, out size: %lu\n", inBufSize, outBufSize);
//
// create input and output buffers
//
SInt16 inBuf[inBufSize / sizeof(SInt16)];
float outBuf[outBufSize / sizeof(float)];
printf("in size: %lu, out size: %lu\n", sizeof inBuf, sizeof outBuf);
//
// convert the buffer (fails with error -50)
//
UInt32 outSize = 0;
err = AudioConverterConvertBuffer(conv,
inBufSize,
(void*)inBuf,
&outSize,
(void*)outBuf);
if (err != kAudioHardwareNoError) {
printf("AudioConverterConvertBuffer() returned error: %ld\n", err);
}
printf("out size = %lu\n", outSize);
}
TIA,
Patrick
---
Hieper Software
e: email@hidden
w: http://www.hieper.nl
_______________________________________________
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