Sparky icon indicating copy to clipboard operation
Sparky copied to clipboard

Basic 3D audio added

Open cappah opened this issue 8 years ago • 3 comments

Audio scales based on the distance of the object emitting sound within a given radius.

Audio is panned left, center or right based on the angle of the object emitting sound in conjunction with the direction the camera is facing. Objects emitting sound that are left of the camera in accordance to the camera's facing direction will pan the audio to the left speaker for example.

cappah avatar May 11 '16 08:05 cappah

UPDATE: 5/18/2016 SetPanByAngle broken

UPDATE: 5/19/2016 Fixed and improved SetPanByAngle SetPanByAngle requires the following in the base Camera class:

protected:
float m_Yaw;
public:
inline float GetYaw() const { return m_Yaw; }

Example Usage Within Test3D::OnInit():

audio::SoundManager::Add(new audio::Sound("name", "resource audio dir/name.*"));
audio::SoundManager::Get("name")->Loop();

Within Test3D::OnUpdate() (specifically in this order):

audio::SoundManager::Get("name")->SetGainByDistance(m_Scene->GetCamera()->GetPosition(), g_CubeTransform, 50.0f, 0.7f);
audio::SoundManager::Get("name")->SetPanByAngle(m_Scene->GetCamera()->GetPosition(), g_CubeTransform, m_Scene->GetCamera()->GetYaw(), 25.0f);

cappah avatar May 17 '16 03:05 cappah

I would recommend using SP_INFO instead of std::cout.

Jacob-Mango avatar Jun 03 '16 08:06 Jacob-Mango

@Jacob-Mango That's part of the original Sound.cpp

cappah avatar Jun 03 '16 09:06 cappah