Top |
Creating and Destroying Sound ChannelsCreating and Destroying Sound Channels — Creating new sound channels and closing them |
Sounds in Glk are played through sound channels. Sound channels are another type of opaque object, like windows, streams, and file references.
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.
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.
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).