Re: AudioFileComponents
Re: AudioFileComponents
- Subject: Re: AudioFileComponents
- From: William Stewart <email@hidden>
- Date: Tue, 13 Sep 2005 16:48:24 -0700
On 13/09/2005, at 3:09 PM, Francisco Gimeno wrote:
As I said in my previous email, the first thing I would do is
provide an AudioCodec for vorbis (and possibly flac). Then at
least you can have files - QuickTime movie files for instance -
that you'd be able to use in iTunes. When you've got that working,
you could then look at the ogg support if you still felt that was
necessary.
do you mean audiocodec + audiofile?
I don't understand how QuickTime would know how to extract the
vorbis data from an Ogg file if the ogg file format is not supported.
Confusing isn't it :-)
We tried to talk about this distinction at WWDC sessions - where we
make the distinction between data (for the world of audio, this is
AudioCodecs) and the containers that you put it in - ie. files.
The data side is easy, because you are dealing with just blobs of data.
The file side is a little more complicated, because it really depends
on how you want to use that data. Then there's all of the
restrictions that different file types can have on the data they can
contain.
One of the things that we wanted to do with CAF files is to remove at
least this restriction - the intention is that you can put *any*
audio data into a CAF file (including vorbis, flac). Now, I'm really
going to try and confuse you all here! - this turns out to be really
good for development.
In our SDK we provide both an example AudioCodec as well as a
collection of AudioFileTools - afconvert/afinfo/afplay. These file
tools will read/write/play/get info about any file CoreAudio
understands - including of course, CAF files.
So, how do you add custom data to a CAF file? How does this work with
Apple Lossless:
% afconvert /System/Library/Sounds/Submarine.aiff /tmp/out.caf -f
caff -d alac
Here, we take the Submarine sound and convert it to a CAF file with
the alac data format. Lets have a look at that resulting file:
% afinfo /tmp/out.caf
File: /tmp/out.caf
File type ID: caff
Data format: 2 ch, 44100 Hz, 'alac' (0x00000001) from 16-bit
source, 4096 frames/packet
no channel layout.
audio bytes: 35845
audio packets: 11
audio 42998 valid frames + 0 priming + 2058 remainder = 45056
duration: 0.9750 seconds
maximum packet size: 4399
audio data file offset: 4096
optimized
----
And of course I can play this file:
% afplay /tmp/out.caf
If I wanted to convert this caf file back to an AIFF file:
% afconvert /tmp/out.caf /tmp/out.aiff -f AIFF -d BEI16@44100
% afinfo /tmp/out.aiff
File: /tmp/out.aiff
File type ID: AIFF
Data format: 2 ch, 44100 Hz, 'lpcm' (0x0000000E) 16-bit big-
endian signed integer
no channel layout.
audio bytes: 171992
audio packets: 42998
duration: 0.9750 seconds
maximum packet size: 4
audio data file offset: 4096
optimized
----
So, if I wanted to support a new audio data format (say FLAC) - the
first thing I have to do is decide what 4 char code I'm going to use
- 'FLAC' (or 'flac') - whatever seems best. Then to encode a file I'd
do this:
% afconvert /System/Library/Sounds/Submarine.aiff /tmp/flac.caf -f
caff -d FLAC
Now, this line tests my new FLAC encoder (aenc) component. It is
encoding Linear PCM in the AIFF file to FLAC put into the CAF file.
I could do afinfo on this file - and I'd get 'FLAC' as the data
format (with its corresponding X frames/packet, etc). I don't have a
FLAC encoder yet(!), so I can't do this of course. This call just
tells me something about what ended up in the CAF file
Next, to test the FLAC decoder (adec) component - I can either play
this CAF file, or I can convert it back to an AIFF file (I could also
convert back to a CAF file too - CAF can have linear PCM data in it
of course, just like AIFF and WAV can too)
% afplay /tmp/flac.caf
or
% afconvert /tmp/flac.caf /tmp/pcm.caf -f caff -d BEI16@44100
and of course, I could do afinfo on this output file
So, how does this all tie in?
CoreAudio (and QuickTime) use the audio (media) data type that is
stored in their files to match with the appropriate components to
encode/decode this data. So, when we see a CAF file with 'FLAC' data
in it, we look for an audio codec (decoder - 'adec') that has a sub-
type of 'FLAC'. If we find it, then we use it to decode the data.
QuickTime does the same thing - the audio data type is stored as the
media data type in the media's Sample Description of a track in a
Quicktime movie.
So, once you've written an audio codec as described above, it should
just work with QuickTime playback.
When you go to write the file with afconvert, you provide a data
format of a 4 char code. afconvert uses that to look for an audio
codec (encoder - 'aenc') with a subtype that matches that - if the
file format supports it (which with CAF it does) - you can see the
various file and data formats supported at any time on the system, by
just doing afconvert with no args:
% afconvert
When you export with QuickTime, the same thing happens - for audio
data it looks for all of the 'aenc' components around that are
supported by the different file formats and presents these as options
to the user. There is probably more to say about this, but someone
gets to this point we can talk about that stuff then :-)
Oh, and at this point, iTunes will work with these - either CAF or
Movies with FLAC data in them - but it seems like you want to also
support ogg files. That's a different topic; you still have to do
what I describe above first though, then you also need the eat/spit
components for QT to be able to read/write ogg files.
HTH
Bill
--
mailto:email@hidden
tel: +1 408 974 4056
________________________________________________________________________
__
"Much human ingenuity has gone into finding the ultimate Before.
The current state of knowledge can be summarized thus:
In the beginning, there was nothing, which exploded" - Terry Pratchett
________________________________________________________________________
__
_______________________________________________
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