#include "porting.h"
#include <vector>
#include <fstream>
-#include "util/cpp11_container.h"
+#include <unordered_map>
#define BUFFER_SIZE 30000
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() {}
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;
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;
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);
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;
}
PlayingSound* createPlayingSound(SoundBuffer *buf, bool loop,
- float volume)
+ float volume, float pitch)
{
infostream<<"OpenALSoundManager: Creating playing sound"<<std::endl;
assert(buf);
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;
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++;
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++;
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;
<<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;
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 == "")
}
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 == "")
<<std::endl;
return -1;
}
- return playSoundRawAt(buf, loop, volume, pos);
+ return playSoundRawAt(buf, loop, volume, pos, pitch);
}
void stopSound(int sound)
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);
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;
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;
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;