Creating and Destroying Sound Channels

Creating and Destroying Sound Channels — Creating new sound channels and closing them

Functions

Includes

#include <libchimara/glk.h>

Description

Sounds in Glk are played through sound channels. Sound channels are another type of opaque object, like windows, streams, and file references.

Functions

glk_schannel_create ()

schanid_t
glk_schannel_create (glui32 rock);

This creates a sound channel, about as you'd expect.

Remember that it is possible that the library will be unable to create a new channel, in which case glk_schannel_create() will return NULL.

When you create a channel using glk_schannel_create(), it has full volume, represented by the value 0x10000. Half volume would be 0x8000, three-quarters volume would be 0xC000, and so on. A volume of zero represents silence.

You can overdrive the volume of a channel by setting a volume greater than 0x10000. However, this is not recommended; the library may be unable to increase the volume past full, or the sound may become distorted. You should always create sound resources with the maximum volume you will need, and then reduce the volume when appropriate using the channel-volume calls.

Mathematically, these volume changes should be taken as linear multiplication of a waveform represented as linear samples. As I understand it, linear PCM encodes the sound pressure, and therefore a volume of 0x8000 should represent a 6 dB drop.

Parameters

rock

The rock value to give the new sound channel.

 

Returns

A new sound channel, or NULL.


glk_schannel_create_ext ()

schanid_t
glk_schannel_create_ext (glui32 rock,
                         glui32 volume);

The glk_schannel_create_ext() call lets you create a channel with the volume already set at a given level.

Not all libraries support glk_schannel_create_ext(). You should test the gestalt_Sound2 selector before you rely on it; see Testing for Sound Capabilities.

Parameters

rock

The rock value to give the new sound channel.

 

volume

Integer representing the volume; 0x10000 is 100%.

 

Returns

A new sound channel, or NULL.


glk_schannel_destroy ()

void
glk_schannel_destroy (schanid_t chan);

Destroys the channel. If the channel is playing a sound, the sound stops immediately (with no notification event).

Parameters

chan

The sound channel to destroy.