Name
AllocAudioChannel -- allocate new audio channel (V6.0)
Synopsis
APTR chandle = AllocAudioChannel(APTR handle, int fmt, int freq, int vol,
                  int (*feedproc)(APTR handle, APTR chandle, APTR buf,
                  int count, APTR userdata), ULONG flags, APTR userdata,
                  struct hwTagList *tags);
Function
This function must allocate a new audio channel on the audio device passed in the first parameter. Hollywood will inform you about the PCM sample format that should be played on this channel in parameters 2 to 4. The fmt parameter can be one of the following formats:

HWSMPFMT_U8M:
Unsigned 8-bit mono PCM data is fed to this channel.

HWSMPFMT_U8S:
Unsigned 8-bit stereo PCM data is fed to this channel.

HWSMPFMT_S8M:
Signed 8-bit mono PCM data is fed to this channel.

HWSMPFMT_S8S:
Signed 8-bit stereo PCM data is fed to this channel.

HWSMPFMT_S16M:
Signed 16-bit mono PCM data is fed to this channel.

HWSMPFMT_S16S:
Signed 16-bit stereo PCM data is fed to this channel.

Parameter 3 contains the number of PCM frames that will be played on this channel per second. Common values are 44100 or 48000 here. Parameter 4 contains the desired volume for this channel. This can range from 0 (mute) to 64 (full volume).

Hollywood will also pass a pointer to an audio feed procedure to this function. Whenever you need more PCM data to play on this audio channel, call this feed procedure. The prototype of this procedure looks like this:

 
int feedproc(APTR hdl, APTR ch, APTR buf, int count, APTR userdata);

Here is how you have to call this feed procedure:

hdl:
This parameter must be set to the handle of the audio device opened via OpenAudio().

ch:
This parameter must be set to the handle of the audio channel allocated via AllocAudioChannel().

buf:
You have to pass a pointer to a memory buffer that should receive the new PCM data here.

count:
You have to pass the number of PCM frames you want to receive here. Please note that this parameter must be specified in PCM frames, not in bytes. So if you set this to 1024 and your PCM samples are formatted as 16-bit wide stereo frames, the buffer you pass would have to be at least 4096 bytes in size. You should request PCM frames from Hollywood only in small portions. For a playback rate of 44100 frames per second, a request of 2048 PCM frames per feedproc() call is a reasonable size.

userdata:
You always have to set this parameter to the user data pointer that Hollywood has passed to your AllocAudioChannel() function here.

feedproc() returns the number of PCM frames successfully copied. Once again, be careful that this value is in PCM frames, not in bytes (see above). If this value is less than you requested, the channel has finished playing and Hollywood will soon call FreeAudioChannel() on it.

The feed procedure that Hollywood passes to you is thread-safe so you can call this from worker threads or audio interrupts as well.

Inputs
handle
audio device allocated by OpenAudio()
fmt
format of PCM data passed to this channel (see above)
freq
number of PCM frames per second to be played on this channel
vol
initial channel volume (0 to 64)
feedproc
pointer to a function that needs to be called to request more PCM data from Hollywood
flags
reserved for future use (currently 0)
userdata
userdata that needs to be passed to feedproc()
tags
reserved for future use (currently NULL)
Results
chandle
handle to this audio channel or NULL on error

Show TOC