Intermediate Audio

From SDL.NET

Table of contents

Introduction

SDL.NET's audio is comprised of a number of different classes for playing sound and music file formats. This tutorial expands on the basic audio tutorial and provides further details on working with the audio classes in the SDL.NET library. For a live demo, please see the Audio Example.

Channels

By using a channel you can have a finer level of control over audio samples being played; however with this can also require some additional setup.

A channel can support one Sound being played at a time, this means that if you trigger a different sound to play on the same channel, the first sound will be stopped and the second sound started.

To create an array of channels:

public static Channel[] ch = new Channel[1000];

The channels then need to be defined:

for (int i = 0; i < 1000; i++)
{
    ch[i] = Mixer.CreateChannel(i);
}

The audio sounds can still be loaded the same way:

Sound getBusy = new Sound("getBusy.wav");
Sound boing = new Sound("boing.wav");

But can now be played directly in to a channel:

ch[0].Play(boing);

and if another sound is played on the same channel, the first sound stops and the second starts:

ch[0].Play(getBusy);

Conclusion

This little expansion on the basic audio tutorial should help when facing an audio structure slightly more difficult. The Audio Example is an available demo of the sound and music classes in action.

See Also