diff --git a/code/nel/include/nel/misc/fast_id_map.h b/code/nel/include/nel/misc/fast_id_map.h
new file mode 100644
index 000000000..dbd05bc76
--- /dev/null
+++ b/code/nel/include/nel/misc/fast_id_map.h
@@ -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
+ * .
+ */
+
+#ifndef NLMISC_FAST_ID_MAP_H
+#define NLMISC_FAST_ID_MAP_H
+#include
+
+// STL includes
+
+// NeL includes
+#include
+
+// 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
+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 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 */
diff --git a/code/nel/include/nel/misc/p_thread.h b/code/nel/include/nel/misc/p_thread.h
index cd027aa37..7e6a4d5a5 100644
--- a/code/nel/include/nel/misc/p_thread.h
+++ b/code/nel/include/nel/misc/p_thread.h
@@ -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;
};
/**
diff --git a/code/nel/include/nel/misc/thread.h b/code/nel/include/nel/misc/thread.h
index 82ef78a13..983e6b12a 100644
--- a/code/nel/include/nel/misc/thread.h
+++ b/code/nel/include/nel/misc/thread.h
@@ -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.
diff --git a/code/nel/include/nel/misc/win_thread.h b/code/nel/include/nel/misc/win_thread.h
index a2e8b5389..628942dde 100644
--- a/code/nel/include/nel/misc/win_thread.h
+++ b/code/nel/include/nel/misc/win_thread.h
@@ -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
diff --git a/code/nel/include/nel/sound/audio_decoder.h b/code/nel/include/nel/sound/audio_decoder.h
new file mode 100644
index 000000000..3babc1de1
--- /dev/null
+++ b/code/nel/include/nel/sound/audio_decoder.h
@@ -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
+ * .
+ */
+
+#ifndef NLSOUND_AUDIO_DECODER_H
+#define NLSOUND_AUDIO_DECODER_H
+#include
+
+// 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 &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 */
diff --git a/code/nel/include/nel/sound/driver/music_buffer_vorbis.h b/code/nel/include/nel/sound/audio_decoder_vorbis.h
similarity index 50%
rename from code/nel/include/nel/sound/driver/music_buffer_vorbis.h
rename to code/nel/include/nel/sound/audio_decoder_vorbis.h
index 978f393da..bd7e45019 100644
--- a/code/nel/include/nel/sound/driver/music_buffer_vorbis.h
+++ b/code/nel/include/nel/sound/audio_decoder_vorbis.h
@@ -1,21 +1,33 @@
-// NeL - MMORPG Framework
-// 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 .
+/**
+ * \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
+ * .
+ */
+
+#ifndef NLSOUND_AUDIO_DECODER_VORBIS_H
+#define NLSOUND_AUDIO_DECODER_VORBIS_H
+#include
// STL includes
@@ -30,21 +42,20 @@
#endif
// NeL includes
+#include
// 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 */
diff --git a/code/nel/include/nel/sound/audio_mixer_user.h b/code/nel/include/nel/sound/audio_mixer_user.h
index 7cd0de051..1316fe34a 100644
--- a/code/nel/include/nel/sound/audio_mixer_user.h
+++ b/code/nel/include/nel/sound/audio_mixer_user.h
@@ -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
-struct THashPtr : public std::unary_function
-{
- static const size_t bucket_size = 4;
- static const size_t min_buckets = 8;
- size_t operator () (const Pointer &ptr) const
- {
- //CHashSet::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 > TSourceContainer;
typedef CHashSet > TMixerUpdateContainer;
typedef CHashMap, THashPtr > TBufferToSourceContainer;
// typedef std::multimap TTimedEventContainer;
@@ -565,6 +552,9 @@ private:
// Instance of the background music manager
CMusicSoundManager *_BackgroundMusicManager;
+ /// Group controller
+ CGroupControllerRoot _GroupController;
+
public:
struct TSampleBankHeader
{
diff --git a/code/nel/include/nel/sound/background_source.h b/code/nel/include/nel/sound/background_source.h
index cdf044776..14ea1cf53 100644
--- a/code/nel/include/nel/sound/background_source.h
+++ b/code/nel/include/nel/sound/background_source.h
@@ -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 ();
diff --git a/code/nel/include/nel/sound/complex_source.h b/code/nel/include/nel/sound/complex_source.h
index d27b5af5b..d1135b1ad 100644
--- a/code/nel/include/nel/sound/complex_source.h
+++ b/code/nel/include/nel/sound/complex_source.h
@@ -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 ();
diff --git a/code/nel/include/nel/sound/containers.h b/code/nel/include/nel/sound/containers.h
new file mode 100644
index 000000000..bd4fe7fb9
--- /dev/null
+++ b/code/nel/include/nel/sound/containers.h
@@ -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
+ * .
+ */
+
+#ifndef NLSOUND_CONTAINERS_H
+#define NLSOUND_CONTAINERS_H
+#include
+
+// STL includes
+
+// NeL includes
+
+// Project includes
+
+namespace NLSOUND {
+ class CSourceCommon;
+
+/// Hasher functor for hashed container with pointer key.
+template
+struct THashPtr : public std::unary_function
+{
+ static const size_t bucket_size = 4;
+ static const size_t min_buckets = 8;
+ size_t operator () (const Pointer &ptr) const
+ {
+ //CHashSet::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 > TSourceContainer;
+
+} /* namespace NLSOUND */
+
+#endif /* #ifndef NLSOUND_CONTAINERS_H */
+
+/* end of file */
diff --git a/code/nel/include/nel/sound/driver/buffer.h b/code/nel/include/nel/sound/driver/buffer.h
index 5d488f1c7..27a8d9f00 100644
--- a/code/nel/include/nel/sound/driver/buffer.h
+++ b/code/nel/include/nel/sound/driver/buffer.h
@@ -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
diff --git a/code/nel/include/nel/sound/driver/music_buffer.h b/code/nel/include/nel/sound/driver/music_buffer.h
deleted file mode 100644
index 571e27a31..000000000
--- a/code/nel/include/nel/sound/driver/music_buffer.h
+++ /dev/null
@@ -1,119 +0,0 @@
-// NeL - MMORPG Framework
-// 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 .
-
-#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 */
diff --git a/code/nel/include/nel/sound/driver/music_channel.h b/code/nel/include/nel/sound/driver/music_channel.h
index 9878744c5..116865628 100644
--- a/code/nel/include/nel/sound/driver/music_channel.h
+++ b/code/nel/include/nel/sound/driver/music_channel.h
@@ -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;
diff --git a/code/nel/include/nel/sound/driver/sound_driver.h b/code/nel/include/nel/sound/driver/sound_driver.h
index 193026a42..c9551f16b 100644
--- a/code/nel/include/nel/sound/driver/sound_driver.h
+++ b/code/nel/include/nel/sound/driver/sound_driver.h
@@ -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)
diff --git a/code/nel/include/nel/sound/driver/source.h b/code/nel/include/nel/sound/driver/source.h
index 1858e6f24..b43c83914 100644
--- a/code/nel/include/nel/sound/driver/source.h
+++ b/code/nel/include/nel/sound/driver/source.h
@@ -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;
diff --git a/code/nel/include/nel/sound/group_controller.h b/code/nel/include/nel/sound/group_controller.h
new file mode 100644
index 000000000..08d474129
--- /dev/null
+++ b/code/nel/include/nel/sound/group_controller.h
@@ -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
+ * .
+ */
+
+#ifndef NLSOUND_GROUP_CONTROLLER_H
+#define NLSOUND_GROUP_CONTROLLER_H
+#include
+
+// STL includes
+#include
+#include