summaryrefslogtreecommitdiffstats
path: root/src/sound
diff options
context:
space:
mode:
authorPiotr Dziwinski <piotrdz@gmail.com>2013-05-26 17:47:54 +0200
committerPiotr Dziwinski <piotrdz@gmail.com>2013-05-27 10:19:16 +0200
commit8765d58b02c9afd00186bae4a0045dff32f7d102 (patch)
tree884cd72d4b8b2fabbd109001412e315aa908b0e8 /src/sound
parent538745a731d07facd7a1574c04a5d34d23ce3bfa (diff)
downloadcolobot-8765d58b02c9afd00186bae4a0045dff32f7d102.tar.gz
colobot-8765d58b02c9afd00186bae4a0045dff32f7d102.tar.bz2
colobot-8765d58b02c9afd00186bae4a0045dff32f7d102.zip
Fixed code formatting
* moved braces to new lines * fixed some function/variable names * fixed whitespace issues
Diffstat (limited to 'src/sound')
-rw-r--r--src/sound/oalsound/alsound.cpp44
-rw-r--r--src/sound/oalsound/buffer.cpp2
-rw-r--r--src/sound/oalsound/channel.cpp28
-rw-r--r--src/sound/oalsound/channel.h14
-rw-r--r--src/sound/sound.h4
5 files changed, 46 insertions, 46 deletions
diff --git a/src/sound/oalsound/alsound.cpp b/src/sound/oalsound/alsound.cpp
index dc2b64d..c50f6ec 100644
--- a/src/sound/oalsound/alsound.cpp
+++ b/src/sound/oalsound/alsound.cpp
@@ -375,7 +375,7 @@ bool ALSound::AddEnvelope(int channel, float amplitude, float frequency, float t
if (mChannels.find(channel) == mChannels.end()) {
return false;
}
-
+
SoundOper op;
op.finalAmplitude = amplitude;
op.finalFrequency = frequency;
@@ -401,7 +401,7 @@ bool ALSound::Position(int channel, Math::Vector pos)
mChannels[channel]->SetPan(pos);
} else {
ComputeVolumePan2D(channel, pos);
-
+
if (!mChannels[channel]->HasEnvelope()) {
float volume = mChannels[channel]->GetStartAmplitude();
mChannels[channel]->SetVolume(powf(volume * mChannels[channel]->GetVolumeAtrib(), 0.2f) * mAudioVolume);
@@ -459,7 +459,7 @@ bool ALSound::MuteAll(bool bMute)
{
if (!mEnabled)
return false;
-
+
for (auto it : mChannels) {
if (it.second->IsPlaying()) {
it.second->Mute(bMute);
@@ -486,7 +486,7 @@ void ALSound::FrameMove(float delta)
if (!it.second->IsPlaying()) {
continue;
}
-
+
if (it.second->IsMuted()) {
it.second->SetVolume(0.0f);
continue;
@@ -499,7 +499,7 @@ void ALSound::FrameMove(float delta)
oper.currentTime += delta;
progress = oper.currentTime / oper.totalTime;
progress = MIN(progress, 1.0f);
-
+
// setting volume
volume = progress * (oper.finalAmplitude - it.second->GetStartAmplitude());
volume = volume + it.second->GetStartAmplitude();
@@ -536,20 +536,20 @@ void ALSound::SetListener(Math::Vector eye, Math::Vector lookat)
mEye = eye;
mLookat = lookat;
if (m3D) {
- float orientation[] = {lookat.x, lookat.y, lookat.z, 0.f, 1.f, 0.f};
- alListener3f(AL_POSITION, eye.x, eye.y, eye.z);
+ float orientation[] = {lookat.x, lookat.y, lookat.z, 0.f, 1.f, 0.f};
+ alListener3f(AL_POSITION, eye.x, eye.y, eye.z);
alListenerfv(AL_ORIENTATION, orientation);
} else {
- float orientation[] = {0.0f, 0.0f, 0.0f, 0.f, 1.f, 0.f};
- alListener3f(AL_POSITION, 0.0f, 0.0f, 0.0f);
+ float orientation[] = {0.0f, 0.0f, 0.0f, 0.f, 1.f, 0.f};
+ alListener3f(AL_POSITION, 0.0f, 0.0f, 0.0f);
alListenerfv(AL_ORIENTATION, orientation);
-
+
// recalculate sound position
for (auto it : mChannels) {
if (it.second->IsPlaying()) {
Math::Vector pos = it.second->GetPosition();
ComputeVolumePan2D(it.first, pos);
-
+
if (!it.second->HasEnvelope()) {
float volume = it.second->GetStartAmplitude();
it.second->SetVolume(powf(volume * it.second->GetVolumeAtrib(), 0.2f) * mAudioVolume);
@@ -586,14 +586,14 @@ bool ALSound::PlayMusic(std::string filename, bool bRepeat)
buffer->LoadFromFile(file.str(), static_cast<Sound>(-1));
mCurrentMusic->SetBuffer(buffer);
} else {
- GetLogger()->Debug("Music loaded from cache\n");
- mCurrentMusic->SetBuffer(mMusic[filename]);
+ GetLogger()->Debug("Music loaded from cache\n");
+ mCurrentMusic->SetBuffer(mMusic[filename]);
}
-
+
mCurrentMusic->SetVolume(mMusicVolume);
mCurrentMusic->SetLoop(bRepeat);
mCurrentMusic->Play();
-
+
return true;
}
@@ -614,7 +614,7 @@ void ALSound::StopMusic()
if (!mEnabled || !mCurrentMusic) {
return;
}
-
+
SuspendMusic();
}
@@ -624,7 +624,7 @@ bool ALSound::IsPlayingMusic()
if (!mEnabled || !mCurrentMusic) {
return false;
}
-
+
return mCurrentMusic->IsPlaying();
}
@@ -634,7 +634,7 @@ void ALSound::SuspendMusic()
if (!mEnabled || !mCurrentMusic) {
return;
}
-
+
mCurrentMusic->Stop();
}
@@ -665,17 +665,17 @@ void ALSound::ComputeVolumePan2D(int channel, Math::Vector &pos)
Math::Vector one = Math::Vector(1.0f, 0.0f, 0.0f);
float angle_a = Angle(Math::Vector(mLookat.x - mEye.x, mLookat.z - mEye.z, 0.0f), one);
float angle_g = Angle(Math::Vector(pos.x - mEye.x, pos.z - mEye.z, 0.0f), one);
-
+
a = fmodf(angle_a, Math::PI * 2.0f);
g = fmodf(angle_g, Math::PI * 2.0f);
-
+
if ( a < 0.0f ) {
a += Math::PI * 2.0f;
}
if ( g < 0.0f ) {
g += Math::PI * 2.0f;
}
-
+
if ( a < g ) {
if (a + Math::PI * 2.0f - g < g - a ) {
a += Math::PI * 2.0f;
@@ -685,6 +685,6 @@ void ALSound::ComputeVolumePan2D(int channel, Math::Vector &pos)
g += Math::PI * 2.0f;
}
}
-
+
mChannels[channel]->SetPan( Math::Vector(0.0f, 0.0f, sinf(g - a)) );
}
diff --git a/src/sound/oalsound/buffer.cpp b/src/sound/oalsound/buffer.cpp
index edc3d74..4640504 100644
--- a/src/sound/oalsound/buffer.cpp
+++ b/src/sound/oalsound/buffer.cpp
@@ -67,7 +67,7 @@ bool Buffer::LoadFromFile(std::string filename, Sound sound) {
while ((read = sf_read_short(file, buffer.data(), buffer.size())) != 0) {
data.insert(data.end(), buffer.begin(), buffer.begin() + read);
}
- sf_close(file);
+ sf_close(file);
alBufferData(mBuffer, fileInfo.channels == 1 ? AL_FORMAT_MONO16 : AL_FORMAT_STEREO16, &data.front(), data.size() * sizeof(uint16_t), fileInfo.samplerate);
mDuration = static_cast<float>(fileInfo.frames) / fileInfo.samplerate;
diff --git a/src/sound/oalsound/channel.cpp b/src/sound/oalsound/channel.cpp
index c5b05fa..d64d6b5 100644
--- a/src/sound/oalsound/channel.cpp
+++ b/src/sound/oalsound/channel.cpp
@@ -27,7 +27,7 @@ Channel::Channel()
} else {
mReady = true;
}
-
+
mPriority = 0;
mBuffer = nullptr;
mLoop = false;
@@ -74,7 +74,7 @@ bool Channel::SetPan(Math::Vector pos)
if (!mReady || mBuffer == nullptr) {
return false;
}
-
+
alSource3f(mSource, AL_POSITION, pos.x, pos.y, pos.z);
if (alCheck()) {
GetLogger()->Warn("Could not set sound position. Code: %d\n", alGetCode());
@@ -117,7 +117,7 @@ float Channel::GetFrequency()
if (!mReady || mBuffer == nullptr) {
return 0;
}
-
+
alGetSourcef(mSource, AL_PITCH, &freq);
if (alCheck()) {
GetLogger()->Warn("Could not get sound pitch. Code: %d\n", alGetCode());
@@ -133,7 +133,7 @@ bool Channel::SetVolume(float vol)
if (!mReady || vol < 0 || mBuffer == nullptr) {
return false;
}
-
+
alSourcef(mSource, AL_GAIN, vol);
if (alCheck()) {
GetLogger()->Warn("Could not set sound volume to '%f'. Code: %d\n", vol, alGetCode());
@@ -149,7 +149,7 @@ float Channel::GetVolume()
if (!mReady || mBuffer == nullptr) {
return 0;
}
-
+
alGetSourcef(mSource, AL_GAIN, &vol);
if (alCheck()) {
GetLogger()->Warn("Could not get sound volume. Code: %d\n", alGetCode());
@@ -243,7 +243,7 @@ Sound Channel::GetSoundType() {
if (!mReady || mBuffer == nullptr) {
return SOUND_NONE;
}
-
+
return mBuffer->GetSoundType();
}
@@ -252,13 +252,13 @@ bool Channel::SetBuffer(Buffer *buffer) {
if (!mReady)
return false;
- Stop();
+ Stop();
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());
@@ -287,7 +287,7 @@ bool Channel::IsPlaying() {
if (!mReady || mBuffer == nullptr) {
return false;
}
-
+
alGetSourcei(mSource, AL_SOURCE_STATE, &status);
if (alCheck()) {
GetLogger()->Warn("Could not get sound status. Code: %d\n", alGetCode());
@@ -311,7 +311,7 @@ bool Channel::Stop() {
if (!mReady || mBuffer == nullptr) {
return false;
}
-
+
alSourceStop(mSource);
if (alCheck()) {
GetLogger()->Warn("Could not stop sound. Code: %d\n", alGetCode());
@@ -326,7 +326,7 @@ float Channel::GetCurrentTime()
if (!mReady || mBuffer == nullptr) {
return 0.0f;
}
-
+
ALfloat current;
alGetSourcef(mSource, AL_SEC_OFFSET, &current);
if (alCheck()) {
@@ -342,7 +342,7 @@ void Channel::SetCurrentTime(float current)
if (!mReady || mBuffer == nullptr) {
return;
}
-
+
alSourcef(mSource, AL_SEC_OFFSET, current);
if (alCheck()) {
GetLogger()->Warn("Could not get source current play time. Code: %d\n", alGetCode());
@@ -355,7 +355,7 @@ float Channel::GetDuration()
if (!mReady || mBuffer == nullptr) {
return 0.0f;
}
-
+
return mBuffer->GetDuration();
}
diff --git a/src/sound/oalsound/channel.h b/src/sound/oalsound/channel.h
index 6717f03..c0b0436 100644
--- a/src/sound/oalsound/channel.h
+++ b/src/sound/oalsound/channel.h
@@ -48,7 +48,7 @@ class Channel
bool Play();
bool Stop();
-
+
bool SetPan(Math::Vector);
void SetPosition(Math::Vector);
Math::Vector GetPosition();
@@ -64,21 +64,21 @@ class Channel
float GetVolume();
void SetVolumeAtrib(float);
float GetVolumeAtrib();
-
+
bool IsPlaying();
bool IsReady();
bool IsLoaded();
bool SetBuffer(Buffer *);
bool FreeBuffer();
-
+
bool HasEnvelope();
SoundOper& GetEnvelope();
void PopEnvelope();
-
+
int GetPriority();
void SetPriority(int);
-
+
void SetStartAmplitude(float);
void SetStartFrequency(float);
void SetChangeFrequency(float);
@@ -87,14 +87,14 @@ class Channel
float GetStartFrequency();
float GetChangeFrequency();
float GetInitFrequency();
-
+
void AddOper(SoundOper);
void ResetOper();
Sound GetSoundType();
void SetLoop(bool);
void Mute(bool);
bool IsMuted();
-
+
private:
Buffer *mBuffer;
ALuint mSource;
diff --git a/src/sound/sound.h b/src/sound/sound.h
index 360f0de..1fd79c3 100644
--- a/src/sound/sound.h
+++ b/src/sound/sound.h
@@ -48,7 +48,7 @@
**/
enum Sound
{
- SOUND_NONE = -1,
+ SOUND_NONE = -1,
SOUND_CLICK = 0,
SOUND_BOUM = 1,
SOUND_EXPLO = 2,
@@ -183,7 +183,7 @@ class CSoundInterface
CacheMusic("music010.ogg");
CacheMusic("music011.ogg");
};
-
+
/** Function called to cache sound effect file.
* This function is called by plugin interface for each file.
* \param bSound - id of a file, will be used to identify sound files