Re: More AudioConverter problems...
Re: More AudioConverter problems...
- Subject: Re: More AudioConverter problems...
- From: email@hidden
- Date: Tue, 5 Nov 2002 17:09:43 +0000
Hi Doug,
Thanks for the reply!
I am converting between 32 bit float data and 16 bit integer, big to
little endian.
The call I use is AudioConverterConvertBuffer(). I need more control
over when the data is converted, so I don't use an input callback - I
just convert in 1.5MB segments (until the last one with the remaining
data to be converted, however much remains).
Below is the actual code. Looking at it I guess I can see some things
that could be done better...but do you notice anything obvious?
Thanks!
-- John
- (NSMutableData*) convert32FloatAudioTo16Int
{
AudioConverterRef audioConverter;
AudioStreamBasicDescription sourceFormat, destinationFormat;
UInt32 theSourceSize = [self bufferLength];
NSMutableData *audio16Data = [NSMutableData dataWithLength:
(theSourceSize / 2)];
UInt32 theDestSize = [audio16Data length];
unsigned long theResult = 0;
// fill out the source description
sourceFormat.mSampleRate = 44100.0;
sourceFormat.mFormatID = kAudioFormatLinearPCM;
sourceFormat.mFormatFlags = kAudioFormatFlagIsBigEndian |
kAudioFormatFlagIsFloat;
sourceFormat.mBytesPerPacket = 8;
sourceFormat.mFramesPerPacket = 1;
sourceFormat.mBytesPerFrame = 8;
sourceFormat.mChannelsPerFrame = 2;
sourceFormat.mBitsPerChannel = 32;
// fill out the destination description
destinationFormat.mSampleRate = 44100.0;
destinationFormat.mFormatID = kAudioFormatLinearPCM;
destinationFormat.mFormatFlags =
kLinearPCMFormatFlagIsSignedInteger;
destinationFormat.mBytesPerPacket = 4;
destinationFormat.mFramesPerPacket = 1;
destinationFormat.mBytesPerFrame = 4;
destinationFormat.mChannelsPerFrame = 2;
destinationFormat.mBitsPerChannel = 16;
// make the audio converter
theResult = AudioConverterNew(&sourceFormat, &destinationFormat,
&audioConverter);
// continue if no error
if (!theResult)
{ // convert the data
theResult = AudioConverterConvertBuffer(audioConverter,
theSourceSize, (void*)[self bytes], &theDestSize, (void*)[audio16Data
mutableBytes]);
}
// return the new bytes
return audio16Data;
}
_______________________________________________
coreaudio-api mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/coreaudio-api
Do not post admin requests to the list. They will be ignored.