From 58f35e44ae17a8d4c55b1b19696245666d3697d3 Mon Sep 17 00:00:00 2001 From: erihel Date: Mon, 14 Jan 2013 22:55:16 +0100 Subject: * Removed alut * Using libsndfile to load sounds and music * Added support for playing music files --- src/sound/oalsound/channel.cpp | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) (limited to 'src/sound/oalsound/channel.cpp') diff --git a/src/sound/oalsound/channel.cpp b/src/sound/oalsound/channel.cpp index 4069313..83420ea 100644 --- a/src/sound/oalsound/channel.cpp +++ b/src/sound/oalsound/channel.cpp @@ -34,12 +34,15 @@ Channel::Channel() { mBuffer = nullptr; mLoop = false; mInitFrequency = 0.0f; + mStartAmplitude = 0.0f; + mStartFrequency = 0.0f; + mChangeFrequency = 0.0f; } Channel::~Channel() { if (mReady) { - alSourceStop(mSource); + alSourceStop(mSource); alSourcei(mSource, AL_BUFFER, 0); alDeleteSources(1, &mSource); if (alCheck()) @@ -223,8 +226,8 @@ bool Channel::SetBuffer(Buffer *buffer) { mBuffer = buffer; if (buffer == nullptr) { - alSourcei(mSource, AL_BUFFER, 0); - return true; + alSourcei(mSource, AL_BUFFER, 0); + return true; } alSourcei(mSource, AL_BUFFER, buffer->GetBuffer()); @@ -237,10 +240,26 @@ bool Channel::SetBuffer(Buffer *buffer) { } +bool Channel::FreeBuffer() { + if (!mReady) + return false; + + if (!mBuffer) { + return false; + } + + alSourceStop(mSource); + alSourcei(mSource, AL_BUFFER, 0); + delete mBuffer; + mBuffer = nullptr; + return true; +} + + bool Channel::IsPlaying() { ALint status; if (!mReady || mBuffer == nullptr) - return false; + return false; alGetSourcei(mSource, AL_SOURCE_STATE, &status); if (alCheck()) { @@ -263,7 +282,7 @@ bool Channel::IsLoaded() { bool Channel::Stop() { if (!mReady || mBuffer == nullptr) - return false; + return false; alSourceStop(mSource); if (alCheck()) { @@ -277,7 +296,7 @@ bool Channel::Stop() { float Channel::GetCurrentTime() { if (!mReady || mBuffer == nullptr) - return 0.0f; + return 0.0f; ALfloat current; alGetSourcef(mSource, AL_SEC_OFFSET, ¤t); @@ -292,7 +311,7 @@ float Channel::GetCurrentTime() void Channel::SetCurrentTime(float current) { if (!mReady || mBuffer == nullptr) - return; + return; alSourcef(mSource, AL_SEC_OFFSET, current); if (alCheck()) @@ -303,7 +322,7 @@ void Channel::SetCurrentTime(float current) float Channel::GetDuration() { if (!mReady || mBuffer == nullptr) - return 0.0f; + return 0.0f; return mBuffer->GetDuration(); } -- cgit v1.2.3-1-g7c22