summaryrefslogtreecommitdiffstats
path: root/src/sound/oalsound/channel.cpp
diff options
context:
space:
mode:
authorerihel <erihel@gmail.com>2013-01-14 22:55:16 +0100
committererihel <erihel@gmail.com>2013-01-14 22:55:16 +0100
commit58f35e44ae17a8d4c55b1b19696245666d3697d3 (patch)
tree26d593e1af405939f8c8c44c605a657c15aceb6c /src/sound/oalsound/channel.cpp
parent35faf628cf8085a9262c2b89999cacdd3f5bee79 (diff)
downloadcolobot-58f35e44ae17a8d4c55b1b19696245666d3697d3.tar.gz
colobot-58f35e44ae17a8d4c55b1b19696245666d3697d3.tar.bz2
colobot-58f35e44ae17a8d4c55b1b19696245666d3697d3.zip
* Removed alut
* Using libsndfile to load sounds and music * Added support for playing music files
Diffstat (limited to 'src/sound/oalsound/channel.cpp')
-rw-r--r--src/sound/oalsound/channel.cpp35
1 files changed, 27 insertions, 8 deletions
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, &current);
@@ -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();
}