handle initialization errors cleanly, clean stuff up
This was SVN commit r13359.
This commit is contained in:
parent
b22320a85f
commit
503b481468
@ -59,9 +59,6 @@ public:
|
||||
delete m_DeadItems;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by main thread, when the online reporting is enabled/disabled.
|
||||
*/
|
||||
void SetEnabled(bool enabled)
|
||||
{
|
||||
CScopeLock lock(m_WorkerMutex);
|
||||
@ -71,17 +68,11 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by main thread to request shutdown.
|
||||
* Returns true if we've shut down successfully.
|
||||
* Returns false if shutdown is taking too long (we might be blocked on a
|
||||
* sync network operation) - you mustn't destroy this object, just leak it
|
||||
* and terminate.
|
||||
*/
|
||||
bool Shutdown()
|
||||
{
|
||||
{
|
||||
CScopeLock lock(m_WorkerMutex);
|
||||
|
||||
m_Shutdown = true;
|
||||
m_Enabled = false;
|
||||
|
||||
@ -98,6 +89,7 @@ public:
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void addItem( ISoundItem* anItem )
|
||||
{
|
||||
CScopeLock lock(m_WorkerMutex);
|
||||
@ -132,8 +124,6 @@ private:
|
||||
|
||||
void Run()
|
||||
{
|
||||
|
||||
// Wait until the main thread wakes us up
|
||||
while ( true )
|
||||
{
|
||||
g_Profiler2.RecordRegionLeave("semaphore wait");
|
||||
@ -207,7 +197,7 @@ private:
|
||||
CMutex m_DeadItemsMutex;
|
||||
|
||||
// Shared by main thread and worker thread:
|
||||
// These variables are all protected by m_WorkerMutex
|
||||
// These variables are all protected by a mutexes
|
||||
ItemsList* m_Items;
|
||||
ItemsList* m_DeadItems;
|
||||
|
||||
@ -263,8 +253,10 @@ CSoundManager::CSoundManager()
|
||||
{
|
||||
m_CurrentEnvirons = 0;
|
||||
m_ALSourceBuffer = NULL;
|
||||
m_Device = NULL;
|
||||
m_Context = NULL;
|
||||
m_Worker = NULL;
|
||||
m_CurrentTune = 0;
|
||||
m_SourceCOunt = 0;
|
||||
m_Gain = 1;
|
||||
m_MusicGain = 1;
|
||||
m_AmbientGain = 1;
|
||||
@ -280,26 +272,42 @@ CSoundManager::CSoundManager()
|
||||
m_DistressTime = 0;
|
||||
m_DistressErrCount = 0;
|
||||
|
||||
m_Enabled = AlcInit() == INFO::OK;
|
||||
m_ItemsMap = new ItemsMap;
|
||||
InitListener();
|
||||
m_Enabled = false;
|
||||
AlcInit();
|
||||
|
||||
m_Worker = new CSoundManagerWorker();
|
||||
m_Worker->SetEnabled( true );
|
||||
if ( m_Enabled )
|
||||
{
|
||||
InitListener();
|
||||
|
||||
m_Worker = new CSoundManagerWorker();
|
||||
m_Worker->SetEnabled( true );
|
||||
}
|
||||
}
|
||||
|
||||
CSoundManager::~CSoundManager()
|
||||
{
|
||||
if (m_Worker->Shutdown())
|
||||
delete m_Worker;
|
||||
{
|
||||
if (m_Worker )
|
||||
{
|
||||
AL_CHECK
|
||||
m_Worker->Shutdown();
|
||||
AL_CHECK
|
||||
m_Worker->CleanupItems();
|
||||
AL_CHECK
|
||||
|
||||
delete m_Worker;
|
||||
}
|
||||
AL_CHECK
|
||||
|
||||
delete m_ItemsMap;
|
||||
|
||||
if ( m_ALSourceBuffer != NULL )
|
||||
delete[] m_ALSourceBuffer;
|
||||
|
||||
alcDestroyContext(m_Context);
|
||||
alcCloseDevice(m_Device);
|
||||
if ( m_Context )
|
||||
alcDestroyContext(m_Context);
|
||||
|
||||
AL_CHECK
|
||||
|
||||
if ( m_Device )
|
||||
alcCloseDevice(m_Device);
|
||||
}
|
||||
|
||||
|
||||
@ -309,12 +317,12 @@ Status CSoundManager::AlcInit()
|
||||
Status ret = INFO::OK;
|
||||
|
||||
m_Device = alcOpenDevice(NULL);
|
||||
if(m_Device)
|
||||
if (m_Device)
|
||||
{
|
||||
ALCint attribs[] = {ALC_STEREO_SOURCES, 16, 0};
|
||||
m_Context = alcCreateContext(m_Device, &attribs[0]);
|
||||
|
||||
if(m_Context)
|
||||
if (m_Context)
|
||||
{
|
||||
alcMakeContextCurrent(m_Context);
|
||||
m_ALSourceBuffer = new ALSourceHolder[SOURCE_NUM];
|
||||
@ -332,6 +340,7 @@ Status CSoundManager::AlcInit()
|
||||
m_ALSourceBuffer[x].SourceItem = NULL;
|
||||
|
||||
}
|
||||
m_Enabled = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -410,7 +419,6 @@ ALuint CSoundManager::GetALSource( ISoundItem* anItem)
|
||||
{
|
||||
if ( ! m_ALSourceBuffer[x].SourceItem )
|
||||
{
|
||||
m_SourceCOunt++;
|
||||
m_ALSourceBuffer[x].SourceItem = anItem;
|
||||
return m_ALSourceBuffer[x].ALSource;
|
||||
}
|
||||
@ -425,7 +433,6 @@ void CSoundManager::ReleaseALSource(ALuint theSource)
|
||||
{
|
||||
if ( m_ALSourceBuffer[x].ALSource == theSource )
|
||||
{
|
||||
m_SourceCOunt--;
|
||||
m_ALSourceBuffer[x].SourceItem = NULL;
|
||||
return;
|
||||
}
|
||||
@ -448,9 +455,12 @@ long CSoundManager::GetBufferSize()
|
||||
|
||||
void CSoundManager::SetMasterGain(float gain)
|
||||
{
|
||||
m_Gain = gain;
|
||||
alListenerf( AL_GAIN, m_Gain);
|
||||
AL_CHECK
|
||||
if ( m_Enabled )
|
||||
{
|
||||
m_Gain = gain;
|
||||
alListenerf( AL_GAIN, m_Gain);
|
||||
AL_CHECK
|
||||
}
|
||||
}
|
||||
|
||||
void CSoundManager::SetMusicGain(float gain)
|
||||
@ -471,11 +481,14 @@ ISoundItem* CSoundManager::LoadItem(const VfsPath& itemPath)
|
||||
{
|
||||
AL_CHECK
|
||||
|
||||
CSoundData* itemData = CSoundData::SoundDataFromFile(itemPath);
|
||||
if ( m_Enabled )
|
||||
{
|
||||
CSoundData* itemData = CSoundData::SoundDataFromFile(itemPath);
|
||||
|
||||
AL_CHECK
|
||||
if ( itemData )
|
||||
return CSoundManager::ItemForData( itemData );
|
||||
AL_CHECK
|
||||
if ( itemData )
|
||||
return CSoundManager::ItemForData( itemData );
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@ -487,7 +500,7 @@ ISoundItem* CSoundManager::ItemForData(CSoundData* itemData)
|
||||
|
||||
AL_CHECK
|
||||
|
||||
if (itemData != NULL)
|
||||
if ( m_Enabled && (itemData != NULL) )
|
||||
{
|
||||
if (itemData->IsOneShot())
|
||||
{
|
||||
@ -511,21 +524,26 @@ ISoundItem* CSoundManager::ItemForData(CSoundData* itemData)
|
||||
|
||||
void CSoundManager::IdleTask()
|
||||
{
|
||||
AL_CHECK
|
||||
if (m_CurrentTune)
|
||||
m_CurrentTune->EnsurePlay();
|
||||
AL_CHECK
|
||||
if (m_CurrentEnvirons)
|
||||
m_CurrentEnvirons->EnsurePlay();
|
||||
AL_CHECK
|
||||
if (m_Worker)
|
||||
m_Worker->CleanupItems();
|
||||
AL_CHECK
|
||||
if ( m_Enabled )
|
||||
{
|
||||
if (m_CurrentTune)
|
||||
m_CurrentTune->EnsurePlay();
|
||||
|
||||
if (m_CurrentEnvirons)
|
||||
m_CurrentEnvirons->EnsurePlay();
|
||||
|
||||
if (m_Worker)
|
||||
m_Worker->CleanupItems();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
ISoundItem* CSoundManager::ItemForEntity( entity_id_t UNUSED(source), CSoundData* sndData)
|
||||
{
|
||||
ISoundItem* currentItem = ItemForData( sndData );
|
||||
ISoundItem* currentItem = NULL;
|
||||
|
||||
if ( m_Enabled )
|
||||
currentItem = ItemForData( sndData );
|
||||
|
||||
return currentItem;
|
||||
}
|
||||
@ -556,6 +574,7 @@ void CSoundManager::PlayActionItem(ISoundItem* anItem)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CSoundManager::PlayGroupItem(ISoundItem* anItem, ALfloat groupGain )
|
||||
{
|
||||
if (anItem)
|
||||
@ -594,7 +613,6 @@ void CSoundManager::SetMusicItem(ISoundItem* anItem)
|
||||
if (m_MusicEnabled && m_Enabled)
|
||||
{
|
||||
m_CurrentTune = anItem;
|
||||
m_CurrentTune->SetIsManaged( true );
|
||||
m_CurrentTune->SetGain(0);
|
||||
m_CurrentTune->PlayLoop();
|
||||
m_CurrentTune->FadeToIn( m_MusicGain, 1.00);
|
||||
@ -621,7 +639,6 @@ void CSoundManager::SetAmbientItem(ISoundItem* anItem)
|
||||
if (m_Enabled && (m_AmbientGain > 0))
|
||||
{
|
||||
m_CurrentEnvirons = anItem;
|
||||
m_CurrentEnvirons->SetIsManaged( true );
|
||||
m_CurrentEnvirons->SetGain(0);
|
||||
m_CurrentEnvirons->PlayLoop();
|
||||
m_CurrentEnvirons->FadeToIn( m_AmbientGain, 2.00);
|
||||
|
@ -57,7 +57,6 @@ protected:
|
||||
ISoundItem* m_CurrentTune;
|
||||
ISoundItem* m_CurrentEnvirons;
|
||||
CSoundManagerWorker* m_Worker;
|
||||
ItemsMap* m_ItemsMap;
|
||||
CMutex m_DistressMutex;
|
||||
|
||||
float m_Gain;
|
||||
@ -65,7 +64,6 @@ protected:
|
||||
float m_AmbientGain;
|
||||
float m_ActionGain;
|
||||
bool m_Enabled;
|
||||
long m_SourceCOunt;
|
||||
long m_BufferSize;
|
||||
int m_BufferCount;
|
||||
bool m_MusicEnabled;
|
||||
@ -126,10 +124,10 @@ public:
|
||||
void SetDistressThroughShortage();
|
||||
void SetDistressThroughError();
|
||||
|
||||
void Pause(bool pauseIt);
|
||||
void PauseMusic (bool pauseIt);
|
||||
void PauseAmbient (bool pauseIt);
|
||||
void PauseAction (bool pauseIt);
|
||||
void Pause(bool pauseIt);
|
||||
void PauseMusic (bool pauseIt);
|
||||
void PauseAmbient (bool pauseIt);
|
||||
void PauseAction (bool pauseIt);
|
||||
|
||||
protected:
|
||||
void InitListener();
|
||||
|
@ -37,9 +37,15 @@ COggData::COggData()
|
||||
|
||||
COggData::~COggData()
|
||||
{
|
||||
AL_CHECK
|
||||
ogg->Close();
|
||||
|
||||
alDeleteBuffers(m_BuffersUsed, m_Buffer);
|
||||
AL_CHECK
|
||||
if ( m_BuffersUsed > 0 )
|
||||
alDeleteBuffers(m_BuffersUsed, &m_Buffer[0] );
|
||||
|
||||
AL_CHECK
|
||||
m_BuffersUsed = 0;
|
||||
}
|
||||
|
||||
void COggData::SetFormatAndFreq(int form, ALsizei freq)
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include "precompiled.h"
|
||||
|
||||
#include "SoundData.h"
|
||||
#include "soundmanager/SoundManager.h"
|
||||
|
||||
#if CONFIG2_AUDIO
|
||||
|
||||
@ -35,11 +36,11 @@ CSoundData::CSoundData()
|
||||
|
||||
CSoundData::~CSoundData()
|
||||
{
|
||||
// LOGERROR(L"Sound data deleted %ls\n", m_FileName->c_str() );
|
||||
|
||||
AL_CHECK
|
||||
if (m_ALBuffer != 0)
|
||||
alDeleteBuffers(1, &m_ALBuffer);
|
||||
|
||||
m_ALBuffer = 0;
|
||||
AL_CHECK
|
||||
delete m_FileName;
|
||||
}
|
||||
|
||||
|
@ -36,30 +36,31 @@ CBufferItem::CBufferItem(CSoundData* sndData)
|
||||
|
||||
CBufferItem::~CBufferItem()
|
||||
{
|
||||
Stop();
|
||||
ReleaseOpenALBuffer();
|
||||
}
|
||||
|
||||
|
||||
void CBufferItem::ReleaseOpenAL()
|
||||
void CBufferItem::ReleaseOpenALBuffer()
|
||||
{
|
||||
if ( m_ALSource == 0 )
|
||||
return;
|
||||
|
||||
int num_processed;
|
||||
AL_CHECK
|
||||
alGetSourcei(m_ALSource, AL_BUFFERS_PROCESSED, &num_processed);
|
||||
|
||||
AL_CHECK
|
||||
|
||||
if (num_processed > 0)
|
||||
{
|
||||
int num_processed;
|
||||
alGetSourcei(m_ALSource, AL_BUFFERS_PROCESSED, &num_processed);
|
||||
ALuint* al_buf = new ALuint[num_processed];
|
||||
alSourceUnqueueBuffers(m_ALSource, num_processed, al_buf);
|
||||
|
||||
if (num_processed > 0)
|
||||
{
|
||||
ALuint* al_buf = new ALuint[num_processed];
|
||||
alSourceUnqueueBuffers(m_ALSource, num_processed, al_buf);
|
||||
|
||||
AL_CHECK
|
||||
delete[] al_buf;
|
||||
}
|
||||
AL_CHECK
|
||||
delete[] al_buf;
|
||||
}
|
||||
|
||||
CSoundBase::ReleaseOpenAL();
|
||||
alSourcei(m_ALSource, AL_BUFFER, NULL);
|
||||
m_ALSource = 0;
|
||||
}
|
||||
|
||||
bool CBufferItem::IdleTask()
|
||||
@ -68,7 +69,6 @@ bool CBufferItem::IdleTask()
|
||||
return false;
|
||||
|
||||
HandleFade();
|
||||
TouchTimer();
|
||||
|
||||
if (m_LastPlay)
|
||||
{
|
||||
@ -81,45 +81,26 @@ bool CBufferItem::IdleTask()
|
||||
|
||||
if (GetLooping())
|
||||
{
|
||||
CScopeLock lock(m_ItemMutex);
|
||||
int num_processed;
|
||||
AL_CHECK
|
||||
alGetSourcei(m_ALSource, AL_BUFFERS_PROCESSED, &num_processed);
|
||||
|
||||
AL_CHECK
|
||||
for (int i = 0; i < num_processed; i++)
|
||||
{
|
||||
int proc_state;
|
||||
alGetSourceiv(m_ALSource, AL_SOURCE_STATE, &proc_state);
|
||||
ALuint al_buf;
|
||||
alSourceUnqueueBuffers(m_ALSource, 1, &al_buf);
|
||||
AL_CHECK
|
||||
alSourceQueueBuffers(m_ALSource, 1, &al_buf);
|
||||
AL_CHECK
|
||||
|
||||
return (proc_state != AL_STOPPED);
|
||||
}
|
||||
|
||||
if (GetLooping())
|
||||
{
|
||||
int num_processed;
|
||||
alGetSourcei(m_ALSource, AL_BUFFERS_PROCESSED, &num_processed);
|
||||
|
||||
for (int i = 0; i < num_processed; i++)
|
||||
{
|
||||
ALuint al_buf;
|
||||
alSourceUnqueueBuffers(m_ALSource, 1, &al_buf);
|
||||
AL_CHECK
|
||||
alSourceQueueBuffers(m_ALSource, 1, &al_buf);
|
||||
AL_CHECK
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
bool CBufferItem::CanAttach(CSoundData* itemData)
|
||||
{
|
||||
return itemData->IsOneShot() && (itemData->GetBufferCount() > 1);
|
||||
}
|
||||
|
||||
void CBufferItem::Attach(CSoundData* itemData)
|
||||
{
|
||||
AL_CHECK
|
||||
if ( m_ALSource == 0 )
|
||||
return;
|
||||
|
||||
|
@ -32,11 +32,11 @@ public:
|
||||
|
||||
virtual void SetLooping(bool loops);
|
||||
virtual bool IdleTask();
|
||||
void Attach(CSoundData* itemData);
|
||||
bool CanAttach(CSoundData* itemData);
|
||||
|
||||
virtual void Attach(CSoundData* itemData);
|
||||
|
||||
protected:
|
||||
virtual void ReleaseOpenAL();
|
||||
void ReleaseOpenALBuffer();
|
||||
|
||||
};
|
||||
|
||||
|
@ -43,13 +43,18 @@ void CSoundBase::ReleaseOpenAL()
|
||||
{
|
||||
if (m_ALSource != 0)
|
||||
{
|
||||
alSourcei(m_ALSource, AL_BUFFER, 0);
|
||||
AL_CHECK
|
||||
alSourcei(m_ALSource, AL_BUFFER, NULL);
|
||||
AL_CHECK
|
||||
g_SoundManager->ReleaseALSource(m_ALSource);
|
||||
AL_CHECK
|
||||
m_ALSource = 0;
|
||||
}
|
||||
if (m_SoundData != 0)
|
||||
{
|
||||
AL_CHECK
|
||||
CSoundData::ReleaseSoundData(m_SoundData);
|
||||
AL_CHECK
|
||||
m_SoundData = 0;
|
||||
}
|
||||
}
|
||||
@ -58,11 +63,6 @@ void CSoundBase::Attach(CSoundData* itemData)
|
||||
{
|
||||
UNUSED2(itemData);
|
||||
}
|
||||
bool CSoundBase::CanAttach(CSoundData* itemData)
|
||||
{
|
||||
UNUSED2(itemData);
|
||||
return false;
|
||||
}
|
||||
|
||||
void CSoundBase::ResetVars()
|
||||
{
|
||||
@ -74,8 +74,7 @@ void CSoundBase::ResetVars()
|
||||
m_EndFadeTime = 0;
|
||||
m_StartVolume = 0;
|
||||
m_EndVolume = 0;
|
||||
m_IsManaged = false;
|
||||
m_TouchTime = timer_Time();
|
||||
|
||||
ResetFade();
|
||||
}
|
||||
|
||||
@ -109,17 +108,11 @@ bool CSoundBase::InitOpenAL()
|
||||
}
|
||||
else
|
||||
{
|
||||
// LOGERROR(L"Source not allocated by SOundManager\n", 0);
|
||||
// LOGERROR(L"Source not allocated by SoundManager\n", 0);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void CSoundBase::SetIsManaged(bool manage)
|
||||
{
|
||||
m_IsManaged = manage;
|
||||
}
|
||||
|
||||
void CSoundBase::SetGain(ALfloat gain)
|
||||
{
|
||||
AL_CHECK
|
||||
@ -141,7 +134,7 @@ void CSoundBase::SetRollOff(ALfloat rolls)
|
||||
AL_CHECK
|
||||
alSourcef(m_ALSource, AL_MAX_DISTANCE, 200.0);
|
||||
AL_CHECK
|
||||
alSourcef(m_ALSource, AL_ROLLOFF_FACTOR, rolls);
|
||||
alSourcef(m_ALSource, AL_ROLLOFF_FACTOR, rolls);
|
||||
AL_CHECK
|
||||
}
|
||||
}
|
||||
@ -212,12 +205,6 @@ bool CSoundBase::IdleTask()
|
||||
return true;
|
||||
}
|
||||
|
||||
void CSoundBase::TouchTimer()
|
||||
{
|
||||
if ( IsPlaying() )
|
||||
m_TouchTime = timer_Time();
|
||||
}
|
||||
|
||||
void CSoundBase::SetLocation (const CVector3D& position)
|
||||
{
|
||||
if ( m_ALSource != 0 )
|
||||
@ -231,6 +218,9 @@ void CSoundBase::SetLocation (const CVector3D& position)
|
||||
bool CSoundBase::HandleFade()
|
||||
{
|
||||
AL_CHECK
|
||||
if (m_ALSource == 0)
|
||||
return true;
|
||||
|
||||
if (m_StartFadeTime != 0)
|
||||
{
|
||||
double currTime = timer_Time();
|
||||
@ -270,11 +260,6 @@ bool CSoundBase::GetLooping()
|
||||
return m_Looping;
|
||||
}
|
||||
|
||||
bool CSoundBase::SoundStale()
|
||||
{
|
||||
return !m_IsManaged && ( ( timer_Time() - m_TouchTime ) > 120 );
|
||||
}
|
||||
|
||||
void CSoundBase::SetLooping(bool loops)
|
||||
{
|
||||
m_Looping = loops;
|
||||
@ -289,7 +274,6 @@ void CSoundBase::Play()
|
||||
{
|
||||
CScopeLock lock(m_ItemMutex);
|
||||
|
||||
m_TouchTime = timer_Time();
|
||||
m_ShouldBePlaying = true;
|
||||
AL_CHECK
|
||||
if (m_ALSource != 0)
|
||||
@ -334,7 +318,6 @@ void CSoundBase::PlayLoop()
|
||||
{
|
||||
if (m_ALSource != 0)
|
||||
{
|
||||
m_TouchTime = timer_Time();
|
||||
SetLooping(true);
|
||||
Play();
|
||||
AL_CHECK
|
||||
@ -374,13 +357,12 @@ void CSoundBase::Stop()
|
||||
if (m_ALSource != 0)
|
||||
{
|
||||
CScopeLock lock(m_ItemMutex);
|
||||
int proc_state;
|
||||
alSourcei(m_ALSource, AL_LOOPING, AL_FALSE);
|
||||
alGetSourceiv(m_ALSource, AL_SOURCE_STATE, &proc_state);
|
||||
if (proc_state == AL_PLAYING)
|
||||
alSourceStop(m_ALSource);
|
||||
|
||||
AL_CHECK
|
||||
alSourcei(m_ALSource, AL_LOOPING, AL_FALSE);
|
||||
AL_CHECK
|
||||
alSourceStop(m_ALSource);
|
||||
AL_CHECK
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -24,8 +24,8 @@
|
||||
|
||||
#include "lib/external_libraries/openal.h"
|
||||
#include "ps/ThreadUtil.h"
|
||||
#include "soundmanager/items/ISoundItem.h"
|
||||
#include "soundmanager/data/SoundData.h"
|
||||
#include "soundmanager/items/ISoundItem.h"
|
||||
|
||||
class CSoundBase : public ISoundItem
|
||||
{
|
||||
@ -34,7 +34,6 @@ protected:
|
||||
ALuint m_ALSource;
|
||||
CSoundData* m_SoundData;
|
||||
|
||||
bool m_IsManaged;
|
||||
bool m_LastPlay;
|
||||
bool m_Looping;
|
||||
bool m_ShouldBePlaying;
|
||||
@ -42,7 +41,7 @@ protected:
|
||||
|
||||
double m_StartFadeTime;
|
||||
double m_EndFadeTime;
|
||||
double m_TouchTime;
|
||||
|
||||
ALfloat m_StartVolume;
|
||||
ALfloat m_EndVolume;
|
||||
CMutex m_ItemMutex;
|
||||
@ -52,47 +51,44 @@ public:
|
||||
|
||||
virtual ~CSoundBase();
|
||||
|
||||
virtual bool InitOpenAL();
|
||||
virtual void ResetVars();
|
||||
virtual void EnsurePlay();
|
||||
bool InitOpenAL();
|
||||
void ResetVars();
|
||||
void EnsurePlay();
|
||||
|
||||
virtual void SetGain(ALfloat gain);
|
||||
virtual void SetRollOff(ALfloat gain);
|
||||
virtual void SetPitch(ALfloat pitch);
|
||||
virtual void SetDirection(const CVector3D& direction);
|
||||
virtual void SetCone(ALfloat innerCone, ALfloat outerCone, ALfloat coneGain);
|
||||
virtual void SetLastPlay(bool last);
|
||||
virtual void ReleaseOpenAL();
|
||||
virtual void TouchTimer();
|
||||
virtual void SetIsManaged(bool manage);
|
||||
|
||||
virtual bool IsFading();
|
||||
void SetGain(ALfloat gain);
|
||||
void SetRollOff(ALfloat gain);
|
||||
void SetPitch(ALfloat pitch);
|
||||
void SetDirection(const CVector3D& direction);
|
||||
void SetCone(ALfloat innerCone, ALfloat outerCone, ALfloat coneGain);
|
||||
void SetLastPlay(bool last);
|
||||
void ReleaseOpenAL();
|
||||
bool IsFading();
|
||||
|
||||
void Play();
|
||||
void PlayAndDelete();
|
||||
bool IdleTask();
|
||||
void PlayLoop();
|
||||
void Stop();
|
||||
void StopAndDelete();
|
||||
void FadeToIn(ALfloat newVolume, double fadeDuration);
|
||||
void Attach(CSoundData* itemData);
|
||||
bool CanAttach(CSoundData* itemData);
|
||||
|
||||
void PlayAsMusic();
|
||||
void PlayAsAmbient();
|
||||
bool GetLooping();
|
||||
bool IsPlaying();
|
||||
|
||||
CStrW* GetName();
|
||||
|
||||
virtual bool GetLooping();
|
||||
virtual void SetLooping(bool loops);
|
||||
virtual bool IsPlaying();
|
||||
virtual void SetLocation(const CVector3D& position);
|
||||
virtual void FadeAndDelete(double fadeTime);
|
||||
virtual void FadeAndPause(double fadeTime);
|
||||
virtual bool SoundStale();
|
||||
void SetLocation(const CVector3D& position);
|
||||
void FadeAndDelete(double fadeTime);
|
||||
void FadeAndPause(double fadeTime);
|
||||
|
||||
void Pause();
|
||||
void Resume();
|
||||
|
||||
CStrW* GetName();
|
||||
|
||||
virtual void SetLooping(bool loops);
|
||||
virtual bool IdleTask();
|
||||
virtual void Attach(CSoundData* itemData);
|
||||
|
||||
protected:
|
||||
|
||||
void SetNameFromPath(VfsPath& itemPath);
|
||||
|
@ -40,13 +40,8 @@ CSoundItem::CSoundItem(CSoundData* sndData)
|
||||
|
||||
CSoundItem::~CSoundItem()
|
||||
{
|
||||
}
|
||||
|
||||
void CSoundItem::ReleaseOpenAL()
|
||||
{
|
||||
alSourcei(m_ALSource, AL_BUFFER, 0);
|
||||
|
||||
CSoundBase::ReleaseOpenAL();
|
||||
Stop();
|
||||
ReleaseOpenAL();
|
||||
}
|
||||
|
||||
bool CSoundItem::IdleTask()
|
||||
@ -54,7 +49,6 @@ bool CSoundItem::IdleTask()
|
||||
if ( m_ALSource == 0 )
|
||||
return false;
|
||||
|
||||
TouchTimer();
|
||||
HandleFade();
|
||||
|
||||
if (m_LastPlay && m_ALSource)
|
||||
@ -67,22 +61,18 @@ bool CSoundItem::IdleTask()
|
||||
}
|
||||
return true;
|
||||
}
|
||||
bool CSoundItem::CanAttach(CSoundData* itemData)
|
||||
{
|
||||
return itemData->IsOneShot() && (itemData->GetBufferCount() == 1);
|
||||
}
|
||||
|
||||
void CSoundItem::Attach(CSoundData* itemData)
|
||||
{
|
||||
AL_CHECK
|
||||
if (m_SoundData != NULL)
|
||||
{
|
||||
CSoundData::ReleaseSoundData(m_SoundData);
|
||||
m_SoundData = 0;
|
||||
}
|
||||
AL_CHECK
|
||||
|
||||
if (itemData != NULL)
|
||||
{
|
||||
AL_CHECK
|
||||
alSourcei(m_ALSource, AL_BUFFER, 0);
|
||||
AL_CHECK
|
||||
m_SoundData = itemData->IncrementCount();
|
||||
|
@ -30,13 +30,10 @@ class CSoundItem : public CSoundBase
|
||||
public:
|
||||
CSoundItem();
|
||||
CSoundItem(CSoundData* sndData);
|
||||
|
||||
virtual ~CSoundItem();
|
||||
void Attach(CSoundData* itemData);
|
||||
bool CanAttach(CSoundData* itemData);
|
||||
bool IdleTask();
|
||||
void ReleaseOpenAL();
|
||||
|
||||
void Attach(CSoundData* itemData);
|
||||
bool IdleTask();
|
||||
};
|
||||
|
||||
#endif // CONFIG2_AUDIO
|
||||
|
@ -35,18 +35,19 @@ CStreamItem::CStreamItem(CSoundData* sndData)
|
||||
|
||||
CStreamItem::~CStreamItem()
|
||||
{
|
||||
Stop();
|
||||
ReleaseOpenALStream();
|
||||
}
|
||||
|
||||
void CStreamItem::ReleaseOpenAL()
|
||||
{
|
||||
int num_processed;
|
||||
alGetSourcei(m_ALSource, AL_BUFFERS_PROCESSED, &num_processed);
|
||||
|
||||
void CStreamItem::ReleaseOpenALStream()
|
||||
{
|
||||
if (m_ALSource != 0)
|
||||
{
|
||||
int num_processed;
|
||||
AL_CHECK
|
||||
alGetSourcei(m_ALSource, AL_BUFFERS_PROCESSED, &num_processed);
|
||||
|
||||
AL_CHECK
|
||||
|
||||
if (num_processed > 0)
|
||||
{
|
||||
ALuint* al_buf = new ALuint[num_processed];
|
||||
@ -54,14 +55,15 @@ void CStreamItem::ReleaseOpenAL()
|
||||
AL_CHECK
|
||||
delete[] al_buf;
|
||||
}
|
||||
alSourcei(m_ALSource, AL_BUFFER, NULL);
|
||||
AL_CHECK
|
||||
m_ALSource = 0;
|
||||
}
|
||||
CSoundBase::ReleaseOpenAL();
|
||||
}
|
||||
|
||||
bool CStreamItem::IdleTask()
|
||||
{
|
||||
AL_CHECK
|
||||
TouchTimer();
|
||||
HandleFade();
|
||||
AL_CHECK
|
||||
|
||||
@ -103,12 +105,9 @@ bool CStreamItem::IdleTask()
|
||||
}
|
||||
}
|
||||
}
|
||||
AL_CHECK
|
||||
return true;
|
||||
}
|
||||
bool CStreamItem::CanAttach(CSoundData* itemData)
|
||||
{
|
||||
return ! itemData->IsOneShot();
|
||||
}
|
||||
|
||||
void CStreamItem::Attach(CSoundData* itemData)
|
||||
{
|
||||
|
@ -33,11 +33,10 @@ public:
|
||||
|
||||
virtual void SetLooping(bool loops);
|
||||
virtual bool IdleTask();
|
||||
virtual bool CanAttach(CSoundData* itemData);
|
||||
virtual void Attach(CSoundData* itemData);
|
||||
|
||||
protected:
|
||||
virtual void ReleaseOpenAL();
|
||||
void ReleaseOpenALStream();
|
||||
};
|
||||
|
||||
#endif // CONFIG2_AUDIO
|
||||
|
@ -43,15 +43,12 @@ public:
|
||||
|
||||
virtual void Play() = 0;
|
||||
virtual void Stop() = 0;
|
||||
virtual bool SoundStale() = 0;
|
||||
virtual void TouchTimer() = 0;
|
||||
|
||||
virtual void Attach(CSoundData* itemData) = 0;
|
||||
virtual bool CanAttach(CSoundData* itemData) = 0;
|
||||
|
||||
virtual void EnsurePlay() = 0;
|
||||
virtual void PlayAsMusic() = 0;
|
||||
virtual void PlayAsAmbient() = 0;
|
||||
virtual void SetIsManaged(bool manage) = 0;
|
||||
|
||||
virtual void PlayAndDelete() = 0;
|
||||
virtual void StopAndDelete() = 0;
|
||||
|
@ -41,8 +41,6 @@ bool JAmbientSound::Play(JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSE
|
||||
|
||||
if (aSnd)
|
||||
aSnd->PlayAsAmbient();
|
||||
else
|
||||
LOGERROR(L"sound item could not be loaded to play: %ls\n", m_FileName.string().c_str());
|
||||
}
|
||||
#endif // CONFIG2_AUDIO
|
||||
return true;
|
||||
@ -57,8 +55,6 @@ bool JAmbientSound::Loop(JSContext* UNUSED(cx), uintN UNUSED(argc), jsval* UNUSE
|
||||
|
||||
if (aSnd)
|
||||
aSnd->PlayAsAmbient();
|
||||
else
|
||||
LOGERROR(L"sound item could not be loaded to loop: %ls\n", m_FileName.string().c_str());
|
||||
}
|
||||
#endif // CONFIG2_AUDIO
|
||||
return true;
|
||||
|
@ -182,27 +182,30 @@ void CSoundGroup::UploadPropertiesAndPlay(size_t theIndex, const CVector3D& posi
|
||||
|
||||
ISoundItem* hSound = g_SoundManager->ItemForEntity( source, sndData);
|
||||
|
||||
if (!TestFlag(eOmnipresent))
|
||||
if ( hSound )
|
||||
{
|
||||
if (TestFlag(eDistanceless))
|
||||
itemRollOff = 0;
|
||||
|
||||
hSound->SetLocation(CVector3D((sndDist * sin(offSet)), 0, - sndDist * cos(offSet)));
|
||||
hSound->SetRollOff(itemRollOff);
|
||||
if (!TestFlag(eOmnipresent))
|
||||
{
|
||||
if (TestFlag(eDistanceless))
|
||||
itemRollOff = 0;
|
||||
|
||||
hSound->SetLocation(CVector3D((sndDist * sin(offSet)), 0, - sndDist * cos(offSet)));
|
||||
hSound->SetRollOff(itemRollOff);
|
||||
}
|
||||
|
||||
if (TestFlag(eRandPitch))
|
||||
hSound->SetPitch(RandFloat(m_PitchLower, m_PitchUpper));
|
||||
else
|
||||
hSound->SetPitch(m_Pitch);
|
||||
|
||||
ALfloat theGain = m_Gain;
|
||||
if (TestFlag(eRandGain))
|
||||
theGain = RandFloat(m_GainLower, m_GainUpper);
|
||||
|
||||
hSound->SetCone(m_ConeInnerAngle, m_ConeOuterAngle, m_ConeOuterGain);
|
||||
|
||||
g_SoundManager->PlayGroupItem(hSound, theGain);
|
||||
}
|
||||
|
||||
if (TestFlag(eRandPitch))
|
||||
hSound->SetPitch(RandFloat(m_PitchLower, m_PitchUpper));
|
||||
else
|
||||
hSound->SetPitch(m_Pitch);
|
||||
|
||||
ALfloat theGain = m_Gain;
|
||||
if (TestFlag(eRandGain))
|
||||
theGain = RandFloat(m_GainLower, m_GainUpper);
|
||||
|
||||
hSound->SetCone(m_ConeInnerAngle, m_ConeOuterAngle, m_ConeOuterGain);
|
||||
|
||||
g_SoundManager->PlayGroupItem(hSound, theGain);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user