Merged: From sound_dev to default. (Summary: Implemented Stream Sound and Group Controller feature. Various performance improvements and bug fixes in the sound code. Fixed sanity of IThread start and isRunning, added setPriority)

This commit is contained in:
kaetemi 2012-04-12 21:18:02 +02:00
commit 76eae94605
187 changed files with 4230 additions and 2299 deletions

View file

@ -0,0 +1,151 @@
/**
* \file fast_id_map.h
* \brief CFastIdMap
* \date 2012-04-10 19:28GMT
* \author Jan Boon (Kaetemi)
* CFastIdMap
*/
/*
* Copyright (C) 2012 by authors
*
* This file is part of RYZOM CORE.
* RYZOM CORE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* RYZOM CORE is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with RYZOM CORE. If not, see
* <http://www.gnu.org/licenses/>.
*/
#ifndef NLMISC_FAST_ID_MAP_H
#define NLMISC_FAST_ID_MAP_H
#include <nel/misc/types_nl.h>
// STL includes
// NeL includes
#include <nel/misc/debug.h>
// Project includes
namespace NLMISC {
/**
* \brief CFastIdMap
* \date 2012-04-10 19:28GMT
* \author Jan Boon (Kaetemi)
* This template allows for assigning unique uint32 identifiers to pointers.
* Useful when externally only exposing an identifier, when pointers may have been deleted.
* The identifier is made from two uint16's, one being the direct index in the identifier vector,
* and the other being a verification value that is increased when the identifier index is re-used.
* TId must be a typedef of uint32.
* TValue should be a pointer.
*/
template<typename TId, class TValue>
class CFastIdMap
{
protected:
struct CIdInfo
{
CIdInfo() { }
CIdInfo(uint16 verification, uint16 next, TValue value) :
Verification(verification), Next(next), Value(value) { }
uint16 Verification;
uint16 Next;
TValue Value;
};
/// ID memory
std::vector<CIdInfo> m_Ids;
/// Nb of assigned IDs
uint m_Size;
/// Assigned IDs
uint16 m_Next;
public:
CFastIdMap(TValue defaultValue) : m_Size(0), m_Next(0)
{
// Id 0 will contain the last available unused id, and be 0 if no more unused id's are available
// defaultValue will be returned when the ID is not found
m_Ids.push_back(CIdInfo(0, 0, defaultValue));
}
virtual ~CFastIdMap() { }
void clear()
{
m_Ids.resize(1);
m_Ids[0].Next = 0;
}
TId insert(TValue value)
{
// get next unused index
uint16 idx = m_Ids[0].Next;
if (idx == 0)
{
// size of used elements must be equal to the vector size minus one, when everything is allocated
nlassert((m_Ids.size() - 1) == m_Size);
idx = m_Ids.size();
uint16 verification = rand();
m_Ids.push_back(CIdInfo(verification, m_Next, value));
m_Next = idx;
return (TId)(((uint32)verification) << 16) & idx;
}
else
{
m_Ids[0].Next = m_Ids[idx].Next; // restore the last unused id
m_Ids[idx].Value = value;
return (TId)(((uint32)m_Ids[idx].Verification) << 16) & idx;
}
}
void erase(TId id)
{
uint32 idx = ((uint32)id) & 0xFFFF;
uint16 verification = (uint16)(((uint32)id) >> 16);
if (m_Ids[idx].Verification == verification)
{
m_Ids[idx].Value = m_Ids[0].Value; // clean value for safety
m_Ids[idx].Verification = (uint16)(((uint32)m_Ids[idx].Verification + 1) & 0xFFFF); // change verification value, allow overflow :)
m_Ids[idx].Next = m_Ids[0].Next; // store the last unused id
m_Ids[0].Next = (uint16)idx; // set this as last unused id
}
else
{
nlwarning("Invalid ID");
}
}
TValue get(TId id)
{
uint32 idx = ((uint32)id) & 0xFFFF;
uint16 verification = (uint16)(((uint32)id) >> 16);
if (m_Ids[idx].Verification == verification)
{
return m_Ids[idx].Value;
}
else
{
nldebug("Invalid ID");
return m_Ids[0].Value;
}
}
inline uint size() { return m_Size; }
}; /* class CFastIdMap */
} /* namespace NLMISC */
#endif /* #ifndef NLMISC_FAST_ID_MAP_H */
/* end of file */

View file

@ -36,6 +36,12 @@ namespace NLMISC {
class CPThread : public IThread
{
public:
enum TThreadState
{
ThreadStateNone,
ThreadStateRunning,
ThreadStateFinished,
};
/// Constructor
CPThread( IRunnable *runnable, uint32 stackSize);
@ -48,6 +54,7 @@ public:
virtual void wait();
virtual bool setCPUMask(uint64 cpuMask);
virtual uint64 getCPUMask();
virtual void setPriority(TThreadPriority priority);
virtual std::string getUserName();
virtual IRunnable *getRunnable()
@ -58,10 +65,11 @@ public:
/// Internal use
IRunnable *Runnable;
private:
uint8 _State; // 0=not created, 1=started, 2=finished
uint32 _StackSize;
TThreadState _State;
pthread_t _ThreadHandle;
private:
uint32 _StackSize;
};
/**

View file

@ -68,6 +68,16 @@ public:
}
};
/// Thread priorities, numbering follows Win32 for now
enum TThreadPriority
{
ThreadPriorityLowest = -2,
ThreadPriorityLow = -1,
ThreadPriorityNormal = 0,
ThreadPriorityHigh = 1,
ThreadPriorityHighest = 2,
};
/**
* Thread base interface, must be implemented for all OS
* \author Vianney Lecroart
@ -119,6 +129,9 @@ public:
*/
virtual uint64 getCPUMask()=0;
/// Set the thread priority. Thread must have been started before.
virtual void setPriority(TThreadPriority priority) = 0;
/**
* Get the thread user name.
* Under Linux return thread owner, under windows return the name of the logon user.

View file

@ -49,6 +49,7 @@ public:
virtual void wait();
virtual bool setCPUMask(uint64 cpuMask);
virtual uint64 getCPUMask();
virtual void setPriority(TThreadPriority priority);
virtual std::string getUserName();
virtual IRunnable *getRunnable()
@ -69,8 +70,7 @@ public:
void suspend();
// Resume the thread. No-op if already resumed
void resume();
// set priority as defined by "SetThreadpriority"
void setPriority(int priority);
// Priority boost
void enablePriorityBoost(bool enabled);
/// private use

View file

@ -0,0 +1,107 @@
/**
* \file audio_decoder.h
* \brief IAudioDecoder
* \date 2012-04-11 09:34GMT
* \author Jan Boon (Kaetemi)
* IAudioDecoder
*/
/*
* Copyright (C) 2008-2012 by authors
*
* This file is part of RYZOM CORE.
* RYZOM CORE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* RYZOM CORE is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with RYZOM CORE. If not, see
* <http://www.gnu.org/licenses/>.
*/
#ifndef NLSOUND_AUDIO_DECODER_H
#define NLSOUND_AUDIO_DECODER_H
#include <nel/misc/types_nl.h>
// STL includes
// NeL includes
// Project includes
namespace NLSOUND {
/**
* \brief IAudioDecoder
* \date 2008-08-30 11:38GMT
* \author Jan Boon (Kaetemi)
* IAudioDecoder is only used by the driver implementation to stream
* music files into a readable format (it's a simple decoder interface).
* You should not call these functions (getSongTitle) on nlsound or user level,
* as a driver might have additional music types implemented.
* TODO: Split IAudioDecoder into IAudioDecoder (actual decoding) and IMediaDemuxer (stream splitter), and change the interface to make more sense.
* TODO: Allow user application to register more decoders.
* TODO: Look into libavcodec for decoding audio?
*/
class IAudioDecoder
{
private:
// pointers
/// Stream from file created by IAudioDecoder
NLMISC::IStream *_InternalStream;
public:
IAudioDecoder();
virtual ~IAudioDecoder();
/// Create a new music buffer, may return NULL if unknown type, destroy with delete. Filepath lookup done here. If async is true, it will stream from hd, else it will load in memory first.
static IAudioDecoder *createAudioDecoder(const std::string &filepath, bool async, bool loop);
/// Create a new music buffer from a stream, type is file extension like "ogg" etc.
static IAudioDecoder *createAudioDecoder(const std::string &type, NLMISC::IStream *stream, bool loop);
/// Get information on a music file (only artist and title at the moment).
static bool getInfo(const std::string &filepath, std::string &artist, std::string &title);
/// Get audio/container extensions that are currently supported by the nel sound library.
static void getMusicExtensions(std::vector<std::string> &extensions);
/// Return if a music extension is supported by the nel sound library.
static bool isMusicExtensionSupported(const std::string &extension);
/// Get how many bytes the music buffer requires for output minimum.
virtual uint32 getRequiredBytes() = 0;
/// Get an amount of bytes between minimum and maximum (can be lower than minimum if at end).
virtual uint32 getNextBytes(uint8 *buffer, uint32 minimum, uint32 maximum) = 0;
/// Get the amount of channels (2 is stereo) in output.
virtual uint8 getChannels() = 0;
/// Get the samples per second (often 44100) in output.
virtual uint getSamplesPerSec() = 0;
/// Get the bits per sample (often 16) in output.
virtual uint8 getBitsPerSample() = 0;
/// Get if the music has ended playing (never true if loop).
virtual bool isMusicEnded() = 0;
/// Get the total time in seconds.
virtual float getLength() = 0;
/// Set looping
virtual void setLooping(bool loop) = 0;
}; /* class IAudioDecoder */
} /* namespace NLSOUND */
#endif /* #ifndef NLSOUND_AUDIO_DECODER_H */
/* end of file */

View file

@ -1,21 +1,33 @@
// NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
// Copyright (C) 2010 Winch Gate Property Limited
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
/**
* \file audio_decoder_vorbis.h
* \brief CAudioDecoderVorbis
* \date 2012-04-11 09:35GMT
* \author Jan Boon (Kaetemi)
* CAudioDecoderVorbis
*/
#ifndef NLSOUND_MUSIC_BUFFER_VORBIS_H
#define NLSOUND_MUSIC_BUFFER_VORBIS_H
/*
* Copyright (C) 2008-2012 by authors
*
* This file is part of RYZOM CORE.
* RYZOM CORE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* RYZOM CORE is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with RYZOM CORE. If not, see
* <http://www.gnu.org/licenses/>.
*/
#ifndef NLSOUND_AUDIO_DECODER_VORBIS_H
#define NLSOUND_AUDIO_DECODER_VORBIS_H
#include <nel/misc/types_nl.h>
// STL includes
@ -30,21 +42,20 @@
#endif
// NeL includes
#include <nel/sound/audio_decoder.h>
// Project includes
#include "music_buffer.h"
namespace NLSOUND
{
namespace NLSOUND {
/**
* \brief CMusicBufferVorbis
* \brief CAudioDecoderVorbis
* \date 2008-08-30 11:38GMT
* \author Jan Boon (Kaetemi)
* CMusicBufferVorbis
* Create trough IMusicBuffer, type "ogg"
* CAudioDecoderVorbis
* Create trough IAudioDecoder, type "ogg"
*/
class CMusicBufferVorbis : public IMusicBuffer
class CAudioDecoderVorbis : public IAudioDecoder
{
protected:
// outside pointers
@ -59,8 +70,8 @@ protected:
sint32 _StreamOffset;
sint32 _StreamSize;
public:
CMusicBufferVorbis(NLMISC::IStream *stream, bool loop);
virtual ~CMusicBufferVorbis();
CAudioDecoderVorbis(NLMISC::IStream *stream, bool loop);
virtual ~CAudioDecoderVorbis();
inline NLMISC::IStream *getStream() { return _Stream; }
inline sint32 getStreamSize() { return _StreamSize; }
inline sint32 getStreamOffset() { return _StreamOffset; }
@ -78,7 +89,7 @@ public:
virtual uint8 getChannels();
/// Get the samples per second (often 44100) in output.
virtual uint32 getSamplesPerSec();
virtual uint getSamplesPerSec();
/// Get the bits per sample (often 16) in output.
virtual uint8 getBitsPerSample();
@ -89,12 +100,12 @@ public:
/// Get the total time in seconds.
virtual float getLength();
/// Get the size of uncompressed data in bytes.
virtual uint getUncompressedSize();
}; /* class CMusicBufferVorbis */
/// Set looping
virtual void setLooping(bool loop);
}; /* class CAudioDecoderVorbis */
} /* namespace NLSOUND */
#endif /* #ifndef NLSOUND_MUSIC_BUFFER_VORBIS_H */
#endif /* #ifndef NLSOUND_AUDIO_DECODER_VORBIS_H */
/* end of file */

View file

@ -34,6 +34,11 @@
#include "nel/sound/mixing_track.h"
#include "nel/sound/sound.h"
#include "nel/sound/music_channel_fader.h"
#include "nel/sound/group_controller_root.h"
// Current version is 2, Ryzom Live uses 1
// Provided to allow compatibility with old binary files
#define NLSOUND_SHEET_VERSION_BUILT 1
namespace NLLIGO {
class CLigoConfig;
@ -51,26 +56,6 @@ namespace NLSOUND {
class CMusicSoundManager;
class IReverbEffect;
/// Hasher functor for hashed container with pointer key.
template <class Pointer>
struct THashPtr : public std::unary_function<const Pointer &, size_t>
{
static const size_t bucket_size = 4;
static const size_t min_buckets = 8;
size_t operator () (const Pointer &ptr) const
{
//CHashSet<uint>::hasher h;
// transtype the pointer into int then hash it
//return h.operator()(uint(uintptr_t(ptr)));
return (size_t)(uintptr_t)ptr;
}
inline bool operator() (const Pointer &ptr1, const Pointer &ptr2) const
{
// delegate the work to someone else as well?
return (uintptr_t)ptr1 < (uintptr_t)ptr2;
}
};
/**
* Implementation of UAudioMixer
*
@ -197,6 +182,9 @@ public:
/// Get a TSoundId from a name (returns NULL if not found)
virtual TSoundId getSoundId( const NLMISC::TStringId &name );
/// Gets the group controller for the given group tree path with separator '/', if it doesn't exist yet it will be created.
/// Examples: "music", "effects", "dialog", "music/background", "music/loading", "music/player", etcetera
virtual UGroupController *getGroupController(const std::string &path);
/** Add a logical sound source (returns NULL if name not found).
* If spawn is true, the source will auto-delete after playing. If so, the return USource* pointer
@ -204,9 +192,9 @@ public:
* pass a callback function that will be called (if not NULL) just before deleting the spawned
* source.
*/
virtual USource *createSource( const NLMISC::TStringId &name, bool spawn=false, TSpawnEndCallback cb=NULL, void *cbUserParam = NULL, NL3D::CCluster *cluster = 0, CSoundContext *context = 0 );
virtual USource *createSource( const NLMISC::TStringId &name, bool spawn=false, TSpawnEndCallback cb=NULL, void *cbUserParam = NULL, NL3D::CCluster *cluster = 0, CSoundContext *context = 0, UGroupController *groupController = NULL);
/// Add a logical sound source (by sound id). To remove a source, just delete it. See createSource(const char*)
virtual USource *createSource( TSoundId id, bool spawn=false, TSpawnEndCallback cb=NULL, void *cbUserParam = NULL, NL3D::CCluster *cluster = 0, CSoundContext *context = 0 );
virtual USource *createSource( TSoundId id, bool spawn=false, TSpawnEndCallback cb=NULL, void *cbUserParam = NULL, NL3D::CCluster *cluster = 0, CSoundContext *context = 0, UGroupController *groupController = NULL);
/// Add a source which was created by an EnvSound
void addSource( CSourceCommon *source );
/** Delete a logical sound source. If you don't call it, the source will be auto-deleted
@ -415,6 +403,7 @@ public:
/// Add a source for play as possible (for non discadable sound)
void addSourceWaitingForPlay(CSourceCommon *source);
void removeSourceWaitingForPlay(CSourceCommon *source);
/// Read all user controled var sheets
void initUserVar();
@ -431,8 +420,6 @@ private:
// utility function for automatic sample bank loading.
bool tryToLoadSampleBank(const std::string &sampleName);
typedef CHashSet<CSourceCommon*, THashPtr<CSourceCommon*> > TSourceContainer;
typedef CHashSet<IMixerUpdate*, THashPtr<IMixerUpdate*> > TMixerUpdateContainer;
typedef CHashMap<IBuffer*, std::vector<class CSound*>, THashPtr<IBuffer*> > TBufferToSourceContainer;
// typedef std::multimap<NLMISC::TTime, IMixerEvent*> TTimedEventContainer;
@ -565,6 +552,9 @@ private:
// Instance of the background music manager
CMusicSoundManager *_BackgroundMusicManager;
/// Group controller
CGroupControllerRoot _GroupController;
public:
struct TSampleBankHeader
{

View file

@ -36,7 +36,7 @@ class CBackgroundSource : public CSourceCommon , public CAudioMixerUser::IMixerU
{
public:
/// Constructor
CBackgroundSource (CBackgroundSound *backgroundSound=NULL, bool spawn=false, TSpawnEndCallback cb=0, void *cbUserParam = 0, NL3D::CCluster *cluster = 0);
CBackgroundSource (CBackgroundSound *backgroundSound=NULL, bool spawn=false, TSpawnEndCallback cb=0, void *cbUserParam = 0, NL3D::CCluster *cluster = 0, CGroupController *groupController = NULL);
/// Destructor
~CBackgroundSource ();

View file

@ -34,7 +34,7 @@ class CComplexSource : public CSourceCommon, public CAudioMixerUser::IMixerEvent
{
public:
/// Constructor
CComplexSource (CComplexSound *soundPattern=NULL, bool spawn=false, TSpawnEndCallback cb=0, void *cbUserParam = 0, NL3D::CCluster *cluster = 0);
CComplexSource (CComplexSound *soundPattern=NULL, bool spawn=false, TSpawnEndCallback cb=0, void *cbUserParam = 0, NL3D::CCluster *cluster = 0, CGroupController *groupController = NULL);
/// Destructor
~CComplexSource ();

View file

@ -0,0 +1,67 @@
/**
* \file containers.h
* \brief CContainers
* \date 2012-04-10 13:57GMT
* \author Unknown (Unknown)
* CContainers
*/
/*
* Copyright (C) 2012 by authors
*
* This file is part of RYZOM CORE.
* RYZOM CORE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* RYZOM CORE is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with RYZOM CORE. If not, see
* <http://www.gnu.org/licenses/>.
*/
#ifndef NLSOUND_CONTAINERS_H
#define NLSOUND_CONTAINERS_H
#include <nel/misc/types_nl.h>
// STL includes
// NeL includes
// Project includes
namespace NLSOUND {
class CSourceCommon;
/// Hasher functor for hashed container with pointer key.
template <class Pointer>
struct THashPtr : public std::unary_function<const Pointer &, size_t>
{
static const size_t bucket_size = 4;
static const size_t min_buckets = 8;
size_t operator () (const Pointer &ptr) const
{
//CHashSet<uint>::hasher h;
// transtype the pointer into int then hash it
//return h.operator()(uint(uintptr_t(ptr)));
return (size_t)(uintptr_t)ptr;
}
inline bool operator() (const Pointer &ptr1, const Pointer &ptr2) const
{
// delegate the work to someone else as well?
return (uintptr_t)ptr1 < (uintptr_t)ptr2;
}
};
typedef CHashSet<CSourceCommon*, THashPtr<CSourceCommon*> > TSourceContainer;
} /* namespace NLSOUND */
#endif /* #ifndef NLSOUND_CONTAINERS_H */
/* end of file */

View file

@ -48,6 +48,8 @@ public:
/// Intel/DVI ADPCM format, only available for 1 channel at 16 bits per sample, encoded at 4 bits per sample.
/// This is only implemented in the DSound and XAudio2 driver.
FormatDviAdpcm = 11,
/// No format set. Used when a TBufferFormat value has not been set to any value yet.
FormatNotSet = (~0),
};
/// The storage mode of this buffer. Also controls the X-RAM extension of OpenAL.
enum TStorageMode

View file

@ -1,119 +0,0 @@
// NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
// Copyright (C) 2010 Winch Gate Property Limited
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef NLSOUND_MUSIC_BUFFER_H
#define NLSOUND_MUSIC_BUFFER_H
namespace NLMISC
{
class IStream;
class CIFile;
}
namespace NLSOUND
{
/*
* TODO: Streaming
* Some kind of decent streaming functionality, to get rid of the current music implementation. Audio decoding should be done on nlsound level. IBuffer needs a writable implementation, it allocates and owns the data memory, which can be written to by nlsound. When buffer is written, a function needs to be called to 'finalize' the buffer (so it can be submitted to OpenAL for example).
* Required interface functions, IBuffer:
* /// Allocate a new writable buffer. If this buffer was already allocated, the previous data is released.
* /// May return NULL if the format or frequency is not supported by the driver.
* uint8 *IBuffer::openWritable(uint size, TBufferFormat bufferFormat, uint8 channels, uint8 bitsPerSample, uint32 frequency);
* /// Tell that you are done writing to this buffer, so it can be copied over to hardware if needed.
* /// If keepLocal is true, a local copy of the buffer will be kept (so allocation can be re-used later).
* /// keepLocal overrides the OptionLocalBufferCopy flag. The buffer can use this function internally.
* void IBuffer::lockWritable(bool keepLocal);
* Required interface functions, ISource:
* /// Enable or disable the streaming facilities.
* void ISource::setStreaming(bool streaming);
* /// Submits a new buffer to the stream. A buffer of 100ms length is optimal for streaming.
* /// Should be called by a thread which checks countStreamingBuffers every 100ms
* void ISource::submitStreamingBuffer(IBuffer *buffer);
* /// Returns the number of buffers that are queued (includes playing buffer). 3 buffers is optimal.
* uint ISource::countStreamingBuffers();
* Other required interface functions, ISource:
* /// Enable or disable 3d calculations (to send directly to speakers).
* void ISource::set3DMode(bool enable);
* For compatibility with music trough fmod, ISoundDriver:
* /// Returns true if the sound driver has a native implementation of IMusicChannel (bad!).
* /// If this returns false, use the nlsound music channel, which goes trough Ctrack/ISource,
* /// The nlsound music channel requires support for IBuffer/ISource streaming.
* bool ISoundDriver::hasMusicChannel();
*/
/**
* \brief IMusicBuffer
* \date 2008-08-30 11:38GMT
* \author Jan Boon (Kaetemi)
* IMusicBuffer is only used by the driver implementation to stream
* music files into a readable format (it's a simple decoder interface).
* You should not call these functions (getSongTitle) on nlsound or user level,
* as a driver might have additional music types implemented.
* TODO: Change IMusicBuffer to IAudioDecoder, and change the interface to make more sense.
* TODO: Allow user application to register more decoders.
* TODO: Look into libavcodec for decoding audio.
*/
class IMusicBuffer
{
private:
// pointers
/// Stream from file created by IMusicBuffer
NLMISC::IStream *_InternalStream;
public:
IMusicBuffer();
virtual ~IMusicBuffer();
/// Create a new music buffer, may return NULL if unknown type, destroy with delete. Filepath lookup done here. If async is true, it will stream from hd, else it will load in memory first.
static IMusicBuffer *createMusicBuffer(const std::string &filepath, bool async, bool loop);
/// Create a new music buffer from a stream, type is file extension like "ogg" etc.
static IMusicBuffer *createMusicBuffer(const std::string &type, NLMISC::IStream *stream, bool loop);
/// Get information on a music file (only artist and title at the moment).
static bool getInfo(const std::string &filepath, std::string &artist, std::string &title);
/// Get how many bytes the music buffer requires for output minimum.
virtual uint32 getRequiredBytes() =0;
/// Get an amount of bytes between minimum and maximum (can be lower than minimum if at end).
virtual uint32 getNextBytes(uint8 *buffer, uint32 minimum, uint32 maximum) =0;
/// Get the amount of channels (2 is stereo) in output.
virtual uint8 getChannels() =0;
/// Get the samples per second (often 44100) in output.
virtual uint32 getSamplesPerSec() =0;
/// Get the bits per sample (often 16) in output.
virtual uint8 getBitsPerSample() =0;
/// Get if the music has ended playing (never true if loop).
virtual bool isMusicEnded() =0;
/// Get the total time in seconds.
virtual float getLength() =0;
/// Get the size of uncompressed data in bytes.
virtual uint getUncompressedSize() =0;
}; /* class IMusicBuffer */
} /* namespace NLSOUND */
#endif /* #ifndef NLSOUND_MUSIC_BUFFER_H */
/* end of file */

View file

@ -45,6 +45,9 @@ public:
/// Stop the music previously loaded and played (the Memory is also freed)
virtual void stop() =0;
/// Makes sure any resources are freed, but keeps available for next play call
virtual void reset() =0;
/// Pause the music previously loaded and played (the Memory is not freed)
virtual void pause() =0;

View file

@ -39,9 +39,11 @@ namespace NLSOUND
#endif
/*
* Sound sample format
* Deprecated sound sample format.
* For compatibility with old code.
* Do not modify.
*/
enum TSampleFormat { SampleFormatUnknown, Mono8, Mono16ADPCM, Mono16, Stereo8, Stereo16 };
enum TSampleFormat { Mono8, Mono16ADPCM, Mono16, Stereo8, Stereo16, SampleFormatUnknown = (~0) };
/**
* Abstract sound driver (implemented in sound driver dynamic library)

View file

@ -353,7 +353,7 @@ public:
* In streaming mode, the time spent during buffer outruns is not
* counted towards the playback time, and the playback time is
* be the current time position in the entire submitted queue.
* When using static buffers, the result is the tot time that the
* When using static buffers, the result is the total time that the
* attached buffer has been playing. If the source is looping, the
* time will be the total of all playbacks of the buffer.
* When the source is stopped, this will return the time where the
@ -397,7 +397,7 @@ public:
virtual void setSourceRelativeMode(bool mode = true) = 0;
/// Get the source relative mode
virtual bool getSourceRelativeMode() const = 0;
/// Set the min and max distances (default: 1, MAX_FLOAT) (3D mode only)
/// Set the min and max distances (default: 1, sqrt(MAX_FLOAT)) (3D mode only)
virtual void setMinMaxDistances(float mindist, float maxdist, bool deferred = true) = 0;
/// Get the min and max distances
virtual void getMinMaxDistances(float& mindist, float& maxdist) const = 0;

View file

@ -0,0 +1,105 @@
/**
* \file group_controller.h
* \brief CGroupController
* \date 2012-04-10 09:29GMT
* \author Jan Boon (Kaetemi)
* CGroupController
*/
/*
* Copyright (C) 2012 by authors
*
* This file is part of RYZOM CORE.
* RYZOM CORE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* RYZOM CORE is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with RYZOM CORE. If not, see
* <http://www.gnu.org/licenses/>.
*/
#ifndef NLSOUND_GROUP_CONTROLLER_H
#define NLSOUND_GROUP_CONTROLLER_H
#include <nel/misc/types_nl.h>
// STL includes
#include <string>
#include <map>
// NeL includes
#include <nel/misc/common.h>
#include <nel/sound/u_group_controller.h>
#include <nel/sound/containers.h>
// Project includes
namespace NLSOUND {
class CGroupControllerRoot;
/**
* \brief CGroupController
* \date 2012-04-10 09:29GMT
* \author Jan Boon (Kaetemi)
* CGroupController
*/
class CGroupController : public UGroupController
{
public:
friend class CGroupControllerRoot;
private:
CGroupController *m_Parent;
std::map<std::string, CGroupController *> m_Children;
float m_DevGain;
float m_UserGain;
float m_FinalGain;
int m_NbSourcesInclChild;
TSourceContainer m_Sources;
public:
CGroupController(CGroupController *parent);
/// \name UGroupController
//@{
virtual void setDevGain(float gain) { NLMISC::clamp(gain, 0.0f, 1.0f); m_DevGain = gain; updateSourceGain(); }
virtual float getDevGain() { return m_DevGain; }
virtual void setUserGain(float gain) { NLMISC::clamp(gain, 0.0f, 1.0f); m_UserGain = gain; updateSourceGain(); }
virtual float getUserGain() { return m_UserGain; }
virtual void setGain(float devGain, float userGain) { NLMISC::clamp(devGain, 0.0f, 1.0f); NLMISC::clamp(userGain, 0.0f, 1.0f); m_DevGain = devGain; m_UserGain = userGain; updateSourceGain(); }
//@}
inline float getFinalGain() const { return m_FinalGain; }
void addSource(CSourceCommon *source);
void removeSource(CSourceCommon *source);
virtual std::string getPath();
protected:
virtual ~CGroupController(); // subnodes can only be deleted by the root
private:
inline float calculateTotalGain() { return m_DevGain * m_UserGain; }
virtual void calculateFinalGain();
virtual void increaseSources();
virtual void decreaseSources();
void updateSourceGain();
}; /* class CGroupController */
} /* namespace NLSOUND */
#endif /* #ifndef NLSOUND_GROUP_CONTROLLER_H */
/* end of file */

View file

@ -0,0 +1,69 @@
/**
* \file group_controller_root.h
* \brief CGroupControllerRoot
* \date 2012-04-10 09:44GMT
* \author Jan Boon (Kaetemi)
* CGroupControllerRoot
*/
/*
* Copyright (C) 2012 by authors
*
* This file is part of RYZOM CORE.
* RYZOM CORE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* RYZOM CORE is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with RYZOM CORE. If not, see
* <http://www.gnu.org/licenses/>.
*/
#ifndef NLSOUND_GROUP_CONTROLLER_ROOT_H
#define NLSOUND_GROUP_CONTROLLER_ROOT_H
#include <nel/misc/types_nl.h>
// STL includes
// NeL includes
#include <nel/misc/singleton.h>
// Project includes
#include <nel/sound/group_controller.h>
namespace NLSOUND {
/**
* \brief CGroupControllerRoot
* \date 2012-04-10 09:44GMT
* \author Jan Boon (Kaetemi)
* CGroupControllerRoot
*/
class CGroupControllerRoot : public CGroupController, public NLMISC::CManualSingleton<CGroupControllerRoot>
{
public:
CGroupControllerRoot();
virtual ~CGroupControllerRoot();
/// Gets the group controller in a certain path with separator '/', if it doesn't exist yet it will be created.
CGroupController *getGroupController(const std::string &path);
protected:
virtual std::string getPath();
virtual void calculateFinalGain();
virtual void increaseSources();
virtual void decreaseSources();
}; /* class CGroupControllerRoot */
} /* namespace NLSOUND */
#endif /* #ifndef NLSOUND_GROUP_CONTROLLER_ROOT_H */
/* end of file */

View file

@ -87,6 +87,8 @@ public:
void init(ISoundDriver *soundDriver);
void release();
void reset();
void update(); // time in seconds
inline bool isInitOk() { return _SoundDriver != NULL; }

View file

@ -35,7 +35,7 @@ class CMusicSource : public CSourceCommon
{
public:
/// Constructor
CMusicSource (class CMusicSound *sound=NULL, bool spawn=false, TSpawnEndCallback cb=0, void *cbUserParam = 0, NL3D::CCluster *cluster = 0);
CMusicSource (class CMusicSound *sound=NULL, bool spawn=false, TSpawnEndCallback cb=0, void *cbUserParam = 0, NL3D::CCluster *cluster = 0, CGroupController *groupController = NULL);
/// Destructor
~CMusicSource ();

View file

@ -40,7 +40,7 @@ class CSimpleSource : public CSourceCommon, public CAudioMixerUser::IMixerEvent
{
public:
/// Constructor
CSimpleSource(CSimpleSound *simpleSound = NULL, bool spawn = false, TSpawnEndCallback cb = 0, void *cbUserParam = 0, NL3D::CCluster *cluster = 0);
CSimpleSource(CSimpleSound *simpleSound = NULL, bool spawn = false, TSpawnEndCallback cb = 0, void *cbUserParam = 0, NL3D::CCluster *cluster = 0, CGroupController *groupController = NULL);
/// Destructor
virtual ~CSimpleSource();
@ -97,14 +97,7 @@ public:
* 1.0 -> no attenuation
* values > 1 (amplification) not supported by most drivers
*/
virtual void setGain( float gain );
/** Set the gain amount (value inside [0, 1]) to map between 0 and the nominal gain
* (which is getSource()->getGain()). Does nothing if getSource() is null.
*/
virtual void setRelativeGain( float gain );
/** Shift the frequency. 1.0f equals identity, each reduction of 50% equals a pitch shift
* of one octave. 0 is not a legal value.
*/
virtual void updateFinalGain();
virtual void setPitch( float pitch );
/// Set the source relative mode. If true, positions are interpreted relative to the listener position (default: false)
virtual void setSourceRelativeMode( bool mode );
@ -149,6 +142,8 @@ private:
/// True when the sound is played muted and until the mixer event notifying the end.
bool _PlayMuted;
bool _WaitingForPlay;
};

View file

@ -30,6 +30,7 @@ namespace NLSOUND {
class ISoundDriver;
class IBuffer;
class CSound;
class CGroupController;
/// Sound names hash map
@ -60,8 +61,9 @@ public:
SOUND_COMPLEX,
SOUND_BACKGROUND,
SOUND_CONTEXT,
SOUND_MUSIC,
SOUND_STREAM
SOUND_MUSIC, // soon to be deprecated hopefully
SOUND_STREAM,
SOUND_STREAM_FILE
};
@ -104,6 +106,8 @@ public:
/// Return the max distance (if detailed())
virtual float getMaxDistance() const { return _MaxDist; }
inline CGroupController *getGroupController() const { return _GroupController; }
/// Set looping
void setLooping( bool looping ) { _Looping = looping; }
@ -142,6 +146,9 @@ protected:
/// An optional user var controler.
NLMISC::TStringId _UserVarControler;
/// The group controller, always exists, owned by the audio mixer
CGroupController *_GroupController;
};

View file

@ -22,7 +22,7 @@
#include "nel/sound/u_stream_source.h"
#include "nel/3d/cluster.h"
#include "nel/sound/sound.h"
#include "nel/sound/group_controller.h"
namespace NLSOUND {
@ -36,11 +36,13 @@ public:
SOURCE_SIMPLE,
SOURCE_COMPLEX,
SOURCE_BACKGROUND,
SOURCE_MUSIC,
SOURCE_STREAM
SOURCE_MUSIC, // DEPRECATED
SOURCE_STREAM,
SOURCE_STREAM_FILE
};
CSourceCommon(TSoundId id, bool spawn, TSpawnEndCallback cb, void *cbUserParam, NL3D::CCluster *cluster);
/// When groupController is NULL it will use the groupcontroller specified in the TSoundId. You should manually specify the groupController if this source is a child of another source, so that the parent source controller of the user-specified .sound file is the one that will be used.
CSourceCommon(TSoundId id, bool spawn, TSpawnEndCallback cb, void *cbUserParam, NL3D::CCluster *cluster, CGroupController *groupController);
~CSourceCommon();
@ -63,6 +65,8 @@ public:
void setGain( float gain );
void setRelativeGain( float gain );
float getRelativeGain() const;
/// Called whenever the gain is changed trough setGain, setRelativeGain or the group controller's gain settings change.
virtual void updateFinalGain() { }
void setSourceRelativeMode( bool mode );
/// return the user param for the user callback
void *getCallbackUserParam(void) const { return _CbUserParam; }
@ -74,6 +78,8 @@ public:
virtual void getDirection( NLMISC::CVector& dir ) const { dir = _Direction; }
/// Get the gain
virtual float getGain() const { return _Gain; }
/// Get the final gain, including group controller changes. Use this when setting the physical source output gain.
inline float getFinalGain() const { return _Gain * _GroupController->getFinalGain(); }
/// Get the pitch
virtual float getPitch() const { return _Pitch; }
/// Get the source relative mode
@ -145,6 +151,9 @@ protected:
/// An optional user var controler.
NLMISC::TStringId _UserVarControler;
/// Group controller for gain
CGroupController *_GroupController;
};
} // NLSOUND

View file

@ -0,0 +1,100 @@
/**
* \file source_music_channel.h
* \brief CSourceMusicChannel
* \date 2012-04-11 16:08GMT
* \author Jan Boon (Kaetemi)
* CSourceMusicChannel
*/
/*
* Copyright (C) 2012 by authors
*
* This file is part of RYZOM CORE.
* RYZOM CORE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* RYZOM CORE is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with RYZOM CORE. If not, see
* <http://www.gnu.org/licenses/>.
*/
#ifndef NLSOUND_SOURCE_MUSIC_CHANNEL_H
#define NLSOUND_SOURCE_MUSIC_CHANNEL_H
#include <nel/misc/types_nl.h>
// STL includes
// NeL includes
#include <nel/sound/driver/music_channel.h>
#include <nel/sound/stream_file_sound.h>
// Project includes
namespace NLSOUND {
class CStreamFileSource;
/**
* \brief CSourceMusicChannel
* \date 2012-04-11 16:08GMT
* \author Jan Boon (Kaetemi)
* CSourceMusicChannel
*/
class CSourceMusicChannel : public IMusicChannel
{
public:
CSourceMusicChannel();
virtual ~CSourceMusicChannel();
/** Play some music (.ogg etc...)
* NB: if an old music was played, it is first stop with stopMusic()
* \param filepath file path, CPath::lookup is done here
* \param async stream music from hard disk, preload in memory if false
* \param loop must be true to play the music in loop.
*/
virtual bool play(const std::string &filepath, bool async, bool loop);
/// Stop the music previously loaded and played (the Memory is also freed)
virtual void stop();
/// Makes sure any resources are freed, but keeps available for next play call
virtual void reset();
/// Pause the music previously loaded and played (the Memory is not freed)
virtual void pause();
/// Resume the music previously paused
virtual void resume();
/// Return true if a song is finished.
virtual bool isEnded();
/// Return true if the song is still loading asynchronously and hasn't started playing yet (false if not async), used to delay fading
virtual bool isLoadingAsync();
/// Return the total length (in second) of the music currently played
virtual float getLength();
/** Set the music volume (if any music played). (volume value inside [0 , 1]) (default: 1)
* NB: the volume of music is NOT affected by IListener::setGain()
*/
virtual void setVolume(float gain);
private:
CStreamFileSound m_Sound;
CStreamFileSource *m_Source;
float m_Gain;
}; /* class CSourceMusicChannel */
} /* namespace NLSOUND */
#endif /* #ifndef NLSOUND_SOURCE_MUSIC_CHANNEL_H */
/* end of file */

View file

@ -0,0 +1,94 @@
/**
* \file stream_file_sound.h
* \brief CStreamFileSound
* \date 2012-04-11 09:57GMT
* \author Jan Boon (Kaetemi)
* CStreamFileSound
*/
/*
* Copyright (C) 2012 by authors
*
* This file is part of RYZOM CORE.
* RYZOM CORE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* RYZOM CORE is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with RYZOM CORE. If not, see
* <http://www.gnu.org/licenses/>.
*/
#ifndef NLSOUND_STREAM_FILE_SOUND_H
#define NLSOUND_STREAM_FILE_SOUND_H
#include <nel/misc/types_nl.h>
// STL includes
// NeL includes
// Project includes
#include <nel/sound/stream_sound.h>
namespace NLSOUND {
class CSourceMusicChannel;
/**
* \brief CStreamFileSound
* \date 2012-04-11 09:57GMT
* \author Jan Boon (Kaetemi)
* CStreamFileSound
*/
class CStreamFileSound : public CStreamSound
{
public:
friend class CSourceMusicChannel;
public:
CStreamFileSound();
virtual ~CStreamFileSound();
/// Get the type of the sound.
virtual TSOUND_TYPE getSoundType() { return SOUND_STREAM_FILE; }
/// Load the sound parameters from georges' form
virtual void importForm(const std::string& filename, NLGEORGES::UFormElm& formRoot);
/// Used by the george sound plugin to check sound recursion (ie sound 'toto' use sound 'titi' witch also use sound 'toto' ...).
virtual void getSubSoundList(std::vector<std::pair<std::string, CSound*> > &/* subsounds */) const { }
/// Serialize the sound data.
virtual void serial(NLMISC::IStream &s);
/// Return the length of the sound in ms
virtual uint32 getDuration() { return 0; }
inline bool getAsync() { return m_Async; }
inline const std::string &getFilePath() { return m_FilePath; }
private:
/// Used by CSourceMusicChannel to set the filePath and default settings on other parameters.
void setMusicFilePath(const std::string &filePath, bool async = true, bool loop = false);
private:
CStreamFileSound(const CStreamFileSound &);
CStreamFileSound &operator=(const CStreamFileSound &);
private:
bool m_Async;
std::string m_FilePath;
}; /* class CStreamFileSound */
} /* namespace NLSOUND */
#endif /* #ifndef NLSOUND_STREAM_FILE_SOUND_H */
/* end of file */

View file

@ -0,0 +1,110 @@
/**
* \file stream_file_source.h
* \brief CStreamFileSource
* \date 2012-04-11 09:57GMT
* \author Jan Boon (Kaetemi)
* CStreamFileSource
*/
/*
* Copyright (C) 2012 by authors
*
* This file is part of RYZOM CORE.
* RYZOM CORE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* RYZOM CORE is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with RYZOM CORE. If not, see
* <http://www.gnu.org/licenses/>.
*/
#ifndef NLSOUND_STREAM_FILE_SOURCE_H
#define NLSOUND_STREAM_FILE_SOURCE_H
#include <nel/misc/types_nl.h>
// STL includes
// NeL includes
#include <nel/misc/thread.h>
// Project includes
#include <nel/sound/stream_source.h>
#include <nel/sound/stream_file_sound.h>
namespace NLSOUND {
class IAudioDecoder;
/**
* \brief CStreamFileSource
* \date 2012-04-11 09:57GMT
* \author Jan Boon (Kaetemi)
* CStreamFileSource
*/
class CStreamFileSource : public CStreamSource, private NLMISC::IRunnable
{
public:
CStreamFileSource(CStreamFileSound *streamFileSound = NULL, bool spawn = false, TSpawnEndCallback cb = 0, void *cbUserParam = 0, NL3D::CCluster *cluster = 0, CGroupController *groupController = NULL);
virtual ~CStreamFileSource();
/// Return the source type
TSOURCE_TYPE getType() const { return SOURCE_STREAM_FILE; }
/// \name Playback control
//@{
/// Play
virtual void play();
/// Stop playing
virtual void stop();
/// Get playing state. Return false even if the source has stopped on its own.
virtual bool isPlaying();
/// Pause (following legacy music channel implementation)
void pause();
/// Resume (following legacy music channel implementation)
void resume();
/// check if song ended (following legacy music channel implementation)
bool isEnded();
/// (following legacy music channel implementation)
float getLength();
/// check if still loading (following legacy music channel implementation)
bool isLoadingAsync();
//@}
/// \name Decoding thread
//@{
virtual void getName (std::string &result) const { result = "CStreamFileSource"; }
virtual void run();
//@}
// TODO: getTime
private:
bool prepareDecoder();
inline bool bufferMore(uint bytes);
private:
CStreamFileSource(const CStreamFileSource &);
CStreamFileSource &operator=(const CStreamFileSource &);
private:
inline CStreamFileSound *getStreamFileSound() { return static_cast<CStreamFileSound *>(m_StreamSound); }
NLMISC::IThread *m_Thread;
IAudioDecoder *m_AudioDecoder;
bool m_Paused;
}; /* class CStreamFileSource */
} /* namespace NLSOUND */
#endif /* #ifndef NLSOUND_STREAM_FILE_SOURCE_H */
/* end of file */

View file

@ -41,7 +41,7 @@ namespace NLSOUND {
class CStreamSource : public CSourceCommon
{
public:
CStreamSource(CStreamSound *streamSound = NULL, bool spawn = false, TSpawnEndCallback cb = 0, void *cbUserParam = 0, NL3D::CCluster *cluster = 0);
CStreamSource(CStreamSound *streamSound = NULL, bool spawn = false, TSpawnEndCallback cb = 0, void *cbUserParam = 0, NL3D::CCluster *cluster = 0, CGroupController *groupController = NULL);
virtual ~CStreamSource();
/// Return the sound binded to the source (or NULL if there is no sound)
@ -55,6 +55,9 @@ public:
virtual void setLooping(bool l);
/// Play
virtual void play();
protected:
void stopInt();
public:
/// Stop playing
virtual void stop();
/// Get playing state. Return false even if the source has stopped on its own.
@ -80,18 +83,7 @@ public:
virtual void setVelocity(const NLMISC::CVector& vel);
/// Set the direction vector (3D mode only, ignored in stereo mode) (default: (0,0,0) as non-directional)
virtual void setDirection(const NLMISC::CVector& dir);
/** Set the gain (volume value inside [0 , 1]). (default: 1)
* 0.0 -> silence
* 0.5 -> -6dB
* 1.0 -> no attenuation
* values > 1 (amplification) not supported by most drivers
*/
virtual void setGain(float gain);
/** Set the gain amount (value inside [0, 1]) to map between 0 and the nominal gain
* (which is getSource()->getGain()). Does nothing if getSource() is null.
*/
virtual void setRelativeGain(float gain);
virtual void updateFinalGain();
/** Shift the frequency. 1.0f equals identity, each reduction of 50% equals a pitch shift
* of one octave. 0 is not a legal value.
*/
@ -118,6 +110,9 @@ public:
virtual bool hasFilledBuffersAvailable() const;
//@}
/// Prepare the buffers in this stream for the given maximum capacity. (TODO: Move this into UStreamSource)
void preAllocate(uint capacity);
/// Return the track
CTrack *getTrack() { return m_Track; }
@ -125,7 +120,7 @@ private:
CStreamSource(const CStreamSource &);
CStreamSource &operator=(const CStreamSource &);
private:
protected:
/// Return the source type
TSOURCE_TYPE getType() const { return SOURCE_STREAM; }
@ -173,7 +168,13 @@ private:
/// The bytes per second according to the buffer format
uint m_BytesPerSecond;
/// Waiting for play for high priority sources
bool m_WaitingForPlay;
/// Inverse pitch
float m_PitchInv;
}; /* class CStreamSource */
} /* namespace NLSOUND */

View file

@ -20,6 +20,7 @@
#include "nel/misc/types_nl.h"
#include "nel/misc/string_mapper.h"
#include "nel/sound/u_source.h"
#include "nel/sound/u_group_controller.h"
#include "nel/ligo/primitive.h"
#include <vector>
@ -285,15 +286,19 @@ public:
/// Get a TSoundId from a name (returns NULL if not found)
virtual TSoundId getSoundId( const NLMISC::TStringId &name ) = 0;
/// Gets the group controller for the given group tree path with separator '/', if it doesn't exist yet it will be created.
/// Examples: "music", "effects", "dialog", "music/background", "music/loading", "music/player", etcetera
virtual UGroupController *getGroupController(const std::string &path) = 0;
/** Add a logical sound source (returns NULL if name not found).
* If spawn is true, the source will auto-delete after playing. If so, the return USource* pointer
* is valid only before the time when calling play() plus the duration of the sound. You can
* pass a callback function that will be called (if not NULL) just before deleting the spawned
* source.
*/
virtual USource *createSource( const NLMISC::TStringId &name, bool spawn=false, TSpawnEndCallback cb=NULL, void *callbackUserParam = NULL, NL3D::CCluster *cluster = 0, CSoundContext *context=0) = 0;
virtual USource *createSource(const NLMISC::TStringId &name, bool spawn=false, TSpawnEndCallback cb=NULL, void *callbackUserParam = NULL, NL3D::CCluster *cluster = 0, CSoundContext *context = 0, UGroupController *groupController = NULL) = 0;
/// Add a logical sound source (by sound id). To remove a source, just delete it. See createSource(const char*)
virtual USource *createSource( TSoundId id, bool spawn=false, TSpawnEndCallback cb=NULL, void *callbackUserParam = NULL, NL3D::CCluster *cluster = 0, CSoundContext *context=0 ) = 0;
virtual USource *createSource(TSoundId id, bool spawn=false, TSpawnEndCallback cb=NULL, void *callbackUserParam = NULL, NL3D::CCluster *cluster = 0, CSoundContext *context = 0, UGroupController *groupController = NULL) = 0;
/** Use this method to set the listener position instead of using getListener->setPos();
* It's because we have to update the background sounds in this case.

View file

@ -0,0 +1,70 @@
/**
* \file u_group_controller.h
* \brief UGroupController
* \date 2012-04-10 12:49GMT
* \author Jan Boon (Kaetemi)
* UGroupController
*/
/*
* Copyright (C) 2012 by authors
*
* This file is part of RYZOM CORE.
* RYZOM CORE is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* RYZOM CORE is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with RYZOM CORE. If not, see
* <http://www.gnu.org/licenses/>.
*/
#ifndef NLSOUND_U_GROUP_CONTROLLER_H
#define NLSOUND_U_GROUP_CONTROLLER_H
#include <nel/misc/types_nl.h>
// STL includes
// NeL includes
// Project includes
#define NLSOUND_SHEET_V1_DEFAULT_SOUND_GROUP_CONTROLLER "effects"
#define NLSOUND_SHEET_V1_DEFAULT_SOUND_MUSIC_GROUP_CONTROLLER "music"
#define NLSOUND_SHEET_V1_DEFAULT_SOUND_STREAM_GROUP_CONTROLLER "dialog"
namespace NLSOUND {
/**
* \brief UGroupController
* \date 2012-04-10 12:49GMT
* \author Jan Boon (Kaetemi)
* UGroupController
*/
class UGroupController
{
public:
virtual void setDevGain(float gain) = 0;
virtual float getDevGain() = 0;
virtual void setUserGain(float gain) = 0;
virtual float getUserGain() = 0;
virtual void setGain(float devGain, float userGain) = 0;
protected:
virtual ~UGroupController() { }
}; /* class UGroupController */
} /* namespace NLSOUND */
#endif /* #ifndef NLSOUND_U_GROUP_CONTROLLER_H */
/* end of file */

View file

@ -17,5 +17,5 @@ IF(WITH_PACS)
ENDIF(WITH_PACS)
IF(WITH_SOUND)
ADD_SUBDIRECTORY(sound_sources)
ADD_SUBDIRECTORY(sound)
ENDIF(WITH_SOUND)

View file

@ -0,0 +1,5 @@
ADD_SUBDIRECTORY(sound_sources)
ADD_SUBDIRECTORY(stream_file)
ADD_SUBDIRECTORY(stream_ogg_vorbis)

View file

@ -7,7 +7,7 @@ ADD_DEFINITIONS(-DNL_SOUND_DATA="\\"${NL_SHARE_PREFIX}/nl_sample_sound/\\"" ${LI
INCLUDE_DIRECTORIES(${LIBXML2_INCLUDE_DIR})
TARGET_LINK_LIBRARIES(nl_sample_sound_sources nelmisc nelsound)
NL_DEFAULT_PROPS(nl_sample_sound_sources "NeL, Samples: Sound System")
NL_DEFAULT_PROPS(nl_sample_sound_sources "NeL, Samples: Sound: Sound Sources")
NL_ADD_RUNTIME_FLAGS(nl_sample_sound_sources)
INSTALL(TARGETS nl_sample_sound_sources RUNTIME DESTINATION bin COMPONENT samplessound)

View file

@ -0,0 +1,12 @@
FILE(GLOB SRC *.cpp *.h)
ADD_EXECUTABLE(nl_sample_stream_file ${SRC})
INCLUDE_DIRECTORIES(${LIBXML2_INCLUDE_DIR})
TARGET_LINK_LIBRARIES(nl_sample_stream_file nelmisc nelsound)
NL_DEFAULT_PROPS(nl_sample_stream_file "NeL, Samples: Sound: Stream File")
NL_ADD_RUNTIME_FLAGS(nl_sample_stream_file)
INSTALL(TARGETS nl_sample_stream_file RUNTIME DESTINATION bin COMPONENT samplessound)

View file

@ -0,0 +1,6 @@
<?xml version="1.0"?>
<DFN Version="0.0" State="modified">
<ELEMENT Name="Designation" Type="Type" Filename="string.typ"/>
<ELEMENT Name="Substitute" Type="Type" Filename="string.typ"/>
<COMMENTS></COMMENTS>
</DFN>

View file

@ -0,0 +1,9 @@
<?xml version="1.0"?>
<TYPE Type="String" UI="NonEditableCombo" Version="0.0" State="modified">
<DEFINITION Label="string" Value="string"/>
<DEFINITION Label="sint" Value="sint"/>
<DEFINITION Label="uint" Value="uint"/>
<DEFINITION Label="double" Value="double"/>
<DEFINITION Label="filename" Value="filename"/>
<COMMENTS></COMMENTS>
</TYPE>

View file

@ -0,0 +1,6 @@
<?xml version="1.0"?>
<TYPE Type="String" UI="NonEditableCombo" Default="false" Version="0.0" State="modified">
<DEFINITION Label="true" Value="true"/>
<DEFINITION Label="false" Value="false"/>
<COMMENTS></COMMENTS>
</TYPE>

View file

@ -0,0 +1,4 @@
<?xml version="1.0"?>
<TYPE Type="String" UI="FileBrowser" Version="0.0" State="modified">
<COMMENTS></COMMENTS>
</TYPE>

View file

@ -0,0 +1,4 @@
<?xml version="1.0"?>
<TYPE Type="Double" UI="EditSpin" Default="0.0" Min="-3.402823466e+38" Max="3.402823466e+38F" Version="0.0" State="modified">
<COMMENTS></COMMENTS>
</TYPE>

View file

@ -0,0 +1,6 @@
<?xml version="1.0"?>
<TYPE Type="UnsignedInt" UI="NonEditableCombo" Default="0" Min="0" Max="1" Version="0.0" State="modified">
<DEFINITION Label="true" Value="1"/>
<DEFINITION Label="false" Value="0"/>
<COMMENTS></COMMENTS>
</TYPE>

View file

@ -0,0 +1,4 @@
<?xml version="1.0"?>
<TYPE Type="SignedInt" UI="EditSpin" Default="0" Min="-9223372036854775808" Max="9223372036854775807" Version="0.0" State="modified">
<COMMENTS></COMMENTS>
</TYPE>

View file

@ -0,0 +1,4 @@
<?xml version="1.0"?>
<TYPE Type="SignedInt" UI="EditSpin" Default="0" Min="-32768" Max="32767" Version="0.0" State="modified">
<COMMENTS></COMMENTS>
</TYPE>

View file

@ -0,0 +1,4 @@
<?xml version="1.0"?>
<TYPE Type="SignedInt" UI="EditSpin" Default="0" Min="-2147483648" Max="2147483647" Version="0.0" State="modified">
<COMMENTS></COMMENTS>
</TYPE>

View file

@ -0,0 +1,4 @@
<?xml version="1.0"?>
<TYPE Type="SignedInt" UI="EditSpin" Default="0" Min="-9223372036854775808" Max="9223372036854775807" Version="0.0" State="modified">
<COMMENTS></COMMENTS>
</TYPE>

View file

@ -0,0 +1,4 @@
<?xml version="1.0"?>
<TYPE Type="SignedInt" UI="EditSpin" Default="0" Min="-128" Max="127" Version="0.0" State="modified">
<COMMENTS></COMMENTS>
</TYPE>

View file

@ -0,0 +1,4 @@
<?xml version="1.0"?>
<TYPE Type="String" UI="Edit" Version="0.0" State="modified">
<COMMENTS></COMMENTS>
</TYPE>

View file

@ -0,0 +1,11 @@
<?xml version="1.0"?>
<DFN Version="0.0" State="modified">
<ELEMENT Name="Type" Type="Type" Filename="_type.typ"/>
<ELEMENT Name="Enum" Type="Type" Filename="boolean.typ"/>
<ELEMENT Name="Formula" Type="Type" Filename="string.typ"/>
<ELEMENT Name="Lowlimit" Type="Type" Filename="string.typ"/>
<ELEMENT Name="Highlimit" Type="Type" Filename="string.typ"/>
<ELEMENT Name="DefaultValue" Type="Type" Filename="string.typ"/>
<ELEMENT Name="Predef" Type="Dfn" Filename="_typ.dfn" Array="true"/>
<COMMENTS></COMMENTS>
</DFN>

View file

@ -0,0 +1,4 @@
<?xml version="1.0"?>
<TYPE Type="UnsignedInt" UI="EditSpin" Default="0" Min="0" Max="65535" Version="0.0" State="modified">
<COMMENTS></COMMENTS>
</TYPE>

View file

@ -0,0 +1,4 @@
<?xml version="1.0"?>
<TYPE Type="UnsignedInt" UI="EditSpin" Default="0" Min="0" Max="4294967295" Version="0.0" State="modified">
<COMMENTS></COMMENTS>
</TYPE>

View file

@ -0,0 +1,4 @@
<?xml version="1.0"?>
<TYPE Type="UnsignedInt" UI="EditSpin" Default="0" Min="0" Max="18446744073709551615" Version="0.0" State="modified">
<COMMENTS></COMMENTS>
</TYPE>

View file

@ -0,0 +1,4 @@
<?xml version="1.0"?>
<TYPE Type="UnsignedInt" UI="EditSpin" Default="0" Min="0" Max="255" Version="0.0" State="modified">
<COMMENTS></COMMENTS>
</TYPE>

View file

@ -0,0 +1,2 @@
<?xml version="1.0"?>
<TYPE Type="Double" UI="Edit" Default="0" Min="-1.0" Max="1.0" Version="0.1" State="modified"/>

View file

@ -0,0 +1,2 @@
<?xml version="1.0"?>
<TYPE Type="UnsignedInt" UI="EditSpin" Default="360" Min="0" Max="360" Version="0.8" State="modified"/>

View file

@ -0,0 +1,42 @@
<?xml version="1.0"?>
<DFN Revision="$Revision: 1.1 $" State="modified">
<ELEMENT Name="Sound" Type="Type" Filename="filename.typ" FilenameExt="*.sound"/>
<ELEMENT Name="Filter00" Type="Type" Filename="boolean.typ" Default="false"/>
<ELEMENT Name="Filter01" Type="Type" Filename="boolean.typ" Default="false"/>
<ELEMENT Name="Filter02" Type="Type" Filename="boolean.typ" Default="false"/>
<ELEMENT Name="Filter03" Type="Type" Filename="boolean.typ" Default="false"/>
<ELEMENT Name="Filter04" Type="Type" Filename="boolean.typ" Default="false"/>
<ELEMENT Name="Filter05" Type="Type" Filename="boolean.typ" Default="false"/>
<ELEMENT Name="Filter06" Type="Type" Filename="boolean.typ" Default="false"/>
<ELEMENT Name="Filter07" Type="Type" Filename="boolean.typ" Default="false"/>
<ELEMENT Name="Filter08" Type="Type" Filename="boolean.typ" Default="false"/>
<ELEMENT Name="Filter09" Type="Type" Filename="boolean.typ" Default="false"/>
<ELEMENT Name="Filter10" Type="Type" Filename="boolean.typ" Default="false"/>
<ELEMENT Name="Filter11" Type="Type" Filename="boolean.typ" Default="false"/>
<ELEMENT Name="Filter12" Type="Type" Filename="boolean.typ" Default="false"/>
<ELEMENT Name="Filter13" Type="Type" Filename="boolean.typ" Default="false"/>
<ELEMENT Name="Filter14" Type="Type" Filename="boolean.typ" Default="false"/>
<ELEMENT Name="Filter15" Type="Type" Filename="boolean.typ" Default="false"/>
<ELEMENT Name="Filter16" Type="Type" Filename="boolean.typ" Default="false"/>
<ELEMENT Name="Filter17" Type="Type" Filename="boolean.typ" Default="false"/>
<ELEMENT Name="Filter18" Type="Type" Filename="boolean.typ" Default="false"/>
<ELEMENT Name="Filter19" Type="Type" Filename="boolean.typ" Default="false"/>
<ELEMENT Name="Filter20" Type="Type" Filename="boolean.typ" Default="false"/>
<ELEMENT Name="Filter21" Type="Type" Filename="boolean.typ" Default="false"/>
<ELEMENT Name="Filter22" Type="Type" Filename="boolean.typ" Default="false"/>
<ELEMENT Name="Filter23" Type="Type" Filename="boolean.typ" Default="false"/>
<ELEMENT Name="Filter24" Type="Type" Filename="boolean.typ" Default="false"/>
<ELEMENT Name="Filter25" Type="Type" Filename="boolean.typ" Default="false"/>
<ELEMENT Name="Filter26" Type="Type" Filename="boolean.typ" Default="false"/>
<ELEMENT Name="Filter27" Type="Type" Filename="boolean.typ" Default="false"/>
<ELEMENT Name="Filter28" Type="Type" Filename="boolean.typ" Default="false"/>
<ELEMENT Name="Filter29" Type="Type" Filename="boolean.typ" Default="false"/>
<ELEMENT Name="Filter30" Type="Type" Filename="boolean.typ" Default="false"/>
<ELEMENT Name="Filter31" Type="Type" Filename="boolean.typ" Default="false"/>
<LOG>Tue Oct 08 14:39:12 2002 (boucher) Dfn Structure =
Tue Oct 08 15:03:40 2002 (boucher) Dfn Structure =
Mon Oct 14 16:09:48 2002 (boucher) Dfn Structure =
Wed Oct 16 18:22:30 2002 (boucher) Dfn Structure =
Thu Dec 19 16:26:49 2002 (boucher) Dfn Structure =
Wed Apr 09 19:38:51 2003 (AmazingSound) Dfn Structure = </LOG>
</DFN>

Some files were not shown because too many files have changed in this diff Show more