Fork me on GitHub

Examples

SoLoud package comes with a few simple examples. These can be found under the 'demos' directory. Pre-built binaries for Windows can also be found in the 'bin' directory.

Along with the examples, the 'bin' directory also contains some command-line tools. These are safe to run without parameters, and will print out help when run.

simplest

The simplest example initializes SoLoud, and uses the speech synthesizer to play some sound. Once the sound has finished, the application cleans up and quits.

This example also uses SoLoud's cross-platform thread library to sleep while waiting for the sound to end. The source code is so short that we'll just include it here verbatim:


#include "soloud.h"
#include "soloud_speech.h"
#include "soloud_thread.h"

// Entry point
int main(int argc, char *argv[])
{
  // Define a couple of variables
  SoLoud::Soloud soloud;  // SoLoud engine core
  SoLoud::Speech speech;  // A sound source (speech, in this case)

  // Configure sound source
  speech.setText("1 2 3   1 2 3   Hello world. Welcome to So-Loud.");

  // initialize SoLoud.
  soloud.init();

  // Play the sound source (we could do this several times if we wanted)
  soloud.play(speech);

  // Wait until sounds have finished
  while (soloud.getActiveVoiceCount() > 0)
  {
    // Still going, sleep for a bit
    SoLoud::Thread::sleep(100);
  }

  // Clean up SoLoud
  soloud.deinit();

  // All done.
  return 0;
}

welcome

Slightly more complicated console-based example, playing different kinds of sounds.


Welcome to Soloud!
What is your name?
>john doe
Playing music. Press a key to quit..

multimusic

multimusic demo screenshot

The multimusic example loads two OGG music loops. Use mouse to interact with the GUI to fade between songs, fade replay speed of the songs. The two oggs starts are synchronized through the use of voice groups, so cross fading them works.

Additionally you can trigger sound effects generated by Sfxr.

piano

piano demo screenshot

This example is a simple implementation of a playable instrument. The example also includes a simple waveform generator (soloud_basicwave.cpp/h), which can produce square, saw, sine and triangle waves. If compiled to use portmidi, you can also use an external midi keyboard to drive the example.

piano keys

Don't worry if you don't have an external midi keyboard though, you can also jam from the PC keyboard

You can also adjust some filters and pick waveforms using the GUI. Speech synthesizer describes your option changes.

mixbusses

mixbusses demo screenshot

The mixbusses example demonstrates the use of mixing busses.

The example sets up three busses - sfx, music and speech. The sfx and music busses simply have looping sound playing on them, while the speech bus is used to play some random strings of text periodically.

You can use the GUI to adjust volume of different busses.

env

env demo screenshot

The env demo is a non-interactive demo of how SoLoud could be used to play environmental audio. It is more of a proof of concept than a good example at this point.

pewpew

pewpew demo screenshot

The pewpew demo demonstrates the use of the playClocked commands. Use the GUI buttons to trigger either single sound effect or repeated sound effect via play() and playClocked() calls.

To exaggerate the effect a bit, the demo requests a very large audio buffer from SoLoud. The difference between the play and playClocked effects is that with play(), all sounds triggered between audio buffers begin playing from the start of the next audio buffer, while playClocked spreads the sounds across the audio buffer, making the sounds more separate.

space

space demo screenshot

The space demo is a non-interactive demo showing visualization data captured from different parts of the audio pipeline. The scope displays the data only from the speech synth while the FFT data only uses the music as input.

3dtest

3dtest demo screenshot

Simple 3d audio test. One audio source orbits the listener, another goes on a crazy orbit, and third audio source is where the mouse pointer is. The view is from above, with the listener looking at the top of the screen.

monotone

monotone demo screenshot

This demo plays a MONOTONE song and lets you play with some filters on it.

tedsid

tedsid demo screenshot

This demo plays a SID song and a TED song, and lets you play with some filters as well as fade the volume of the two songs.

virtualvoices

virtual voices demo screenshot

This demo plays over 500 sounds at the same time. You can move the mouse cursor to move the audio listener around. SoLoud calculates the volumes of the sounds based on the listener position, and plays the 16 loudest ones.

Copyright©2013-2015 Jari Komppa