Polycode can load and play sound files from WAV and OGG formats via the Sound class.

Contents

Loading sounds.

To load a sound file in Polycode, you can create a Sound class initialized with the path to the OGG or WAV format file to load.

C++
Sound *demoSound = new Sound("demo.ogg");
Lua
demoSound = Sound("demo.ogg")

Playing sounds.

To play a loaded sound, call the Play method of the Sound class. If you want the sound playback to loop, pass true to the play method.

C++
demoSound->Play();
loopingSound->Play(true);
Lua
demoSound:Play()
loopingSound:Play(true)

Adjusting sound properties.

You can adjust sound properties, such as volume and pitch via the Sound class. To set volume, use the setVolume method, which takes a parameter from 0.0 to 1.0, with 0.0 being totally silent and 1.0 being at full volume.

To set the sound's pitch, use the setPitch method and pass it a new pitch value where 0.5 is half of the sound's original pitch and 2.0 is twice the original pitch.

C++
demoSound->setVolume(0.5);
demoSound->setPitch(0.8);
Lua
demoSound:setVolume(0.5)
demoSound:setPitch(0.8)