2025-05-21 05:55:52 -07:00
|
|
|
/* Copyright (C) 2025 Wildfire Games.
|
2023-12-02 16:30:12 -08:00
|
|
|
* This file is part of 0 A.D.
|
2012-08-14 17:10:44 -07:00
|
|
|
*
|
2023-12-02 16:30:12 -08:00
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
2012-08-14 17:10:44 -07:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
2023-12-02 16:30:12 -08:00
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
2012-08-14 17:10:44 -07:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2023-12-02 16:30:12 -08:00
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
2012-08-14 17:10:44 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "precompiled.h"
|
|
|
|
|
|
|
|
|
|
#include "CSoundBase.h"
|
|
|
|
|
|
2012-08-31 12:08:41 -07:00
|
|
|
#if CONFIG2_AUDIO
|
|
|
|
|
|
2025-08-10 10:59:02 -07:00
|
|
|
#include "lib/path.h"
|
2012-08-14 17:10:44 -07:00
|
|
|
#include "lib/timer.h"
|
2025-08-10 10:59:02 -07:00
|
|
|
#include "maths/Vector3D.h"
|
|
|
|
|
#include "soundmanager/ISoundManager.h"
|
2012-08-14 17:10:44 -07:00
|
|
|
#include "soundmanager/SoundManager.h"
|
2025-10-10 11:49:37 -07:00
|
|
|
#include "soundmanager/data/SoundData.h"
|
2025-08-10 10:59:02 -07:00
|
|
|
|
|
|
|
|
#include <algorithm>
|
2012-08-14 17:10:44 -07:00
|
|
|
|
|
|
|
|
CSoundBase::CSoundBase()
|
|
|
|
|
{
|
|
|
|
|
ResetVars();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CSoundBase::~CSoundBase()
|
|
|
|
|
{
|
|
|
|
|
Stop();
|
2013-03-01 06:22:28 -08:00
|
|
|
ReleaseOpenAL();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CSoundBase::ReleaseOpenAL()
|
|
|
|
|
{
|
2012-08-14 17:10:44 -07:00
|
|
|
if (m_ALSource != 0)
|
|
|
|
|
{
|
2015-02-02 05:44:06 -08:00
|
|
|
AL_CHECK;
|
2013-06-10 17:05:57 -07:00
|
|
|
alSourcei(m_ALSource, AL_BUFFER, 0L);
|
2015-02-02 05:44:06 -08:00
|
|
|
AL_CHECK;
|
2013-06-06 04:13:57 -07:00
|
|
|
((CSoundManager*)g_SoundManager)->ReleaseALSource(m_ALSource);
|
2015-02-02 05:44:06 -08:00
|
|
|
AL_CHECK;
|
2012-08-14 17:10:44 -07:00
|
|
|
m_ALSource = 0;
|
|
|
|
|
}
|
2025-10-10 11:49:37 -07:00
|
|
|
if (m_SoundData != 0)
|
|
|
|
|
{
|
|
|
|
|
AL_CHECK;
|
|
|
|
|
CSoundData::ReleaseSoundData(m_SoundData);
|
|
|
|
|
AL_CHECK;
|
|
|
|
|
m_SoundData = 0;
|
|
|
|
|
}
|
2012-08-14 17:10:44 -07:00
|
|
|
}
|
|
|
|
|
|
2025-10-10 11:49:37 -07:00
|
|
|
void CSoundBase::Attach(CSoundData* /*itemData*/)
|
2013-03-01 06:22:28 -08:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-14 17:10:44 -07:00
|
|
|
void CSoundBase::ResetVars()
|
|
|
|
|
{
|
|
|
|
|
m_ALSource = 0;
|
2025-10-10 11:49:37 -07:00
|
|
|
m_SoundData = 0;
|
2012-08-14 17:10:44 -07:00
|
|
|
m_LastPlay = false;
|
|
|
|
|
m_Looping = false;
|
|
|
|
|
m_StartFadeTime = 0;
|
|
|
|
|
m_EndFadeTime = 0;
|
|
|
|
|
m_StartVolume = 0;
|
|
|
|
|
m_EndVolume = 0;
|
2013-04-24 05:03:42 -07:00
|
|
|
m_ShouldBePlaying = false;
|
|
|
|
|
m_IsPaused = false;
|
2012-08-14 17:10:44 -07:00
|
|
|
ResetFade();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CSoundBase::ResetFade()
|
|
|
|
|
{
|
|
|
|
|
m_StartFadeTime = 0;
|
|
|
|
|
m_EndFadeTime = 0;
|
|
|
|
|
m_StartVolume = 0;
|
|
|
|
|
m_EndVolume = 0;
|
2013-04-10 04:51:42 -07:00
|
|
|
m_PauseAfterFade = false;
|
2012-08-14 17:10:44 -07:00
|
|
|
}
|
|
|
|
|
|
2013-04-24 05:03:42 -07:00
|
|
|
bool CSoundBase::Finished()
|
|
|
|
|
{
|
|
|
|
|
return !m_ShouldBePlaying && !IsPlaying();
|
|
|
|
|
}
|
2013-03-01 06:22:28 -08:00
|
|
|
|
|
|
|
|
bool CSoundBase::InitOpenAL()
|
|
|
|
|
{
|
|
|
|
|
alGetError(); /* clear error */
|
2013-06-06 04:13:57 -07:00
|
|
|
m_ALSource = ((CSoundManager*)g_SoundManager)->GetALSource( this );
|
2013-03-01 06:22:28 -08:00
|
|
|
|
2015-02-02 05:44:06 -08:00
|
|
|
AL_CHECK;
|
2013-03-01 06:22:28 -08:00
|
|
|
|
2016-11-23 06:09:58 -08:00
|
|
|
if ( m_ALSource )
|
|
|
|
|
{
|
2013-03-01 06:22:28 -08:00
|
|
|
alSourcef(m_ALSource,AL_PITCH,1.0f);
|
2015-02-02 05:44:06 -08:00
|
|
|
AL_CHECK;
|
2013-03-01 06:22:28 -08:00
|
|
|
alSourcef(m_ALSource,AL_GAIN,1.0f);
|
2015-02-02 05:44:06 -08:00
|
|
|
AL_CHECK;
|
2013-03-01 06:22:28 -08:00
|
|
|
alSourcei(m_ALSource,AL_LOOPING,AL_FALSE);
|
2015-02-02 05:44:06 -08:00
|
|
|
AL_CHECK;
|
2013-03-01 06:22:28 -08:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-01-22 12:31:30 -08:00
|
|
|
// LOGERROR("Source not allocated by SoundManager\n", 0);
|
2013-03-01 06:22:28 -08:00
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-14 17:10:44 -07:00
|
|
|
void CSoundBase::SetGain(ALfloat gain)
|
|
|
|
|
{
|
2015-02-02 05:44:06 -08:00
|
|
|
AL_CHECK;
|
2012-08-31 12:08:41 -07:00
|
|
|
|
2016-11-23 06:09:58 -08:00
|
|
|
if ( m_ALSource )
|
2012-09-07 05:05:29 -07:00
|
|
|
{
|
2019-06-06 12:30:48 -07:00
|
|
|
std::lock_guard<std::mutex> lock(m_ItemMutex);
|
2012-09-07 05:05:29 -07:00
|
|
|
alSourcef(m_ALSource, AL_GAIN, gain);
|
2015-02-02 05:44:06 -08:00
|
|
|
AL_CHECK;
|
2012-09-07 05:05:29 -07:00
|
|
|
}
|
2012-08-14 17:10:44 -07:00
|
|
|
}
|
|
|
|
|
|
Tweak sound distance attenuation & add configurability
Following D3108 / 876f6d5e50, sounds are attenuated by their actual
distance. However, as noted by players on A24, the dropoff is stark and,
when zoomed out, can easily result in not hearing things that are
happening in the middle of the screen.
The new default settings almost double the max-range, change the minimum
range to have greater dynamic range, and reduce the stereo depth
slightly to better match the default camera FOV.
These are stored per sound-grounp, possibly allowing future tweaks on a
per-soundgroup basis, and are configurable.
Tested by: Imarok
Discussed over mail with: Samulis, Porru
Differential Revision: https://code.wildfiregames.com/D3612
This was SVN commit r25547.
2021-05-24 23:19:25 -07:00
|
|
|
void CSoundBase::SetRollOff(float rolls, float minDist, float maxDist)
|
2012-08-14 17:10:44 -07:00
|
|
|
{
|
2013-03-03 14:28:26 -08:00
|
|
|
if ( m_ALSource )
|
|
|
|
|
{
|
2019-06-06 12:30:48 -07:00
|
|
|
std::lock_guard<std::mutex> lock(m_ItemMutex);
|
Tweak sound distance attenuation & add configurability
Following D3108 / 876f6d5e50, sounds are attenuated by their actual
distance. However, as noted by players on A24, the dropoff is stark and,
when zoomed out, can easily result in not hearing things that are
happening in the middle of the screen.
The new default settings almost double the max-range, change the minimum
range to have greater dynamic range, and reduce the stereo depth
slightly to better match the default camera FOV.
These are stored per sound-grounp, possibly allowing future tweaks on a
per-soundgroup basis, and are configurable.
Tested by: Imarok
Discussed over mail with: Samulis, Porru
Differential Revision: https://code.wildfiregames.com/D3612
This was SVN commit r25547.
2021-05-24 23:19:25 -07:00
|
|
|
alSourcef(m_ALSource, AL_REFERENCE_DISTANCE, minDist);
|
2015-02-02 05:44:06 -08:00
|
|
|
AL_CHECK;
|
Tweak sound distance attenuation & add configurability
Following D3108 / 876f6d5e50, sounds are attenuated by their actual
distance. However, as noted by players on A24, the dropoff is stark and,
when zoomed out, can easily result in not hearing things that are
happening in the middle of the screen.
The new default settings almost double the max-range, change the minimum
range to have greater dynamic range, and reduce the stereo depth
slightly to better match the default camera FOV.
These are stored per sound-grounp, possibly allowing future tweaks on a
per-soundgroup basis, and are configurable.
Tested by: Imarok
Discussed over mail with: Samulis, Porru
Differential Revision: https://code.wildfiregames.com/D3612
This was SVN commit r25547.
2021-05-24 23:19:25 -07:00
|
|
|
alSourcef(m_ALSource, AL_MAX_DISTANCE, maxDist);
|
2015-02-02 05:44:06 -08:00
|
|
|
AL_CHECK;
|
|
|
|
|
alSourcef(m_ALSource, AL_ROLLOFF_FACTOR, rolls);
|
|
|
|
|
AL_CHECK;
|
2012-09-07 05:05:29 -07:00
|
|
|
}
|
2012-08-14 17:10:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CSoundBase::EnsurePlay()
|
|
|
|
|
{
|
2013-04-24 05:03:42 -07:00
|
|
|
if (m_ShouldBePlaying && !m_IsPaused && !IsPlaying())
|
2012-08-14 17:10:44 -07:00
|
|
|
Play();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CSoundBase::SetCone(ALfloat innerCone, ALfloat outerCone, ALfloat coneGain)
|
|
|
|
|
{
|
2012-09-07 05:05:29 -07:00
|
|
|
if ( m_ALSource )
|
|
|
|
|
{
|
2019-06-06 12:30:48 -07:00
|
|
|
std::lock_guard<std::mutex> lock(m_ItemMutex);
|
2015-02-02 05:44:06 -08:00
|
|
|
AL_CHECK;
|
2012-09-07 05:05:29 -07:00
|
|
|
alSourcef(m_ALSource, AL_CONE_INNER_ANGLE, innerCone);
|
2015-02-02 05:44:06 -08:00
|
|
|
AL_CHECK;
|
2012-09-07 05:05:29 -07:00
|
|
|
alSourcef(m_ALSource, AL_CONE_OUTER_ANGLE, outerCone);
|
2015-02-02 05:44:06 -08:00
|
|
|
AL_CHECK;
|
2012-09-07 05:05:29 -07:00
|
|
|
alSourcef(m_ALSource, AL_CONE_OUTER_GAIN, coneGain);
|
2015-02-02 05:44:06 -08:00
|
|
|
AL_CHECK;
|
2012-09-07 05:05:29 -07:00
|
|
|
}
|
2012-08-14 17:10:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CSoundBase::SetPitch(ALfloat pitch)
|
|
|
|
|
{
|
2012-09-07 05:05:29 -07:00
|
|
|
if ( m_ALSource )
|
|
|
|
|
{
|
2019-06-06 12:30:48 -07:00
|
|
|
std::lock_guard<std::mutex> lock(m_ItemMutex);
|
2012-09-07 05:05:29 -07:00
|
|
|
alSourcef(m_ALSource, AL_PITCH, pitch);
|
2015-02-02 05:44:06 -08:00
|
|
|
AL_CHECK;
|
2012-09-07 05:05:29 -07:00
|
|
|
}
|
2012-08-14 17:10:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CSoundBase::SetDirection(const CVector3D& direction)
|
|
|
|
|
{
|
2012-09-07 05:05:29 -07:00
|
|
|
if ( m_ALSource )
|
|
|
|
|
{
|
2019-06-06 12:30:48 -07:00
|
|
|
std::lock_guard<std::mutex> lock(m_ItemMutex);
|
2022-05-02 13:57:22 -07:00
|
|
|
alSourcefv(m_ALSource, AL_DIRECTION, direction.AsFloatArray().data());
|
2015-02-02 05:44:06 -08:00
|
|
|
AL_CHECK;
|
2012-09-07 05:05:29 -07:00
|
|
|
}
|
2012-08-14 17:10:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool CSoundBase::IsPlaying()
|
|
|
|
|
{
|
2013-03-01 06:22:28 -08:00
|
|
|
if ( m_ALSource )
|
2012-12-13 19:10:03 -08:00
|
|
|
{
|
2019-06-06 12:30:48 -07:00
|
|
|
std::lock_guard<std::mutex> lock(m_ItemMutex);
|
2013-03-01 06:22:28 -08:00
|
|
|
int proc_state;
|
2013-04-25 03:48:34 -07:00
|
|
|
alGetSourcei(m_ALSource, AL_SOURCE_STATE, &proc_state);
|
2015-02-02 05:44:06 -08:00
|
|
|
AL_CHECK;
|
2012-08-14 17:10:44 -07:00
|
|
|
|
2013-03-01 06:22:28 -08:00
|
|
|
return (proc_state == AL_PLAYING);
|
|
|
|
|
}
|
|
|
|
|
return false;
|
2012-08-14 17:10:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CSoundBase::SetLastPlay(bool last)
|
|
|
|
|
{
|
|
|
|
|
m_LastPlay = last;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CSoundBase::IdleTask()
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CSoundBase::SetLocation (const CVector3D& position)
|
|
|
|
|
{
|
2012-12-13 19:10:03 -08:00
|
|
|
if ( m_ALSource != 0 )
|
2012-09-07 05:05:29 -07:00
|
|
|
{
|
2019-06-06 12:30:48 -07:00
|
|
|
std::lock_guard<std::mutex> lock(m_ItemMutex);
|
2022-05-02 13:57:22 -07:00
|
|
|
alSourcefv(m_ALSource,AL_POSITION, position.AsFloatArray().data());
|
2015-02-02 05:44:06 -08:00
|
|
|
AL_CHECK;
|
2012-09-07 05:05:29 -07:00
|
|
|
}
|
2012-08-14 17:10:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CSoundBase::HandleFade()
|
|
|
|
|
{
|
2015-02-02 05:44:06 -08:00
|
|
|
AL_CHECK;
|
2013-04-17 20:24:20 -07:00
|
|
|
if (m_ALSource == 0)
|
|
|
|
|
return true;
|
|
|
|
|
|
2012-08-14 17:10:44 -07:00
|
|
|
if (m_StartFadeTime != 0)
|
|
|
|
|
{
|
|
|
|
|
double currTime = timer_Time();
|
|
|
|
|
double pctDone = std::min(1.0, (currTime - m_StartFadeTime) / (m_EndFadeTime - m_StartFadeTime));
|
|
|
|
|
pctDone = std::max(0.0, pctDone);
|
|
|
|
|
ALfloat curGain = ((m_EndVolume - m_StartVolume) * pctDone) + m_StartVolume;
|
|
|
|
|
|
|
|
|
|
if (curGain == 0)
|
2013-04-10 04:51:42 -07:00
|
|
|
{
|
|
|
|
|
if ( m_PauseAfterFade )
|
|
|
|
|
Pause();
|
|
|
|
|
else
|
|
|
|
|
Stop();
|
|
|
|
|
}
|
2012-08-14 17:10:44 -07:00
|
|
|
else if (curGain == m_EndVolume)
|
|
|
|
|
{
|
2012-12-13 19:10:03 -08:00
|
|
|
if (m_ALSource != 0)
|
2016-11-23 06:09:58 -08:00
|
|
|
alSourcef(m_ALSource, AL_GAIN, curGain);
|
2012-08-14 17:10:44 -07:00
|
|
|
ResetFade();
|
|
|
|
|
}
|
2012-12-13 19:10:03 -08:00
|
|
|
else if (m_ALSource != 0)
|
2016-11-23 06:09:58 -08:00
|
|
|
alSourcef(m_ALSource, AL_GAIN, curGain);
|
2012-08-31 12:08:41 -07:00
|
|
|
|
2015-02-02 05:44:06 -08:00
|
|
|
AL_CHECK;
|
2012-08-14 17:10:44 -07:00
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-07 13:02:22 -08:00
|
|
|
bool CSoundBase::IsFading()
|
|
|
|
|
{
|
|
|
|
|
return ((m_ALSource != 0) && (m_StartFadeTime != 0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2012-08-14 17:10:44 -07:00
|
|
|
bool CSoundBase::GetLooping()
|
|
|
|
|
{
|
|
|
|
|
return m_Looping;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CSoundBase::SetLooping(bool loops)
|
|
|
|
|
{
|
|
|
|
|
m_Looping = loops;
|
2012-12-13 19:10:03 -08:00
|
|
|
if (m_ALSource != 0)
|
|
|
|
|
{
|
|
|
|
|
alSourcei(m_ALSource, AL_LOOPING, loops ? AL_TRUE : AL_FALSE);
|
2015-02-02 05:44:06 -08:00
|
|
|
AL_CHECK;
|
2012-12-13 19:10:03 -08:00
|
|
|
}
|
2012-08-14 17:10:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CSoundBase::Play()
|
|
|
|
|
{
|
2019-06-06 12:30:48 -07:00
|
|
|
std::lock_guard<std::mutex> lock(m_ItemMutex);
|
2013-03-01 06:22:28 -08:00
|
|
|
|
2012-08-14 17:10:44 -07:00
|
|
|
m_ShouldBePlaying = true;
|
2013-04-24 05:03:42 -07:00
|
|
|
m_IsPaused = false;
|
2015-02-02 05:44:06 -08:00
|
|
|
AL_CHECK;
|
2012-08-14 17:10:44 -07:00
|
|
|
if (m_ALSource != 0)
|
2013-03-01 06:22:28 -08:00
|
|
|
{
|
2012-08-14 17:10:44 -07:00
|
|
|
alSourcePlay(m_ALSource);
|
2013-03-01 06:22:28 -08:00
|
|
|
ALenum err = alGetError();
|
|
|
|
|
if (err != AL_NO_ERROR)
|
|
|
|
|
{
|
|
|
|
|
if (err == AL_INVALID)
|
2013-06-06 04:13:57 -07:00
|
|
|
((CSoundManager*)g_SoundManager)->SetDistressThroughError();
|
2013-03-01 06:22:28 -08:00
|
|
|
else
|
2013-06-06 04:13:57 -07:00
|
|
|
((CSoundManager*)g_SoundManager)->al_ReportError(err, __func__, __LINE__);
|
2013-03-01 06:22:28 -08:00
|
|
|
}
|
|
|
|
|
}
|
2012-08-14 17:10:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CSoundBase::PlayAndDelete()
|
|
|
|
|
{
|
|
|
|
|
SetLastPlay(true);
|
|
|
|
|
Play();
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-10 04:51:42 -07:00
|
|
|
void CSoundBase::FadeAndPause(double fadeTime)
|
|
|
|
|
{
|
|
|
|
|
m_PauseAfterFade = true;
|
|
|
|
|
FadeToIn(0, fadeTime);
|
|
|
|
|
}
|
2013-03-01 06:22:28 -08:00
|
|
|
|
2012-08-14 17:10:44 -07:00
|
|
|
void CSoundBase::FadeAndDelete(double fadeTime)
|
|
|
|
|
{
|
|
|
|
|
SetLastPlay(true);
|
|
|
|
|
FadeToIn(0, fadeTime);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CSoundBase::StopAndDelete()
|
|
|
|
|
{
|
|
|
|
|
SetLastPlay(true);
|
|
|
|
|
Stop();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CSoundBase::PlayLoop()
|
|
|
|
|
{
|
|
|
|
|
if (m_ALSource != 0)
|
|
|
|
|
{
|
|
|
|
|
SetLooping(true);
|
|
|
|
|
Play();
|
2015-02-02 05:44:06 -08:00
|
|
|
AL_CHECK;
|
2012-08-14 17:10:44 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CSoundBase::FadeToIn(ALfloat newVolume, double fadeDuration)
|
|
|
|
|
{
|
2012-12-13 19:10:03 -08:00
|
|
|
if (m_ALSource != 0)
|
2016-11-23 06:09:58 -08:00
|
|
|
{
|
2012-12-13 19:10:03 -08:00
|
|
|
ALenum proc_state;
|
2013-04-25 03:48:34 -07:00
|
|
|
alGetSourcei(m_ALSource, AL_SOURCE_STATE, &proc_state);
|
2012-12-13 19:10:03 -08:00
|
|
|
if (proc_state == AL_PLAYING)
|
|
|
|
|
{
|
|
|
|
|
m_StartFadeTime = timer_Time();
|
|
|
|
|
m_EndFadeTime = m_StartFadeTime + fadeDuration;
|
|
|
|
|
alGetSourcef(m_ALSource, AL_GAIN, &m_StartVolume);
|
|
|
|
|
m_EndVolume = newVolume;
|
|
|
|
|
}
|
2015-02-02 05:44:06 -08:00
|
|
|
AL_CHECK;
|
2012-08-14 17:10:44 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CSoundBase::Stop()
|
|
|
|
|
{
|
|
|
|
|
m_ShouldBePlaying = false;
|
|
|
|
|
if (m_ALSource != 0)
|
|
|
|
|
{
|
2019-06-06 12:30:48 -07:00
|
|
|
std::lock_guard<std::mutex> lock(m_ItemMutex);
|
2012-08-31 12:08:41 -07:00
|
|
|
|
2015-02-02 05:44:06 -08:00
|
|
|
AL_CHECK;
|
2013-04-17 20:24:20 -07:00
|
|
|
alSourcei(m_ALSource, AL_LOOPING, AL_FALSE);
|
2015-02-02 05:44:06 -08:00
|
|
|
AL_CHECK;
|
2013-04-17 20:24:20 -07:00
|
|
|
alSourceStop(m_ALSource);
|
2015-02-02 05:44:06 -08:00
|
|
|
AL_CHECK;
|
2012-08-14 17:10:44 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-02 05:44:06 -08:00
|
|
|
const Path CSoundBase::GetName()
|
2012-08-14 17:10:44 -07:00
|
|
|
{
|
2015-02-02 05:44:06 -08:00
|
|
|
if (m_SoundData)
|
2025-10-10 11:49:37 -07:00
|
|
|
return m_SoundData->GetFileName();
|
2012-08-14 17:10:44 -07:00
|
|
|
|
2015-02-02 05:44:06 -08:00
|
|
|
return Path();
|
2012-08-14 17:10:44 -07:00
|
|
|
}
|
|
|
|
|
|
2013-04-06 21:13:15 -07:00
|
|
|
void CSoundBase::Pause()
|
|
|
|
|
{
|
2015-02-02 05:44:06 -08:00
|
|
|
if (m_ALSource != 0)
|
|
|
|
|
{
|
2013-04-24 05:03:42 -07:00
|
|
|
m_IsPaused = true;
|
2015-02-02 05:44:06 -08:00
|
|
|
alSourcePause(m_ALSource);
|
|
|
|
|
AL_CHECK;
|
|
|
|
|
}
|
2013-04-06 21:13:15 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CSoundBase::Resume()
|
|
|
|
|
{
|
2015-02-02 05:44:06 -08:00
|
|
|
if (m_ALSource != 0)
|
|
|
|
|
{
|
|
|
|
|
alSourcePlay(m_ALSource);
|
|
|
|
|
AL_CHECK;
|
|
|
|
|
}
|
2013-04-06 21:13:15 -07:00
|
|
|
}
|
|
|
|
|
|
2012-08-31 12:08:41 -07:00
|
|
|
#endif // CONFIG2_AUDIO
|
|
|
|
|
|