Move gain config setting retrieval to the sound manager. Fixes #3030.

Also clean up the sound manager a bit.

This was SVN commit r16257.
This commit is contained in:
leper 2015-02-02 13:44:06 +00:00
parent d71161fe4c
commit ec7c8f2d65
14 changed files with 205 additions and 278 deletions

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2014 Wildfire Games.
/* Copyright (C) 2015 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -24,7 +24,6 @@
#include "ps/CLogger.h"
#include "ps/ConfigDB.h"
#include "ps/GameSetup/CmdLineArgs.h"
#include "soundmanager/ISoundManager.h"
// (these variables are documented in the header.)
@ -107,28 +106,6 @@ static void LoadGlobals()
CFG_GET_VAL("showsky", g_ShowSky);
CFG_GET_VAL("gui.scale", g_GuiScale);
if (g_SoundManager)
{
float gain = 0.5f;
float musicGain = 0.5f;
float ambientGain = 0.5f;
float actionGain = 0.5f;
float uiGain = 0.5f;
CFG_GET_VAL("sound.mastergain", gain);
CFG_GET_VAL("sound.musicgain", musicGain);
CFG_GET_VAL("sound.ambientgain", ambientGain);
CFG_GET_VAL("sound.actiongain", actionGain);
CFG_GET_VAL("sound.uigain", uiGain);
g_SoundManager->SetMasterGain(gain);
g_SoundManager->SetMusicGain(musicGain);
g_SoundManager->SetAmbientGain(ambientGain);
g_SoundManager->SetActionGain(actionGain);
g_SoundManager->SetUIGain(uiGain);
}
CFG_GET_VAL("jsdebugger.enable", g_JSDebuggerEnabled);
CFG_GET_VAL("profiler2.script.enable", g_ScriptProfilingEnabled);

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2014 Wildfire Games.
/* Copyright (C) 2015 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -27,6 +27,7 @@
#include "lib/external_libraries/libsdl.h"
#include "ps/CLogger.h"
#include "ps/CStr.h"
#include "ps/ConfigDB.h"
#include "ps/Filesystem.h"
#include "ps/Profiler2.h"
@ -88,14 +89,14 @@ public:
void CleanupItems()
{
CScopeLock lock(m_DeadItemsMutex);
AL_CHECK
AL_CHECK;
ItemsList::iterator deadItems = m_DeadItems->begin();
while (deadItems != m_DeadItems->end())
{
delete *deadItems;
++deadItems;
AL_CHECK
AL_CHECK;
}
m_DeadItems->clear();
}
@ -131,7 +132,7 @@ private:
while (lstr != m_Items->end())
{
AL_CHECK
AL_CHECK;
if ((*lstr)->IdleTask())
{
if ((pauseTime == 500) && (*lstr)->IsFading())
@ -146,13 +147,13 @@ private:
}
++lstr;
AL_CHECK
AL_CHECK;
}
delete m_Items;
m_Items = nextItemList;
AL_CHECK
AL_CHECK;
}
SDL_Delay(pauseTime);
}
@ -216,8 +217,7 @@ void CSoundManager::al_check(const char* caller, int line)
Status CSoundManager::ReloadChangedFiles(const VfsPath& UNUSED(path))
{
// LOGERROR("GUI file '%s' changed - reloading page", path.string8());
// TODO implement sound file hotloading
return INFO::OK;
}
@ -227,40 +227,27 @@ Status CSoundManager::ReloadChangedFiles(const VfsPath& UNUSED(path))
}
CSoundManager::CSoundManager()
: m_Context(nullptr), m_Device(nullptr), m_ALSourceBuffer(nullptr),
m_CurrentTune(nullptr), m_CurrentEnvirons(nullptr),
m_Worker(nullptr), m_DistressMutex(), m_PlayListItems(nullptr), m_SoundGroups(),
m_Gain(.5f), m_MusicGain(.5f), m_AmbientGain(.5f), m_ActionGain(.5f), m_UIGain(.5f),
m_Enabled(false), m_BufferSize(98304), m_BufferCount(50),
m_SoundEnabled(true), m_MusicEnabled(true), m_MusicPaused(false),
m_AmbientPaused(false), m_ActionPaused(false),
m_RunningPlaylist(false), m_PlayingPlaylist(false), m_LoopingPlaylist(false),
m_PlaylistGap(0), m_DistressErrCount(0), m_DistressTime(0)
{
m_CurrentEnvirons = NULL;
m_ALSourceBuffer = NULL;
m_Device = NULL;
m_Context = NULL;
m_Worker = NULL;
m_PlayListItems = NULL;
m_CurrentTune = NULL;
m_Gain = 1;
m_MusicGain = 1;
m_AmbientGain = 1;
m_ActionGain = 1;
m_UIGain = 1;
m_BufferCount = 50;
m_BufferSize = 98304;
m_SoundEnabled = true;
m_MusicEnabled = true;
m_MusicPaused = false;
m_AmbientPaused = false;
m_ActionPaused = false;
CFG_GET_VAL("sound.mastergain", m_Gain);
CFG_GET_VAL("sound.musicgain", m_MusicGain);
CFG_GET_VAL("sound.ambientgain", m_AmbientGain);
CFG_GET_VAL("sound.actiongain", m_ActionGain);
CFG_GET_VAL("sound.uigain", m_UIGain);
m_DistressTime = 0;
m_DistressErrCount = 0;
m_PlayingPlaylist = false;
m_LoopingPlaylist = false;
m_RunningPlaylist = false;
m_PlaylistGap = 0;
m_Enabled = false;
AlcInit();
if (m_Enabled)
{
SetMasterGain(m_Gain);
InitListener();
m_PlayListItems = new PlayList;
@ -275,15 +262,15 @@ CSoundManager::~CSoundManager()
if (m_Worker)
{
AL_CHECK
AL_CHECK;
m_Worker->Shutdown();
AL_CHECK
AL_CHECK;
m_Worker->CleanupItems();
AL_CHECK
AL_CHECK;
delete m_Worker;
}
AL_CHECK
AL_CHECK;
for (std::map<std::wstring, CSoundGroup*>::iterator it = m_SoundGroups.begin(); it != m_SoundGroups.end(); ++it)
delete it->second;
@ -486,7 +473,7 @@ void CSoundManager::SetMasterGain(float gain)
{
m_Gain = gain;
alListenerf(AL_GAIN, m_Gain);
AL_CHECK
AL_CHECK;
}
}
@ -510,13 +497,13 @@ void CSoundManager::SetUIGain(float gain)
ISoundItem* CSoundManager::LoadItem(const VfsPath& itemPath)
{
AL_CHECK
AL_CHECK;
if (m_Enabled)
{
CSoundData* itemData = CSoundData::SoundDataFromFile(itemPath);
AL_CHECK
AL_CHECK;
if (itemData)
return CSoundManager::ItemForData(itemData);
}
@ -526,10 +513,10 @@ ISoundItem* CSoundManager::LoadItem(const VfsPath& itemPath)
ISoundItem* CSoundManager::ItemForData(CSoundData* itemData)
{
AL_CHECK
AL_CHECK;
ISoundItem* answer = NULL;
AL_CHECK
AL_CHECK;
if (m_Enabled && (itemData != NULL))
{
@ -570,7 +557,7 @@ void CSoundManager::IdleTask()
else if (m_PlaylistGap < timer_Time())
{
m_PlaylistGap = 0;
PlayList::iterator it = find(m_PlayListItems->begin(), m_PlayListItems->end(), *(m_CurrentTune->GetName()));
PlayList::iterator it = find(m_PlayListItems->begin(), m_PlayListItems->end(), m_CurrentTune->GetName());
if (it != m_PlayListItems->end())
{
++it;
@ -630,7 +617,7 @@ void CSoundManager::PlayGroupItem(ISoundItem* anItem, ALfloat groupGain)
{
anItem->SetGain(m_ActionGain * groupGain);
anItem->PlayAndDelete();
AL_CHECK
AL_CHECK;
}
}
}
@ -710,7 +697,7 @@ void CSoundManager::PlayAsUI(const VfsPath& itemPath, bool looping)
anItem->PlayAndDelete();
}
}
AL_CHECK
AL_CHECK;
}
}
@ -755,7 +742,7 @@ void CSoundManager::SetMusicItem(ISoundItem* anItem)
{
if (m_Enabled)
{
AL_CHECK
AL_CHECK;
if (m_CurrentTune)
{
m_CurrentTune->FadeAndDelete(2.00);
@ -787,7 +774,7 @@ void CSoundManager::SetMusicItem(ISoundItem* anItem)
anItem->StopAndDelete();
}
}
AL_CHECK
AL_CHECK;
}
}
@ -812,7 +799,7 @@ void CSoundManager::SetAmbientItem(ISoundItem* anItem)
m_CurrentEnvirons->FadeToIn(m_AmbientGain, 2.00);
}
}
AL_CHECK
AL_CHECK;
}
}
#else // CONFIG2_AUDIO

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2014 Wildfire Games.
/* Copyright (C) 2015 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -35,7 +35,7 @@
#include <vector>
#include <map>
#define AL_CHECK CSoundManager::al_check(__func__, __LINE__);
#define AL_CHECK CSoundManager::al_check(__func__, __LINE__)
struct ALSourceHolder
{
@ -58,9 +58,9 @@ class CSoundManager : public ISoundManager
protected:
ALuint m_ALEnvironment;
ALCcontext* m_Context;
ALCdevice* m_Device;
ALSourceHolder* m_ALSourceBuffer;
ISoundItem* m_CurrentTune;
ISoundItem* m_CurrentEnvirons;
CSoundManagerWorker* m_Worker;
@ -76,8 +76,8 @@ protected:
bool m_Enabled;
long m_BufferSize;
int m_BufferCount;
bool m_MusicEnabled;
bool m_SoundEnabled;
bool m_MusicEnabled;
bool m_MusicPaused;
bool m_AmbientPaused;
@ -90,7 +90,6 @@ protected:
long m_DistressErrCount;
long m_DistressTime;
ALSourceHolder* m_ALSourceBuffer;
public:
CSoundManager();
@ -118,7 +117,7 @@ public:
static void al_check(const char* caller, int line);
void SetMusicEnabled(bool isEnabled);
void setSoundEnabled(bool enabled);
void SetSoundEnabled(bool enabled);
ALuint GetALSource(ISoundItem* anItem);
void ReleaseALSource(ALuint theSource);

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2012 Wildfire Games.
/* Copyright (C) 2015 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -19,33 +19,29 @@
#include "OggData.h"
#if CONFIG2_AUDIO
#include "ps/CLogger.h"
#include "ps/CLogger.h"
#include "ps/Filesystem.h"
#include "soundmanager/SoundManager.h"
#include "ps/CLogger.h"
COggData::COggData()
: m_Format(0), m_Frequency(0), m_OneShot(false), m_BuffersUsed(0)
{
m_OneShot = false;
m_Format = 0;
m_Frequency = 0;
m_BuffersUsed = 0;
}
COggData::~COggData()
{
AL_CHECK
AL_CHECK;
if (ogg)
ogg->Close();
AL_CHECK
AL_CHECK;
if ( m_BuffersUsed > 0 )
alDeleteBuffers(m_BuffersUsed, &m_Buffer[0] );
alDeleteBuffers(m_BuffersUsed, &m_Buffer[0]);
AL_CHECK
AL_CHECK;
m_BuffersUsed = 0;
}
@ -57,48 +53,47 @@ void COggData::SetFormatAndFreq(int form, ALsizei freq)
bool COggData::IsStereo()
{
return ( m_Format == AL_FORMAT_STEREO16 );
return m_Format == AL_FORMAT_STEREO16;
}
bool COggData::InitOggFile(const VfsPath& itemPath)
{
if ( CSoundManager* sndManager = (CSoundManager*)g_SoundManager )
{
int buffersToStart = sndManager->GetBufferCount();
if ( OpenOggNonstream( g_VFS, itemPath, ogg) == INFO::OK )
{
m_FileFinished = false;
CSoundManager* sndManager = (CSoundManager*)g_SoundManager;
if (!sndManager)
return false;
SetFormatAndFreq(ogg->Format(), ogg->SamplingRate() );
SetFileName( itemPath );
AL_CHECK
alGenBuffers(buffersToStart, m_Buffer);
if(alGetError() != AL_NO_ERROR)
{
LOGERROR( "- Error creating initial buffer !!\n");
return false;
}
else
{
m_BuffersUsed = FetchDataIntoBuffer(buffersToStart, m_Buffer);
if (m_FileFinished)
{
m_OneShot = true;
if (m_BuffersUsed < buffersToStart)
{
alDeleteBuffers(buffersToStart - m_BuffersUsed, &m_Buffer[m_BuffersUsed]);
}
}
AL_CHECK
}
return true;
}
int buffersToStart = sndManager->GetBufferCount();
if (OpenOggNonstream(g_VFS, itemPath, ogg) != INFO::OK)
return false;
m_FileFinished = false;
SetFormatAndFreq(ogg->Format(), ogg->SamplingRate());
SetFileName(itemPath);
AL_CHECK;
alGenBuffers(buffersToStart, m_Buffer);
ALenum err = alGetError();
if (err != AL_NO_ERROR)
{
LOGERROR("Failed to create initial buffer. OpenAL error: %s\n", alGetString(err));
return false;
}
return false;
m_BuffersUsed = FetchDataIntoBuffer(buffersToStart, m_Buffer);
if (m_FileFinished)
{
m_OneShot = true;
if (m_BuffersUsed < buffersToStart)
{
alDeleteBuffers(buffersToStart - m_BuffersUsed, &m_Buffer[m_BuffersUsed]);
}
}
AL_CHECK;
return true;
}
ALsizei COggData::GetBufferCount()
@ -124,28 +119,28 @@ bool COggData::IsOneShot()
int COggData::FetchDataIntoBuffer(int count, ALuint* buffers)
{
if ( CSoundManager* sndManager = (CSoundManager*)g_SoundManager )
{
long bufferSize = sndManager->GetBufferSize();
u8* pcmout = new u8[bufferSize + 5000];
int buffersWritten = 0;
for (int i = 0; (i < count) && !m_FileFinished; i++)
CSoundManager* sndManager = (CSoundManager*)g_SoundManager;
if (!sndManager)
return 0;
long bufferSize = sndManager->GetBufferSize();
u8* pcmout = new u8[bufferSize + 5000];
int buffersWritten = 0;
for (int i = 0; i < count && !m_FileFinished; ++i)
{
memset(pcmout, 0, bufferSize + 5000);
Status totalRet = ogg->GetNextChunk(pcmout, bufferSize);
m_FileFinished = ogg->atFileEOF();
if (totalRet > 0)
{
memset( pcmout, 0, bufferSize + 5000 );
Status totalRet = ogg->GetNextChunk( pcmout, bufferSize);
m_FileFinished = ogg->atFileEOF();
if (totalRet > 0)
{
buffersWritten++;
alBufferData(buffers[i], m_Format, pcmout, (ALsizei)totalRet, (int)m_Frequency);
}
buffersWritten++;
alBufferData(buffers[i], m_Format, pcmout, (ALsizei)totalRet, (int)m_Frequency);
}
delete[] pcmout;
return buffersWritten;
}
return 0;
delete[] pcmout;
return buffersWritten;
}
@ -160,4 +155,3 @@ ALuint* COggData::GetBufferPtr()
}
#endif // CONFIG2_AUDIO

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2012 Wildfire Games.
/* Copyright (C) 2015 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -47,7 +47,6 @@ public:
protected:
OggStreamPtr ogg;
// int m_current_section;
bool m_FileFinished;
bool m_OneShot;
ALuint m_Buffer[100];

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2012 Wildfire Games.
/* Copyright (C) 2015 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -25,30 +25,20 @@
#include "OggData.h"
#include "ps/CLogger.h"
#include <iostream>
DataMap CSoundData::sSoundData;
CSoundData::CSoundData()
: m_ALBuffer(0), m_RetentionCount(0)
{
InitProperties();
}
CSoundData::~CSoundData()
{
AL_CHECK
AL_CHECK;
if (m_ALBuffer != 0)
alDeleteBuffers(1, &m_ALBuffer);
m_ALBuffer = 0;
AL_CHECK
delete m_FileName;
}
void CSoundData::InitProperties()
{
m_ALBuffer = 0;
m_RetentionCount = 0;
m_FileName = NULL;
AL_CHECK;
}
void CSoundData::ReleaseSoundData(CSoundData* theData)
@ -57,7 +47,7 @@ void CSoundData::ReleaseSoundData(CSoundData* theData)
if (theData->DecrementCount())
{
if ((itemFind = CSoundData::sSoundData.find( theData->GetFileName()->string() )) != sSoundData.end())
if ((itemFind = CSoundData::sSoundData.find( theData->GetFileName().string() )) != sSoundData.end())
{
CSoundData::sSoundData.erase(itemFind);
}
@ -98,20 +88,16 @@ bool CSoundData::IsOneShot()
CSoundData* CSoundData::SoundDataFromOgg(const VfsPath& itemPath)
{
CSoundData* answer = NULL;
COggData* oggAnswer = new COggData();
if ( oggAnswer->InitOggFile(itemPath) )
{
answer = oggAnswer;
}
else
if (!oggAnswer->InitOggFile(itemPath))
{
LOGERROR("could not initialize ogg data at %s", itemPath.string8());
delete oggAnswer;
return NULL;
}
return answer;
return oggAnswer;
}
int CSoundData::GetBufferCount()
@ -119,16 +105,14 @@ int CSoundData::GetBufferCount()
return 1;
}
Path* CSoundData::GetFileName()
const Path& CSoundData::GetFileName()
{
return m_FileName;
}
void CSoundData::SetFileName(const Path& aName)
{
delete m_FileName;
m_FileName = new Path( aName );
m_FileName = aName;
}
CSoundData* CSoundData::IncrementCount()

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2012 Wildfire Games.
/* Copyright (C) 2015 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -44,14 +44,13 @@ public:
CSoundData* IncrementCount();
bool DecrementCount();
void InitProperties();
virtual bool IsOneShot();
virtual bool IsStereo();
virtual unsigned int GetBuffer();
virtual int GetBufferCount();
virtual Path* GetFileName();
virtual const Path& GetFileName();
virtual void SetFileName(const Path& aName);
virtual unsigned int* GetBufferPtr();
@ -61,7 +60,7 @@ protected:
unsigned int m_ALBuffer;
int m_RetentionCount;
Path* m_FileName;
Path m_FileName;
};

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2013 Wildfire Games.
/* Copyright (C) 2015 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -21,10 +21,8 @@
#if CONFIG2_AUDIO
#include "soundmanager/data/SoundData.h"
#include "soundmanager/SoundManager.h"
#include <iostream>
#include "soundmanager/data/SoundData.h"
CBufferItem::CBufferItem(CSoundData* sndData)
{
@ -47,21 +45,21 @@ void CBufferItem::ReleaseOpenALBuffer()
return;
int num_processed;
AL_CHECK
AL_CHECK;
alGetSourcei(m_ALSource, AL_BUFFERS_PROCESSED, &num_processed);
AL_CHECK
AL_CHECK;
if (num_processed > 0)
{
ALuint* al_buf = new ALuint[num_processed];
alSourceUnqueueBuffers(m_ALSource, num_processed, al_buf);
AL_CHECK
AL_CHECK;
delete[] al_buf;
}
alSourcei(m_ALSource, AL_BUFFER, 0);
((CSoundManager*)g_SoundManager)->ReleaseALSource(m_ALSource);
AL_CHECK
AL_CHECK;
m_ALSource = 0;
}
@ -78,7 +76,7 @@ bool CBufferItem::IdleTask()
CScopeLock lock(m_ItemMutex);
int proc_state;
alGetSourcei(m_ALSource, AL_SOURCE_STATE, &proc_state);
AL_CHECK
AL_CHECK;
m_ShouldBePlaying = (proc_state != AL_STOPPED);
return (proc_state != AL_STOPPED);
}
@ -86,17 +84,17 @@ bool CBufferItem::IdleTask()
if (GetLooping())
{
int num_processed;
AL_CHECK
AL_CHECK;
alGetSourcei(m_ALSource, AL_BUFFERS_PROCESSED, &num_processed);
AL_CHECK
AL_CHECK;
for (int i = 0; i < num_processed; i++)
{
ALuint al_buf;
alSourceUnqueueBuffers(m_ALSource, 1, &al_buf);
AL_CHECK
AL_CHECK;
alSourceQueueBuffers(m_ALSource, 1, &al_buf);
AL_CHECK
AL_CHECK;
}
}
@ -108,18 +106,18 @@ void CBufferItem::Attach(CSoundData* itemData)
if ( m_ALSource == 0 )
return;
AL_CHECK
AL_CHECK;
if (m_SoundData != NULL)
{
CSoundData::ReleaseSoundData(m_SoundData);
m_SoundData = 0;
}
AL_CHECK
AL_CHECK;
if (itemData != NULL)
{
m_SoundData = itemData->IncrementCount();
alSourceQueueBuffers(m_ALSource, m_SoundData->GetBufferCount(),(const ALuint *) m_SoundData->GetBufferPtr());
AL_CHECK
AL_CHECK;
}
}
@ -129,4 +127,3 @@ void CBufferItem::SetLooping(bool loops)
}
#endif // CONFIG2_AUDIO

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2013 Wildfire Games.
/* Copyright (C) 2015 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -26,8 +26,6 @@
#include "soundmanager/data/SoundData.h"
#include "ps/CLogger.h"
#include <iostream>
CSoundBase::CSoundBase()
{
ResetVars();
@ -43,18 +41,18 @@ void CSoundBase::ReleaseOpenAL()
{
if (m_ALSource != 0)
{
AL_CHECK
AL_CHECK;
alSourcei(m_ALSource, AL_BUFFER, 0L);
AL_CHECK
AL_CHECK;
((CSoundManager*)g_SoundManager)->ReleaseALSource(m_ALSource);
AL_CHECK
AL_CHECK;
m_ALSource = 0;
}
if (m_SoundData != 0)
{
AL_CHECK
AL_CHECK;
CSoundData::ReleaseSoundData(m_SoundData);
AL_CHECK
AL_CHECK;
m_SoundData = 0;
}
}
@ -98,16 +96,16 @@ bool CSoundBase::InitOpenAL()
alGetError(); /* clear error */
m_ALSource = ((CSoundManager*)g_SoundManager)->GetALSource( this );
AL_CHECK
AL_CHECK;
if ( m_ALSource )
{
alSourcef(m_ALSource,AL_PITCH,1.0f);
AL_CHECK
AL_CHECK;
alSourcef(m_ALSource,AL_GAIN,1.0f);
AL_CHECK
AL_CHECK;
alSourcei(m_ALSource,AL_LOOPING,AL_FALSE);
AL_CHECK
AL_CHECK;
return true;
}
else
@ -119,13 +117,13 @@ bool CSoundBase::InitOpenAL()
void CSoundBase::SetGain(ALfloat gain)
{
AL_CHECK
AL_CHECK;
if ( m_ALSource )
{
CScopeLock lock(m_ItemMutex);
alSourcef(m_ALSource, AL_GAIN, gain);
AL_CHECK
AL_CHECK;
}
}
@ -135,11 +133,11 @@ void CSoundBase::SetRollOff(ALfloat rolls)
{
CScopeLock lock(m_ItemMutex);
alSourcef(m_ALSource, AL_REFERENCE_DISTANCE, 70.0f);
AL_CHECK
AL_CHECK;
alSourcef(m_ALSource, AL_MAX_DISTANCE, 200.0);
AL_CHECK
alSourcef(m_ALSource, AL_ROLLOFF_FACTOR, rolls);
AL_CHECK
AL_CHECK;
alSourcef(m_ALSource, AL_ROLLOFF_FACTOR, rolls);
AL_CHECK;
}
}
@ -154,13 +152,13 @@ void CSoundBase::SetCone(ALfloat innerCone, ALfloat outerCone, ALfloat coneGain)
if ( m_ALSource )
{
CScopeLock lock(m_ItemMutex);
AL_CHECK
AL_CHECK;
alSourcef(m_ALSource, AL_CONE_INNER_ANGLE, innerCone);
AL_CHECK
AL_CHECK;
alSourcef(m_ALSource, AL_CONE_OUTER_ANGLE, outerCone);
AL_CHECK
AL_CHECK;
alSourcef(m_ALSource, AL_CONE_OUTER_GAIN, coneGain);
AL_CHECK
AL_CHECK;
}
}
@ -170,7 +168,7 @@ void CSoundBase::SetPitch(ALfloat pitch)
{
CScopeLock lock(m_ItemMutex);
alSourcef(m_ALSource, AL_PITCH, pitch);
AL_CHECK
AL_CHECK;
}
}
@ -180,7 +178,7 @@ void CSoundBase::SetDirection(const CVector3D& direction)
{
CScopeLock lock(m_ItemMutex);
alSourcefv(m_ALSource, AL_DIRECTION, direction.GetFloatArray());
AL_CHECK
AL_CHECK;
}
}
@ -192,7 +190,7 @@ bool CSoundBase::IsPlaying()
CScopeLock lock(m_ItemMutex);
int proc_state;
alGetSourcei(m_ALSource, AL_SOURCE_STATE, &proc_state);
AL_CHECK
AL_CHECK;
return (proc_state == AL_PLAYING);
}
@ -215,13 +213,13 @@ void CSoundBase::SetLocation (const CVector3D& position)
{
CScopeLock lock(m_ItemMutex);
alSourcefv(m_ALSource,AL_POSITION, position.GetFloatArray());
AL_CHECK
AL_CHECK;
}
}
bool CSoundBase::HandleFade()
{
AL_CHECK
AL_CHECK;
if (m_ALSource == 0)
return true;
@ -248,7 +246,7 @@ bool CSoundBase::HandleFade()
else if (m_ALSource != 0)
alSourcef(m_ALSource, AL_GAIN, curGain);
AL_CHECK
AL_CHECK;
}
return true;
}
@ -270,7 +268,7 @@ void CSoundBase::SetLooping(bool loops)
if (m_ALSource != 0)
{
alSourcei(m_ALSource, AL_LOOPING, loops ? AL_TRUE : AL_FALSE);
AL_CHECK
AL_CHECK;
}
}
@ -280,7 +278,7 @@ void CSoundBase::Play()
m_ShouldBePlaying = true;
m_IsPaused = false;
AL_CHECK
AL_CHECK;
if (m_ALSource != 0)
{
alSourcePlay(m_ALSource);
@ -325,7 +323,7 @@ void CSoundBase::PlayLoop()
{
SetLooping(true);
Play();
AL_CHECK
AL_CHECK;
}
}
@ -342,7 +340,7 @@ void CSoundBase::FadeToIn(ALfloat newVolume, double fadeDuration)
alGetSourcef(m_ALSource, AL_GAIN, &m_StartVolume);
m_EndVolume = newVolume;
}
AL_CHECK
AL_CHECK;
}
}
@ -353,39 +351,39 @@ void CSoundBase::Stop()
{
CScopeLock lock(m_ItemMutex);
AL_CHECK
AL_CHECK;
alSourcei(m_ALSource, AL_LOOPING, AL_FALSE);
AL_CHECK
AL_CHECK;
alSourceStop(m_ALSource);
AL_CHECK
AL_CHECK;
}
}
Path* CSoundBase::GetName()
const Path CSoundBase::GetName()
{
if ( m_SoundData )
if (m_SoundData)
return m_SoundData->GetFileName();
return NULL;
return Path();
}
void CSoundBase::Pause()
{
if (m_ALSource != 0)
{
if (m_ALSource != 0)
{
m_IsPaused = true;
alSourcePause(m_ALSource);
AL_CHECK
}
alSourcePause(m_ALSource);
AL_CHECK;
}
}
void CSoundBase::Resume()
{
if (m_ALSource != 0)
{
alSourcePlay(m_ALSource);
AL_CHECK
}
if (m_ALSource != 0)
{
alSourcePlay(m_ALSource);
AL_CHECK;
}
}
#endif // CONFIG2_AUDIO

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2012 Wildfire Games.
/* Copyright (C) 2015 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -83,7 +83,7 @@ public:
void Pause();
void Resume();
Path* GetName();
const Path GetName();
virtual void SetLooping(bool loops);
virtual bool IdleTask();

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2012 Wildfire Games.
/* Copyright (C) 2015 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -21,10 +21,8 @@
#if CONFIG2_AUDIO
#include "soundmanager/data/SoundData.h"
#include "soundmanager/SoundManager.h"
#include <iostream>
#include "soundmanager/data/SoundData.h"
CSoundItem::CSoundItem()
{
@ -56,7 +54,7 @@ bool CSoundItem::IdleTask()
CScopeLock lock(m_ItemMutex);
int proc_state;
alGetSourcei(m_ALSource, AL_SOURCE_STATE, &proc_state);
AL_CHECK
AL_CHECK;
m_ShouldBePlaying = (proc_state != AL_STOPPED);
return (proc_state != AL_STOPPED);
}
@ -73,15 +71,14 @@ void CSoundItem::Attach(CSoundData* itemData)
if (itemData != NULL)
{
AL_CHECK
AL_CHECK;
alSourcei(m_ALSource, AL_BUFFER, 0);
AL_CHECK
AL_CHECK;
m_SoundData = itemData->IncrementCount();
alSourcei(m_ALSource, AL_BUFFER, m_SoundData->GetBuffer());
AL_CHECK
AL_CHECK;
}
}
#endif // CONFIG2_AUDIO

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2013 Wildfire Games.
/* Copyright (C) 2015 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -21,10 +21,8 @@
#if CONFIG2_AUDIO
#include "soundmanager/data/OggData.h"
#include "soundmanager/SoundManager.h"
#include <iostream>
#include "soundmanager/data/OggData.h"
CStreamItem::CStreamItem(CSoundData* sndData)
{
@ -44,36 +42,36 @@ void CStreamItem::ReleaseOpenALStream()
if (m_ALSource != 0)
{
int num_processed;
AL_CHECK
AL_CHECK;
alGetSourcei(m_ALSource, AL_BUFFERS_PROCESSED, &num_processed);
AL_CHECK
AL_CHECK;
if (num_processed > 0)
{
ALuint* al_buf = new ALuint[num_processed];
alSourceUnqueueBuffers(m_ALSource, num_processed, al_buf);
AL_CHECK
AL_CHECK;
delete[] al_buf;
}
alSourcei(m_ALSource, AL_BUFFER, 0);
AL_CHECK
AL_CHECK;
((CSoundManager*)g_SoundManager)->ReleaseALSource(m_ALSource);
AL_CHECK
AL_CHECK;
m_ALSource = 0;
}
}
bool CStreamItem::IdleTask()
{
AL_CHECK
AL_CHECK;
HandleFade();
AL_CHECK
AL_CHECK;
if (m_ALSource != 0)
{
int proc_state;
alGetSourcei(m_ALSource, AL_SOURCE_STATE, &proc_state);
AL_CHECK
AL_CHECK;
if (proc_state == AL_STOPPED)
{
@ -88,16 +86,16 @@ bool CStreamItem::IdleTask()
{
int num_processed;
alGetSourcei(m_ALSource, AL_BUFFERS_PROCESSED, &num_processed);
AL_CHECK
AL_CHECK;
if (num_processed > 0)
{
ALuint* al_buf = new ALuint[num_processed];
alSourceUnqueueBuffers(m_ALSource, num_processed, al_buf);
AL_CHECK
AL_CHECK;
int didWrite = theData->FetchDataIntoBuffer(num_processed, al_buf);
alSourceQueueBuffers(m_ALSource, didWrite, al_buf);
AL_CHECK
AL_CHECK;
delete[] al_buf;
}
}
@ -113,7 +111,7 @@ bool CStreamItem::IdleTask()
}
}
}
AL_CHECK
AL_CHECK;
return true;
}
@ -129,7 +127,7 @@ void CStreamItem::Attach(CSoundData* itemData)
{
m_SoundData = itemData->IncrementCount();
alSourceQueueBuffers(m_ALSource, m_SoundData->GetBufferCount(), (const ALuint *)m_SoundData->GetBufferPtr());
AL_CHECK
AL_CHECK;
}
}
@ -139,4 +137,3 @@ void CStreamItem::SetLooping(bool loops)
}
#endif // CONFIG2_AUDIO

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2012 Wildfire Games.
/* Copyright (C) 2015 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -36,7 +36,7 @@ public:
virtual bool IsPlaying() = 0;
virtual Path* GetName() = 0;
virtual const Path GetName() = 0;
virtual bool IdleTask() = 0;
virtual bool IsFading() = 0;
virtual bool Finished() = 0;
@ -68,4 +68,3 @@ public:
#endif // CONFIG2_AUDIO
#endif // INCLUDED_ISOUNDITEM_H

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2012 Wildfire Games.
/* Copyright (C) 2015 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -197,7 +197,7 @@ void CSoundGroup::UploadPropertiesAndPlay(size_t theIndex, const CVector3D& posi
itemRollOff = 0;
if ( sndData->IsStereo() )
LOGWARNING( "OpenAL: stereo sounds can't be positioned: %s", sndData->GetFileName()->string8() );
LOGWARNING("OpenAL: stereo sounds can't be positioned: %s", sndData->GetFileName().string8());
hSound->SetLocation(CVector3D((sndDist * sin(offSet)), 0, - sndDist * cos(offSet)));
hSound->SetRollOff(itemRollOff);