Re: Streams, Channels: How do they relate?
Re: Streams, Channels: How do they relate?
- Subject: Re: Streams, Channels: How do they relate?
- From: Jeff Moore <email@hidden>
- Date: Thu, 29 Nov 2001 17:04:56 -0800
on 11/29/01 3:41 PM, Jeremy Cooper <email@hidden> wrote:
>
I don't understand how streams, channels, and audiodevices are related to
>
one another. I am sorely in need of some example code. Is there an
>
archive of example core audio code out there?
The first place to start is /Developer/Examples/CoreAudio. There are a few
things there to get you started. Daisy will be of particular interest since
you seem to be interested in the HAL.
Here's the quick run down on the "objects" in the HAL's API. I use the term
"object" loosely here since the HAL is a pure C API, but it is designed in a
more or less object oriented fashion. Note that the HAL is a per process
entity. Everything below is in each process.
The top level is the system object. It collects together the global
information like the default devices and the list of devices. The
AudioHardware* routines perform operations on this object.
The global object contains the Device objects. Devices are referred to using
AudioDeviceIDs. The AudioDevice* routines perform operations on them.
The Device is the unit of IO within the HAL. In the abstract, the Device
represents a set of Streams and the time line to which they are
synchronized. It's Streams are divided into input and output sections.
The HAL will create a single IOThread for the Device. All the IOProcs added
to that device will be called from within that IOThread. The IOProcs also
all share the same IO buffer size (but have different actual buffers).
Devices contain Stream objects. The Stream object represents a single
unidirectional unit of IO for some number of channels on the device. For
linear PCM formatted data, this means a single N-channel interleaved stream
of data.
Ok. That's the basic containment hierarchy of the objects. Each object has
properties. You access the properties of each kind of object slightly
differently using similar terminology. Further, Device and Stream properties
are, for the most part, interchangeable. You can get at the same property
through either object. Here's how it works:
The global object's properties just take the ID of the property. Pretty
straight forward.
The Device's properties need to know which section (input or output) and
what device channel number in addition to the ID to identify the property.
The Stream's properties need to now the ID and the stream channel number.
In both cases channels are numbered from 1-N (for Streams, N is the number
of channels it has and for Devices, N is the total number of channels in all
the streams in that direction for the device) and channel number 0
represents the master or global part of the device.
Here's a diagram of a fictional device to show you what this means:
Device
Input Stream 1 (2 channels)
Input Stream 2 (2 channels)
The Device's input channels go from 1 to 4.
Input Stream 1's channels go from 1 to 2.
Input Stream 2's channels also go from 1 to 2.
So to tweak the volume control on channel 1 of Input Stream 2, you can
either use device channel 3 or Input Stream 2's channel 1. Both properties
refer to the same control on the Device.
Hope this helps straighten things out a little.
--
Jeff Moore
Core Audio
Apple