Skip to content

Commit 6f5480a

Browse files
committed
Doppler factor
1 parent 86c79a0 commit 6f5480a

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

3Dev/include/SoundManager.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class SoundManager
3838
void SetMinDistance(float dist, const std::string& name, int id = 0);
3939
void SetAttenuation(float attenuation, const std::string& name, int id = 0);
4040
void SetPitch(float pitch, const std::string& name, int id = 0);
41+
void SetDopplerFactor(float dopplerFactor, const std::string& name, int id = 0);
4142

4243
rp3d::Vector3 GetPosition(const std::string& name, int id = 0);
4344
bool GetRelativeToListener(const std::string& name, int id = 0);
@@ -46,6 +47,7 @@ class SoundManager
4647
float GetMinDistance(const std::string& name, int id = 0);
4748
float GetAttenuation(const std::string& name, int id = 0);
4849
float GetPitch(const std::string& name, int id = 0);
50+
float GetDopplerFactor(const std::string& name, int id = 0);
4951

5052
void UpdateAll();
5153
void UpdateAll(const std::string& name);
@@ -70,7 +72,7 @@ class SoundManager
7072

7173
std::string name, filename;
7274

73-
float volume = 100, minDistance = 1, attenuation = 0, pitch = 1;
75+
float volume = 100, minDistance = 1, attenuation = 0, pitch = 1, dopplerFactor = 0;
7476
bool loop = false, relativeToListener = false;
7577

7678
rp3d::Vector3 pos, prevPos;
@@ -86,7 +88,7 @@ class SoundManager
8688
it->second->setSpatializationEnabled(false);
8789
else
8890
it->second->setSpatializationEnabled(true);
89-
it->second->setDopplerFactor(0.0);
91+
it->second->setDopplerFactor(dopplerFactor);
9092
it->second->setVolume(volume);
9193
it->second->setMinDistance(minDistance);
9294
it->second->setAttenuation(attenuation);

3Dev/src/ScriptManager.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,13 +716,15 @@ void ScriptManager::RegisterSoundManager()
716716
{ "void SetMinDistance(float, const string& in, int = 0)", WRAP_MFN(SoundManager, SetMinDistance) },
717717
{ "void SetAttenuation(float, const string& in, int = 0)", WRAP_MFN(SoundManager, SetAttenuation) },
718718
{ "void SetPitch(float, const string& in, int = 0)", WRAP_MFN(SoundManager, SetPitch) },
719+
{ "void SetDopplerFactor(float, const string& in, int = 0)", WRAP_MFN(SoundManager, SetDopplerFactor) },
719720
{ "Vector3 GetPosition(const string& in, int = 0)", WRAP_MFN(SoundManager, GetPosition) },
720721
{ "bool GetRelativeToListener(const string& in, int = 0)", WRAP_MFN(SoundManager, GetRelativeToListener) },
721722
{ "bool GetLoop(const string& in, int = 0)", WRAP_MFN(SoundManager, GetLoop) },
722723
{ "float GetVolume(const string& in, int = 0)", WRAP_MFN(SoundManager, GetVolume) },
723724
{ "float GetMinDistance(const string& in, int = 0)", WRAP_MFN(SoundManager, GetMinDistance) },
724725
{ "float GetAttenuation(const string& in, int = 0)", WRAP_MFN(SoundManager, GetAttenuation) },
725726
{ "float GetPitch(const string& in, int = 0)", WRAP_MFN(SoundManager, GetPitch) },
727+
{ "float GetDopplerFactor(const string& in, int = 0)", WRAP_MFN(SoundManager, GetDopplerFactor) },
726728
{ "void UpdateAll()", WRAP_MFN_PR(SoundManager, UpdateAll, (), void) },
727729
{ "void UpdateAll(const string& in)", WRAP_MFN_PR(SoundManager, UpdateAll, (const std::string&), void) }
728730
}, {});

3Dev/src/SoundManager.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,16 @@ void SoundManager::SetPitch(float pitch, const std::string& name, int id)
200200
}
201201
}
202202

203+
void SoundManager::SetDopplerFactor(float dopplerFactor, const std::string& name, int id)
204+
{
205+
auto it = std::find(buffers.begin(), buffers.end(), name);
206+
if(it != buffers.end())
207+
{
208+
it->dopplerFactor = dopplerFactor;
209+
it->UpdateActiveSound(sounds, id);
210+
}
211+
}
212+
203213
rp3d::Vector3 SoundManager::GetPosition(const std::string& name, int id)
204214
{
205215
auto it = std::find(buffers.begin(), buffers.end(), name);
@@ -256,6 +266,14 @@ float SoundManager::GetPitch(const std::string& name, int id)
256266
return 0;
257267
}
258268

269+
float SoundManager::GetDopplerFactor(const std::string& name, int id)
270+
{
271+
auto it = std::find(buffers.begin(), buffers.end(), name);
272+
if(it != buffers.end())
273+
return it->dopplerFactor;
274+
return 0;
275+
}
276+
259277
void SoundManager::UpdateAll()
260278
{
261279
std::for_each(buffers.begin(), buffers.end(), [&](auto& b)

0 commit comments

Comments
 (0)