Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Sanity check on AudioEndianAtom usage




On Feb 21, 2006, at 1:47 PM, Timothy J. Wood wrote:



  We have some audio compression code using SoundConverter which we are feeding input via float values from CoreAudio input.  On PPC everything worked fine, but under x86, apparently we need to tell the SC the endianness of the data (i.e., it assumes big endian).

  After a bit of googling, I ended up writing the code attached below.  It seems to work (tells the SC it can _not_ byte swap the input host-endian float stream when 'decompress'ing it), but I had a few questions:

    1) should I put a #pragma around my 'atoms' definition to pack it tightly?

Not necessary.

    2) does the SoundConverterSetInfo call copy the memory passed in?  right now I'm passing bytes from the stack...

It copies, so stack-based is ok.

    3) any other obvious problems?  :)

To be totally correct, you're supposed to pass in the format atom as well, so the codec knows whether this is data intended for it.  Here's how to do it using a Handle:

{
// we need to add the extension that says "it's little endian".
AudioFormatAtom formatData = {0};
AudioEndianAtom endianData = {0};
AudioTerminatorAtom terminatorData = {0};
Handle extension = NULL;


formatData.size = EndianU32_NtoB(sizeof(AudioFormatAtom));
formatData.atomType = EndianU32_NtoB(kAudioFormatAtomType);
formatData.format = EndianU32_NtoB(dataFormat); // i.e. kFloat32Format, kFloat64Format, k24BitFormat
err = PtrToHand(&formatData, &extension, sizeof(AudioFormatAtom));
if (err)
goto bail;



endianData.size = EndianU32_NtoB(sizeof(AudioEndianAtom));
endianData.atomType = EndianU32_NtoB(kAudioEndianAtomType);
endianData.littleEndian = EndianU16_NtoB(isLittleEndian);
err = PtrAndHand(&endianData, extension, sizeof(AudioEndianAtom));
if (err)
goto bail;


terminatorData.size = EndianU32_NtoB(sizeof(AudioTerminatorAtom));
terminatorData.atomType = EndianU32_NtoB(kAudioTerminatorAtomType);
err = PtrAndHand(&terminatorData, extension, sizeof(AudioTerminatorAtom));
if (err)
goto bail;

SoundConverterSetInfo(_soundConverter, siDecompressionParams, *extension);

DisposeHandle(extension);
}


HTH
-Brad Ford
QuickTime Engineering



-tim


#ifdef __LITTLE_ENDIAN__
short isLittleEndian = true;
#else
short isLittleEndian = false;
#endif


// Atoms are always big-endian
struct {
    AudioEndianAtom endian;
    AudioTerminatorAtom terminator;
} atoms;
memset(&atoms, 0, sizeof(atoms));
atoms.endian.size = CFSwapInt32HostToBig(sizeof(atoms.endian));
atoms.endian.atomType = CFSwapInt32HostToBig(kAudioEndianAtomType);
atoms.endian.littleEndian = CFSwapInt16HostToBig(isLittleEndian);
atoms.terminator.size = CFSwapInt32HostToBig(sizeof(atoms.terminator));
atoms.terminator.atomType = CFSwapInt32HostToBig(kAudioTerminatorAtomType);


SoundConverterSetInfo(_soundConverter, siDecompressionParams, &atoms);

_______________________________________________
Do not post admin requests to the list. They will be ignored.
QuickTime-API mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
QuickTime-API mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/quicktime-api/email@hidden

This email sent to email@hidden

References: 
 >Sanity check on AudioEndianAtom usage (From: "Timothy J. Wood" <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.