summaryrefslogtreecommitdiffstats
path: root/src/sound/oalsound/channel.cpp
diff options
context:
space:
mode:
authorerihel <erihel@gmail.com>2013-04-08 01:42:12 +0200
committererihel <erihel@gmail.com>2013-04-08 01:42:12 +0200
commit846e7b6578058cf6d52bf2bf0b2133f84220d670 (patch)
tree1c9c103d08a83b2a0039c6cf584c414bbccb378b /src/sound/oalsound/channel.cpp
parent7513bc5864efce2d6366f8836f1cb178adff6965 (diff)
downloadcolobot-846e7b6578058cf6d52bf2bf0b2133f84220d670.tar.gz
colobot-846e7b6578058cf6d52bf2bf0b2133f84220d670.tar.bz2
colobot-846e7b6578058cf6d52bf2bf0b2133f84220d670.zip
* Adjusted pan computing function from original game (2D sound should work correctly)
* Set max sound distance to 110.0f to match original colobot (for issue #123)
Diffstat (limited to 'src/sound/oalsound/channel.cpp')
-rw-r--r--src/sound/oalsound/channel.cpp49
1 files changed, 31 insertions, 18 deletions
diff --git a/src/sound/oalsound/channel.cpp b/src/sound/oalsound/channel.cpp
index f5967ab..746282e 100644
--- a/src/sound/oalsound/channel.cpp
+++ b/src/sound/oalsound/channel.cpp
@@ -49,20 +49,25 @@ Channel::~Channel() {
bool Channel::Play() {
- if (!mReady || mBuffer == nullptr)
+ if (!mReady || mBuffer == nullptr) {
return false;
+ }
alSourcei(mSource, AL_LOOPING, static_cast<ALint>(mLoop));
+ alSourcei(mSource, AL_REFERENCE_DISTANCE, 10.0f);
+ alSourcei(mSource, AL_MAX_DISTANCE, 110.0f);
alSourcePlay(mSource);
- if (alCheck())
+ if (alCheck()) {
GetLogger()->Warn("Could not play audio sound source. Code: %d\n", alGetCode());
+ }
return true;
}
bool Channel::SetPosition(Math::Vector pos) {
- if (!mReady || mBuffer == nullptr)
+ if (!mReady || mBuffer == nullptr) {
return false;
+ }
alSource3f(mSource, AL_POSITION, pos.x, pos.y, pos.z);
if (alCheck()) {
@@ -75,8 +80,9 @@ bool Channel::SetPosition(Math::Vector pos) {
bool Channel::SetFrequency(float freq)
{
- if (!mReady || mBuffer == nullptr)
+ if (!mReady || mBuffer == nullptr) {
return false;
+ }
alSourcef(mSource, AL_PITCH, freq);
if (alCheck()) {
@@ -90,8 +96,9 @@ bool Channel::SetFrequency(float freq)
float Channel::GetFrequency()
{
ALfloat freq;
- if (!mReady || mBuffer == nullptr)
+ if (!mReady || mBuffer == nullptr) {
return 0;
+ }
alGetSourcef(mSource, AL_PITCH, &freq);
if (alCheck()) {
@@ -105,8 +112,9 @@ float Channel::GetFrequency()
bool Channel::SetVolume(float vol)
{
- if (!mReady || vol < 0 || mBuffer == nullptr)
+ if (!mReady || vol < 0 || mBuffer == nullptr) {
return false;
+ }
alSourcef(mSource, AL_GAIN, vol);
if (alCheck()) {
@@ -120,8 +128,9 @@ bool Channel::SetVolume(float vol)
float Channel::GetVolume()
{
ALfloat vol;
- if (!mReady || mBuffer == nullptr)
+ if (!mReady || mBuffer == nullptr) {
return 0;
+ }
alGetSourcef(mSource, AL_GAIN, &vol);
if (alCheck()) {
@@ -201,8 +210,9 @@ void Channel::ResetOper()
Sound Channel::GetSoundType() {
- if (!mReady || mBuffer == nullptr)
+ if (!mReady || mBuffer == nullptr) {
return SOUND_NONE;
+ }
return mBuffer->GetSoundType();
}
@@ -230,10 +240,7 @@ bool Channel::SetBuffer(Buffer *buffer) {
bool Channel::FreeBuffer() {
- if (!mReady)
- return false;
-
- if (!mBuffer) {
+ if (!mReady || !mBuffer) {
return false;
}
@@ -247,8 +254,9 @@ bool Channel::FreeBuffer() {
bool Channel::IsPlaying() {
ALint status;
- if (!mReady || mBuffer == nullptr)
+ if (!mReady || mBuffer == nullptr) {
return false;
+ }
alGetSourcei(mSource, AL_SOURCE_STATE, &status);
if (alCheck()) {
@@ -270,8 +278,9 @@ bool Channel::IsLoaded() {
bool Channel::Stop() {
- if (!mReady || mBuffer == nullptr)
+ if (!mReady || mBuffer == nullptr) {
return false;
+ }
alSourceStop(mSource);
if (alCheck()) {
@@ -284,8 +293,9 @@ bool Channel::Stop() {
float Channel::GetCurrentTime()
{
- if (!mReady || mBuffer == nullptr)
+ if (!mReady || mBuffer == nullptr) {
return 0.0f;
+ }
ALfloat current;
alGetSourcef(mSource, AL_SEC_OFFSET, &current);
@@ -299,19 +309,22 @@ float Channel::GetCurrentTime()
void Channel::SetCurrentTime(float current)
{
- if (!mReady || mBuffer == nullptr)
+ if (!mReady || mBuffer == nullptr) {
return;
+ }
alSourcef(mSource, AL_SEC_OFFSET, current);
- if (alCheck())
+ if (alCheck()) {
GetLogger()->Warn("Could not get source current play time. Code: %d\n", alGetCode());
+ }
}
float Channel::GetDuration()
{
- if (!mReady || mBuffer == nullptr)
+ if (!mReady || mBuffer == nullptr) {
return 0.0f;
+ }
return mBuffer->GetDuration();
}