Changed: #1031 Music is "stopped" when client is loading with OpenAL driver
This commit is contained in:
parent
8a193abef3
commit
079946f022
3 changed files with 104 additions and 38 deletions
|
@ -279,7 +279,7 @@ bool CMusicChannelAL::isEnded()
|
||||||
/// Return true if the song is still loading asynchronously and hasn't started playing yet (false if not async), used to delay fading
|
/// Return true if the song is still loading asynchronously and hasn't started playing yet (false if not async), used to delay fading
|
||||||
bool CMusicChannelAL::isLoadingAsync()
|
bool CMusicChannelAL::isLoadingAsync()
|
||||||
{
|
{
|
||||||
return _Async && _Playing;
|
return _Async && _Playing && !_Source->isPlaying();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the total length (in second) of the music currently played
|
/// Return the total length (in second) of the music currently played
|
||||||
|
|
|
@ -15,30 +15,48 @@
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
#include "stdopenal.h"
|
#include "stdopenal.h"
|
||||||
|
#include "source_al.h"
|
||||||
#include "sound_driver_al.h"
|
#include "sound_driver_al.h"
|
||||||
#include "listener_al.h"
|
#include "listener_al.h"
|
||||||
#include "effect_al.h"
|
#include "effect_al.h"
|
||||||
#include "buffer_al.h"
|
#include "buffer_al.h"
|
||||||
#include "source_al.h"
|
|
||||||
#include "ext_al.h"
|
#include "ext_al.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace NLMISC;
|
using namespace NLMISC;
|
||||||
|
|
||||||
namespace NLSOUND {
|
namespace NLSOUND
|
||||||
|
|
||||||
CSourceAL::CSourceAL(CSoundDriverAL *soundDriver) :
|
|
||||||
_SoundDriver(NULL), _Buffer(NULL), _BuffersMax(0), _BufferSize(32768), _Source(AL_NONE),
|
|
||||||
_DirectFilter(AL_FILTER_NULL), _EffectFilter(AL_FILTER_NULL),
|
|
||||||
_IsPlaying(false), _IsPaused(false),
|
|
||||||
_Pos(0.0f, 0.0f, 0.0f), _Gain(NLSOUND_DEFAULT_GAIN), _Alpha(1.0),
|
|
||||||
_MinDistance(1.0f), _MaxDistance(numeric_limits<float>::max()),
|
|
||||||
_Effect(NULL), _Direct(true),
|
|
||||||
_DirectGain(NLSOUND_DEFAULT_DIRECT_GAIN), _EffectGain(NLSOUND_DEFAULT_EFFECT_GAIN),
|
|
||||||
_DirectFilterType(ISource::FilterLowPass), _EffectFilterType(ISource::FilterLowPass),
|
|
||||||
_DirectFilterEnabled(false), _EffectFilterEnabled(false),
|
|
||||||
_DirectFilterPassGain(NLSOUND_DEFAULT_FILTER_PASS_GAIN), _EffectFilterPassGain(NLSOUND_DEFAULT_FILTER_PASS_GAIN)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
|
CSourceAL::CSourceAL(CSoundDriverAL *soundDriver):ISource(), _SoundDriver(NULL), _Source(AL_NONE),
|
||||||
|
_DirectFilter(AL_FILTER_NULL), _EffectFilter(AL_FILTER_NULL)
|
||||||
|
{
|
||||||
|
_IsPlaying = false;
|
||||||
|
_IsPaused = false;
|
||||||
|
|
||||||
|
_Type = SourceSound;
|
||||||
|
_Buffer = NULL;
|
||||||
|
_BuffersMax = 0;
|
||||||
|
_BufferSize = 32768;
|
||||||
|
|
||||||
|
_PosRelative = false;
|
||||||
|
_Gain = NLSOUND_DEFAULT_GAIN;
|
||||||
|
_Alpha = 0.0;
|
||||||
|
_Pos = CVector::Null;
|
||||||
|
_MinDistance = 1.0f;
|
||||||
|
_MaxDistance = numeric_limits<float>::max();
|
||||||
|
|
||||||
|
_Effect = NULL;
|
||||||
|
_Direct = true;
|
||||||
|
_DirectGain = NLSOUND_DEFAULT_DIRECT_GAIN;
|
||||||
|
_EffectGain = NLSOUND_DEFAULT_EFFECT_GAIN;
|
||||||
|
_DirectFilterType = ISource::FilterLowPass;
|
||||||
|
_EffectFilterType = ISource::FilterLowPass;
|
||||||
|
_DirectFilterEnabled = false;
|
||||||
|
_EffectFilterEnabled = false;
|
||||||
|
_DirectFilterPassGain = NLSOUND_DEFAULT_FILTER_PASS_GAIN;
|
||||||
|
_EffectFilterPassGain = NLSOUND_DEFAULT_FILTER_PASS_GAIN;
|
||||||
|
|
||||||
// create the al source
|
// create the al source
|
||||||
alGenSources(1, &_Source);
|
alGenSources(1, &_Source);
|
||||||
alTestError();
|
alTestError();
|
||||||
|
@ -63,6 +81,7 @@ _DirectFilterPassGain(NLSOUND_DEFAULT_FILTER_PASS_GAIN), _EffectFilterPassGain(N
|
||||||
alFilterf(_DirectFilter, AL_LOWPASS_GAIN, NLSOUND_DEFAULT_DIRECT_GAIN);
|
alFilterf(_DirectFilter, AL_LOWPASS_GAIN, NLSOUND_DEFAULT_DIRECT_GAIN);
|
||||||
alFilterf(_DirectFilter, AL_LOWPASS_GAINHF, NLSOUND_DEFAULT_FILTER_PASS_GAIN);
|
alFilterf(_DirectFilter, AL_LOWPASS_GAINHF, NLSOUND_DEFAULT_FILTER_PASS_GAIN);
|
||||||
alTestError();
|
alTestError();
|
||||||
|
|
||||||
alGenFilters(1, &_EffectFilter);
|
alGenFilters(1, &_EffectFilter);
|
||||||
alFilteri(_EffectFilter, AL_FILTER_TYPE, AL_FILTER_LOWPASS);
|
alFilteri(_EffectFilter, AL_FILTER_TYPE, AL_FILTER_LOWPASS);
|
||||||
alFilterf(_EffectFilter, AL_LOWPASS_GAIN, NLSOUND_DEFAULT_EFFECT_GAIN);
|
alFilterf(_EffectFilter, AL_LOWPASS_GAIN, NLSOUND_DEFAULT_EFFECT_GAIN);
|
||||||
|
@ -94,13 +113,37 @@ void CSourceAL::release()
|
||||||
/// (Internal) Update the 3d changes.
|
/// (Internal) Update the 3d changes.
|
||||||
void CSourceAL::updateManualRolloff()
|
void CSourceAL::updateManualRolloff()
|
||||||
{
|
{
|
||||||
CVector distanceVector = _Pos - CListenerAL::getInstance()->getPos();
|
CVector pos = getPos();
|
||||||
float distanceSquare = distanceVector.sqrnorm();
|
|
||||||
float rolloff = ISource::computeManualRolloff(_Alpha, distanceSquare, _MinDistance, _MaxDistance);
|
// make relative to listener (if not already!)
|
||||||
alSourcef(_Source, AL_GAIN, _Gain * rolloff);
|
if (!_PosRelative)
|
||||||
|
pos -= CListenerAL::getInstance()->getPos();
|
||||||
|
|
||||||
|
float sqrdist = pos.sqrnorm();
|
||||||
|
float rolloff = ISource::computeManualRolloff(_Alpha, sqrdist, _MinDistance, _MaxDistance);
|
||||||
|
float volume = _Gain * rolloff;
|
||||||
|
|
||||||
|
// apply SFX volume
|
||||||
|
if (_SoundDriver && _Type == SourceSound)
|
||||||
|
volume *= _SoundDriver->getGain();
|
||||||
|
|
||||||
|
// set the attenuated volume
|
||||||
|
alSourcef(_Source, AL_GAIN, volume);
|
||||||
alTestError();
|
alTestError();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Set type of the source
|
||||||
|
void CSourceAL::setType(TSourceType type)
|
||||||
|
{
|
||||||
|
_Type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get type of the source
|
||||||
|
TSourceType CSourceAL::getType() const
|
||||||
|
{
|
||||||
|
return _Type;
|
||||||
|
}
|
||||||
|
|
||||||
/// Enable or disable streaming mode. Source must be stopped to call this.
|
/// Enable or disable streaming mode. Source must be stopped to call this.
|
||||||
void CSourceAL::setStreaming(bool /* streaming */)
|
void CSourceAL::setStreaming(bool /* streaming */)
|
||||||
{
|
{
|
||||||
|
@ -392,9 +435,16 @@ void CSourceAL::getDirection( NLMISC::CVector& dir ) const
|
||||||
void CSourceAL::setGain(float gain)
|
void CSourceAL::setGain(float gain)
|
||||||
{
|
{
|
||||||
_Gain = std::min(std::max(gain, NLSOUND_MIN_GAIN), NLSOUND_MAX_GAIN);
|
_Gain = std::min(std::max(gain, NLSOUND_MIN_GAIN), NLSOUND_MAX_GAIN);
|
||||||
|
|
||||||
if ((_SoundDriver == NULL) || !_SoundDriver->getOption(ISoundDriver::OptionManualRolloff))
|
if ((_SoundDriver == NULL) || !_SoundDriver->getOption(ISoundDriver::OptionManualRolloff))
|
||||||
{
|
{
|
||||||
alSourcef(_Source, AL_GAIN, _Gain);
|
float gain = _Gain;
|
||||||
|
|
||||||
|
// apply SFX volume
|
||||||
|
if (_SoundDriver && _Type == SourceSound)
|
||||||
|
gain *= _SoundDriver->getGain();
|
||||||
|
|
||||||
|
alSourcef(_Source, AL_GAIN, gain);
|
||||||
alTestError();
|
alTestError();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -428,6 +478,7 @@ float CSourceAL::getPitch() const
|
||||||
/// Set the source relative mode. If true, positions are interpreted relative to the listener position.
|
/// Set the source relative mode. If true, positions are interpreted relative to the listener position.
|
||||||
void CSourceAL::setSourceRelativeMode( bool mode )
|
void CSourceAL::setSourceRelativeMode( bool mode )
|
||||||
{
|
{
|
||||||
|
_PosRelative = mode;
|
||||||
alSourcei(_Source, AL_SOURCE_RELATIVE, mode?AL_TRUE:AL_FALSE );
|
alSourcei(_Source, AL_SOURCE_RELATIVE, mode?AL_TRUE:AL_FALSE );
|
||||||
alTestError();
|
alTestError();
|
||||||
}
|
}
|
||||||
|
@ -435,10 +486,11 @@ void CSourceAL::setSourceRelativeMode( bool mode )
|
||||||
/// Get the source relative mode (3D mode only)
|
/// Get the source relative mode (3D mode only)
|
||||||
bool CSourceAL::getSourceRelativeMode() const
|
bool CSourceAL::getSourceRelativeMode() const
|
||||||
{
|
{
|
||||||
ALint b;
|
return _PosRelative;
|
||||||
alGetSourcei(_Source, AL_SOURCE_RELATIVE, &b );
|
// ALint b;
|
||||||
alTestError();
|
// alGetSourcei(_Source, AL_SOURCE_RELATIVE, &b );
|
||||||
return (b==AL_TRUE);
|
// alTestError();
|
||||||
|
// return (b==AL_TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the min and max distances (3D mode only)
|
/// Set the min and max distances (3D mode only)
|
||||||
|
@ -447,12 +499,12 @@ void CSourceAL::setMinMaxDistances( float mindist, float maxdist, bool /* deferr
|
||||||
nlassert( (mindist >= 0.0f) && (maxdist >= 0.0f) );
|
nlassert( (mindist >= 0.0f) && (maxdist >= 0.0f) );
|
||||||
_MinDistance = mindist;
|
_MinDistance = mindist;
|
||||||
_MaxDistance = maxdist;
|
_MaxDistance = maxdist;
|
||||||
if ((_SoundDriver == NULL) || !_SoundDriver->getOption(ISoundDriver::OptionManualRolloff))
|
// if ((_SoundDriver == NULL) || !_SoundDriver->getOption(ISoundDriver::OptionManualRolloff))
|
||||||
{
|
// {
|
||||||
alSourcef(_Source, AL_REFERENCE_DISTANCE, mindist);
|
alSourcef(_Source, AL_REFERENCE_DISTANCE, mindist);
|
||||||
alSourcef(_Source, AL_MAX_DISTANCE, maxdist);
|
alSourcef(_Source, AL_MAX_DISTANCE, maxdist);
|
||||||
alTestError();
|
alTestError();
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the min and max distances
|
/// Get the min and max distances
|
||||||
|
|
|
@ -17,14 +17,17 @@
|
||||||
#ifndef NL_SOURCE_AL_H
|
#ifndef NL_SOURCE_AL_H
|
||||||
#define NL_SOURCE_AL_H
|
#define NL_SOURCE_AL_H
|
||||||
|
|
||||||
#include <nel/sound/driver/source.h>
|
#include "nel/sound/driver/source.h"
|
||||||
|
|
||||||
namespace NLSOUND {
|
namespace NLSOUND
|
||||||
|
{
|
||||||
class IBuffer;
|
class IBuffer;
|
||||||
class CBufferAL;
|
class CBufferAL;
|
||||||
class CSoundDriverAL;
|
class CSoundDriverAL;
|
||||||
class CEffectAL;
|
class CEffectAL;
|
||||||
|
|
||||||
|
enum TSourceType { SourceSound, SourceMusic };
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* OpenAL sound source
|
* OpenAL sound source
|
||||||
*
|
*
|
||||||
|
@ -47,6 +50,10 @@ private:
|
||||||
/// Sound driver
|
/// Sound driver
|
||||||
CSoundDriverAL *_SoundDriver;
|
CSoundDriverAL *_SoundDriver;
|
||||||
|
|
||||||
|
/// AL Handles
|
||||||
|
ALuint _Source;
|
||||||
|
ALuint _DirectFilter, _EffectFilter;
|
||||||
|
|
||||||
/// Assigned buffer object
|
/// Assigned buffer object
|
||||||
CBufferAL *_Buffer;
|
CBufferAL *_Buffer;
|
||||||
/// Queued buffers map (uint is buffer name)
|
/// Queued buffers map (uint is buffer name)
|
||||||
|
@ -59,9 +66,8 @@ private:
|
||||||
/// Default size of a buffer
|
/// Default size of a buffer
|
||||||
uint _BufferSize;
|
uint _BufferSize;
|
||||||
|
|
||||||
/// AL Handles
|
/// Position is relative to listener
|
||||||
ALuint _Source;
|
bool _PosRelative;
|
||||||
ALuint _DirectFilter, _EffectFilter;
|
|
||||||
|
|
||||||
/// Playing status
|
/// Playing status
|
||||||
bool _IsPlaying;
|
bool _IsPlaying;
|
||||||
|
@ -84,6 +90,9 @@ private:
|
||||||
bool _DirectFilterEnabled, _EffectFilterEnabled;
|
bool _DirectFilterEnabled, _EffectFilterEnabled;
|
||||||
float _DirectFilterPassGain, _EffectFilterPassGain;
|
float _DirectFilterPassGain, _EffectFilterPassGain;
|
||||||
|
|
||||||
|
/// Source type can be SourceSound or SourceMusic
|
||||||
|
TSourceType _Type;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/// Constructor
|
/// Constructor
|
||||||
CSourceAL(CSoundDriverAL *soundDriver);
|
CSourceAL(CSoundDriverAL *soundDriver);
|
||||||
|
@ -96,6 +105,11 @@ public:
|
||||||
/// Return the OpenAL source name
|
/// Return the OpenAL source name
|
||||||
inline ALuint getSource() const { return _Source; }
|
inline ALuint getSource() const { return _Source; }
|
||||||
|
|
||||||
|
/// Set type of the source
|
||||||
|
void setType(TSourceType type);
|
||||||
|
/// Get type of the source
|
||||||
|
TSourceType getType() const;
|
||||||
|
|
||||||
/// (Internal) Set the effect send for this source, NULL to disable.
|
/// (Internal) Set the effect send for this source, NULL to disable.
|
||||||
void setEffect(CEffectAL *effect);
|
void setEffect(CEffectAL *effect);
|
||||||
/// (Internal) Setup the direct send filter.
|
/// (Internal) Setup the direct send filter.
|
||||||
|
|
Loading…
Reference in a new issue