Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/soundmanager/items/CSoundBase.cpp
/* Copyright (C) 2015 Wildfire Games. | /* Copyright (C) 2019 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
▲ Show 20 Lines • Show All 106 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
void CSoundBase::SetGain(ALfloat gain) | void CSoundBase::SetGain(ALfloat gain) | ||||
{ | { | ||||
AL_CHECK; | AL_CHECK; | ||||
if ( m_ALSource ) | if ( m_ALSource ) | ||||
{ | { | ||||
CScopeLock lock(m_ItemMutex); | std::lock_guard<std::mutex> lock(m_ItemMutex); | ||||
alSourcef(m_ALSource, AL_GAIN, gain); | alSourcef(m_ALSource, AL_GAIN, gain); | ||||
AL_CHECK; | AL_CHECK; | ||||
} | } | ||||
} | } | ||||
void CSoundBase::SetRollOff(ALfloat rolls) | void CSoundBase::SetRollOff(ALfloat rolls) | ||||
{ | { | ||||
if ( m_ALSource ) | if ( m_ALSource ) | ||||
{ | { | ||||
CScopeLock lock(m_ItemMutex); | std::lock_guard<std::mutex> lock(m_ItemMutex); | ||||
alSourcef(m_ALSource, AL_REFERENCE_DISTANCE, 70.0f); | alSourcef(m_ALSource, AL_REFERENCE_DISTANCE, 70.0f); | ||||
AL_CHECK; | AL_CHECK; | ||||
alSourcef(m_ALSource, AL_MAX_DISTANCE, 200.0); | alSourcef(m_ALSource, AL_MAX_DISTANCE, 200.0); | ||||
AL_CHECK; | AL_CHECK; | ||||
alSourcef(m_ALSource, AL_ROLLOFF_FACTOR, rolls); | alSourcef(m_ALSource, AL_ROLLOFF_FACTOR, rolls); | ||||
AL_CHECK; | AL_CHECK; | ||||
} | } | ||||
} | } | ||||
void CSoundBase::EnsurePlay() | void CSoundBase::EnsurePlay() | ||||
{ | { | ||||
if (m_ShouldBePlaying && !m_IsPaused && !IsPlaying()) | if (m_ShouldBePlaying && !m_IsPaused && !IsPlaying()) | ||||
Play(); | Play(); | ||||
} | } | ||||
void CSoundBase::SetCone(ALfloat innerCone, ALfloat outerCone, ALfloat coneGain) | void CSoundBase::SetCone(ALfloat innerCone, ALfloat outerCone, ALfloat coneGain) | ||||
{ | { | ||||
if ( m_ALSource ) | if ( m_ALSource ) | ||||
{ | { | ||||
CScopeLock lock(m_ItemMutex); | std::lock_guard<std::mutex> lock(m_ItemMutex); | ||||
AL_CHECK; | AL_CHECK; | ||||
alSourcef(m_ALSource, AL_CONE_INNER_ANGLE, innerCone); | alSourcef(m_ALSource, AL_CONE_INNER_ANGLE, innerCone); | ||||
AL_CHECK; | AL_CHECK; | ||||
alSourcef(m_ALSource, AL_CONE_OUTER_ANGLE, outerCone); | alSourcef(m_ALSource, AL_CONE_OUTER_ANGLE, outerCone); | ||||
AL_CHECK; | AL_CHECK; | ||||
alSourcef(m_ALSource, AL_CONE_OUTER_GAIN, coneGain); | alSourcef(m_ALSource, AL_CONE_OUTER_GAIN, coneGain); | ||||
AL_CHECK; | AL_CHECK; | ||||
} | } | ||||
} | } | ||||
void CSoundBase::SetPitch(ALfloat pitch) | void CSoundBase::SetPitch(ALfloat pitch) | ||||
{ | { | ||||
if ( m_ALSource ) | if ( m_ALSource ) | ||||
{ | { | ||||
CScopeLock lock(m_ItemMutex); | std::lock_guard<std::mutex> lock(m_ItemMutex); | ||||
alSourcef(m_ALSource, AL_PITCH, pitch); | alSourcef(m_ALSource, AL_PITCH, pitch); | ||||
AL_CHECK; | AL_CHECK; | ||||
} | } | ||||
} | } | ||||
void CSoundBase::SetDirection(const CVector3D& direction) | void CSoundBase::SetDirection(const CVector3D& direction) | ||||
{ | { | ||||
if ( m_ALSource ) | if ( m_ALSource ) | ||||
{ | { | ||||
CScopeLock lock(m_ItemMutex); | std::lock_guard<std::mutex> lock(m_ItemMutex); | ||||
alSourcefv(m_ALSource, AL_DIRECTION, direction.GetFloatArray()); | alSourcefv(m_ALSource, AL_DIRECTION, direction.GetFloatArray()); | ||||
AL_CHECK; | AL_CHECK; | ||||
} | } | ||||
} | } | ||||
bool CSoundBase::IsPlaying() | bool CSoundBase::IsPlaying() | ||||
{ | { | ||||
if ( m_ALSource ) | if ( m_ALSource ) | ||||
{ | { | ||||
CScopeLock lock(m_ItemMutex); | std::lock_guard<std::mutex> lock(m_ItemMutex); | ||||
int proc_state; | int proc_state; | ||||
alGetSourcei(m_ALSource, AL_SOURCE_STATE, &proc_state); | alGetSourcei(m_ALSource, AL_SOURCE_STATE, &proc_state); | ||||
AL_CHECK; | AL_CHECK; | ||||
return (proc_state == AL_PLAYING); | return (proc_state == AL_PLAYING); | ||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
void CSoundBase::SetLastPlay(bool last) | void CSoundBase::SetLastPlay(bool last) | ||||
{ | { | ||||
m_LastPlay = last; | m_LastPlay = last; | ||||
} | } | ||||
bool CSoundBase::IdleTask() | bool CSoundBase::IdleTask() | ||||
{ | { | ||||
return true; | return true; | ||||
} | } | ||||
void CSoundBase::SetLocation (const CVector3D& position) | void CSoundBase::SetLocation (const CVector3D& position) | ||||
{ | { | ||||
if ( m_ALSource != 0 ) | if ( m_ALSource != 0 ) | ||||
{ | { | ||||
CScopeLock lock(m_ItemMutex); | std::lock_guard<std::mutex> lock(m_ItemMutex); | ||||
alSourcefv(m_ALSource,AL_POSITION, position.GetFloatArray()); | alSourcefv(m_ALSource,AL_POSITION, position.GetFloatArray()); | ||||
AL_CHECK; | AL_CHECK; | ||||
} | } | ||||
} | } | ||||
bool CSoundBase::HandleFade() | bool CSoundBase::HandleFade() | ||||
{ | { | ||||
AL_CHECK; | AL_CHECK; | ||||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | void CSoundBase::SetLooping(bool loops) | ||||
{ | { | ||||
alSourcei(m_ALSource, AL_LOOPING, loops ? AL_TRUE : AL_FALSE); | alSourcei(m_ALSource, AL_LOOPING, loops ? AL_TRUE : AL_FALSE); | ||||
AL_CHECK; | AL_CHECK; | ||||
} | } | ||||
} | } | ||||
void CSoundBase::Play() | void CSoundBase::Play() | ||||
{ | { | ||||
CScopeLock lock(m_ItemMutex); | std::lock_guard<std::mutex> lock(m_ItemMutex); | ||||
m_ShouldBePlaying = true; | m_ShouldBePlaying = true; | ||||
m_IsPaused = false; | m_IsPaused = false; | ||||
AL_CHECK; | AL_CHECK; | ||||
if (m_ALSource != 0) | if (m_ALSource != 0) | ||||
{ | { | ||||
alSourcePlay(m_ALSource); | alSourcePlay(m_ALSource); | ||||
ALenum err = alGetError(); | ALenum err = alGetError(); | ||||
▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | void CSoundBase::FadeToIn(ALfloat newVolume, double fadeDuration) | ||||
} | } | ||||
} | } | ||||
void CSoundBase::Stop() | void CSoundBase::Stop() | ||||
{ | { | ||||
m_ShouldBePlaying = false; | m_ShouldBePlaying = false; | ||||
if (m_ALSource != 0) | if (m_ALSource != 0) | ||||
{ | { | ||||
CScopeLock lock(m_ItemMutex); | std::lock_guard<std::mutex> lock(m_ItemMutex); | ||||
AL_CHECK; | AL_CHECK; | ||||
alSourcei(m_ALSource, AL_LOOPING, AL_FALSE); | alSourcei(m_ALSource, AL_LOOPING, AL_FALSE); | ||||
AL_CHECK; | AL_CHECK; | ||||
alSourceStop(m_ALSource); | alSourceStop(m_ALSource); | ||||
AL_CHECK; | AL_CHECK; | ||||
} | } | ||||
} | } | ||||
Show All 30 Lines |
Wildfire Games · Phabricator