diff --git a/Escape-the-Dawn/GameWorld.h b/Escape-the-Dawn/GameWorld.h index c6a6140..1628205 100644 --- a/Escape-the-Dawn/GameWorld.h +++ b/Escape-the-Dawn/GameWorld.h @@ -72,9 +72,10 @@ void GameWorld::Initialize() model->ModelFile = "ship.obj"; auto soundEmitter = AddComponent(ent, "SoundEmitter"); soundEmitter->Gain = 1; - soundEmitter->MaxDistance = 10; + soundEmitter->MaxDistance = FLT_MAX; + soundEmitter->ReferenceDistance = 10; soundEmitter->Loop = true; - soundEmitter->ReferenceDistance = 0.1; + soundEmitter->Pitch = 1; GetSystem("SoundSystem")->PlaySound(soundEmitter, "Sounds/hallelujah.wav"); diff --git a/Escape-the-Dawn/Systems/SoundSystem.h b/Escape-the-Dawn/Systems/SoundSystem.h index d56faf3..7284ad1 100644 --- a/Escape-the-Dawn/Systems/SoundSystem.h +++ b/Escape-the-Dawn/Systems/SoundSystem.h @@ -23,11 +23,10 @@ public: void UpdateEntity(double dt, EntityID entity, EntityID parent) override; void OnComponentCreated(std::string type, std::shared_ptr component) override; void PlaySound(std::shared_ptr emitter, std::string fileName); - ALuint LoadFile(std::string fileName); - ALuint CreateSource(); private: - ALCcontext* context; + ALuint LoadFile(std::string fileName); + ALuint CreateSource(); //File-info char type[4]; @@ -37,7 +36,7 @@ private: short bytesPerSample, bitsPerSample; DWORD dataSize; - + std::map m_Source; std::map m_BufferCache; // string = fileName }; diff --git a/Escape-the-Dawn/Systems/SoundsSystem.cpp b/Escape-the-Dawn/Systems/SoundsSystem.cpp index 6f34e8c..d35e322 100644 --- a/Escape-the-Dawn/Systems/SoundsSystem.cpp +++ b/Escape-the-Dawn/Systems/SoundsSystem.cpp @@ -1,14 +1,12 @@ #include "SoundSystem.h" #include "World.h" -//#include - Systems::SoundSystem::SoundSystem(World* world) : System(world) { //initialize OpenAL ALCdevice* Device = alcOpenDevice(NULL); - + ALCcontext* context; if(Device) { context = alcCreateContext(Device, NULL); @@ -24,7 +22,7 @@ Systems::SoundSystem::SoundSystem(World* world) void Systems::SoundSystem::Update(double dt) { - + } void Systems::SoundSystem::UpdateEntity(double dt, EntityID entity, EntityID parent) @@ -57,6 +55,7 @@ void Systems::SoundSystem::UpdateEntity(double dt, EntityID entity, EntityID par if(soundEmitter != nullptr) { ALuint source = m_Source[soundEmitter.get()]; + alSourcei(source, AL_GAIN, soundEmitter->Gain); alSourcei(source, AL_MAX_DISTANCE, soundEmitter->MaxDistance); alSourcei(source, AL_REFERENCE_DISTANCE, soundEmitter->ReferenceDistance); alSourcef(source, AL_PITCH, soundEmitter->Pitch); @@ -65,7 +64,7 @@ void Systems::SoundSystem::UpdateEntity(double dt, EntityID entity, EntityID par glm::vec3 emitterPos = transformComponent->Position; ALfloat sourcePos[3] = { emitterPos.x, emitterPos.y, -emitterPos.z }; - glm::vec3 emitterVel= transformComponent->Position; + glm::vec3 emitterVel= transformComponent->Velocity; ALfloat sourceVel[3] = { emitterVel.x, emitterVel.y, -emitterVel.z }; alSourcefv(source, AL_POSITION, sourcePos); @@ -159,7 +158,7 @@ ALuint Systems::SoundSystem::LoadFile(std::string fileName) ALuint buffer; alGenBuffers(1, &buffer); alBufferData(buffer, format, buf, dataSize, sampleRate); - //delete[] buf; + delete[] buf; m_BufferCache[fileName] = buffer; return buffer;