diff --git a/minetest.conf.example b/minetest.conf.example index eb0ac63d9..edc2222bb 100644 --- a/minetest.conf.example +++ b/minetest.conf.example @@ -107,6 +107,9 @@ #console_color = (0,0,0) # In-game chat console background alpha (opaqueness, between 0 and 255) #console_alpha = 200 +# Sound settings +#enable_sound = true +#sound_volume = 0.7 # # Server stuff diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp index 8f1b8b6f0..67f2e4055 100644 --- a/src/defaultsettings.cpp +++ b/src/defaultsettings.cpp @@ -98,6 +98,8 @@ void set_default_settings(Settings *settings) settings->setDefault("opaque_water", "false"); settings->setDefault("console_color", "(0,0,0)"); settings->setDefault("console_alpha", "200"); + settings->setDefault("enable_sound", "true"); + settings->setDefault("sound_volume", "0.8"); // Server stuff // "map-dir" doesn't exist by default. diff --git a/src/game.cpp b/src/game.cpp index ec5881d25..7d049edf0 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -955,10 +955,14 @@ void the_game( ISoundManager *sound = NULL; bool sound_is_dummy = false; #if USE_SOUND - infostream<<"Attempting to use OpenAL audio"<getBool("enable_sound")){ + infostream<<"Attempting to use OpenAL audio"<getUpVector()); + sound->setListenerGain(g_settings->getFloat("sound_volume")); /* Update sound maker diff --git a/src/sound.h b/src/sound.h index c342f4e5e..c267a452f 100644 --- a/src/sound.h +++ b/src/sound.h @@ -58,6 +58,7 @@ public: const std::string &filedata) = 0; virtual void updateListener(v3f pos, v3f vel, v3f at, v3f up) = 0; + virtual void setListenerGain(float gain) = 0; // playSound functions return -1 on failure, otherwise a handle to the // sound. If name=="", call should be ignored without error. @@ -83,6 +84,7 @@ public: virtual bool loadSoundData(const std::string &name, const std::string &filedata) {return true;} void updateListener(v3f pos, v3f vel, v3f at, v3f up) {} + void setListenerGain(float gain) {} int playSound(const std::string &name, bool loop, float volume) {return 0;} int playSoundAt(const std::string &name, bool loop, diff --git a/src/sound_openal.cpp b/src/sound_openal.cpp index 66faf40c1..c74fa276c 100644 --- a/src/sound_openal.cpp +++ b/src/sound_openal.cpp @@ -198,12 +198,14 @@ private: std::map m_sounds_playing; v3f m_listener_pos; public: + bool m_is_initialized; OpenALSoundManager(OnDemandSoundFetcher *fetcher): m_fetcher(fetcher), m_device(NULL), m_context(NULL), m_can_vorbis(false), - m_next_id(1) + m_next_id(1), + m_is_initialized(false) { ALCenum error = ALC_NO_ERROR; @@ -252,6 +254,8 @@ public: infostream<<"Audio: Initialized: OpenAL "<m_is_initialized) + return m; + delete m; + return NULL; };