diff --git a/platforms/windows/SoundSystemWindows.cpp b/platforms/windows/SoundSystemWindows.cpp index 3a6294f..334d7df 100644 --- a/platforms/windows/SoundSystemWindows.cpp +++ b/platforms/windows/SoundSystemWindows.cpp @@ -138,14 +138,18 @@ void SoundSystemWindows::playAt(const SoundDesc& sound, float x, float y, float { return; } - + //Release sounds that finished playing for (size_t i = 0; i < m_buffers.size(); i++) { DWORD status; - m_buffers[i]->GetStatus(&status); + m_buffers[i].buffer->GetStatus(&status); if (status != DSBSTATUS_PLAYING) { - m_buffers[i]->Release(); + m_buffers[i].buffer->Release(); + if (m_buffers[i].object3d != NULL) + { + m_buffers[i].object3d->Release(); + } m_buffers.erase(m_buffers.begin() + i); i--; } @@ -225,7 +229,7 @@ void SoundSystemWindows::playAt(const SoundDesc& sound, float x, float y, float //return false; } - // Copy the wave data into the buffer. + //Move the wave data into the buffer. memcpy(bufferPtr, sound.m_pData, length); // Unlock the secondary buffer after the data has been written to it. @@ -259,6 +263,10 @@ void SoundSystemWindows::playAt(const SoundDesc& sound, float x, float y, float } soundbuffer->SetVolume(LONG(attenuation)); + BufferInfo info; + info.buffer = soundbuffer; + info.object3d = NULL; + //Check if position is not 0,0,0 and for mono to play 3D sound if (!is2D && sound.m_pHeader->m_channels == 1) { @@ -280,8 +288,11 @@ void SoundSystemWindows::playAt(const SoundDesc& sound, float x, float y, float //Im not really sure what values original MCPE would use. object3d->SetMinDistance(2.f, DS3D_IMMEDIATE); object3d->SetMaxDistance(100.f, DS3D_IMMEDIATE); + + info.object3d = object3d; } soundbuffer->Play(0, 0, 0); - m_buffers.push_back(soundbuffer); + + m_buffers.push_back(info); } \ No newline at end of file diff --git a/platforms/windows/SoundSystemWindows.hpp b/platforms/windows/SoundSystemWindows.hpp index 29d4aea..45ad9a1 100644 --- a/platforms/windows/SoundSystemWindows.hpp +++ b/platforms/windows/SoundSystemWindows.hpp @@ -37,8 +37,15 @@ public: virtual void stop(const std::string& sound); virtual void playAt(const SoundDesc& sound, float x, float y, float z, float a, float b); private: + + struct BufferInfo + { + LPDIRECTSOUNDBUFFER buffer; + LPDIRECTSOUND3DBUFFER8 object3d; + }; + bool m_available; IDirectSound8* m_directsound; LPDIRECTSOUND3DLISTENER8 m_listener; - std::vector m_buffers; + std::vector m_buffers; }; \ No newline at end of file