OPENAL BUG FIXED, FFS
This commit is contained in:
@@ -6,7 +6,6 @@
|
|||||||
Systems::SoundSystem::SoundSystem(World* world)
|
Systems::SoundSystem::SoundSystem(World* world)
|
||||||
: System(world)
|
: System(world)
|
||||||
{
|
{
|
||||||
|
|
||||||
//initialize OpenAL
|
//initialize OpenAL
|
||||||
ALCdevice* Device = alcOpenDevice(NULL);
|
ALCdevice* Device = alcOpenDevice(NULL);
|
||||||
|
|
||||||
@@ -21,7 +20,6 @@ Systems::SoundSystem::SoundSystem(World* world)
|
|||||||
}
|
}
|
||||||
|
|
||||||
alGetError();
|
alGetError();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Systems::SoundSystem::Update(double dt)
|
void Systems::SoundSystem::Update(double dt)
|
||||||
@@ -51,54 +49,18 @@ void Systems::SoundSystem::UpdateEntity(double dt, EntityID entity, EntityID par
|
|||||||
|
|
||||||
//Listener
|
//Listener
|
||||||
alListenerfv(AL_POSITION, listenerPos);
|
alListenerfv(AL_POSITION, listenerPos);
|
||||||
ALenum error;
|
|
||||||
if ((error = alGetError()) != AL_NO_ERROR)
|
|
||||||
{
|
|
||||||
LOG_ERROR("AL Error: %d", error);
|
|
||||||
}
|
|
||||||
alListenerfv(AL_VELOCITY, listenerVel);
|
alListenerfv(AL_VELOCITY, listenerVel);
|
||||||
if ((error = alGetError()) != AL_NO_ERROR)
|
|
||||||
{
|
|
||||||
LOG_ERROR("AL Error: %d", error);
|
|
||||||
}
|
|
||||||
alListenerfv(AL_ORIENTATION, listenerOri);
|
alListenerfv(AL_ORIENTATION, listenerOri);
|
||||||
if ((error = alGetError()) != AL_NO_ERROR)
|
|
||||||
{
|
|
||||||
LOG_ERROR("AL Error: %d", error);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto soundEmitter = m_World->GetComponent<Components::SoundEmitter>(entity, "SoundEmitter");
|
auto soundEmitter = m_World->GetComponent<Components::SoundEmitter>(entity, "SoundEmitter");
|
||||||
if(soundEmitter != nullptr)
|
if(soundEmitter != nullptr)
|
||||||
{
|
{
|
||||||
ALuint source = m_Source[soundEmitter.get()];
|
ALuint source = m_Source[soundEmitter.get()];
|
||||||
|
|
||||||
ALenum error;
|
|
||||||
alSourcef(source, AL_GAIN, soundEmitter->Gain); //Volume
|
|
||||||
if ((error = alGetError()) != AL_NO_ERROR)
|
|
||||||
{
|
|
||||||
LOG_ERROR("AL Error: %d", error);
|
|
||||||
}
|
|
||||||
alSourcei(source, AL_MAX_DISTANCE, soundEmitter->MaxDistance);
|
alSourcei(source, AL_MAX_DISTANCE, soundEmitter->MaxDistance);
|
||||||
if ((error = alGetError()) != AL_NO_ERROR)
|
|
||||||
{
|
|
||||||
LOG_ERROR("AL Error: %d", error);
|
|
||||||
}
|
|
||||||
alSourcei(source, AL_REFERENCE_DISTANCE, soundEmitter->ReferenceDistance);
|
alSourcei(source, AL_REFERENCE_DISTANCE, soundEmitter->ReferenceDistance);
|
||||||
if ((error = alGetError()) != AL_NO_ERROR)
|
|
||||||
{
|
|
||||||
LOG_ERROR("AL Error: %d", error);
|
|
||||||
}
|
|
||||||
alSourcef(source, AL_PITCH, soundEmitter->Pitch);
|
alSourcef(source, AL_PITCH, soundEmitter->Pitch);
|
||||||
if ((error = alGetError()) != AL_NO_ERROR)
|
|
||||||
{
|
|
||||||
LOG_ERROR("AL Error: %d", error);
|
|
||||||
}
|
|
||||||
alSourcei(source, AL_LOOPING, soundEmitter->Loop);
|
alSourcei(source, AL_LOOPING, soundEmitter->Loop);
|
||||||
if ((error = alGetError()) != AL_NO_ERROR)
|
|
||||||
{
|
|
||||||
LOG_ERROR("AL Error: %d", error);
|
|
||||||
}
|
|
||||||
|
|
||||||
glm::vec3 emitterPos = transformComponent->Position;
|
glm::vec3 emitterPos = transformComponent->Position;
|
||||||
ALfloat sourcePos[3] = { emitterPos.x, emitterPos.y, emitterPos.z };
|
ALfloat sourcePos[3] = { emitterPos.x, emitterPos.y, emitterPos.z };
|
||||||
@@ -107,17 +69,7 @@ void Systems::SoundSystem::UpdateEntity(double dt, EntityID entity, EntityID par
|
|||||||
ALfloat sourceVel[3] = { emitterVel.x, emitterVel.y, emitterVel.z };
|
ALfloat sourceVel[3] = { emitterVel.x, emitterVel.y, emitterVel.z };
|
||||||
|
|
||||||
alSourcefv(source, AL_POSITION, sourcePos);
|
alSourcefv(source, AL_POSITION, sourcePos);
|
||||||
if ((error = alGetError()) != AL_NO_ERROR)
|
|
||||||
{
|
|
||||||
LOG_ERROR("AL Error: %d", error);
|
|
||||||
}
|
|
||||||
alSourcefv(source, AL_VELOCITY, sourceVel);
|
alSourcefv(source, AL_VELOCITY, sourceVel);
|
||||||
if ((error = alGetError()) != AL_NO_ERROR)
|
|
||||||
{
|
|
||||||
LOG_ERROR("AL Error: %d", error);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,19 +78,7 @@ void Systems::SoundSystem::PlaySound(std::shared_ptr<Components::SoundEmitter> e
|
|||||||
ALuint buffer = LoadFile(fileName);
|
ALuint buffer = LoadFile(fileName);
|
||||||
ALuint source = m_Source[emitter.get()];
|
ALuint source = m_Source[emitter.get()];
|
||||||
alSourcei(source, AL_BUFFER, buffer);
|
alSourcei(source, AL_BUFFER, buffer);
|
||||||
ALenum error;
|
|
||||||
if ((error = alGetError()) != AL_NO_ERROR)
|
|
||||||
{
|
|
||||||
LOG_ERROR("AL Error: %d", error);
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
alSourcePlay(m_Source[emitter.get()]);
|
alSourcePlay(m_Source[emitter.get()]);
|
||||||
if ((error = alGetError()) != AL_NO_ERROR)
|
|
||||||
{
|
|
||||||
LOG_ERROR("AL Error: %d", error);
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Systems::SoundSystem::OnComponentCreated(std::string type, std::shared_ptr<Component> component)
|
void Systems::SoundSystem::OnComponentCreated(std::string type, std::shared_ptr<Component> component)
|
||||||
@@ -215,21 +155,10 @@ ALuint Systems::SoundSystem::LoadFile(std::string fileName)
|
|||||||
else if (channels == 2)
|
else if (channels == 2)
|
||||||
format = AL_FORMAT_STEREO16;
|
format = AL_FORMAT_STEREO16;
|
||||||
}
|
}
|
||||||
|
|
||||||
ALuint buffer;
|
ALuint buffer;
|
||||||
alGenBuffers(1, &buffer);
|
alGenBuffers(1, &buffer);
|
||||||
ALenum error;
|
|
||||||
if ((error = alGetError()) != AL_NO_ERROR)
|
|
||||||
{
|
|
||||||
LOG_ERROR("AL Error: %d", error);
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
alBufferData(buffer, format, buf, dataSize, sampleRate);
|
alBufferData(buffer, format, buf, dataSize, sampleRate);
|
||||||
if ((error = alGetError()) != AL_NO_ERROR)
|
|
||||||
{
|
|
||||||
LOG_ERROR("AL Error: %d", error);
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
|
|
||||||
}
|
|
||||||
//delete[] buf;
|
//delete[] buf;
|
||||||
|
|
||||||
m_BufferCache[fileName] = buffer;
|
m_BufferCache[fileName] = buffer;
|
||||||
@@ -239,41 +168,13 @@ ALuint Systems::SoundSystem::LoadFile(std::string fileName)
|
|||||||
ALuint Systems::SoundSystem::CreateSource()
|
ALuint Systems::SoundSystem::CreateSource()
|
||||||
{
|
{
|
||||||
ALuint source;
|
ALuint source;
|
||||||
alGenBuffers((ALuint)1, &source);
|
alGenSources((ALuint)1, &source);
|
||||||
|
|
||||||
ALenum error;
|
|
||||||
if ((error = alGetError()) != AL_NO_ERROR)
|
|
||||||
{
|
|
||||||
LOG_ERROR("AL Error: %d", error);
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
alSourcef(source, AL_GAIN, 1); //Volume
|
alSourcef(source, AL_GAIN, 1); //Volume
|
||||||
if ((error = alGetError()) != AL_NO_ERROR)
|
|
||||||
{
|
|
||||||
LOG_ERROR("AL Error: %d", error);
|
|
||||||
}
|
|
||||||
alSourcef(source, AL_PITCH, 1);
|
alSourcef(source, AL_PITCH, 1);
|
||||||
if ((error = alGetError()) != AL_NO_ERROR)
|
|
||||||
{
|
|
||||||
LOG_ERROR("AL Error: %d", error);
|
|
||||||
}
|
|
||||||
alSourcei(source, AL_LOOPING, AL_FALSE);
|
alSourcei(source, AL_LOOPING, AL_FALSE);
|
||||||
if ((error = alGetError()) != AL_NO_ERROR)
|
|
||||||
{
|
|
||||||
LOG_ERROR("AL Error: %d", error);
|
|
||||||
}
|
|
||||||
alSource3f(source, AL_POSITION, 0, 0, 0);
|
alSource3f(source, AL_POSITION, 0, 0, 0);
|
||||||
if ((error = alGetError()) != AL_NO_ERROR)
|
|
||||||
{
|
|
||||||
LOG_ERROR("AL Error: %d", error);
|
|
||||||
}
|
|
||||||
alSource3f(source, AL_VELOCITY, 0, 0, 0);
|
alSource3f(source, AL_VELOCITY, 0, 0, 0);
|
||||||
if ((error = alGetError()) != AL_NO_ERROR)
|
|
||||||
{
|
|
||||||
LOG_ERROR("AL Error: %d", error);
|
|
||||||
}
|
|
||||||
|
|
||||||
return source;
|
return source;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user