Like Sound Effects, background music is initialized statically in RudeSound. The Bork3D Game Engine supports M4A and MP3 audio formats.
To add a new background audio track, start by modifying the enumeration of music streams in RudeSound.h:
typedef enum {
kBGMNone = -1,
kBGMTitle,
kBGMPutting,
kNumBGMs,
} eSoundBGM;
And then edit the associated list of filenames in RudeSound.cpp:
const char * kSoundBGMs[kNumBGMs] = {
"bgm_title.m4a",
"bgm_putting.m4a"
};
To play an audio track call PlaySong() with a value from the enumeration:
RudeSound::GetInstance()->PlaySong(kBGMPutting);
You can stop the background music at any time with StopSong(), but it's recommended instead you fade it out very fast (see below).
You can smoothly transition in and out of background music using the BgmVolFade() method by specifying the "slope" at which to fade in or out. Positive numbers fade-in, negative numbers fade out. A slope of 0.1 will fade the music in over 10 seconds. -10.0 will fade the background music out over 0.1 seconds.