Fix OSX build errors

This commit is contained in:
Murat Suri 2011-06-05 21:47:07 +00:00
parent a38f99589e
commit 313a043eff
4 changed files with 988 additions and 982 deletions

View File

@ -1,376 +1,376 @@
//****************************************************************
//cAudio 2.2.0 Tutorial 5
//Audio effects
//****************************************************************
#include <iostream>
#include <string>
///Include cAudio.h so we can work wtih cAudio
#include "cAudio.h"
#ifdef CAUDIO_PLATFORM_WIN
# define AUDIO_FILE(_soundName_) CAUDIO_MEDIA_ROOT##_soundName_
#else
# define AUDIO_FILE(_soundName_) CAUDIO_MEDIA_ROOT#_soundName_
#endif
using namespace std;
int main(int argc, char* argv[])
{
//Some fancy text
cout << "cAudio 2.2.0 Tutorial 5: Basic Audio Effects. \n \n";
//Create an uninitialized Audio Manager
cAudio::IAudioManager* manager = cAudio::createAudioManager(false);
if(manager)
{
//Allow the user to choose a playback device
cout << "\nAvailable Playback Devices: \n";
cAudio::IAudioDeviceList* pDeviceList = cAudio::createAudioDeviceList();
unsigned int deviceCount = pDeviceList->getDeviceCount();
cAudio::cAudioString defaultDeviceName = pDeviceList->getDefaultDeviceName();
for(unsigned int i=0; i<deviceCount; ++i)
{
cAudio::cAudioString deviceName = pDeviceList->getDeviceName(i);
if(deviceName.compare(defaultDeviceName) == 0)
cout << i << "): " << deviceName.c_str() << " [DEFAULT] \n";
else
cout << i << "): " << deviceName.c_str() << " \n";
}
cout << std::endl;
cout << "Choose a device by number: ";
unsigned int deviceSelection = 0;
cin >> deviceSelection;
cout << std::endl;
//Initialize the manager with the user settings
manager->initialize(pDeviceList->getDeviceName(deviceSelection).c_str());
CAUDIO_DELETE pDeviceList;
pDeviceList = 0;
#ifdef CAUDIO_EFX_ENABLED
cAudio::IAudioEffects* effects = manager->getEffects();
if(effects)
{
cAudio::IEffect* effect = effects->createEffect();
cAudio::IFilter* filter = effects->createFilter();
if(effect && effect->isValid() && filter && filter->isValid())
{
filter->setHighFrequencyVolume(0.1f);
filter->setLowFrequencyVolume(0.1f);
//Create a IAudio object and load a sound from a file
#ifdef CAUDIO_PLATFORM_WIN
cAudio::IAudioSource* mysound = manager->create("bling", AUDIO_FILE("Footsteps.wav"),false);
#else
cAudio::IAudioSource* mysound = manager->create("bling", AUDIO_FILE(Footsteps.wav),false);
#endif
if(mysound)
{
mysound->setVolume(1.0f);
mysound->attachFilter(filter);
mysound->attachEffect(0, effect);
std::cout << std::endl;
std::cout << "Simultaneous Effects Supported: " << effects->getMaxEffectsSupported() << ". \n";
std::cout << std::endl;
{
std::cout << "Playing sound with no effect or filter. \n";
filter->setType(cAudio::EFT_NULL);
effect->setType(cAudio::EET_NULL);
mysound->play2d(false);
while(mysound->isPlaying())
cAudio::cAudioSleep(10);
}
if(effects->isFilterSupported(cAudio::EFT_LOWPASS))
{
std::cout << "Playing sound with lowpass filter. \n";
filter->setType(cAudio::EFT_LOWPASS);
mysound->play2d(false);
while(mysound->isPlaying())
cAudio::cAudioSleep(10);
}
else
{
std::cout << "Lowpass filter not supported by this OpenAL device. \n";
}
if(effects->isFilterSupported(cAudio::EFT_HIGHPASS))
{
std::cout << "Playing sound with highpass filter. \n";
filter->setType(cAudio::EFT_HIGHPASS);
mysound->play2d(false);
while(mysound->isPlaying())
cAudio::cAudioSleep(10);
}
else
{
std::cout << "Highpass filter not supported by this OpenAL device. \n";
}
if(effects->isFilterSupported(cAudio::EFT_BANDPASS))
{
std::cout << "Playing sound with bandpass filter. \n";
filter->setType(cAudio::EFT_BANDPASS);
mysound->play2d(false);
while(mysound->isPlaying())
cAudio::cAudioSleep(10);
}
else
{
std::cout << "Bandpass filter not supported by this OpenAL device. \n";
}
filter->setType(cAudio::EFT_NULL);
if(effects->isEffectSupported(cAudio::EET_EAX_REVERB))
{
std::cout << "Playing sound with EAX Reverb effect. \n";
//Set the effect to a setting that distinctly shows off the effect (EAX_BATHROOM)
effect->setType(cAudio::EET_EAX_REVERB);
cAudio::sEAXReverbParameters param;
param.Gain = 0.316f;
param.GainHF = 0.251f;
param.GainLF = 1.0f;
param.Density = 0.17f;
param.DecayHFRatio = 0.54f;
param.ReflectionsGain = 0.653f;
param.ReflectionsDelay = 0.01f;
param.LateReverbDelay = 0.01f;
param.LateReverbGain = 3.273f;
effect->setEAXReverbParameters(param);
mysound->play2d(false);
while(mysound->isPlaying())
cAudio::cAudioSleep(10);
}
else
{
std::cout << "EAX Reverb effect not supported by this OpenAL device. \n";
}
if(effects->isEffectSupported(cAudio::EET_REVERB))
{
std::cout << "Playing sound with Reverb effect. \n";
//Set the effect to a setting that distinctly shows off the effect (EAX_BATHROOM)
effect->setType(cAudio::EET_REVERB);
cAudio::sReverbParameters param;
param.Gain = 0.316f;
param.GainHF = 0.251f;
param.Density = 0.17f;
param.DecayHFRatio = 0.54f;
param.ReflectionsGain = 0.653f;
param.ReflectionsDelay = 0.01f;
param.LateReverbDelay = 0.01f;
param.LateReverbGain = 3.273f;
effect->setReverbParameters(param);
mysound->play2d(false);
while(mysound->isPlaying())
cAudio::cAudioSleep(10);
}
else
{
std::cout << "Reverb effect not supported by this OpenAL device. \n";
}
if(effects->isEffectSupported(cAudio::EET_CHORUS))
{
std::cout << "Playing sound with Chorus effect. \n";
//Default settings
effect->setType(cAudio::EET_CHORUS);
mysound->play2d(false);
while(mysound->isPlaying())
cAudio::cAudioSleep(10);
}
else
{
std::cout << "Chorus effect not supported by this OpenAL device. \n";
}
if(effects->isEffectSupported(cAudio::EET_DISTORTION))
{
std::cout << "Playing sound with Distortion effect. \n";
//Default settings
effect->setType(cAudio::EET_DISTORTION);
mysound->play2d(false);
while(mysound->isPlaying())
cAudio::cAudioSleep(10);
}
else
{
std::cout << "Distortion effect not supported by this OpenAL device. \n";
}
if(effects->isEffectSupported(cAudio::EET_ECHO))
{
std::cout << "Playing sound with Echo effect. \n";
//Default settings
effect->setType(cAudio::EET_ECHO);
mysound->play2d(false);
while(mysound->isPlaying())
cAudio::cAudioSleep(10);
}
else
{
std::cout << "Echo effect not supported by this OpenAL device. \n";
}
if(effects->isEffectSupported(cAudio::EET_FLANGER))
{
std::cout << "Playing sound with Flanger effect. \n";
//Default settings
effect->setType(cAudio::EET_FLANGER);
mysound->play2d(false);
while(mysound->isPlaying())
cAudio::cAudioSleep(10);
}
else
{
std::cout << "Flanger effect not supported by this OpenAL device. \n";
}
if(effects->isEffectSupported(cAudio::EET_FREQUENCY_SHIFTER))
{
std::cout << "Playing sound with Frequency Shifter effect. \n";
//Default settings
effect->setType(cAudio::EET_FREQUENCY_SHIFTER);
mysound->play2d(false);
while(mysound->isPlaying())
cAudio::cAudioSleep(10);
}
else
{
std::cout << "Frequency Shifter effect not supported by this OpenAL device. \n";
}
if(effects->isEffectSupported(cAudio::EET_VOCAL_MORPHER))
{
std::cout << "Playing sound with Vocal Morpher effect. \n";
//Default settings
effect->setType(cAudio::EET_VOCAL_MORPHER);
mysound->play2d(false);
while(mysound->isPlaying())
cAudio::cAudioSleep(10);
}
else
{
std::cout << "Vocal Morpher effect not supported by this OpenAL device. \n";
}
if(effects->isEffectSupported(cAudio::EET_PITCH_SHIFTER))
{
std::cout << "Playing sound with Pitch Shifter effect. \n";
//Default settings
effect->setType(cAudio::EET_PITCH_SHIFTER);
mysound->play2d(false);
while(mysound->isPlaying())
cAudio::cAudioSleep(10);
}
else
{
std::cout << "Pitch Shifter effect not supported by this OpenAL device. \n";
}
if(effects->isEffectSupported(cAudio::EET_RING_MODULATOR))
{
std::cout << "Playing sound with Ring Modulator effect. \n";
//Default settings
effect->setType(cAudio::EET_RING_MODULATOR);
mysound->play2d(false);
while(mysound->isPlaying())
cAudio::cAudioSleep(10);
}
else
{
std::cout << "Ring Modulator effect not supported by this OpenAL device. \n";
}
if(effects->isEffectSupported(cAudio::EET_AUTOWAH))
{
std::cout << "Playing sound with Autowah effect. \n";
//Default settings
effect->setType(cAudio::EET_AUTOWAH);
mysound->play2d(false);
while(mysound->isPlaying())
cAudio::cAudioSleep(10);
}
else
{
std::cout << "Autowah effect not supported by this OpenAL device. \n";
}
if(effects->isEffectSupported(cAudio::EET_COMPRESSOR))
{
std::cout << "Playing sound with Compressor effect. \n";
//Default settings
effect->setType(cAudio::EET_COMPRESSOR);
mysound->play2d(false);
while(mysound->isPlaying())
cAudio::cAudioSleep(10);
}
else
{
std::cout << "Compressor effect not supported by this OpenAL device. \n";
}
if(effects->isEffectSupported(cAudio::EET_EQUALIZER))
{
std::cout << "Playing sound with Equalizer effect. \n";
//Default settings
effect->setType(cAudio::EET_EQUALIZER);
mysound->play2d(false);
while(mysound->isPlaying())
cAudio::cAudioSleep(10);
}
else
{
std::cout << "Equalizer effect not supported by this OpenAL device. \n";
}
}
manager->release(mysound);
filter->drop();
effect->drop();
}
}
#endif
//Delete all IAudio sounds
manager->releaseAllSources();
//Shutdown cAudio
manager->shutDown();
cAudio::destroyAudioManager(manager);
}
else
{
std::cout << "Failed to create audio playback manager. \n";
}
std::cout << "Press any key to quit \n";
std::cin.get();
std::cin.get();
return 0;
}
//****************************************************************
//cAudio 2.2.0 Tutorial 5
//Audio effects
//****************************************************************
#include <iostream>
#include <string>
///Include cAudio.h so we can work wtih cAudio
#include "cAudio.h"
#ifdef CAUDIO_PLATFORM_WIN
# define AUDIO_FILE(_soundName_) CAUDIO_MEDIA_ROOT##_soundName_
#else
# define AUDIO_FILE(_soundName_) CAUDIO_MEDIA_ROOT#_soundName_
#endif
using namespace std;
int main(int argc, char* argv[])
{
//Some fancy text
cout << "cAudio 2.2.0 Tutorial 5: Basic Audio Effects. \n \n";
//Create an uninitialized Audio Manager
cAudio::IAudioManager* manager = cAudio::createAudioManager(false);
if(manager)
{
//Allow the user to choose a playback device
cout << "\nAvailable Playback Devices: \n";
cAudio::IAudioDeviceList* pDeviceList = cAudio::createAudioDeviceList();
unsigned int deviceCount = pDeviceList->getDeviceCount();
cAudio::cAudioString defaultDeviceName = pDeviceList->getDefaultDeviceName();
for(unsigned int i=0; i<deviceCount; ++i)
{
cAudio::cAudioString deviceName = pDeviceList->getDeviceName(i);
if(deviceName.compare(defaultDeviceName) == 0)
cout << i << "): " << deviceName.c_str() << " [DEFAULT] \n";
else
cout << i << "): " << deviceName.c_str() << " \n";
}
cout << std::endl;
cout << "Choose a device by number: ";
unsigned int deviceSelection = 0;
cin >> deviceSelection;
cout << std::endl;
//Initialize the manager with the user settings
manager->initialize(pDeviceList->getDeviceName(deviceSelection).c_str());
CAUDIO_DELETE pDeviceList;
pDeviceList = 0;
#if CAUDIO_EFX_ENABLED == 1
cAudio::IAudioEffects* effects = manager->getEffects();
if(effects)
{
cAudio::IEffect* effect = effects->createEffect();
cAudio::IFilter* filter = effects->createFilter();
if(effect && effect->isValid() && filter && filter->isValid())
{
filter->setHighFrequencyVolume(0.1f);
filter->setLowFrequencyVolume(0.1f);
//Create a IAudio object and load a sound from a file
#ifdef CAUDIO_PLATFORM_WIN
cAudio::IAudioSource* mysound = manager->create("bling", AUDIO_FILE("Footsteps.wav"),false);
#else
cAudio::IAudioSource* mysound = manager->create("bling", AUDIO_FILE(Footsteps.wav),false);
#endif
if(mysound)
{
mysound->setVolume(1.0f);
mysound->attachFilter(filter);
mysound->attachEffect(0, effect);
std::cout << std::endl;
std::cout << "Simultaneous Effects Supported: " << effects->getMaxEffectsSupported() << ". \n";
std::cout << std::endl;
{
std::cout << "Playing sound with no effect or filter. \n";
filter->setType(cAudio::EFT_NULL);
effect->setType(cAudio::EET_NULL);
mysound->play2d(false);
while(mysound->isPlaying())
cAudio::cAudioSleep(10);
}
if(effects->isFilterSupported(cAudio::EFT_LOWPASS))
{
std::cout << "Playing sound with lowpass filter. \n";
filter->setType(cAudio::EFT_LOWPASS);
mysound->play2d(false);
while(mysound->isPlaying())
cAudio::cAudioSleep(10);
}
else
{
std::cout << "Lowpass filter not supported by this OpenAL device. \n";
}
if(effects->isFilterSupported(cAudio::EFT_HIGHPASS))
{
std::cout << "Playing sound with highpass filter. \n";
filter->setType(cAudio::EFT_HIGHPASS);
mysound->play2d(false);
while(mysound->isPlaying())
cAudio::cAudioSleep(10);
}
else
{
std::cout << "Highpass filter not supported by this OpenAL device. \n";
}
if(effects->isFilterSupported(cAudio::EFT_BANDPASS))
{
std::cout << "Playing sound with bandpass filter. \n";
filter->setType(cAudio::EFT_BANDPASS);
mysound->play2d(false);
while(mysound->isPlaying())
cAudio::cAudioSleep(10);
}
else
{
std::cout << "Bandpass filter not supported by this OpenAL device. \n";
}
filter->setType(cAudio::EFT_NULL);
if(effects->isEffectSupported(cAudio::EET_EAX_REVERB))
{
std::cout << "Playing sound with EAX Reverb effect. \n";
//Set the effect to a setting that distinctly shows off the effect (EAX_BATHROOM)
effect->setType(cAudio::EET_EAX_REVERB);
cAudio::sEAXReverbParameters param;
param.Gain = 0.316f;
param.GainHF = 0.251f;
param.GainLF = 1.0f;
param.Density = 0.17f;
param.DecayHFRatio = 0.54f;
param.ReflectionsGain = 0.653f;
param.ReflectionsDelay = 0.01f;
param.LateReverbDelay = 0.01f;
param.LateReverbGain = 3.273f;
effect->setEAXReverbParameters(param);
mysound->play2d(false);
while(mysound->isPlaying())
cAudio::cAudioSleep(10);
}
else
{
std::cout << "EAX Reverb effect not supported by this OpenAL device. \n";
}
if(effects->isEffectSupported(cAudio::EET_REVERB))
{
std::cout << "Playing sound with Reverb effect. \n";
//Set the effect to a setting that distinctly shows off the effect (EAX_BATHROOM)
effect->setType(cAudio::EET_REVERB);
cAudio::sReverbParameters param;
param.Gain = 0.316f;
param.GainHF = 0.251f;
param.Density = 0.17f;
param.DecayHFRatio = 0.54f;
param.ReflectionsGain = 0.653f;
param.ReflectionsDelay = 0.01f;
param.LateReverbDelay = 0.01f;
param.LateReverbGain = 3.273f;
effect->setReverbParameters(param);
mysound->play2d(false);
while(mysound->isPlaying())
cAudio::cAudioSleep(10);
}
else
{
std::cout << "Reverb effect not supported by this OpenAL device. \n";
}
if(effects->isEffectSupported(cAudio::EET_CHORUS))
{
std::cout << "Playing sound with Chorus effect. \n";
//Default settings
effect->setType(cAudio::EET_CHORUS);
mysound->play2d(false);
while(mysound->isPlaying())
cAudio::cAudioSleep(10);
}
else
{
std::cout << "Chorus effect not supported by this OpenAL device. \n";
}
if(effects->isEffectSupported(cAudio::EET_DISTORTION))
{
std::cout << "Playing sound with Distortion effect. \n";
//Default settings
effect->setType(cAudio::EET_DISTORTION);
mysound->play2d(false);
while(mysound->isPlaying())
cAudio::cAudioSleep(10);
}
else
{
std::cout << "Distortion effect not supported by this OpenAL device. \n";
}
if(effects->isEffectSupported(cAudio::EET_ECHO))
{
std::cout << "Playing sound with Echo effect. \n";
//Default settings
effect->setType(cAudio::EET_ECHO);
mysound->play2d(false);
while(mysound->isPlaying())
cAudio::cAudioSleep(10);
}
else
{
std::cout << "Echo effect not supported by this OpenAL device. \n";
}
if(effects->isEffectSupported(cAudio::EET_FLANGER))
{
std::cout << "Playing sound with Flanger effect. \n";
//Default settings
effect->setType(cAudio::EET_FLANGER);
mysound->play2d(false);
while(mysound->isPlaying())
cAudio::cAudioSleep(10);
}
else
{
std::cout << "Flanger effect not supported by this OpenAL device. \n";
}
if(effects->isEffectSupported(cAudio::EET_FREQUENCY_SHIFTER))
{
std::cout << "Playing sound with Frequency Shifter effect. \n";
//Default settings
effect->setType(cAudio::EET_FREQUENCY_SHIFTER);
mysound->play2d(false);
while(mysound->isPlaying())
cAudio::cAudioSleep(10);
}
else
{
std::cout << "Frequency Shifter effect not supported by this OpenAL device. \n";
}
if(effects->isEffectSupported(cAudio::EET_VOCAL_MORPHER))
{
std::cout << "Playing sound with Vocal Morpher effect. \n";
//Default settings
effect->setType(cAudio::EET_VOCAL_MORPHER);
mysound->play2d(false);
while(mysound->isPlaying())
cAudio::cAudioSleep(10);
}
else
{
std::cout << "Vocal Morpher effect not supported by this OpenAL device. \n";
}
if(effects->isEffectSupported(cAudio::EET_PITCH_SHIFTER))
{
std::cout << "Playing sound with Pitch Shifter effect. \n";
//Default settings
effect->setType(cAudio::EET_PITCH_SHIFTER);
mysound->play2d(false);
while(mysound->isPlaying())
cAudio::cAudioSleep(10);
}
else
{
std::cout << "Pitch Shifter effect not supported by this OpenAL device. \n";
}
if(effects->isEffectSupported(cAudio::EET_RING_MODULATOR))
{
std::cout << "Playing sound with Ring Modulator effect. \n";
//Default settings
effect->setType(cAudio::EET_RING_MODULATOR);
mysound->play2d(false);
while(mysound->isPlaying())
cAudio::cAudioSleep(10);
}
else
{
std::cout << "Ring Modulator effect not supported by this OpenAL device. \n";
}
if(effects->isEffectSupported(cAudio::EET_AUTOWAH))
{
std::cout << "Playing sound with Autowah effect. \n";
//Default settings
effect->setType(cAudio::EET_AUTOWAH);
mysound->play2d(false);
while(mysound->isPlaying())
cAudio::cAudioSleep(10);
}
else
{
std::cout << "Autowah effect not supported by this OpenAL device. \n";
}
if(effects->isEffectSupported(cAudio::EET_COMPRESSOR))
{
std::cout << "Playing sound with Compressor effect. \n";
//Default settings
effect->setType(cAudio::EET_COMPRESSOR);
mysound->play2d(false);
while(mysound->isPlaying())
cAudio::cAudioSleep(10);
}
else
{
std::cout << "Compressor effect not supported by this OpenAL device. \n";
}
if(effects->isEffectSupported(cAudio::EET_EQUALIZER))
{
std::cout << "Playing sound with Equalizer effect. \n";
//Default settings
effect->setType(cAudio::EET_EQUALIZER);
mysound->play2d(false);
while(mysound->isPlaying())
cAudio::cAudioSleep(10);
}
else
{
std::cout << "Equalizer effect not supported by this OpenAL device. \n";
}
}
manager->release(mysound);
filter->drop();
effect->drop();
}
}
#endif
//Delete all IAudio sounds
manager->releaseAllSources();
//Shutdown cAudio
manager->shutDown();
cAudio::destroyAudioManager(manager);
}
else
{
std::cout << "Failed to create audio playback manager. \n";
}
std::cout << "Press any key to quit \n";
std::cin.get();
std::cin.get();
return 0;
}

View File

@ -27,6 +27,8 @@
# else
# define CAUDIO_API extern "C"
# endif // CAUDIO_STATIC_LIB
#else
# define CAUDIO_API
#endif
//! Define enables threading for the main update loop. Disable to run the internal update loop yourself. NOTE: Internal threading should NOT be used if the library is not thread safe!

View File

@ -1,496 +1,498 @@
// Copyright (c) 2008-2011 Raynaldo (Wildicv) Rivera, Joshua (Dark_Kilauea) Jones, Murat (wolfmanfx) Sari
// This file is part of the "cAudio Engine"
// For conditions of distribution and use, see copyright notice in cAudio.h
#include "cAudioManager.h"
#include "cAudio.h"
#include "cAudioSource.h"
#include "cAudioPlatform.h"
#include "cAudioSleep.h"
#include "cUtils.h"
#include "cThread.h"
#include "cLogger.h"
#include "cPluginManager.h"
#include "cThread.h"
#include "cMemorySource.h"
#include "cRawAudioDecoderFactory.h"
#include <string.h>
#include <algorithm>
#include "cOpenALDeviceContext.h"
namespace cAudio
{
cAudioManager::~cAudioManager()
{
shutDown();
}
bool cAudioManager::initialize(const char* deviceName, int outputFrequency, int eaxEffectSlots)
{
cAudioMutexBasicLock lock(Mutex);
if(Initialized)
return false;
AudioContext = CAUDIO_NEW cOpenALDeviceContext(this);
if(!AudioContext->initialize(deviceName, outputFrequency, eaxEffectSlots))
return false;
#ifdef CAUDIO_USE_INTERNAL_THREAD
if (!AudioThread)
{
AudioThread = new cAudioThread(this);
}
AudioThread->start();
#endif
Initialized = true;
return true;
}
void cAudioManager::shutDown()
{
if(Initialized)
{
if (AudioThread) // First wait for our update thread to finish up
{
AudioThread->join();
delete AudioThread;
AudioThread = NULL;
}
cAudioMutexBasicLock lock(Mutex);
releaseAllSources();
// For conditions of distribution and use, see copyright notice in cAudio.h
#include "cAudioManager.h"
#include "cAudio.h"
#include "cAudioSource.h"
#include "cAudioPlatform.h"
#include "cAudioSleep.h"
#include "cUtils.h"
#include "cThread.h"
#include "cLogger.h"
#include "cPluginManager.h"
#include "cThread.h"
#include "cMemorySource.h"
#include "cRawAudioDecoderFactory.h"
#include <string.h>
#include <algorithm>
#include "cOpenALDeviceContext.h"
namespace cAudio
{
cAudioManager::~cAudioManager()
{
shutDown();
}
bool cAudioManager::initialize(const char* deviceName, int outputFrequency, int eaxEffectSlots)
{
cAudioMutexBasicLock lock(Mutex);
if(Initialized)
return false;
AudioContext = CAUDIO_NEW cOpenALDeviceContext(this);
if(!AudioContext->initialize(deviceName, outputFrequency, eaxEffectSlots))
return false;
#ifdef CAUDIO_USE_INTERNAL_THREAD
if (!AudioThread)
{
AudioThread = new cAudioThread(this);
}
AudioThread->start();
#endif
Initialized = true;
return true;
}
void cAudioManager::shutDown()
{
if(Initialized)
{
if (AudioThread) // First wait for our update thread to finish up
{
AudioThread->join();
delete AudioThread;
AudioThread = NULL;
}
cAudioMutexBasicLock lock(Mutex);
releaseAllSources();
if (AudioContext)
{
AudioContext->shutDown();
CAUDIO_DELETE AudioContext;
AudioContext->shutDown();
CAUDIO_DELETE AudioContext;
AudioContext = NULL;
}
Initialized = false;
getLogger()->logInfo("AudioManager", "Manager successfully shutdown.");
}
}
void cAudioManager::update()
{
cAudioMutexBasicLock lock(Mutex);
size_t count = audioSources.size();
for(unsigned int i=0; i<count; i++)
{
IAudioSource* source = audioSources[i];
if (source->isValid())
{
source->update();
}
}
}
void cAudioManager::run()
{
if(!audioSources.empty())
update();
}
Initialized = false;
getLogger()->logInfo("AudioManager", "Manager successfully shutdown.");
}
}
void cAudioManager::update()
{
cAudioMutexBasicLock lock(Mutex);
size_t count = audioSources.size();
for(unsigned int i=0; i<count; i++)
{
IAudioSource* source = audioSources[i];
if (source->isValid())
{
source->update();
}
}
}
void cAudioManager::run()
{
if(!audioSources.empty())
update();
cAudioSleep(1);
}
bool cAudioManager::isUpdateThreadRunning()
{
return (AudioThread != NULL && AudioThread->isRunning());
}
IAudioEffects* cAudioManager::getEffects()
{
cAudioSleep(1);
}
bool cAudioManager::isUpdateThreadRunning()
{
return (AudioThread != NULL && AudioThread->isRunning());
}
#if CAUDIO_EFX_ENABLED == 1
IAudioEffects* cAudioManager::getEffects()
{
if (AudioContext)
{
return AudioContext->getEffects();
}
return NULL;
}
IAudioSource* cAudioManager::createAudioSource(IAudioDecoder* decoder, const cAudioString& audioName, const cAudioString& dataSource)
{
if(decoder && decoder->isValid())
{
#if CAUDIO_EFX_ENABLED == 1
IAudioSource* audio = CAUDIO_NEW cAudioSource(decoder, ((cOpenALDeviceContext*)AudioContext)->getOpenALContext(), ((cAudioEffects*)getEffects())->getEFXInterface());
#else
IAudioSource* audio = CAUDIO_NEW cAudioSource(decoder, ((cOpenALDeviceContext*)AudioContext)->getOpenALContext());
#endif
decoder->drop();
if(audio && audio->isValid())
{
if(!audioName.empty())
audioIndex[audioName] = audio;
audioSources.push_back(audio);
getLogger()->logInfo("AudioManager", "Audio Source (%s) created from Data Source %s.", audioName.c_str(), dataSource.c_str());
return audio;
}
getLogger()->logError("AudioManager", "Failed to create Audio Source (%s): Error creating audio source.", audioName.c_str());
audio->drop();
return NULL;
}
getLogger()->logError("AudioManager", "Failed to create Audio Source (%s): Audio data could not be decoded by (.%s) decoder.", audioName.c_str(), decoder->getType());
decoder->drop();
return NULL;
}
IAudioSource* cAudioManager::create(const char* name, const char* filename, bool stream)
{
if(!Initialized) return NULL;
cAudioMutexBasicLock lock(Mutex);
cAudioString audioName = safeCStr(name);
cAudioString path = safeCStr(filename);
cAudioString ext = getExt(path);
IAudioDecoderFactory* factory = getAudioDecoderFactory(ext.c_str());
if(!factory) {
getLogger()->logError("AudioManager", "Failed to create Audio Source (%s): No decoder could be found for (.%s).", audioName.c_str(), ext.c_str());
return NULL;
}
for(size_t i=0; i<dataSourcePriorityList.size(); ++i)
{
const cAudioString dataSourceName = dataSourcePriorityList[i].second;
IDataSourceFactory* dataFactory = datasourcemap[dataSourceName];
if(dataFactory)
{
IDataSource* source = dataFactory->CreateDataSource(filename, stream);
if(source && source->isValid())
{
IAudioDecoder* decoder = factory->CreateAudioDecoder(source);
source->drop();
IAudioSource* audio = createAudioSource(decoder, audioName, dataSourceName);
if(audio != NULL)
return audio;
if(source)
source->drop();
return NULL;
}
}
}
return NULL;
}
IAudioSource* cAudioManager::createFromMemory(const char* name, const char* data, size_t length, const char* extension)
{
if(!Initialized) return NULL;
cAudioMutexBasicLock lock(Mutex);
cAudioString audioName = safeCStr(name);
cAudioString ext = safeCStr(extension);
IAudioDecoderFactory* factory = getAudioDecoderFactory(ext.c_str());
if(!factory) {
getLogger()->logError("AudioManager", "Failed to create Audio Source (%s): Codec (.%s) is not supported.", audioName.c_str(), ext.c_str());
return NULL;
}
cMemorySource* source = CAUDIO_NEW cMemorySource(data, length, true);
if(source && source->isValid())
{
IAudioDecoder* decoder = factory->CreateAudioDecoder(source);
source->drop();
IAudioSource* audio = createAudioSource(decoder, audioName, "cMemorySource");
if(audio != NULL)
return audio;
if(source)
source->drop();
}
return NULL;
}
IAudioSource* cAudioManager::createFromRaw(const char* name, const char* data, size_t length, unsigned int frequency, AudioFormats format)
{
if(!Initialized) return NULL;
cAudioMutexBasicLock lock(Mutex);
cAudioString audioName = safeCStr(name);
IAudioDecoderFactory* factory = getAudioDecoderFactory("raw");
if(!factory) {
getLogger()->logError("AudioManager", "Failed to create Audio Source (%s): Codec (.raw) is not supported.", audioName.c_str());
return NULL;
}
cMemorySource* source = CAUDIO_NEW cMemorySource(data, length, true);
if(source && source->isValid())
{
IAudioDecoder* decoder = ((cRawAudioDecoderFactory*)factory)->CreateAudioDecoder(source, frequency, format);
source->drop();
IAudioSource* audio = createAudioSource(decoder, audioName, "cMemorySource");
if(audio != NULL)
return audio;
if(source)
source->drop();
}
return NULL;
}
bool cAudioManager::registerAudioDecoder(IAudioDecoderFactory* factory, const char* extension)
{
cAudioMutexBasicLock lock(Mutex);
cAudioString ext = safeCStr(extension);
decodermap[ext] = factory;
getLogger()->logInfo("AudioManager", "Audio Decoder for extension .%s registered.", ext.c_str());
return true;
}
void cAudioManager::unRegisterAudioDecoder(const char* extension)
{
cAudioMutexBasicLock lock(Mutex);
cAudioString ext = safeCStr(extension);
decodermapIterator it = decodermap.find(ext);
if(it != decodermap.end())
{
decodermap.erase(it);
getLogger()->logInfo("AudioManager", "Audio Decoder for extension .%s unregistered.", ext.c_str());
}
}
bool cAudioManager::isAudioDecoderRegistered(const char* extension)
{
cAudioMutexBasicLock lock(Mutex);
cAudioString ext = safeCStr(extension);
decodermapIterator it = decodermap.find(ext);
return (it != decodermap.end());
}
IAudioDecoderFactory* cAudioManager::getAudioDecoderFactory(const char* extension)
{
cAudioMutexBasicLock lock(Mutex);
cAudioString ext = safeCStr(extension);
decodermapIterator it = decodermap.find(ext);
if(it != decodermap.end())
{
return it->second;
}
return NULL;
}
void cAudioManager::unRegisterAllAudioDecoders()
{
cAudioMutexBasicLock lock(Mutex);
decodermap.clear();
}
bool compareDataSourcePriorities(std::pair<int, cAudioString> left, std::pair<int, cAudioString> right)
{
return (left.first > right.first);
}
bool cAudioManager::registerDataSource(IDataSourceFactory* factory, const char* name, int priority)
{
cAudioMutexBasicLock lock(Mutex);
cAudioString safeName = safeCStr(name);
datasourcemap[safeName] = factory;
dataSourcePriorityList.push_back(std::pair<int, cAudioString>(priority, safeName));
std::sort(dataSourcePriorityList.begin(), dataSourcePriorityList.end(), compareDataSourcePriorities);
getLogger()->logInfo("AudioManager", "Data Source named %s registered (Priority %i).", safeName.c_str(), priority);
return true;
}
void cAudioManager::unRegisterDataSource(const char* name)
{
cAudioMutexBasicLock lock(Mutex);
cAudioString safeName = safeCStr(name);
datasourcemapIterator it = datasourcemap.find(safeName);
if(it != datasourcemap.end())
{
datasourcemap.erase(it);
getLogger()->logInfo("AudioManager", "Data Source named %s unregistered.", safeName.c_str());
}
for(size_t i=0; i<dataSourcePriorityList.size(); ++i)
{
if(dataSourcePriorityList[i].second == safeName)
{
dataSourcePriorityList.erase(dataSourcePriorityList.begin()+i);
break;
}
}
std::sort(dataSourcePriorityList.begin(), dataSourcePriorityList.end(), compareDataSourcePriorities);
}
bool cAudioManager::isDataSourceRegistered(const char* name)
{
cAudioMutexBasicLock lock(Mutex);
cAudioString safeName = safeCStr(name);
datasourcemapIterator it = datasourcemap.find(safeName);
return (it != datasourcemap.end());
}
IDataSourceFactory* cAudioManager::getDataSourceFactory(const char* name)
{
cAudioMutexBasicLock lock(Mutex);
cAudioString safeName = safeCStr(name);
datasourcemapIterator it = datasourcemap.find(safeName);
if(it != datasourcemap.end())
{
return it->second;
}
return NULL;
}
void cAudioManager::unRegisterAllDataSources()
{
cAudioMutexBasicLock lock(Mutex);
datasourcemap.clear();
dataSourcePriorityList.clear();
}
void cAudioManager::registerEventHandler(IManagerEventHandler* handler)
{
if(handler)
{
eventHandlerList.push_back(handler);
}
}
void cAudioManager::unRegisterEventHandler(IManagerEventHandler* handler)
{
if(handler)
{
eventHandlerList.remove(handler);
}
}
void cAudioManager::unRegisterAllEventHandlers()
{
eventHandlerList.clear();
}
void cAudioManager::signalEvent(Events sevent)
{
cAudioMutexBasicLock lock(Mutex);
cAudioList<IManagerEventHandler*>::Type::iterator it = eventHandlerList.begin();
if(it != eventHandlerList.end())
{
switch(sevent)
{
case ON_INIT:
for(it; it != eventHandlerList.end(); it++)
{
(*it)->onInit();
}
break;
case ON_UPDATE:
for(it; it != eventHandlerList.end(); it++)
{
(*it)->onUpdate();
}
break;
case ON_RELEASE:
for(it; it != eventHandlerList.end(); it++)
{
(*it)->onRelease();
}
break;
case ON_SOURCECREATE:
for(it; it != eventHandlerList.end(); it++)
{
(*it)->onSourceCreate();
}
break;
case ON_DECODERREGISTER:
for(it; it != eventHandlerList.end(); it++)
{
(*it)->onDecoderRegister();
}
break;
case ON_DATASOURCEREGISTER:
for(it; it != eventHandlerList.end(); it++)
{
(*it)->onDataSourceRegister();
}
break;
}
}
}
IAudioSource* cAudioManager::getSoundByName(const char* name)
{
cAudioMutexBasicLock lock(Mutex);
cAudioString audioName = safeCStr(name);
audioIndexIterator i = audioIndex.find(audioName);
if (i == audioIndex.end())
{
return NULL;
}
return i->second;
}
void cAudioManager::releaseAllSources()
{
cAudioMutexBasicLock lock(Mutex);
for(unsigned int i=0; i<audioSources.size(); ++i)
{
IAudioSource* source = audioSources[i];
if(source)
source->drop();
}
audioSources.clear();
audioIndex.clear();
}
void cAudioManager::release(IAudioSource* source)
{
if(source)
{
cAudioMutexBasicLock lock(Mutex);
audioIndexIterator it = audioIndex.begin();
for ( it=audioIndex.begin(); it != audioIndex.end(); it++ )
{
if( it->second == source )
{
audioIndex.erase(it);
break;
}
}
for(unsigned int i=0; i<audioSources.size(); ++i)
{
if(source == audioSources[i])
{
audioSources.erase(audioSources.begin()+i);
source->drop();
break;
}
}
}
}
};
{
return AudioContext->getEffects();
}
return NULL;
}
#endif
IAudioSource* cAudioManager::createAudioSource(IAudioDecoder* decoder, const cAudioString& audioName, const cAudioString& dataSource)
{
if(decoder && decoder->isValid())
{
#if CAUDIO_EFX_ENABLED == 1
IAudioSource* audio = CAUDIO_NEW cAudioSource(decoder, ((cOpenALDeviceContext*)AudioContext)->getOpenALContext(), ((cAudioEffects*)getEffects())->getEFXInterface());
#else
IAudioSource* audio = CAUDIO_NEW cAudioSource(decoder, ((cOpenALDeviceContext*)AudioContext)->getOpenALContext());
#endif
decoder->drop();
if(audio && audio->isValid())
{
if(!audioName.empty())
audioIndex[audioName] = audio;
audioSources.push_back(audio);
getLogger()->logInfo("AudioManager", "Audio Source (%s) created from Data Source %s.", audioName.c_str(), dataSource.c_str());
return audio;
}
getLogger()->logError("AudioManager", "Failed to create Audio Source (%s): Error creating audio source.", audioName.c_str());
audio->drop();
return NULL;
}
getLogger()->logError("AudioManager", "Failed to create Audio Source (%s): Audio data could not be decoded by (.%s) decoder.", audioName.c_str(), decoder->getType().c_str());
decoder->drop();
return NULL;
}
IAudioSource* cAudioManager::create(const char* name, const char* filename, bool stream)
{
if(!Initialized) return NULL;
cAudioMutexBasicLock lock(Mutex);
cAudioString audioName = safeCStr(name);
cAudioString path = safeCStr(filename);
cAudioString ext = getExt(path);
IAudioDecoderFactory* factory = getAudioDecoderFactory(ext.c_str());
if(!factory) {
getLogger()->logError("AudioManager", "Failed to create Audio Source (%s): No decoder could be found for (.%s).", audioName.c_str(), ext.c_str());
return NULL;
}
for(size_t i=0; i<dataSourcePriorityList.size(); ++i)
{
const cAudioString dataSourceName = dataSourcePriorityList[i].second;
IDataSourceFactory* dataFactory = datasourcemap[dataSourceName];
if(dataFactory)
{
IDataSource* source = dataFactory->CreateDataSource(filename, stream);
if(source && source->isValid())
{
IAudioDecoder* decoder = factory->CreateAudioDecoder(source);
source->drop();
IAudioSource* audio = createAudioSource(decoder, audioName, dataSourceName);
if(audio != NULL)
return audio;
if(source)
source->drop();
return NULL;
}
}
}
return NULL;
}
IAudioSource* cAudioManager::createFromMemory(const char* name, const char* data, size_t length, const char* extension)
{
if(!Initialized) return NULL;
cAudioMutexBasicLock lock(Mutex);
cAudioString audioName = safeCStr(name);
cAudioString ext = safeCStr(extension);
IAudioDecoderFactory* factory = getAudioDecoderFactory(ext.c_str());
if(!factory) {
getLogger()->logError("AudioManager", "Failed to create Audio Source (%s): Codec (.%s) is not supported.", audioName.c_str(), ext.c_str());
return NULL;
}
cMemorySource* source = CAUDIO_NEW cMemorySource(data, length, true);
if(source && source->isValid())
{
IAudioDecoder* decoder = factory->CreateAudioDecoder(source);
source->drop();
IAudioSource* audio = createAudioSource(decoder, audioName, "cMemorySource");
if(audio != NULL)
return audio;
if(source)
source->drop();
}
return NULL;
}
IAudioSource* cAudioManager::createFromRaw(const char* name, const char* data, size_t length, unsigned int frequency, AudioFormats format)
{
if(!Initialized) return NULL;
cAudioMutexBasicLock lock(Mutex);
cAudioString audioName = safeCStr(name);
IAudioDecoderFactory* factory = getAudioDecoderFactory("raw");
if(!factory) {
getLogger()->logError("AudioManager", "Failed to create Audio Source (%s): Codec (.raw) is not supported.", audioName.c_str());
return NULL;
}
cMemorySource* source = CAUDIO_NEW cMemorySource(data, length, true);
if(source && source->isValid())
{
IAudioDecoder* decoder = ((cRawAudioDecoderFactory*)factory)->CreateAudioDecoder(source, frequency, format);
source->drop();
IAudioSource* audio = createAudioSource(decoder, audioName, "cMemorySource");
if(audio != NULL)
return audio;
if(source)
source->drop();
}
return NULL;
}
bool cAudioManager::registerAudioDecoder(IAudioDecoderFactory* factory, const char* extension)
{
cAudioMutexBasicLock lock(Mutex);
cAudioString ext = safeCStr(extension);
decodermap[ext] = factory;
getLogger()->logInfo("AudioManager", "Audio Decoder for extension .%s registered.", ext.c_str());
return true;
}
void cAudioManager::unRegisterAudioDecoder(const char* extension)
{
cAudioMutexBasicLock lock(Mutex);
cAudioString ext = safeCStr(extension);
decodermapIterator it = decodermap.find(ext);
if(it != decodermap.end())
{
decodermap.erase(it);
getLogger()->logInfo("AudioManager", "Audio Decoder for extension .%s unregistered.", ext.c_str());
}
}
bool cAudioManager::isAudioDecoderRegistered(const char* extension)
{
cAudioMutexBasicLock lock(Mutex);
cAudioString ext = safeCStr(extension);
decodermapIterator it = decodermap.find(ext);
return (it != decodermap.end());
}
IAudioDecoderFactory* cAudioManager::getAudioDecoderFactory(const char* extension)
{
cAudioMutexBasicLock lock(Mutex);
cAudioString ext = safeCStr(extension);
decodermapIterator it = decodermap.find(ext);
if(it != decodermap.end())
{
return it->second;
}
return NULL;
}
void cAudioManager::unRegisterAllAudioDecoders()
{
cAudioMutexBasicLock lock(Mutex);
decodermap.clear();
}
bool compareDataSourcePriorities(std::pair<int, cAudioString> left, std::pair<int, cAudioString> right)
{
return (left.first > right.first);
}
bool cAudioManager::registerDataSource(IDataSourceFactory* factory, const char* name, int priority)
{
cAudioMutexBasicLock lock(Mutex);
cAudioString safeName = safeCStr(name);
datasourcemap[safeName] = factory;
dataSourcePriorityList.push_back(std::pair<int, cAudioString>(priority, safeName));
std::sort(dataSourcePriorityList.begin(), dataSourcePriorityList.end(), compareDataSourcePriorities);
getLogger()->logInfo("AudioManager", "Data Source named %s registered (Priority %i).", safeName.c_str(), priority);
return true;
}
void cAudioManager::unRegisterDataSource(const char* name)
{
cAudioMutexBasicLock lock(Mutex);
cAudioString safeName = safeCStr(name);
datasourcemapIterator it = datasourcemap.find(safeName);
if(it != datasourcemap.end())
{
datasourcemap.erase(it);
getLogger()->logInfo("AudioManager", "Data Source named %s unregistered.", safeName.c_str());
}
for(size_t i=0; i<dataSourcePriorityList.size(); ++i)
{
if(dataSourcePriorityList[i].second == safeName)
{
dataSourcePriorityList.erase(dataSourcePriorityList.begin()+i);
break;
}
}
std::sort(dataSourcePriorityList.begin(), dataSourcePriorityList.end(), compareDataSourcePriorities);
}
bool cAudioManager::isDataSourceRegistered(const char* name)
{
cAudioMutexBasicLock lock(Mutex);
cAudioString safeName = safeCStr(name);
datasourcemapIterator it = datasourcemap.find(safeName);
return (it != datasourcemap.end());
}
IDataSourceFactory* cAudioManager::getDataSourceFactory(const char* name)
{
cAudioMutexBasicLock lock(Mutex);
cAudioString safeName = safeCStr(name);
datasourcemapIterator it = datasourcemap.find(safeName);
if(it != datasourcemap.end())
{
return it->second;
}
return NULL;
}
void cAudioManager::unRegisterAllDataSources()
{
cAudioMutexBasicLock lock(Mutex);
datasourcemap.clear();
dataSourcePriorityList.clear();
}
void cAudioManager::registerEventHandler(IManagerEventHandler* handler)
{
if(handler)
{
eventHandlerList.push_back(handler);
}
}
void cAudioManager::unRegisterEventHandler(IManagerEventHandler* handler)
{
if(handler)
{
eventHandlerList.remove(handler);
}
}
void cAudioManager::unRegisterAllEventHandlers()
{
eventHandlerList.clear();
}
void cAudioManager::signalEvent(Events sevent)
{
cAudioMutexBasicLock lock(Mutex);
cAudioList<IManagerEventHandler*>::Type::iterator it = eventHandlerList.begin();
if(it != eventHandlerList.end())
{
switch(sevent)
{
case ON_INIT:
for(it; it != eventHandlerList.end(); it++)
{
(*it)->onInit();
}
break;
case ON_UPDATE:
for(it; it != eventHandlerList.end(); it++)
{
(*it)->onUpdate();
}
break;
case ON_RELEASE:
for(it; it != eventHandlerList.end(); it++)
{
(*it)->onRelease();
}
break;
case ON_SOURCECREATE:
for(it; it != eventHandlerList.end(); it++)
{
(*it)->onSourceCreate();
}
break;
case ON_DECODERREGISTER:
for(it; it != eventHandlerList.end(); it++)
{
(*it)->onDecoderRegister();
}
break;
case ON_DATASOURCEREGISTER:
for(it; it != eventHandlerList.end(); it++)
{
(*it)->onDataSourceRegister();
}
break;
}
}
}
IAudioSource* cAudioManager::getSoundByName(const char* name)
{
cAudioMutexBasicLock lock(Mutex);
cAudioString audioName = safeCStr(name);
audioIndexIterator i = audioIndex.find(audioName);
if (i == audioIndex.end())
{
return NULL;
}
return i->second;
}
void cAudioManager::releaseAllSources()
{
cAudioMutexBasicLock lock(Mutex);
for(unsigned int i=0; i<audioSources.size(); ++i)
{
IAudioSource* source = audioSources[i];
if(source)
source->drop();
}
audioSources.clear();
audioIndex.clear();
}
void cAudioManager::release(IAudioSource* source)
{
if(source)
{
cAudioMutexBasicLock lock(Mutex);
audioIndexIterator it = audioIndex.begin();
for ( it=audioIndex.begin(); it != audioIndex.end(); it++ )
{
if( it->second == source )
{
audioIndex.erase(it);
break;
}
}
for(unsigned int i=0; i<audioSources.size(); ++i)
{
if(source == audioSources[i])
{
audioSources.erase(audioSources.begin()+i);
source->drop();
break;
}
}
}
}
};

View File

@ -7,14 +7,14 @@
#include "cLogger.h"
#include "cAudioEffects.h"
#if CAUDIO_EFX_ENABLED == 1
# ifdef CAUDIO_PLATFORM_WIN
# include <efx.h>
# include <efx-creative.h>
# include <xram.h>
# elif defined(CAUDIO_PLATFORM_LINUX)
# include <AL/alext.h>
# endif
#if CAUDIO_EFX_ENABLED == 1
# ifdef CAUDIO_PLATFORM_WIN
# include <efx.h>
# include <efx-creative.h>
# include <xram.h>
# elif defined(CAUDIO_PLATFORM_LINUX)
# include <AL/alext.h>
# endif
#endif
namespace cAudio
@ -36,78 +36,78 @@ namespace cAudio
if(Initialized)
return false;
//Stores the context attributes (MAX of 4, with 2 zeros to terminate)
ALint attribs[6] = { 0 };
unsigned int currentAttrib = 0;
if(outputFrequency > 0)
{
attribs[currentAttrib++] = ALC_FREQUENCY;
attribs[currentAttrib++] = outputFrequency;
}
#if CAUDIO_EFX_ENABLED == 1
if(eaxEffectSlots > 0)
{
attribs[currentAttrib++] = ALC_MAX_AUXILIARY_SENDS;
attribs[currentAttrib++] = eaxEffectSlots;
}
#endif
//Create a new device
Device = alcOpenDevice(deviceName);
//Check if device can be created
if (Device == NULL)
{
getLogger()->logError("AudioManager", "Failed to Create OpenAL Device.");
checkError();
return false;
}
Context = alcCreateContext(Device, attribs);
if (Context == NULL)
{
getLogger()->logError("AudioManager", "Failed to Create OpenAL Context.");
checkError();
alcCloseDevice(Device);
Device = NULL;
return false;
}
if(!alcMakeContextCurrent(Context))
{
getLogger()->logError("AudioManager", "Failed to make OpenAL Context current.");
checkError();
alcDestroyContext(Context);
alcCloseDevice(Device);
Context = NULL;
Device = NULL;
return false;
}
getLogger()->logInfo("AudioManager", "OpenAL Version: %s", alGetString(AL_VERSION));
getLogger()->logInfo("AudioManager", "Vendor: %s", alGetString(AL_VENDOR));
getLogger()->logInfo("AudioManager", "Renderer: %s", alGetString(AL_RENDERER));
#if CAUDIO_EFX_ENABLED == 1
initEffects.getEFXInterface()->Mutex.lock();
EFXSupported = initEffects.getEFXInterface()->CheckEFXSupport(Device);
initEffects.getEFXInterface()->Mutex.unlock();
initEffects.checkEFXSupportDetails();
if(EFXSupported)
{
int EFXMajorVersion = 0;
int EFXMinorVersion = 0;
alcGetIntegerv(Device, ALC_EFX_MAJOR_VERSION, 1, &EFXMajorVersion);
alcGetIntegerv(Device, ALC_EFX_MINOR_VERSION, 1, &EFXMinorVersion);
getLogger()->logInfo("AudioManager", "EFX Version: %i.%i", EFXMajorVersion, EFXMinorVersion);
getLogger()->logInfo("AudioManager", "EFX supported and enabled.");
}
else
{
getLogger()->logWarning("AudioManager", "EFX is not supported, EFX disabled.");
}
#endif
//Stores the context attributes (MAX of 4, with 2 zeros to terminate)
ALint attribs[6] = { 0 };
unsigned int currentAttrib = 0;
if(outputFrequency > 0)
{
attribs[currentAttrib++] = ALC_FREQUENCY;
attribs[currentAttrib++] = outputFrequency;
}
#if CAUDIO_EFX_ENABLED == 1
if(eaxEffectSlots > 0)
{
attribs[currentAttrib++] = ALC_MAX_AUXILIARY_SENDS;
attribs[currentAttrib++] = eaxEffectSlots;
}
#endif
//Create a new device
Device = alcOpenDevice(deviceName);
//Check if device can be created
if (Device == NULL)
{
getLogger()->logError("AudioManager", "Failed to Create OpenAL Device.");
checkError();
return false;
}
Context = alcCreateContext(Device, attribs);
if (Context == NULL)
{
getLogger()->logError("AudioManager", "Failed to Create OpenAL Context.");
checkError();
alcCloseDevice(Device);
Device = NULL;
return false;
}
if(!alcMakeContextCurrent(Context))
{
getLogger()->logError("AudioManager", "Failed to make OpenAL Context current.");
checkError();
alcDestroyContext(Context);
alcCloseDevice(Device);
Context = NULL;
Device = NULL;
return false;
}
getLogger()->logInfo("AudioManager", "OpenAL Version: %s", alGetString(AL_VERSION));
getLogger()->logInfo("AudioManager", "Vendor: %s", alGetString(AL_VENDOR));
getLogger()->logInfo("AudioManager", "Renderer: %s", alGetString(AL_RENDERER));
#if CAUDIO_EFX_ENABLED == 1
initEffects.getEFXInterface()->Mutex.lock();
EFXSupported = initEffects.getEFXInterface()->CheckEFXSupport(Device);
initEffects.getEFXInterface()->Mutex.unlock();
initEffects.checkEFXSupportDetails();
if(EFXSupported)
{
int EFXMajorVersion = 0;
int EFXMinorVersion = 0;
alcGetIntegerv(Device, ALC_EFX_MAJOR_VERSION, 1, &EFXMajorVersion);
alcGetIntegerv(Device, ALC_EFX_MINOR_VERSION, 1, &EFXMinorVersion);
getLogger()->logInfo("AudioManager", "EFX Version: %i.%i", EFXMajorVersion, EFXMinorVersion);
getLogger()->logInfo("AudioManager", "EFX supported and enabled.");
}
else
{
getLogger()->logWarning("AudioManager", "EFX is not supported, EFX disabled.");
}
#endif
getLogger()->logInfo("AudioManager", "Supported Extensions: %s", alGetString(AL_EXTENSIONS));
return true;
@ -115,20 +115,20 @@ namespace cAudio
void cOpenALDeviceContext::shutDown()
{
if(Initialized)
{
cAudioMutexBasicLock lock(Mutex);
//Reset context to null
alcMakeContextCurrent(NULL);
//Delete the context
alcDestroyContext(Context);
Context = NULL;
//Close the device
alcCloseDevice(Device);
checkError();
Device = NULL;
Initialized = false;
if(Initialized)
{
cAudioMutexBasicLock lock(Mutex);
//Reset context to null
alcMakeContextCurrent(NULL);
//Delete the context
alcDestroyContext(Context);
Context = NULL;
//Close the device
alcCloseDevice(Device);
checkError();
Device = NULL;
Initialized = false;
}
}
@ -144,8 +144,10 @@ namespace cAudio
IAudioEffects* cOpenALDeviceContext::getEffects() const
{
#if CAUDIO_EFX_ENABLED == 1
if(EFXSupported)
return (IAudioEffects*)&initEffects;
#endif
return NULL;
}
@ -155,28 +157,28 @@ namespace cAudio
return Context;
}
bool cOpenALDeviceContext::checkError()
{
int error = alGetError();
const char* errorString;
if (error != AL_NO_ERROR)
{
errorString = alGetString(error);
getLogger()->logError("AudioManager", "OpenAL Error: %s.", errorString);
return true;
}
if(Device)
{
error = alcGetError(Device);
if (error != AL_NO_ERROR)
{
errorString = alGetString(error);
getLogger()->logError("AudioManager", "OpenAL Error: %s.", errorString);
return true;
}
}
return false;
bool cOpenALDeviceContext::checkError()
{
int error = alGetError();
const char* errorString;
if (error != AL_NO_ERROR)
{
errorString = alGetString(error);
getLogger()->logError("AudioManager", "OpenAL Error: %s.", errorString);
return true;
}
if(Device)
{
error = alcGetError(Device);
if (error != AL_NO_ERROR)
{
errorString = alGetString(error);
getLogger()->logError("AudioManager", "OpenAL Error: %s.", errorString);
return true;
}
}
return false;
}
}