1
0
forked from 0ad/0ad

silence repeated errors when buffers don't allocate, fix up reference counting

This was SVN commit r12638.
This commit is contained in:
stwf 2012-09-07 12:05:29 +00:00
parent d04f737c5e
commit df0c4559ad
4 changed files with 64 additions and 26 deletions

View File

@ -51,7 +51,8 @@ bool COggData::InitOggFile(const VfsPath& itemPath)
m_FileFinished = false;
SetFormatAndFreq(ogg->Format(), ogg->SamplingRate() );
SetFileName( itemPath );
AL_CHECK
alGenBuffers(buffersToStart, m_Buffer);

View File

@ -37,12 +37,15 @@ CSoundData::~CSoundData()
{
if (m_ALBuffer != 0)
alDeleteBuffers(1, &m_ALBuffer);
if ( m_FileName )
delete m_FileName;
}
void CSoundData::InitProperties()
{
m_ALBuffer = 0;
m_RetentionCount = 0;
m_FileName = NULL;
}
void CSoundData::ReleaseSoundData(CSoundData* theData)
@ -51,12 +54,11 @@ void CSoundData::ReleaseSoundData(CSoundData* theData)
if (theData->DecrementCount())
{
if ((itemFind = CSoundData::sSoundData->find(theData->GetFileName())) != sSoundData->end())
if ((itemFind = CSoundData::sSoundData->find( *theData->GetFileName() )) != sSoundData->end())
{
CSoundData* dier = itemFind->second;
CSoundData::sSoundData->erase(itemFind);
delete dier;
}
delete theData;
}
}
@ -79,10 +81,13 @@ CSoundData* CSoundData::SoundDataFromFile(const VfsPath& itemPath)
if (fExt == ".ogg")
answer = SoundDataFromOgg(itemPath);
if (answer && answer->IsOneShot())
if (answer && answer->IsOneShot())
{
(*CSoundData::sSoundData)[itemPath.string()] = answer;
}
}
return answer;
}
@ -115,11 +120,19 @@ ALsizei CSoundData::GetBufferCount()
return 1;
}
CStrW CSoundData::GetFileName()
std::wstring* CSoundData::GetFileName()
{
return m_FileName;
}
void CSoundData::SetFileName(const Path& aName)
{
if ( m_FileName )
delete m_FileName;
m_FileName = new std::wstring( aName.string() );
}
CSoundData* CSoundData::IncrementCount()
{
m_RetentionCount++;
@ -137,6 +150,7 @@ ALuint CSoundData::GetBuffer()
{
return m_ALBuffer;
}
ALuint* CSoundData::GetBufferPtr()
{
return &m_ALBuffer;

View File

@ -53,7 +53,9 @@ public:
virtual ALuint GetBuffer();
virtual ALsizei GetBufferCount();
CStrW GetFileName();
virtual std::wstring* GetFileName();
virtual void SetFileName(const Path& aName);
virtual ALuint* GetBufferPtr();
protected:
@ -61,7 +63,7 @@ protected:
ALuint m_ALBuffer;
int m_RetentionCount;
CStrW m_FileName;
std::wstring* m_FileName;
};

View File

@ -78,15 +78,20 @@ void CSoundBase::SetGain(ALfloat gain)
{
AL_CHECK
alSourcef(m_ALSource, AL_GAIN, gain);
AL_CHECK
if ( m_ALSource )
{
alSourcef(m_ALSource, AL_GAIN, gain);
AL_CHECK
}
}
void CSoundBase::SetRollOff(ALfloat rolls)
{
alSourcef(m_ALSource, AL_ROLLOFF_FACTOR, rolls);
AL_CHECK
if ( m_ALSource )
{
alSourcef(m_ALSource, AL_ROLLOFF_FACTOR, rolls);
AL_CHECK
}
}
void CSoundBase::EnsurePlay()
@ -97,25 +102,34 @@ void CSoundBase::EnsurePlay()
void CSoundBase::SetCone(ALfloat innerCone, ALfloat outerCone, ALfloat coneGain)
{
AL_CHECK
alSourcef(m_ALSource, AL_CONE_INNER_ANGLE, innerCone);
AL_CHECK
alSourcef(m_ALSource, AL_CONE_OUTER_ANGLE, outerCone);
AL_CHECK
alSourcef(m_ALSource, AL_CONE_OUTER_GAIN, coneGain);
AL_CHECK
if ( m_ALSource )
{
AL_CHECK
alSourcef(m_ALSource, AL_CONE_INNER_ANGLE, innerCone);
AL_CHECK
alSourcef(m_ALSource, AL_CONE_OUTER_ANGLE, outerCone);
AL_CHECK
alSourcef(m_ALSource, AL_CONE_OUTER_GAIN, coneGain);
AL_CHECK
}
}
void CSoundBase::SetPitch(ALfloat pitch)
{
alSourcef(m_ALSource, AL_PITCH, pitch);
AL_CHECK
if ( m_ALSource )
{
alSourcef(m_ALSource, AL_PITCH, pitch);
AL_CHECK
}
}
void CSoundBase::SetDirection(const CVector3D& direction)
{
alSourcefv(m_ALSource, AL_DIRECTION, direction.GetFloatArray());
AL_CHECK
if ( m_ALSource )
{
alSourcefv(m_ALSource, AL_DIRECTION, direction.GetFloatArray());
AL_CHECK
}
}
bool CSoundBase::InitOpenAL()
@ -140,6 +154,10 @@ bool CSoundBase::InitOpenAL()
return true;
}
else
{
CSoundManager::al_ReportError( anErr, __func__, __LINE__);
}
return false;
}
@ -164,8 +182,11 @@ bool CSoundBase::IdleTask()
void CSoundBase::SetLocation (const CVector3D& position)
{
alSourcefv(m_ALSource,AL_POSITION, position.GetFloatArray());
AL_CHECK
if ( m_ALSource )
{
alSourcefv(m_ALSource,AL_POSITION, position.GetFloatArray());
AL_CHECK
}
}
bool CSoundBase::HandleFade()