summaryrefslogtreecommitdiffstats
path: root/src/sound/oalsound/channel.cpp
diff options
context:
space:
mode:
authorerihel <erihel@gmail.com>2013-01-09 23:19:10 +0100
committererihel <erihel@gmail.com>2013-01-09 23:19:10 +0100
commit983373f150f6b122e92f054fa1b8e1af60b21197 (patch)
tree2b11bd93c1a3ba10d5f3663785077fe43d8119e2 /src/sound/oalsound/channel.cpp
parent5a6b3f005a83363d323e00b499756d6ecc277574 (diff)
downloadcolobot-983373f150f6b122e92f054fa1b8e1af60b21197.tar.gz
colobot-983373f150f6b122e92f054fa1b8e1af60b21197.tar.bz2
colobot-983373f150f6b122e92f054fa1b8e1af60b21197.zip
* Fixed pitch calculation (sound in cut scenes will work as well as robot tracks sound)
* Fixed applying effects to sounds * Changed volume to range 0.0-1.0 except for values in UI
Diffstat (limited to 'src/sound/oalsound/channel.cpp')
-rw-r--r--src/sound/oalsound/channel.cpp45
1 files changed, 26 insertions, 19 deletions
diff --git a/src/sound/oalsound/channel.cpp b/src/sound/oalsound/channel.cpp
index e1bf202..4069313 100644
--- a/src/sound/oalsound/channel.cpp
+++ b/src/sound/oalsound/channel.cpp
@@ -18,6 +18,7 @@
#include "channel.h"
+#define MIN(a, b) (a > b ? b : a)
Channel::Channel() {
alGenSources(1, &mSource);
@@ -31,6 +32,8 @@ Channel::Channel() {
mPriority = 0;
mBuffer = nullptr;
+ mLoop = false;
+ mInitFrequency = 0.0f;
}
@@ -49,6 +52,7 @@ bool Channel::Play() {
if (!mReady || mBuffer == nullptr)
return false;
+ alSourcei(mSource, AL_LOOPING, static_cast<ALint>(mLoop));
alSourcePlay(mSource);
if (alCheck())
GetLogger()->Warn("Could not play audio sound source. Code: %d\n", alGetCode());
@@ -83,6 +87,15 @@ bool Channel::SetFrequency(float freq)
}
+bool Channel::AdjustFrequency(float freq)
+{
+ if (!mReady || mBuffer == nullptr)
+ return false;
+
+ return SetFrequency(mInitFrequency - freq);
+}
+
+
float Channel::GetFrequency()
{
ALfloat freq;
@@ -104,7 +117,7 @@ bool Channel::SetVolume(float vol)
if (!mReady || vol < 0 || mBuffer == nullptr)
return false;
- alSourcef(mSource, AL_GAIN, vol / MAXVOLUME);
+ alSourcef(mSource, AL_GAIN, MIN(vol, 1.0f));
if (alCheck()) {
GetLogger()->Warn("Could not set sound volume to '%f'. Code: %d\n", vol, alGetCode());
return false;
@@ -125,7 +138,7 @@ float Channel::GetVolume()
return 0;
}
- return vol * MAXVOLUME;
+ return vol;
}
@@ -144,6 +157,7 @@ void Channel::SetPriority(int pri)
void Channel::SetStartAmplitude(float gain)
{
mStartAmplitude = gain;
+ SetVolume(mStartAmplitude);
}
@@ -159,12 +173,6 @@ void Channel::SetChangeFrequency(float freq)
}
-void Channel::SetInitFrequency(float freq)
-{
- mInitFrequency = freq;
-}
-
-
float Channel::GetStartAmplitude()
{
return mStartAmplitude;
@@ -213,8 +221,12 @@ bool Channel::SetBuffer(Buffer *buffer) {
if (!mReady)
return false;
- assert(buffer);
mBuffer = buffer;
+ if (buffer == nullptr) {
+ alSourcei(mSource, AL_BUFFER, 0);
+ return true;
+ }
+
alSourcei(mSource, AL_BUFFER, buffer->GetBuffer());
if (alCheck()) {
GetLogger()->Warn("Could not set sound buffer. Code: %d\n", alGetCode());
@@ -225,16 +237,6 @@ bool Channel::SetBuffer(Buffer *buffer) {
}
-void Channel::AdjustFrequency(float freq) {
- SetFrequency(freq * mInitFrequency);
-}
-
-
-void Channel::AdjustVolume(float volume) {
- SetVolume(mStartAmplitude * volume);
-}
-
-
bool Channel::IsPlaying() {
ALint status;
if (!mReady || mBuffer == nullptr)
@@ -323,3 +325,8 @@ void Channel::PopEnvelope()
{
mOper.pop_front();
}
+
+
+void Channel::SetLoop(bool loop) {
+ mLoop = loop;
+} \ No newline at end of file