Cleanup nel sound music channel

--HG--
branch : sound
hg/feature/sound
kaetemi 12 years ago
parent 39976ad903
commit a91627c250

@ -1,9 +1,9 @@
/** /**
* \file source_music_channel.h * \file source_music_channel.h
* \brief CSourceMusicChannel * \brief CMusicChannel
* \date 2012-04-11 16:08GMT * \date 2012-04-11 16:08GMT
* \author Jan Boon (Kaetemi) * \author Jan Boon (Kaetemi)
* CSourceMusicChannel * CMusicChannel
*/ */
/* /*
@ -40,58 +40,58 @@ namespace NLSOUND {
class CStreamFileSource; class CStreamFileSource;
/** /**
* \brief CSourceMusicChannel * \brief CMusicChannel
* \date 2012-04-11 16:08GMT * \date 2012-04-11 16:08GMT
* \author Jan Boon (Kaetemi) * \author Jan Boon (Kaetemi)
* CSourceMusicChannel * CMusicChannel
* TODO_DEPRECATED * Background music channel
*/ */
class CSourceMusicChannel class CMusicChannel
{ {
public: public:
CSourceMusicChannel(); CMusicChannel();
virtual ~CSourceMusicChannel(); ~CMusicChannel();
/** Play some music (.ogg etc...) /** Play some music (.ogg only)
* NB: if an old music was played, it is first stop with stopMusic() * NB: if an old music was played, it is first stop with stopMusic()
* \param filepath file path, CPath::lookup is done here * \param filepath file path, CPath::lookup is done here
* \param async stream music from hard disk, preload in memory if false * \param async stream music from hard disk, preload in memory if false
* \param loop must be true to play the music in loop. * \param loop must be true to play the music in loop.
*/ */
virtual bool play(const std::string &filepath, bool async, bool loop); bool play(const std::string &filepath, bool async, bool loop);
/// Stop the music previously loaded and played (the Memory is also freed) /// Stop the music previously loaded and played (the Memory is also freed)
virtual void stop(); void stop();
/// Makes sure any resources are freed, but keeps available for next play call /// Makes sure any resources are freed, but keeps available for next play call
virtual void reset(); void reset();
/// Pause the music previously loaded and played (the Memory is not freed) /// Pause the music previously loaded and played (the Memory is not freed)
virtual void pause(); void pause();
/// Resume the music previously paused /// Resume the music previously paused
virtual void resume(); void resume();
/// Return true if a song is finished. /// Return true if a song is finished.
virtual bool isEnded(); 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 /// 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(); bool isLoadingAsync();
/// Return the total length (in second) of the music currently played /// Return the total length (in second) of the music currently played
virtual float getLength(); float getLength();
/** Set the music volume (if any music played). (volume value inside [0 , 1]) (default: 1) /** 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() * NB: the volume of music is NOT affected by IListener::setGain()
*/ */
virtual void setVolume(float gain); void setVolume(float gain);
private: private:
CStreamFileSound m_Sound; CStreamFileSound m_Sound;
CStreamFileSource *m_Source; CStreamFileSource *m_Source;
float m_Gain; float m_Gain;
}; /* class CSourceMusicChannel */ }; /* class CMusicChannel */
} /* namespace NLSOUND */ } /* namespace NLSOUND */

@ -33,7 +33,7 @@
namespace NLSOUND { namespace NLSOUND {
class ISoundDriver; class ISoundDriver;
class CSourceMusicChannel; class CMusicChannel;
/** /**
* \brief CMusicChannelFader * \brief CMusicChannelFader
@ -47,7 +47,7 @@ private:
struct _CMusicFader struct _CMusicFader
{ {
_CMusicFader() : MusicChannel(NULL), XFadeVolume(0.f), XFadeDVolume(0.f), Playing(false), Fade(false) { } _CMusicFader() : MusicChannel(NULL), XFadeVolume(0.f), XFadeDVolume(0.f), Playing(false), Fade(false) { }
CSourceMusicChannel *MusicChannel; CMusicChannel *MusicChannel;
float XFadeVolume; // 0--1 float XFadeVolume; // 0--1
float XFadeDVolume; // delta float XFadeDVolume; // delta
bool Playing; bool Playing;
@ -96,7 +96,7 @@ private:
void updateVolume(); void updateVolume();
public: public:
/** Play some music (.ogg etc...) /** Play some music (.ogg only)
* NB: if an old music was played, it is first stop with stopMusic() * NB: if an old music was played, it is first stop with stopMusic()
* \param filepath file path, CPath::lookup is done here * \param filepath file path, CPath::lookup is done here
* \param async stream music from hard disk, preload in memory if false * \param async stream music from hard disk, preload in memory if false
@ -104,10 +104,10 @@ public:
*/ */
bool play(const std::string &filepath, uint xFadeTime = 0, bool async = true, bool loop = true); bool play(const std::string &filepath, uint xFadeTime = 0, bool async = true, bool loop = true);
/// Stop the music previously loaded and played (the Memory is also freed) /// Stop the music previously loaded and played
void stop(uint xFadeTime = 0); void stop(uint xFadeTime = 0);
/// Pause the music previously loaded and played (the Memory is not freed) /// Pause the music previously loaded and played
void pause(); void pause();
/// Resume the music previously paused /// Resume the music previously paused

@ -37,7 +37,7 @@
#include <nel/sound/stream_sound.h> #include <nel/sound/stream_sound.h>
namespace NLSOUND { namespace NLSOUND {
class CSourceMusicChannel; class CMusicChannel;
/** /**
* \brief CStreamFileSound * \brief CStreamFileSound
@ -48,7 +48,7 @@ namespace NLSOUND {
class CStreamFileSound : public CStreamSound class CStreamFileSound : public CStreamSound
{ {
public: public:
friend class CSourceMusicChannel; friend class CMusicChannel;
public: public:
CStreamFileSound(); CStreamFileSound();
@ -74,7 +74,7 @@ public:
inline const std::string &getFilePath() { return m_FilePath; } inline const std::string &getFilePath() { return m_FilePath; }
private: private:
/// Used by CSourceMusicChannel to set the filePath and default settings on other parameters. /// Used by CMusicChannel to set the filePath and default settings on other parameters.
void setMusicFilePath(const std::string &filePath, bool async = true, bool loop = false); void setMusicFilePath(const std::string &filePath, bool async = true, bool loop = false);
private: private:

@ -1,9 +1,9 @@
/** /**
* \file source_music_channel.cpp * \file source_music_channel.cpp
* \brief CSourceMusicChannel * \brief CMusicChannel
* \date 2012-04-11 16:08GMT * \date 2012-04-11 16:08GMT
* \author Jan Boon (Kaetemi) * \author Jan Boon (Kaetemi)
* CSourceMusicChannel * CMusicChannel
*/ */
/* /*
@ -26,7 +26,7 @@
*/ */
#include "stdsound.h" #include "stdsound.h"
#include <nel/sound/source_music_channel.h> #include <nel/sound/music_channel.h>
// STL includes // STL includes
@ -41,19 +41,19 @@ using namespace std;
namespace NLSOUND { namespace NLSOUND {
CSourceMusicChannel::CSourceMusicChannel() : m_Source(NULL), m_Gain(1.0f) CMusicChannel::CMusicChannel() : m_Source(NULL), m_Gain(1.0f)
{ {
} }
CSourceMusicChannel::~CSourceMusicChannel() CMusicChannel::~CMusicChannel()
{ {
nlassert(!m_Source); nlassert(!m_Source);
delete m_Source; delete m_Source;
m_Source = NULL; m_Source = NULL;
} }
bool CSourceMusicChannel::play(const std::string &filepath, bool async, bool loop) bool CMusicChannel::play(const std::string &filepath, bool async, bool loop)
{ {
// delete previous source if any // delete previous source if any
// note that this waits for the source's thread to finish if the source was still playing // note that this waits for the source's thread to finish if the source was still playing
@ -72,33 +72,33 @@ bool CSourceMusicChannel::play(const std::string &filepath, bool async, bool loo
return m_Source->isPlaying(); return m_Source->isPlaying();
} }
void CSourceMusicChannel::stop() void CMusicChannel::stop()
{ {
// stop but don't delete the source, deleting source may cause waiting for thread // stop but don't delete the source, deleting source may cause waiting for thread
if (m_Source) if (m_Source)
m_Source->stop(); m_Source->stop();
} }
void CSourceMusicChannel::reset() void CMusicChannel::reset()
{ {
// forces the source to be deleted, happens when audio mixer is reset // forces the source to be deleted, happens when audio mixer is reset
delete m_Source; delete m_Source;
m_Source = NULL; m_Source = NULL;
} }
void CSourceMusicChannel::pause() void CMusicChannel::pause()
{ {
if (m_Source) if (m_Source)
m_Source->pause(); m_Source->pause();
} }
void CSourceMusicChannel::resume() void CMusicChannel::resume()
{ {
if (m_Source) if (m_Source)
m_Source->resume(); m_Source->resume();
} }
bool CSourceMusicChannel::isEnded() bool CMusicChannel::isEnded()
{ {
if (m_Source) if (m_Source)
{ {
@ -114,21 +114,21 @@ bool CSourceMusicChannel::isEnded()
return true; return true;
} }
bool CSourceMusicChannel::isLoadingAsync() bool CMusicChannel::isLoadingAsync()
{ {
if (m_Source) if (m_Source)
return m_Source->isLoadingAsync(); return m_Source->isLoadingAsync();
return false; return false;
} }
float CSourceMusicChannel::getLength() float CMusicChannel::getLength()
{ {
if (m_Source) if (m_Source)
return m_Source->getLength(); return m_Source->getLength();
return 0.0f; return 0.0f;
} }
void CSourceMusicChannel::setVolume(float gain) void CMusicChannel::setVolume(float gain)
{ {
m_Gain = gain; m_Gain = gain;
if (m_Source) if (m_Source)

@ -19,7 +19,7 @@
// Project includes // Project includes
#include "nel/sound/driver/sound_driver.h" #include "nel/sound/driver/sound_driver.h"
#include "nel/sound/source_music_channel.h" #include "nel/sound/music_channel.h"
using namespace std; using namespace std;
using namespace NLMISC; using namespace NLMISC;
@ -48,7 +48,7 @@ void CMusicChannelFader::init(ISoundDriver *soundDriver)
nlassert(!_MusicFader[i].MusicChannel); nlassert(!_MusicFader[i].MusicChannel);
if (_SoundDriver->getOption(ISoundDriver::OptionHasBufferStreaming)) if (_SoundDriver->getOption(ISoundDriver::OptionHasBufferStreaming))
{ {
_MusicFader[i].MusicChannel = new CSourceMusicChannel(); _MusicFader[i].MusicChannel = new CMusicChannel();
} }
else else
{ {

Loading…
Cancel
Save