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 protected])
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/coreaudio-api/archive%40mail-archive.com
This email sent to [email protected]