Added: #1460 Music channel on top of stream file source when driver does not have built-in music channels
--HG-- branch : sound_devhg/feature/gsoc2012-fabien
parent
2f504788f0
commit
695dac7783
@ -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 */
|
@ -0,0 +1,123 @@
|
||||
/**
|
||||
* \file source_music_channel.cpp
|
||||
* \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/>.
|
||||
*/
|
||||
|
||||
#include "stdsound.h"
|
||||
#include <nel/sound/source_music_channel.h>
|
||||
|
||||
// STL includes
|
||||
|
||||
// NeL includes
|
||||
// #include <nel/misc/debug.h>
|
||||
#include <nel/sound/stream_file_source.h>
|
||||
|
||||
// Project includes
|
||||
|
||||
using namespace std;
|
||||
// using namespace NLMISC;
|
||||
|
||||
namespace NLSOUND {
|
||||
|
||||
CSourceMusicChannel::CSourceMusicChannel() : m_Source(NULL), m_Gain(1.0f)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CSourceMusicChannel::~CSourceMusicChannel()
|
||||
{
|
||||
delete m_Source;
|
||||
m_Source = NULL;
|
||||
}
|
||||
|
||||
bool CSourceMusicChannel::play(const std::string &filepath, bool async, bool loop)
|
||||
{
|
||||
if (m_Source)
|
||||
delete m_Source;
|
||||
|
||||
m_Sound.setMusicFilePath(filepath, async, loop);
|
||||
|
||||
m_Source = new CStreamFileSource(&m_Sound, false, NULL, NULL, NULL, NULL);
|
||||
|
||||
m_Source->play();
|
||||
|
||||
return m_Source->isPlaying();
|
||||
}
|
||||
|
||||
void CSourceMusicChannel::stop()
|
||||
{
|
||||
if (m_Source)
|
||||
m_Source->stop();
|
||||
}
|
||||
|
||||
void CSourceMusicChannel::reset()
|
||||
{
|
||||
delete m_Source;
|
||||
m_Source = NULL;
|
||||
}
|
||||
|
||||
void CSourceMusicChannel::pause()
|
||||
{
|
||||
if (m_Source)
|
||||
m_Source->pause();
|
||||
}
|
||||
|
||||
void CSourceMusicChannel::resume()
|
||||
{
|
||||
if (m_Source)
|
||||
m_Source->resume();
|
||||
}
|
||||
|
||||
bool CSourceMusicChannel::isEnded()
|
||||
{
|
||||
if (m_Source)
|
||||
return m_Source->isEnded();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CSourceMusicChannel::isLoadingAsync()
|
||||
{
|
||||
if (m_Source)
|
||||
return m_Source->isLoadingAsync();
|
||||
return false;
|
||||
}
|
||||
|
||||
float CSourceMusicChannel::getLength()
|
||||
{
|
||||
if (m_Source)
|
||||
return m_Source->getLength();
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
void CSourceMusicChannel::setVolume(float gain)
|
||||
{
|
||||
m_Gain = gain;
|
||||
if (m_Source)
|
||||
m_Source->setRelativeGain(gain);
|
||||
}
|
||||
|
||||
} /* namespace NLSOUND */
|
||||
|
||||
/* end of file */
|
Loading…
Reference in New Issue