• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Converting samples of 32 bit float big endian format CAF file to little endian.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Converting samples of 32 bit float big endian format CAF file to little endian.
      • From: Steve Bird <email@hidden>
  • Prev by Date: Re: avfoundation “error -10868”
  • Next by Date: Re: Converting samples of 32 bit float big endian format CAF file to little endian.
  • Previous by thread: RE: Enabling echo canceller on macosx
  • Next by thread: Re: Converting samples of 32 bit float big endian format CAF file to little endian.
  • Index(es):
    • Date
    • Thread