Re: AudioFile -> AudioConverter -> float PCM
Re: AudioFile -> AudioConverter -> float PCM
- Subject: Re: AudioFile -> AudioConverter -> float PCM
- From: email@hidden
- Date: Thu, 04 Aug 2005 07:39:47 -0700
Marc,
Regarding packets vs. frames in relation to channels vs. samples,
here's my current understanding from what documentation exists:
We'll handle frames first, and discuss packets at the end of this note.
Remember that Version 1 of Audio Units was architected around
INTERLEAVED streams. So for a 6-CHANNEL (5.1) surround stream, the
individual SAMPLES would be in a FRAME as follows (sample "times"
are A, B, C...) for INTERLEAVED data, in ONE buffer:
BUFFER 1:
A1 A2 A3 A4 A5 A6 B1 B2 B3 B4 B5 B6 C1 C2 C3 C4 C5 C6 ...
<--+---frameA---> <-----frameB----> <-----frameC---->
^
|
individual sample (A2) for channel 2
This is intuitive for the interleaved case, that each interleaved sample
"lives in" a surrounding frame, and there is one frame per "sample point
across all channels".
In Version 2 of Audio Units, the convention moved to having
NON-interleaved buffers because these proved to be more convenient
to process. V2 can still handle interleaved data "at the boundaries"
via the converter, but the canonical format internally is linear PCM
32-bit floating point with SEPARATE buffers for each channel.
So the NON-interleaved version of the above example would look like:
BUFFER 1: A1 B1 C1 ...
BUFFER 2: A2 B2 C2 ...
BUFFER 3: A3 B3 C3 ...
BUFFER 4: A4 B4 C4 ...
BUFFER 5: A5 B5 C5 ...
BUFFER 6: A6 B6 C6 ...
frameA frameB frameC ...
So the frame has now "turned" 90-degrees and cuts ACROSS the buffers.
In both cases, a frame holds all the data points, across all channels,
for a given instant in time.
In the 1-channel case, a frame IS a single sample.
All of the above is for the case where you have ACCESS to individual
samples. What about compressed or variable bitrate formats where
the smallest manipulable chunk of data contains multiple frames?
That's where the "packet" comes in.
If you have some encoding scheme whereby, say, 1024 frames are combined
together in some manner, such that the individual frames are
algorithmically commingled and cannot be separated from each other
by simple array indexing, then you need another name for this chunk,
and that name is "packet".
That's why you'll see "frames per packet" in the Audio Stream Basic
Description.
With separable samples, a packet is the same size as a frame, since
you can easily separate data into discrete chunks at the frame level.
(In the degenerate case of just 1 channel with separable samples,
a packet IS a frame IS a sample.)
In the surround stream example above, a frameA and packetA are the
same thing.
It's only when the frames get commingled in the encoding that Apple
makes the distinction between packets and frames, since you can't
access the individual frames without decoding.
Hope this helps,
Peter
At 02:33 AM 8/4/05, you wrote:
Hi Marc,
On 02/08/2005, at 4:10 AM, Marc Poirier wrote:
I am trying to do the following: I want to use AudioFile to get
the contents of an audio file, then use AudioConverter to put it
all into arrays of PCM 32-bit float audio data (1 array per audio
channel). But, after several hours of looking through example
snippets, headers, and docs, I'm still pretty lost. I'm just
having a lot of trouble figuring out the interactions of
AudioBufferLists and AudioConverters, what are packets vs. frames
(possibly in relation to channels vs. samples), etc.
It is *very* difficult to get a handle on packets vs frames (good
example there), AudioBufferLists and so forth from the docs. However,
I've gone through a few examples of their use on this mailing list
which may help. Search the archives for AudioBufferList and possibly
me as the author.
I don't actually have any direct experience with AudioFile
specifically, but that's probably the relatively trivial part. Once
it clicks about frames/packets and buffer lists, I think you'll find
it quite workable.
Anyway, I'm sure that I'm not the only one who has wanted to do
this task, so I was wondering if anyone might have some example
code for this that they'd like to share? I'm just having a lot of
difficulty understanding this stuff...
Same sort of things I was thinking when I was playing with
AudioConverters. There are lots of examples in the CoreAudio SDK, but
you might find it hard to find something specific. Have a look in
AudioFile and PublicUtility. Even search the entire Examples/ CoreAudio
tree for the functions you are playing with.
That said, you might actually be better served posting some of your
own code and asking specific questions about it. I know it'd be nicer
to have some example code to refer to before randomly beating out
some of your own code, but it can be very difficult getting started
otherwise. There's enough knowledge on this list to help you out with
specifics.
Heath
_______________________________________________
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