LocalPlayer::accelerateHorizontal: cleanups
[oweals/minetest.git] / src / sound_openal.cpp
index a425af8274374f34be56380171b5bab5c93ca7fd..1772ee817f8fc81e8675215ea9421d280ab1da5e 100644 (file)
@@ -43,7 +43,7 @@ with this program; ifnot, write to the Free Software Foundation, Inc.,
 #include "porting.h"
 #include <vector>
 #include <fstream>
-#include "util/cpp11_container.h"
+#include <unordered_map>
 
 #define BUFFER_SIZE 30000
 
@@ -271,8 +271,8 @@ private:
        ALCdevice *m_device;
        ALCcontext *m_context;
        int m_next_id;
-       UNORDERED_MAP<std::string, std::vector<SoundBuffer*> > m_buffers;
-       UNORDERED_MAP<int, PlayingSound*> m_sounds_playing;
+       std::unordered_map<std::string, std::vector<SoundBuffer*>> m_buffers;
+       std::unordered_map<int, PlayingSound*> m_sounds_playing;
        v3f m_listener_pos;
        struct FadeState {
                FadeState() {}
@@ -285,7 +285,7 @@ private:
                float target_gain;
        };
 
-       UNORDERED_MAP<int, FadeState> m_sounds_fading;
+       std::unordered_map<int, FadeState> m_sounds_fading;
        float m_fade_delay;
 public:
        bool m_is_initialized;
@@ -351,8 +351,8 @@ public:
                alcCloseDevice(m_device);
                m_device = NULL;
 
-               for (UNORDERED_MAP<std::string, std::vector<SoundBuffer*> >::iterator i = m_buffers.begin();
-                               i != m_buffers.end(); ++i) {
+               for (std::unordered_map<std::string, std::vector<SoundBuffer*>>::iterator i =
+                               m_buffers.begin(); i != m_buffers.end(); ++i) {
                        for (std::vector<SoundBuffer*>::iterator iter = (*i).second.begin();
                                        iter != (*i).second.end(); ++iter) {
                                delete *iter;
@@ -370,7 +370,7 @@ public:
 
        void addBuffer(const std::string &name, SoundBuffer *buf)
        {
-               UNORDERED_MAP<std::string, std::vector<SoundBuffer*> >::iterator i =
+               std::unordered_map<std::string, std::vector<SoundBuffer*>>::iterator i =
                                m_buffers.find(name);
                if(i != m_buffers.end()){
                        i->second.push_back(buf);
@@ -384,7 +384,7 @@ public:
 
        SoundBuffer* getBuffer(const std::string &name)
        {
-               UNORDERED_MAP<std::string, std::vector<SoundBuffer*> >::iterator i =
+               std::unordered_map<std::string, std::vector<SoundBuffer*>>::iterator i =
                                m_buffers.find(name);
                if(i == m_buffers.end())
                        return NULL;
@@ -394,7 +394,7 @@ public:
        }
 
        PlayingSound* createPlayingSound(SoundBuffer *buf, bool loop,
-                       float volume)
+                       float volume, float pitch)
        {
                infostream<<"OpenALSoundManager: Creating playing sound"<<std::endl;
                assert(buf);
@@ -409,13 +409,14 @@ public:
                alSourcei(sound->source_id, AL_LOOPING, loop ? AL_TRUE : AL_FALSE);
                volume = MYMAX(0.0, volume);
                alSourcef(sound->source_id, AL_GAIN, volume);
+               alSourcef(sound->source_id, AL_PITCH, pitch);
                alSourcePlay(sound->source_id);
                warn_if_error(alGetError(), "createPlayingSound");
                return sound;
        }
 
        PlayingSound* createPlayingSoundAt(SoundBuffer *buf, bool loop,
-                       float volume, v3f pos)
+                       float volume, v3f pos, float pitch)
        {
                infostream<<"OpenALSoundManager: Creating positional playing sound"
                                <<std::endl;
@@ -432,15 +433,16 @@ public:
                alSourcei(sound->source_id, AL_LOOPING, loop ? AL_TRUE : AL_FALSE);
                volume = MYMAX(0.0, volume);
                alSourcef(sound->source_id, AL_GAIN, volume);
+               alSourcef(sound->source_id, AL_PITCH, pitch);
                alSourcePlay(sound->source_id);
                warn_if_error(alGetError(), "createPlayingSoundAt");
                return sound;
        }
 
-       int playSoundRaw(SoundBuffer *buf, bool loop, float volume)
+       int playSoundRaw(SoundBuffer *buf, bool loop, float volume, float pitch)
        {
                assert(buf);
-               PlayingSound *sound = createPlayingSound(buf, loop, volume);
+               PlayingSound *sound = createPlayingSound(buf, loop, volume, pitch);
                if(!sound)
                        return -1;
                int id = m_next_id++;
@@ -448,10 +450,10 @@ public:
                return id;
        }
 
-       int playSoundRawAt(SoundBuffer *buf, bool loop, float volume, v3f pos)
+       int playSoundRawAt(SoundBuffer *buf, bool loop, float volume, v3f pos, float pitch)
        {
                assert(buf);
-               PlayingSound *sound = createPlayingSoundAt(buf, loop, volume, pos);
+               PlayingSound *sound = createPlayingSoundAt(buf, loop, volume, pos, pitch);
                if(!sound)
                        return -1;
                int id = m_next_id++;
@@ -461,7 +463,7 @@ public:
 
        void deleteSound(int id)
        {
-               UNORDERED_MAP<int, PlayingSound*>::iterator i = m_sounds_playing.find(id);
+               std::unordered_map<int, PlayingSound*>::iterator i = m_sounds_playing.find(id);
                if(i == m_sounds_playing.end())
                        return;
                PlayingSound *sound = i->second;
@@ -501,7 +503,7 @@ public:
                                <<m_sounds_playing.size()<<" playing sounds, "
                                <<m_buffers.size()<<" sound names loaded"<<std::endl;
                std::set<int> del_list;
-               for(UNORDERED_MAP<int, PlayingSound*>::iterator i = m_sounds_playing.begin();
+               for(std::unordered_map<int, PlayingSound*>::iterator i = m_sounds_playing.begin();
                                i != m_sounds_playing.end(); ++i) {
                        int id = i->first;
                        PlayingSound *sound = i->second;
@@ -561,7 +563,7 @@ public:
                alListenerf(AL_GAIN, gain);
        }
 
-       int playSound(const std::string &name, bool loop, float volume, float fade)
+       int playSound(const std::string &name, bool loop, float volume, float fade, float pitch)
        {
                maintain();
                if(name == "")
@@ -574,15 +576,15 @@ public:
                }
                int handle = -1;
                if (fade > 0) {
-                       handle = playSoundRaw(buf, loop, 0);
+                       handle = playSoundRaw(buf, loop, 0.0f, pitch);
                        fadeSound(handle, fade, volume);
                } else {
-                       handle = playSoundRaw(buf, loop, volume);
+                       handle = playSoundRaw(buf, loop, volume, pitch);
                }
                return handle;
        }
 
-       int playSoundAt(const std::string &name, bool loop, float volume, v3f pos)
+       int playSoundAt(const std::string &name, bool loop, float volume, v3f pos, float pitch)
        {
                maintain();
                if(name == "")
@@ -593,7 +595,7 @@ public:
                                        <<std::endl;
                        return -1;
                }
-               return playSoundRawAt(buf, loop, volume, pos);
+               return playSoundRawAt(buf, loop, volume, pos, pitch);
        }
 
        void stopSound(int sound)
@@ -615,7 +617,7 @@ public:
                        return;
 
                float chkGain = 0;
-               for (UNORDERED_MAP<int, FadeState>::iterator i = m_sounds_fading.begin();
+               for (std::unordered_map<int, FadeState>::iterator i = m_sounds_fading.begin();
                                i != m_sounds_fading.end();) {
                        if (i->second.step < 0.f)
                                chkGain = -(i->second.current_gain);
@@ -646,7 +648,7 @@ public:
 
        void updateSoundPosition(int id, v3f pos)
        {
-               UNORDERED_MAP<int, PlayingSound*>::iterator i = m_sounds_playing.find(id);
+               std::unordered_map<int, PlayingSound*>::iterator i = m_sounds_playing.find(id);
                if (i == m_sounds_playing.end())
                        return;
                PlayingSound *sound = i->second;
@@ -659,7 +661,7 @@ public:
 
        bool updateSoundGain(int id, float gain)
        {
-               UNORDERED_MAP<int, PlayingSound*>::iterator i = m_sounds_playing.find(id);
+               std::unordered_map<int, PlayingSound*>::iterator i = m_sounds_playing.find(id);
                if (i == m_sounds_playing.end())
                        return false;
 
@@ -670,7 +672,7 @@ public:
 
        float getSoundGain(int id)
        {
-               UNORDERED_MAP<int, PlayingSound*>::iterator i = m_sounds_playing.find(id);
+               std::unordered_map<int, PlayingSound*>::iterator i = m_sounds_playing.find(id);
                if (i == m_sounds_playing.end())
                        return 0;