Re: playing AAC+ file
Re: playing AAC+ file
- Subject: Re: playing AAC+ file
- From: William Stewart <email@hidden>
- Date: Mon, 20 Oct 2008 13:06:59 -0700
you can use aqplay as a starting point (/Developer/Examples/CoreAudio)
Basically - HE-AAC is a layered format - it is a format that has at
its core the base layer of AAC. We represent this layering through a
notion of a list of formats - that is, the file's data can be rendered
in different modes, at different resolutions. For HE, you would have
something like (each of these alternatives is published as a different
ASBD)
HE-AAC, 44.1KHz, 2 channels (enhanced layer) -> 'aach'
AAC, 22.05KHz, 2 channels (base layer) -> 'aac '
So the file publishes both formats. With HE-AACv2, you would have a
list of 3 possible formats:
HE-AACv2, 44.1KHz, 2 channels (enhanced layer 2) -> 'aacp'
HE-AAC, 44.1KHz, 1 channel (enhanced layer 1) -> 'aach'
AAC, 22.05KHz, 1 channel (base layer) -> 'aac '
Then you can see which format is available on the system at run-time,
and you chose the richest (or best) currently available format.
For aqplay, the following code will basically work if you add it in
between opening the file and creating the audio queue.
UInt32 size;
XThrowIfError(AudioFileGetPropertyInfo(myInfo.mAudioFile,
kAudioFilePropertyFormatList, &size, NULL), "couldn't get
file's format list info");
UInt32 numFormats = size / sizeof(AudioFormatListItem);
AudioFormatListItem *formatList = new AudioFormatListItem
[ numFormats ];
XThrowIfError(AudioFileGetProperty(myInfo.mAudioFile,
kAudioFilePropertyFormatList, &size, formatList), "couldn't
get file's data format");
numFormats = size / sizeof(AudioFormatListItem); // we need to
reassess the actual number of formats when we get it
if (numFormats == 1) {
// this is the common case
myInfo.mDataFormat = formatList[0].mASBD;
// see if there is a channel layout (multichannel file)
result = AudioFileGetPropertyInfo(myInfo.mAudioFile,
kAudioFilePropertyChannelLayout, &myInfo.mChannelLayoutSize, NULL);
if (result == noErr && myInfo.mChannelLayoutSize > 0) {
myInfo.mChannelLayout = (AudioChannelLayout *)new char
[myInfo.mChannelLayoutSize];
XThrowIfError(AudioFileGetProperty(myInfo.mAudioFile,
kAudioFilePropertyChannelLayout, &myInfo.mChannelLayoutSize,
myInfo.mChannelLayout), "get audio file's channel layout");
}
} else {
printf ("File has a %d layered data format:\n", numFormats);
for (unsigned int i = 0; i < numFormats; ++i)
CAStreamBasicDescription(formatList[i].mASBD).Print();
// now we should look to see which decoders we have on the system
XThrowIfError
(AudioFormatGetPropertyInfo(kAudioFormatProperty_DecodeFormatIDs, 0,
NULL, &size), "couldn't get decoder id's");
UInt32 numDecoders = size / sizeof(OSType);
OSType *decoderIDs = new OSType [ numDecoders ];
XThrowIfError
(AudioFormatGetProperty(kAudioFormatProperty_DecodeFormatIDs, 0, NULL,
&size, decoderIDs), "couldn't get decoder id's");
unsigned int i = 0;
for (; i < numFormats; ++i) {
OSType decoderID = formatList[i].mASBD.mFormatID;
bool found = false;
for (unsigned int j = 0; j < numDecoders; ++j) {
if (decoderID == decoderIDs[j]) {
found = true;
break;
}
}
if (found) break;
}
delete [] decoderIDs;
if (i >= numFormats) {
fprintf (stderr, "Cannot play any of the formats in this file\n");
throw kAudioFileUnsupportedDataFormatError;
}
myInfo.mDataFormat = formatList[i].mASBD;
myInfo.mChannelLayoutSize = sizeof(AudioChannelLayout);
myInfo.mChannelLayout = (AudioChannelLayout*)new char
[myInfo.mChannelLayoutSize];
myInfo.mChannelLayout->mChannelLayoutTag =
formatList[i].mChannelLayoutTag;
myInfo.mChannelLayout->mChannelBitmap = 0;
myInfo.mChannelLayout->mNumberChannelDescriptions = 0;
}
delete [] formatList;
printf ("Playing format: "); myInfo.mDataFormat.Print();
XThrowIfError(AudioQueueNewOutput(&myInfo.mDataFormat,
AQTestBufferCallback, &myInfo,
CFRunLoopGetCurrent(), kCFRunLoopCommonModes, 0,
&myInfo.mQueue), "AudioQueueNew failed");
Bill
On Oct 19, 2008, at 4:27 AM, Arnab Ganguly wrote:
Hi All,
I am very new to Coreaudio apis.So need help on where can I find
tutorials for writing sample applications using coreaudio apis'.I am
planning to write a player in Mac which can play AAC+ files.Any help
would be very much appreciated.
Thanks in advance
-A
_______________________________________________
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
_______________________________________________
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