Converting samples of 32 bit float big endian format CAF file to little endian.
Converting samples of 32 bit float big endian format CAF file to little endian.
- Subject: Converting samples of 32 bit float big endian format CAF file to little endian.
- From: Antonio Nunes <email@hidden>
- Date: Thu, 16 Apr 2015 17:46:06 +0100
Hi,
I have a bunch of CAF files that contain samples in big endian, 32bit float format. (mFormatFlags of ASBD is 11).
The files are small, so I read them into memory:
UInt32 bufferSize = mDataFormat.mBytesPerPacket * packetCount;
audioData = (Float32 *)calloc(packetCount, mDataFormat.mBytesPerPacket);
result = AudioFileReadPacketData(mAudioFile, false, &bufferSize, NULL, 0, &packetsRead, audioData);
if (result != noErr) {
NSLog(@"Could not read packets for file: %@", filePath);
} else if ( mDataFormat.mFormatFlags & kAudioFormatFlagIsBigEndian) {
[self swapDataToLittleEndianWithBufferOfSize:bufferSize];
}
This is my conversion method:
- (void)swapDataToLittleEndianWithBufferOfSize:(UInt32)bufferSize
{
UInt32 count = bufferSize / sizeof(audioData);
for (UInt32 i = 0; i < count; i++) {
audioData[i] = NSSwapBigFloatToHost(NSConvertHostFloatToSwapped(audioData[i]));
}
}
When my app plays the files, they sound fine, except for the fact that they sound an octave (I guess) lower than they are supposed to. I suppose something is not right with my conversion method. Maybe I shouldn’t be using NSConvertHostFloatToSwapped to get the sample data into an NSSwappedFloat format? Any ideas on achieving correct results?
-António
_______________________________________________
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