Re: Decoding raw AMR
Re: Decoding raw AMR
- Subject: Re: Decoding raw AMR
- From: Martin Storsjö <email@hidden>
- Date: Sat, 27 Jan 2007 17:07:38 +0200 (EET)
On Fri, 26 Jan 2007, William Stewart wrote:
Use the AudioConverter API - if you look at:
Yes, I've tried using that too, as I said, but no matter what I do, I get
kAudioCodecStateError when calling AudioConverterFillComplexBuffer.
/Developer/Examples/CoreAudio/SimpleSDK/ConvertFile
this should give you enough to get started.
I actually used this as example on using the AudioConverter API, but
ConvertFile neither seems to be able to decode nor encode AMR files.
Is there any example code which actually can decode amr files?
Test files for what I'm trying to decode are available at
http://albin.abo.fi/~mstorsjo/amr/. The amr-<n>.dat are individual
packets, which should be decoded into 160 16-bit samples. By prepending
the header-file and concatenating the .dat-files, test.amr is created,
which plays fine in QuickTime Player. But I can't decode any of them,
neither the raw packets nor the real amr file including a header, using
the AudioConverter API.
The code I've tried to use for decoding with AudioConverter looks like
this:
const uint8_t* inputData;
int inputLength;
AudioStreamPacketDescription packet;
OSStatus complexInputDataProc(AudioConverterRef converter, UInt32*
ioNumberDataPackets, AudioBufferList* ioData,
AudioStreamPacketDescription** outDataPacketDescription, void* inUserData)
{
if (inputLength > 0) {
*ioNumberDataPackets = 1;
ioData->mNumberBuffers = 1;
ioData->mBuffers[0].mNumberChannels = 1;
ioData->mBuffers[0].mDataByteSize = inputLength;
ioData->mBuffers[0].mData = (void*) inputData;
packet.mStartOffset = 0;
packet.mVariableFramesInPacket = 160;
packet.mDataByteSize = inputLength;
*outDataPacketDescription = &packet;
inputLength = 0;
} else {
*ioNumberDataPackets = 0;
}
return noErr;
}
void decodeAudioConverter(const uint8_t* frame, int size) {
AudioConverterRef converter;
AudioStreamBasicDescription inputFormat, outputFormat;
uint8_t buffer[1000];
inputData = frame;
inputLength = size;
memset(&inputFormat, 0, sizeof(inputFormat));
inputFormat.mFormatID = 'samr';
inputFormat.mSampleRate = 8000;
inputFormat.mChannelsPerFrame = 1;
outputFormat.mSampleRate = 8000;
outputFormat.mFormatID = kAudioFormatLinearPCM;
outputFormat.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger;
outputFormat.mBytesPerPacket = 320;
outputFormat.mFramesPerPacket = 160;
outputFormat.mBytesPerFrame = 2;
outputFormat.mChannelsPerFrame = 1;
outputFormat.mBitsPerChannel = 16;
outputFormat.mReserved = 0;
OSStatus err = AudioConverterNew(&inputFormat, &outputFormat,
&converter);
if (err != noErr)
printf("AudioConverterNew: %d\n", err);
UInt32 outputSize = sizeof(buffer);
AudioBufferList outputData;
outputData.mNumberBuffers = 1;
outputData.mBuffers[0].mNumberChannels = 1;
outputData.mBuffers[0].mDataByteSize = sizeof(buffer);
outputData.mBuffers[0].mData = (void*) buffer;
AudioStreamPacketDescription packet;
UInt32 dataPacketSize = 1;
err = AudioConverterFillComplexBuffer(converter, complexInputDataProc,
NULL, &dataPacketSize, &outputData, NULL);
if (err != noErr) {
printf("AudioConverterFillComplexBuffer err: %d x %c%c%c%c\n",
err, err, (err>>24) & 0xff, (err>>16)&0xff, (err>>8)&0xff, err&0xff);
} else {
printf("outputSize: %d\n", outputSize);
}
}
decodeAudioConverter is called with the contents of the individual
packets, but no matter how I try testing with different parameters, it
still fails with kAudioCodecStateError.
// Martin
_______________________________________________
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