Skip to content

Symphony Audio Engine

Twarit Waikar edited this page Dec 13, 2018 · 4 revisions

Rubeus: Symphony Audio Engine

Created by SDSLabs with ❤️

The Rubeus Engine's audio engine, named as 'Symphony' uses SFML's Audio components as its backend. Symphony's workflow is a hybrid of the OpenGL state machine workflow and SFML's sound buffer loading and cueing.

Jargon

  • Symphony manages two different types of audio tracks. At max, 20 tracks are available for use under each type.
    • Sound tracks:
      • Used for loading short sounds like walking effects, or weapon action sound effects.
    • Music tracks:
      • Used for longer pieces of audio like ambient music and background music.
    • Each type of track lists are currently supporting maximum 20 tracks each.
  • The sound manager needs to know what is the minimum number of tracks you want to play your first piece of audio on. To add a music track, use RSymphony::addMusicTrack(int) to add the specified number of music tracks to use.
  • Next, specify which track you want to load your sound file to. A summary of the steps so far is given below.

How to use Symphony?

Let's see how to use Symphony in C++ code. You would expect to see these scripts inside begin() or onHit() functions of your levels and objects.

// Do not write 'using namespace' outside of function definitions
	using namespace Rubeus;
	using namespace Rubeus::AudioComponents;

	// Gain access to the audio manager
	auto * audio_manager = Rubeus::Engine->getCurrentLevelAudioManager();

	// Add the number of tracks you'd like to use
	audio_manager->addMusicTrack(1);
	audio_manager->addSoundTrack(1);

	// Load the tracks you have chosen at some specific track slots. 
	// Make sure the slot number doesn't exceed the number of track you'd like to use for each track type. 
	audio_manager->loadTrack(MUSIC_TRACK, TRACK_0        , "Assets/bgmusic.wav", 20     , true                     );
	//                       trackType  , track slot name, sound file          , volume , set looping true or false

	audio_manager->loadTrack(SOUND_TRACK, TRACK_0, "Assets/footsteps.wav", 10);
  • Use playTrack() to cue music
audio_manager->playTrack(MUSIC_TRACK, TRACK_0);
audio_manager->playTrack(SOUND_TRACK, TRACK_0);

Contributor's Guide

Symphony works the exact same way as its API makes it look like. There are 20 different SFML tracks for each type of audio track.

  • Music Tracks
    • Music tracks are for longer pieces, which means they are slow to load and slower to cue. They may be a few seconds off in timing when cued.
    • Music tracks need SFML buffers to be loaded into memory first and then they are held on pause for being cued.
  • Sound Tracks
    • Sound tracks are for shorter pieces of audio which are needed to be played instantaneously after cueing.
    • They are shorter pieces by assumption, which means they do not need SFML buffers.

They are other audio effects being prepared for the next release. Look up what features can SFML provide to find which ones can Rubeus use and maybe be worth a PR.