This class is c++ wrapper to BASS audio library with some often requested functions, such as:
- load sound in memory and play it when needs;
- manage loaded sounds;
- repeat playing of song;
- change tempo and pich
- Download BASS audio library from [this link] (http://us.un4seen.com/files/bass24-linux.zip)
- Unpack it in temporary directory
- Place shared library (usually
libbass.so
frommp3-free
subdir) in the system user library directory (usually /usr/local/lib/) - Install BASS_FX addon (
libbass_fx.so
) - is the same as above (http://www.un4seen.com/files/z/0/bass_fx24-linux.zip)
$ wget http://us.un4seen.com/files/bass24-linux.zip
$ unzip bass24-linux.zip -d tmp/
$ sudo cp tmp/x64/libbass.so /usr/local/lib/ # for 32-bit - tmp/libbass.so
$ sudo chmod a+rx /usr/local/lib/libbass.so
$ sudo ldconfig
$ rm -rf tmp/ bass24-linux.zip
Installing libbass_fx.so - is the same as above
P.S.: if something goes wrong while downloading bass audio library, then the best way is to use direct link for downloading library
- Place header files (usually named
bass.h
andbass_fx.h
) into include directory of yours application (preffered3rdparty
subdir ofAudioOut
source dir). - Then we should make static library simple by the following:
$ mkdir build
$ cd build
$ cmake ../
$ make
- In header file of yours application You should include
audio_out.h
or `audio_fx.h. - In Makefile of application we should write path to AudioOut static library (-L flag) and compiler flags: -laudio -lbass -laudio_fx -lbass_fx
AudioOut audio {};
audio.Play("some_song.wav", true);
audio.Stop("some_song.wav");
audio.Stop("some_song.wav", true);
AudioOut& audio;
...
audio_helpers::StopAllNowPlayingSong(audio, true);
std::vector<std::string> playing = audio.NowPlaying(true);
// Prepare audio sound represents engine of a boat
AudioFx audio {};
auto engine_snd = "snd_engine.wav";
auto engine_mod = AudioFx::Modifier::PITCH;
// Show to AudioFx that we want to change pitch in the future in the particular range
auto min_pitch = 0.2f;
auto max_pitch = 1.0f;
audio.LoadFx(engine_snd, true);
audio.SetModifierRange(engine_snd, engine_mod, min_pitch, max_pitch);
audio.SetModifierValue(engine_snd, engine_mod, min_pitch);
audio.PlayFx(engine_snd);
while (true) {
...
// Somewhere in game loop - process player sounds
auto range_1 = std::make_pair(0.0f, boat.GetDynamics().GetMaxSpeed());
auto range_2 = audio.GetModifierRange(engine_snd, engine_mod);
auto curr_vel = boat.GetDynamics().GetCurrentSpeed();
auto modifier_val = math::LeadToRange(range_1, range_2, curr_vel);
audio.SetModifierValue(engine_snd, engine_mod, modifier_val);
..
}