summaryrefslogtreecommitdiffstats
path: root/src/sound
diff options
context:
space:
mode:
Diffstat (limited to 'src/sound')
-rw-r--r--src/sound/oalsound/alsound.cpp (renamed from src/sound/plugins/oalsound/alsound.cpp)70
-rw-r--r--src/sound/oalsound/alsound.h (renamed from src/sound/plugins/oalsound/alsound.h)10
-rw-r--r--src/sound/oalsound/buffer.cpp (renamed from src/sound/plugins/oalsound/buffer.cpp)4
-rw-r--r--src/sound/oalsound/buffer.h (renamed from src/sound/plugins/oalsound/buffer.h)0
-rw-r--r--src/sound/oalsound/channel.cpp (renamed from src/sound/plugins/oalsound/channel.cpp)26
-rw-r--r--src/sound/oalsound/channel.h (renamed from src/sound/plugins/oalsound/channel.h)0
-rw-r--r--src/sound/oalsound/check.h (renamed from src/sound/plugins/oalsound/check.h)0
-rw-r--r--src/sound/plugins/oalsound/CMakeLists.txt23
-rw-r--r--src/sound/plugins/oalsound/test/CMakeLists.txt11
-rw-r--r--src/sound/plugins/oalsound/test/plugin_test.cpp40
-rw-r--r--src/sound/sound.h6
11 files changed, 44 insertions, 146 deletions
diff --git a/src/sound/plugins/oalsound/alsound.cpp b/src/sound/oalsound/alsound.cpp
index 83a4def..f683a62 100644
--- a/src/sound/plugins/oalsound/alsound.cpp
+++ b/src/sound/oalsound/alsound.cpp
@@ -23,51 +23,23 @@
#define MIN(a, b) (a > b ? b : a)
-
-PLUGIN_INTERFACE(ALSound)
-
-
-std::string ALSound::PluginName()
-{
- return "Sound plugin using OpenAL library to play sounds.";
-}
-
-
-int ALSound::PluginVersion()
-{
- return 2;
-}
-
-
-void ALSound::InstallPlugin()
-{
- auto pointer = CInstanceManager::GetInstancePointer();
- if (pointer != nullptr)
- CInstanceManager::GetInstancePointer()->AddInstance(CLASS_SOUND, this);
-}
-
-
-bool ALSound::UninstallPlugin(std::string &reason)
-{
- auto pointer = CInstanceManager::GetInstancePointer();
- if (pointer != nullptr)
- CInstanceManager::GetInstancePointer()->DeleteInstance(CLASS_SOUND, this);
- CleanUp();
- return true;
-}
-
-
ALSound::ALSound()
{
mEnabled = false;
m3D = false;
mAudioVolume = MAXVOLUME;
mMute = false;
+ auto pointer = CInstanceManager::GetInstancePointer();
+ if (pointer != nullptr)
+ CInstanceManager::GetInstancePointer()->AddInstance(CLASS_SOUND, this);
}
ALSound::~ALSound()
{
+ auto pointer = CInstanceManager::GetInstancePointer();
+ if (pointer != nullptr)
+ CInstanceManager::GetInstancePointer()->DeleteInstance(CLASS_SOUND, this);
CleanUp();
}
@@ -114,14 +86,14 @@ void ALSound::SetSound3D(bool bMode)
}
-bool ALSound::RetSound3D()
+bool ALSound::GetSound3D()
{
// TODO stub! need to be implemented
return true;
}
-bool ALSound::RetSound3DCap()
+bool ALSound::GetSound3DCap()
{
// TODO stub! need to be implemented
return true;
@@ -141,7 +113,7 @@ void ALSound::SetAudioVolume(int volume)
}
-int ALSound::RetAudioVolume()
+int ALSound::GetAudioVolume()
{
float volume;
if ( !mEnabled )
@@ -158,7 +130,7 @@ void ALSound::SetMusicVolume(int volume)
}
-int ALSound::RetMusicVolume()
+int ALSound::GetMusicVolume()
{
// TODO stub! Add music support
if ( !mEnabled )
@@ -179,7 +151,7 @@ bool ALSound::Cache(Sound sound, std::string filename)
}
-int ALSound::RetPriority(Sound sound)
+int ALSound::GetPriority(Sound sound)
{
if ( sound == SOUND_FLYh ||
sound == SOUND_FLY ||
@@ -230,7 +202,7 @@ int ALSound::RetPriority(Sound sound)
bool ALSound::SearchFreeBuffer(Sound sound, int &channel, bool &bAlreadyLoaded)
{
- int priority = RetPriority(sound);
+ int priority = GetPriority(sound);
// Seeks a channel used which sound is stopped.
for (auto it : mChannels) {
@@ -287,7 +259,7 @@ bool ALSound::SearchFreeBuffer(Sound sound, int &channel, bool &bAlreadyLoaded)
int lowerOrEqual = -1;
for (auto it : mChannels) {
if (it.second->GetPriority() < priority) {
- GetLogger()->Info("Sound channel with lower priority will be reused.");
+ GetLogger()->Debug("Sound channel with lower priority will be reused.");
channel = it.first;
return true;
}
@@ -297,7 +269,7 @@ bool ALSound::SearchFreeBuffer(Sound sound, int &channel, bool &bAlreadyLoaded)
if (lowerOrEqual != -1) {
channel = lowerOrEqual;
- GetLogger()->Info("Sound channel with lower or equal priority will be reused.");
+ GetLogger()->Debug("Sound channel with lower or equal priority will be reused.");
return true;
}
@@ -324,6 +296,8 @@ int ALSound::Play(Sound sound, Math::Vector pos, float amplitude, float frequenc
GetLogger()->Warn("Sound %d was not loaded!\n", sound);
return -1;
}
+
+ GetLogger()->Trace("ALSound::Play sound: %d volume: %f frequency: %f\n", sound, amplitude, frequency);
int channel;
bool bAlreadyLoaded;
@@ -336,12 +310,12 @@ int ALSound::Play(Sound sound, Math::Vector pos, float amplitude, float frequenc
Position(channel, pos);
// setting initial values
- mChannels[channel]->SetStartAmplitude(amplitude);
+ mChannels[channel]->SetStartAmplitude(mAudioVolume);
mChannels[channel]->SetStartFrequency(frequency);
mChannels[channel]->SetChangeFrequency(1.0f);
mChannels[channel]->ResetOper();
- mChannels[channel]->AdjustFrequency(frequency);
- mChannels[channel]->AdjustVolume(mAudioVolume);
+ mChannels[channel]->AdjustFrequency(frequency);
+ mChannels[channel]->AdjustVolume(amplitude * mAudioVolume);
mChannels[channel]->Play();
return channel;
}
@@ -479,17 +453,17 @@ void ALSound::FrameMove(float delta)
it.second->AdjustVolume(volume * mAudioVolume);
// setting frequency
- frequency = progress * (oper.finalFrequency - it.second->GetStartFrequency()) * it.second->GetStartFrequency() * it.second->GetChangeFrequency();
+ frequency = progress * abs(oper.finalFrequency - it.second->GetStartFrequency()) * it.second->GetStartFrequency() * it.second->GetChangeFrequency();
it.second->AdjustFrequency(frequency);
if (it.second->GetEnvelope().totalTime <= it.second->GetCurrentTime()) {
if (oper.nextOper == SOPER_LOOP) {
- GetLogger()->Info("Replay.\n");
+ GetLogger()->Trace("ALSound::FrameMove oper: replay.\n");
it.second->SetCurrentTime(0.0f);
it.second->Play();
} else {
- GetLogger()->Info("Next.\n");
+ GetLogger()->Trace("ALSound::FrameMove oper: next.\n");
it.second->SetStartAmplitude(oper.finalAmplitude);
it.second->SetStartFrequency(oper.finalFrequency);
it.second->PopEnvelope();
diff --git a/src/sound/plugins/oalsound/alsound.h b/src/sound/oalsound/alsound.h
index a1128e0..7d24ba6 100644
--- a/src/sound/plugins/oalsound/alsound.h
+++ b/src/sound/oalsound/alsound.h
@@ -45,13 +45,13 @@ class ALSound : public CSoundInterface
bool RetEnable();
void SetSound3D(bool bMode);
- bool RetSound3D();
- bool RetSound3DCap();
+ bool GetSound3D();
+ bool GetSound3DCap();
void SetAudioVolume(int volume);
- int RetAudioVolume();
+ int GetAudioVolume();
void SetMusicVolume(int volume);
- int RetMusicVolume();
+ int GetMusicVolume();
void SetListener(Math::Vector eye, Math::Vector lookat);
void FrameMove(float rTime);
@@ -80,7 +80,7 @@ class ALSound : public CSoundInterface
private:
void CleanUp();
- int RetPriority(Sound);
+ int GetPriority(Sound);
bool SearchFreeBuffer(Sound sound, int &channel, bool &bAlreadyLoaded);
bool mEnabled;
diff --git a/src/sound/plugins/oalsound/buffer.cpp b/src/sound/oalsound/buffer.cpp
index 37211e9..dbfdca2 100644
--- a/src/sound/plugins/oalsound/buffer.cpp
+++ b/src/sound/oalsound/buffer.cpp
@@ -36,7 +36,7 @@ Buffer::~Buffer() {
bool Buffer::LoadFromFile(std::string filename, Sound sound) {
mSound = sound;
- GetLogger()->Info("Loading audio file: %s\n", filename.c_str());
+ GetLogger()->Debug("Loading audio file: %s\n", filename.c_str());
mBuffer = alutCreateBufferFromFile(filename.c_str());
ALenum error = alutGetError();
@@ -53,7 +53,7 @@ bool Buffer::LoadFromFile(std::string filename, Sound sound) {
alGetBufferi(mBuffer, AL_CHANNELS, &channels);
alGetBufferi(mBuffer, AL_FREQUENCY, &freq);
- mDuration = (ALfloat)size / channels / bits / 8 / (ALfloat)freq;
+ mDuration = static_cast<ALfloat>(size) / channels / bits / 8 / static_cast<ALfloat>(freq);
mLoaded = true;
return true;
diff --git a/src/sound/plugins/oalsound/buffer.h b/src/sound/oalsound/buffer.h
index 8c4a2d3..8c4a2d3 100644
--- a/src/sound/plugins/oalsound/buffer.h
+++ b/src/sound/oalsound/buffer.h
diff --git a/src/sound/plugins/oalsound/channel.cpp b/src/sound/oalsound/channel.cpp
index 4476dee..7d8244b 100644
--- a/src/sound/plugins/oalsound/channel.cpp
+++ b/src/sound/oalsound/channel.cpp
@@ -39,7 +39,7 @@ Channel::~Channel() {
alSourcei(mSource, AL_BUFFER, 0);
alDeleteSources(1, &mSource);
if (alCheck())
- GetLogger()->Warn("Failed to delete sound source. Code: %s\n", alGetCode());
+ GetLogger()->Warn("Failed to delete sound source. Code: %d\n", alGetCode());
}
}
@@ -50,7 +50,7 @@ bool Channel::Play() {
alSourcePlay(mSource);
if (alCheck())
- GetLogger()->Warn("Could not play audio sound source. Code: %s\n", alGetCode());
+ GetLogger()->Warn("Could not play audio sound source. Code: %d\n", alGetCode());
return true;
}
@@ -61,7 +61,7 @@ bool Channel::SetPosition(Math::Vector pos) {
alSource3f(mSource, AL_POSITION, pos.x, pos.y, pos.z);
if (alCheck()) {
- GetLogger()->Warn("Could not set sound position. Code: %s\n", alGetCode());
+ GetLogger()->Warn("Could not set sound position. Code: %d\n", alGetCode());
return false;
}
return true;
@@ -75,7 +75,7 @@ bool Channel::SetFrequency(float freq)
alSourcef(mSource, AL_PITCH, freq);
if (alCheck()) {
- GetLogger()->Warn("Could not set sound pitch. Code: %s\n", alGetCode());
+ GetLogger()->Warn("Could not set sound pitch to '%f'. Code: %d\n", freq, alGetCode());
return false;
}
return true;
@@ -90,7 +90,7 @@ float Channel::GetFrequency()
alGetSourcef(mSource, AL_PITCH, &freq);
if (alCheck()) {
- GetLogger()->Warn("Could not get sound pitch. Code: %s\n", alGetCode());
+ GetLogger()->Warn("Could not get sound pitch. Code: %d\n", alGetCode());
return 0;
}
@@ -105,7 +105,7 @@ bool Channel::SetVolume(float vol)
alSourcef(mSource, AL_GAIN, vol / MAXVOLUME);
if (alCheck()) {
- GetLogger()->Warn("Could not set sound volume. Code: %s\n", alGetCode());
+ GetLogger()->Warn("Could not set sound volume to '%f'. Code: %d\n", vol, alGetCode());
return false;
}
return true;
@@ -120,7 +120,7 @@ float Channel::GetVolume()
alGetSourcef(mSource, AL_GAIN, &vol);
if (alCheck()) {
- GetLogger()->Warn("Could not get sound volume. Code: %s\n", alGetCode());
+ GetLogger()->Warn("Could not get sound volume. Code: %d\n", alGetCode());
return 0;
}
@@ -213,7 +213,7 @@ bool Channel::SetBuffer(Buffer *buffer) {
mBuffer = buffer;
alSourcei(mSource, AL_BUFFER, buffer->GetBuffer());
if (alCheck()) {
- GetLogger()->Warn("Could not set sound buffer. Code: %s\n", alGetCode());
+ GetLogger()->Warn("Could not set sound buffer. Code: %d\n", alGetCode());
return false;
}
mInitFrequency = GetFrequency();
@@ -227,7 +227,7 @@ void Channel::AdjustFrequency(float freq) {
void Channel::AdjustVolume(float volume) {
- SetVolume(mStartAmplitude * (float) volume);
+ SetVolume(mStartAmplitude * volume);
}
@@ -237,7 +237,7 @@ bool Channel::IsPlaying() {
alGetSourcei(mSource, AL_SOURCE_STATE, &status);
if (alCheck()) {
- GetLogger()->Warn("Could not get sound status. Code: %s\n", alGetCode());
+ GetLogger()->Warn("Could not get sound status. Code: %d\n", alGetCode());
return false;
}
@@ -253,7 +253,7 @@ bool Channel::IsReady() {
bool Channel::Stop() {
alSourceStop(mSource);
if (alCheck()) {
- GetLogger()->Warn("Could not stop sound. Code: %s\n", alGetCode());
+ GetLogger()->Warn("Could not stop sound. Code: %d\n", alGetCode());
return false;
}
return true;
@@ -265,7 +265,7 @@ float Channel::GetCurrentTime()
ALfloat current;
alGetSourcef(mSource, AL_SEC_OFFSET, &current);
if (alCheck()) {
- GetLogger()->Warn("Could not get source current play time. Code: %s\n", alGetCode());
+ GetLogger()->Warn("Could not get source current play time. Code: %d\n", alGetCode());
return 0.0f;
}
return current;
@@ -276,7 +276,7 @@ void Channel::SetCurrentTime(float current)
{
alSourcef(mSource, AL_SEC_OFFSET, current);
if (alCheck())
- GetLogger()->Warn("Could not get source current play time. Code: %s\n", alGetCode());
+ GetLogger()->Warn("Could not get source current play time. Code: %d\n", alGetCode());
}
diff --git a/src/sound/plugins/oalsound/channel.h b/src/sound/oalsound/channel.h
index 165ff50..165ff50 100644
--- a/src/sound/plugins/oalsound/channel.h
+++ b/src/sound/oalsound/channel.h
diff --git a/src/sound/plugins/oalsound/check.h b/src/sound/oalsound/check.h
index cf3e468..cf3e468 100644
--- a/src/sound/plugins/oalsound/check.h
+++ b/src/sound/oalsound/check.h
diff --git a/src/sound/plugins/oalsound/CMakeLists.txt b/src/sound/plugins/oalsound/CMakeLists.txt
deleted file mode 100644
index 0bc9482..0000000
--- a/src/sound/plugins/oalsound/CMakeLists.txt
+++ /dev/null
@@ -1,23 +0,0 @@
-cmake_minimum_required(VERSION 2.8)
-
-set(SOURCES
- alsound.cpp
- buffer.cpp
- channel.cpp
-)
-
-SET (CMAKE_CXX_FLAGS "-Wall -g -std=c++0x -fPIC")
-
-include(FindPkgConfig)
-include(FindOpenAL)
-pkg_check_modules(OPENAL_LIB REQUIRED openal)
-
-set(OPENAL_LIBRARIES
- openal
- alut
-)
-
-include_directories(../../..)
-include_directories(.)
-add_library(openalsound SHARED ${SOURCES})
-target_link_libraries(openalsound ${OPENAL_LIBRARIES})
diff --git a/src/sound/plugins/oalsound/test/CMakeLists.txt b/src/sound/plugins/oalsound/test/CMakeLists.txt
deleted file mode 100644
index d10169b..0000000
--- a/src/sound/plugins/oalsound/test/CMakeLists.txt
+++ /dev/null
@@ -1,11 +0,0 @@
-cmake_minimum_required(VERSION 2.8)
-
-set(CMAKE_BUILD_TYPE debug)
-set(CMAKE_CXX_FLAGS_DEBUG "-Wall -g -O0 -std=c++11 -rdynamic")
-
-add_executable(plugin_test plugin_test.cpp ../../../../common/iman.cpp ../../../../common/logger.cpp ../../../../plugins/pluginloader.cpp)
-
-include_directories(".")
-include_directories("../../../../")
-
-target_link_libraries(plugin_test ltdl)
diff --git a/src/sound/plugins/oalsound/test/plugin_test.cpp b/src/sound/plugins/oalsound/test/plugin_test.cpp
deleted file mode 100644
index 40c1cd2..0000000
--- a/src/sound/plugins/oalsound/test/plugin_test.cpp
+++ /dev/null
@@ -1,40 +0,0 @@
-#include <string>
-#include <cstdio>
-#include <unistd.h>
-
-#include <common/logger.h>
-#include <common/iman.h>
-#include <sound/sound.h>
-#include <plugins/pluginloader.h>
-
-
-int main() {
- new CLogger();
- new CInstanceManager();
-
- lt_dlinit();
-
- CPluginLoader *plugin = new CPluginLoader("libopenalsound");
- if (plugin->LoadPlugin()) {
- CSoundInterface *sound = static_cast<CSoundInterface*>(CInstanceManager::GetInstancePointer()->SearchInstance(CLASS_SOUND));
-
- sound->Create(true);
- sound->CacheAll();
- sound->Play((Sound)8);
- sound->Play((Sound)18);
-
- sleep(10);
- /*
- while (1)
- {
- // just a test, very slow
- plugin->FrameMove(0);
- //if ('n' == getchar())
- // break;
- }*/
- plugin->UnloadPlugin();
- }
-
- lt_dlexit();
- return 0;
-}
diff --git a/src/sound/sound.h b/src/sound/sound.h
index c2b890f..518e2ad 100644
--- a/src/sound/sound.h
+++ b/src/sound/sound.h
@@ -28,8 +28,6 @@
#include "common/iman.h"
#include "common/logger.h"
-#include "plugins/plugininterface.h"
-
#include <string>
#include <iostream>
#include <iomanip>
@@ -152,7 +150,7 @@ enum SoundNext
* \brief Sound plugin interface
*
*/
-class CSoundInterface : public CPluginInterface
+class CSoundInterface
{
public:
inline CSoundInterface() {
@@ -170,7 +168,7 @@ class CSoundInterface : public CPluginInterface
* Function calls \link CSoundInterface::Cache() \endlink for each file
*/
inline void CacheAll(std::string path) {
- for ( int i = 1; i < 69; i++ ) {
+ for ( int i = 1; i <= 81; i++ ) {
std::stringstream filename;
filename << path << "/sound" << std::setfill('0') << std::setw(3) << i << ".wav";
if ( !Cache(static_cast<Sound>(i), filename.str()) )