Compare commits

...

3 Commits

Author SHA1 Message Date
kaetemi 9ef405c86a Merge with default
--HG--
branch : sound
11 years ago
kaetemi a91627c250 Cleanup nel sound music channel
--HG--
branch : sound
11 years ago
kaetemi 39976ad903 Remove legacy music channel interface from sound drivers. Breaks music support for FMod driver completely.
--HG--
branch : sound
11 years ago

@ -1,77 +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_CHANNEL_H
#define NLSOUND_MUSIC_CHANNEL_H
#include "nel/misc/types_nl.h"
namespace NLSOUND
{
/**
* \brief IMusicChannel
* \date 2008-09-04 16:29GMT
* \author Jan Boon (Kaetemi)
* IMusicChannel
*/
class IMusicChannel
{
public:
IMusicChannel() { }
virtual ~IMusicChannel() { }
/** 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) =0;
/// 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;
/// Resume the music previously paused
virtual void resume() =0;
/// Return true if a song is finished.
virtual bool isEnded() =0;
/// 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() =0;
/// Return the total length (in second) of the music currently played
virtual float getLength() =0;
/** 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) =0;
}; /* class IMusicChannel */
} /* namespace NLSOUND */
#endif /* #ifndef NLSOUND_MUSIC_CHANNEL_H */
/* end of file */

@ -183,22 +183,6 @@ public:
/// Filled at createDriver()
const std::string &getDllName() const { return _DllName; }
/// \name Stuff for drivers that have native music support
//@{
/// Create a native music channel, only supported by the FMod driver.
virtual IMusicChannel *createMusicChannel() { return NULL; }
/** Get music info. Returns false if the song is not found or the function is not implemented.
* \param filepath path to file, CPath::lookup done by driver
* \param artist returns the song artist (empty if not available)
* \param title returns the title (empty if not available)
*/
virtual bool getMusicInfo(const std::string &/* filepath */, std::string &artist, std::string &title) { artist.clear(); title.clear(); return false; }
/// Get audio/container extensions that are supported natively by the driver implementation.
virtual void getMusicExtensions(std::vector<std::string> &extensions) const = 0;
/// Return if a music extension is supported by the driver's music channel.
virtual bool isMusicExtensionSupported(const std::string &extension) const = 0;
//@}
private:
std::string _DllName;

@ -1,9 +1,9 @@
/**
* \file source_music_channel.h
* \brief CSourceMusicChannel
* \brief CMusicChannel
* \date 2012-04-11 16:08GMT
* \author Jan Boon (Kaetemi)
* CSourceMusicChannel
* CMusicChannel
*/
/*
@ -32,7 +32,6 @@
// STL includes
// NeL includes
#include <nel/sound/driver/music_channel.h>
#include <nel/sound/stream_file_sound.h>
// Project includes
@ -41,57 +40,58 @@ namespace NLSOUND {
class CStreamFileSource;
/**
* \brief CSourceMusicChannel
* \brief CMusicChannel
* \date 2012-04-11 16:08GMT
* \author Jan Boon (Kaetemi)
* CSourceMusicChannel
* CMusicChannel
* Background music channel
*/
class CSourceMusicChannel : public IMusicChannel
class CMusicChannel
{
public:
CSourceMusicChannel();
virtual ~CSourceMusicChannel();
CMusicChannel();
~CMusicChannel();
/** Play some music (.ogg etc...)
/** Play some music (.ogg only)
* 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);
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();
void stop();
/// 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)
virtual void pause();
void pause();
/// Resume the music previously paused
virtual void resume();
void resume();
/// 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
virtual bool isLoadingAsync();
bool isLoadingAsync();
/// 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)
* NB: the volume of music is NOT affected by IListener::setGain()
*/
virtual void setVolume(float gain);
void setVolume(float gain);
private:
CStreamFileSound m_Sound;
CStreamFileSource *m_Source;
float m_Gain;
}; /* class CSourceMusicChannel */
}; /* class CMusicChannel */
} /* namespace NLSOUND */

@ -33,7 +33,7 @@
namespace NLSOUND {
class ISoundDriver;
class IMusicChannel;
class CMusicChannel;
/**
* \brief CMusicChannelFader
@ -47,7 +47,7 @@ private:
struct _CMusicFader
{
_CMusicFader() : MusicChannel(NULL), XFadeVolume(0.f), XFadeDVolume(0.f), Playing(false), Fade(false) { }
IMusicChannel *MusicChannel;
CMusicChannel *MusicChannel;
float XFadeVolume; // 0--1
float XFadeDVolume; // delta
bool Playing;
@ -96,7 +96,7 @@ private:
void updateVolume();
public:
/** Play some music (.ogg etc...)
/** Play some music (.ogg only)
* 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
@ -104,10 +104,10 @@ public:
*/
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);
/// Pause the music previously loaded and played (the Memory is not freed)
/// Pause the music previously loaded and played
void pause();
/// Resume the music previously paused

@ -37,7 +37,7 @@
#include <nel/sound/stream_sound.h>
namespace NLSOUND {
class CSourceMusicChannel;
class CMusicChannel;
/**
* \brief CStreamFileSound
@ -48,7 +48,7 @@ namespace NLSOUND {
class CStreamFileSound : public CStreamSound
{
public:
friend class CSourceMusicChannel;
friend class CMusicChannel;
public:
CStreamFileSound();
@ -74,7 +74,7 @@ public:
inline const std::string &getFilePath() { return m_FilePath; }
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);
private:

@ -42,7 +42,7 @@
#define NL_SOUND_DATA "."
#endif // NL_SOUND_DATA
#define SAMPLE_OGG "D:/source/kaetemi/toverhex/src/samples/music_stream/data/aeon_1_10_mystic_river.ogg"
#define SAMPLE_OGG "F:/sync/source/_shelved/toverhex/src/samples/music_stream/data/aeon_1_10_mystic_river.ogg"
using namespace std;
using namespace NLMISC;

@ -2685,26 +2685,7 @@ float CAudioMixerUser::getMusicLength()
// ***************************************************************************
bool CAudioMixerUser::getSongTitle(const std::string &filename, std::string &result)
{
if (_SoundDriver)
{
std::string artist;
std::string title;
if (_SoundDriver->getMusicInfo(filename, artist, title))
{
if (!title.empty())
{
if (!artist.empty()) result = artist + " - " + title;
else result = title;
}
else if (!artist.empty())
{
result = artist + " - " + CFile::getFilename(filename);
}
else result = CFile::getFilename(filename);
return true;
}
}
result = "???";
result = CFile::getFilename(filename);;
return false;
}
@ -2751,7 +2732,7 @@ bool CAudioMixerUser::isEventMusicEnded()
/// Get audio/container extensions that are currently supported by nel or the used driver implementation.
void CAudioMixerUser::getMusicExtensions(std::vector<std::string> &extensions)
{
_SoundDriver->getMusicExtensions(extensions);
extensions.push_back("ogg");
}
/// Add a reverb environment

@ -143,12 +143,6 @@ private:
virtual void displayBench(NLMISC::CLog *log);
/// Get audio/container extensions that are supported natively by the driver implementation.
virtual void getMusicExtensions(std::vector<std::string> & /* extensions */) const { }
/// Return if a music extension is supported by the driver's music channel.
virtual bool isMusicExtensionSupported(const std::string & /* extension */) const { return false; }
// The DirectSound object
LPDIRECTSOUND _DirectSound;

@ -1,319 +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/>.
#include "stdfmod.h"
#include "music_channel_fmod.h"
#include "sound_driver_fmod.h"
using namespace std;
using namespace NLMISC;
namespace NLSOUND
{
signed char F_CALLBACKAPI streamEndCallBack(
FSOUND_STREAM *stream,
void * /* buff */,
int /* len */,
void *userdata
)
{
// Avoid any problem, check that the sound driver is still allocated
if (!CSoundDriverFMod::getInstance()) return false;
// mark this fader as music ended
CSoundDriverFMod::getInstance()->markMusicChannelEnded(stream, static_cast<CMusicChannelFMod *>(userdata));
return true;
}
CMusicChannelFMod::CMusicChannelFMod(CSoundDriverFMod *soundDriver)
: _Gain(1.0f), _MusicStream(NULL), _MusicBuffer(NULL),
_MusicChannel(-1), _CallBackEnded(false), _SoundDriver(soundDriver)
{
}
CMusicChannelFMod::~CMusicChannelFMod()
{
stop();
_SoundDriver->removeMusicChannel(this);
}
/// Play async, if bnp give path of bnp and position and size of file inside, else just path to file with fileSize 0.
bool CMusicChannelFMod::playAsync(const std::string &filepath, bool loop, uint fileOffset , uint fileSize)
{
nlassert(!_MusicBuffer);
// open fmod stream async
_MusicStream = FSOUND_Stream_Open((const char *)filepath.c_str(),
FSOUND_2D | ( loop ? FSOUND_LOOP_NORMAL : FSOUND_LOOP_OFF) | FSOUND_NONBLOCKING, fileOffset, fileSize);
nlassert(_MusicStream);
// with FSOUND_NONBLOCKING, the file is surely not ready, but still try now (will retry to replay at each updateMusic())
playStream();
nlassert(!_MusicBuffer);
return true;
}
/// Play from memory.
bool CMusicChannelFMod::playSync(const std::string &filepath, bool loop)
{
CIFile ifile;
ifile.allowBNPCacheFileOnOpen(false);
ifile.setCacheFileOnOpen(false);
ifile.open(filepath);
// try to load the music in memory
uint32 fs = ifile.getFileSize();
if (!fs) { nlwarning("NLSOUND FMod Driver: Empty music file"); return false; }
// read Buffer
nlassert(!_MusicBuffer);
_MusicBuffer = new uint8[fs];
try { ifile.serialBuffer(_MusicBuffer, fs); }
catch (...)
{
nlwarning("NLSOUND FMod Driver: Error while reading music file");
delete[] _MusicBuffer; _MusicBuffer = NULL;
return false;
}
// open FMOD stream
_MusicStream = FSOUND_Stream_Open((const char*)_MusicBuffer,
FSOUND_2D | FSOUND_LOADMEMORY | (loop ? FSOUND_LOOP_NORMAL : FSOUND_LOOP_OFF), 0, fs);
if (!_MusicStream)
{
nlwarning("NLSOUND FMod Driver: Error while creating the FMOD stream for music file");
delete[] _MusicBuffer; _MusicBuffer = NULL;
return false;
}
if (!playStream())
{
nlwarning("NLSOUND FMod Driver: Error While trying to play sync music file");
FSOUND_Stream_Close(_MusicStream); _MusicStream = NULL;
delete[] _MusicBuffer; _MusicBuffer = NULL;
return false;
}
return true;
}
bool CMusicChannelFMod::playStream()
{
if (FSOUND_Stream_GetOpenState(_MusicStream) == -3)
{
nlwarning("NLSOUND FMod Driver: stream failed to open. (file not found, out of memory or other error)");
FSOUND_Stream_Close(_MusicStream); _MusicStream = NULL;
return false;
}
// Start playing
if ((_MusicChannel = FSOUND_Stream_PlayEx(FSOUND_FREE, _MusicStream, NULL, true)) == -1)
return false;
// stereo pan (as reccomended)
FSOUND_SetPan(_MusicChannel, FSOUND_STEREOPAN);
// update volume
int vol255 = (int)(_Gain * 255.0f);
FSOUND_SetVolumeAbsolute(_MusicChannel, vol255);
// Set a callback to know if stream has ended
_CallBackEnded = false;
FSOUND_Stream_SetEndCallback(_MusicStream, streamEndCallBack, static_cast<void *>(this));
// unpause
FSOUND_SetPaused(_MusicChannel, false);
return true;
}
void CMusicChannelFMod::update()
{
// if this channel is playing an async music, may retry to start the music each frame
if (_MusicStream && _MusicBuffer == NULL && _MusicChannel == -1)
{
// keeeep trying
playStream();
}
// close anything that still needs to be closed
updateWaitingForClose();
}
void CMusicChannelFMod::updateWaitingForClose()
{
std::list<FSOUND_STREAM*>::iterator it= _WaitingForClose.begin();
while (it != _WaitingForClose.end())
{
// try to stop, will fail if still loading
bool ok = FSOUND_Stream_Stop(*it) != 0;
if (ok) ok = FSOUND_Stream_Close(*it) !=0;
// erase from list, or next
if (ok) it = _WaitingForClose.erase(it);
else ++it;
}
}
void CMusicChannelFMod::markMusicChannelEnded(void *stream)
{
if (stream == _MusicStream)
_CallBackEnded = true;
}
/** 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.
*/
bool CMusicChannelFMod::play(const std::string &filepath, bool async, bool loop)
{
// stop
stop();
// stuff that was in nlsound for async file in bnp to work with fmod
string pathName = CPath::lookup(filepath, false);
if (pathName.empty())
{
nlwarning("NLSOUND FMod Driver: Music file %s not found!", filepath.c_str());
return false;
}
if (async)
{
// if the file is in a bnp
if (pathName.find('@') != string::npos)
{
// get info for location in this bnp
uint32 fileOffset, fileSize;
if (CBigFile::getInstance().getFileInfo(pathName, fileSize, fileOffset))
{
// then play async this bnp file (with offset/size)
string bnpName = pathName.substr(0, pathName.find('@'));
return playAsync(CPath::lookup(bnpName, false), loop, fileOffset, fileSize);
}
else
{
nlwarning("NLSOUND FMod Driver: BNP BROKEN");
return false;
}
}
// else standard file
else
{
// play it async
return playAsync(pathName, loop);
}
}
else
{
return playSync(pathName, loop);
}
}
/// Stop the music previously loaded and played (the Memory is also freed)
void CMusicChannelFMod::stop()
{
if (_MusicStream)
{
/* just append this channel for closing. We have to maintain such a list because in case of async playing,
FMod FSOUND_Stream_Stop() and FSOUND_Stream_Close() calls fail if the file is not ready (hapens if music stopped
in the 50 ms after the play for instance)
*/
_WaitingForClose.push_back(_MusicStream);
// force stop now (succeed in 99% of case, and if not succeed, it means the play has not yet begun, so no problem)
updateWaitingForClose();
// reset
_MusicChannel = -1;
_MusicStream = NULL;
}
if (_MusicBuffer)
{
delete[] _MusicBuffer;
_MusicBuffer = NULL;
}
_CallBackEnded = false;
}
void CMusicChannelFMod::reset()
{
// don't care
stop();
}
/** Pause the music previously loaded and played (the Memory is not freed)
*/
void CMusicChannelFMod::pause()
{
if (_MusicChannel != -1)
FSOUND_SetPaused(_MusicChannel, true);
}
/// Resume the music previously paused
void CMusicChannelFMod::resume()
{
if (_MusicChannel != -1)
FSOUND_SetPaused(_MusicChannel, false);
}
/// Return true if a song is finished.
bool CMusicChannelFMod::isEnded()
{
if (_MusicStream && _MusicChannel != -1)
{
// test with file position
if ((int)FSOUND_Stream_GetPosition(_MusicStream) == FSOUND_Stream_GetLength(_MusicStream))
return true;
// NB: the preceding code don't work with .ogg vorbis encoded mp3. Thus test also the end with a callback
if(_CallBackEnded)
return true;
}
// if playing, but not starting because of async, not ended (because not even really started)
else if (_MusicStream) return false;
return false;
}
/// Return true if the song is still loading asynchronously and hasn't started playing yet (false if not async), used to delay fading
bool CMusicChannelFMod::isLoadingAsync()
{
return _MusicStream && _MusicBuffer == NULL && _MusicChannel == -1;
}
/// Return the total length (in second) of the music currently played
float CMusicChannelFMod::getLength()
{
if (_MusicStream && _MusicChannel != -1)
return FSOUND_Stream_GetLengthMs(_MusicStream) / 1000.f;
return 0.f;
}
/** 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()
*/
void CMusicChannelFMod::setVolume(float gain)
{
_Gain = gain;
if (_MusicStream && _MusicChannel != -1)
{
int vol255 = (int)(gain * 255.0f);
FSOUND_SetVolumeAbsolute(_MusicChannel, vol255);
}
}
}

@ -1,118 +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 NL_MUSIC_CHANNEL_FMOD_H
#define NL_MUSIC_CHANNEL_FMOD_H
#include "nel/sound/driver/music_channel.h"
struct FSOUND_STREAM;
namespace NLSOUND
{
class CSoundDriverFMod;
/**
* \brief CMusicChannelFMod
* \date 2004
* \author Lionel Berenguier
* \author Nevrax France
* A player of music in sound driver, allowing fade across music
* \date 2008-09-05 13:10GMT
* \author Jan Boon (Kaetemi)
* Stuff for fading moved into nlsound, and modified for new music interface
*/
class CMusicChannelFMod : public IMusicChannel
{
protected:
/// Volume set by user
float _Gain;
/// The FMod stream
FSOUND_STREAM *_MusicStream;
/// the RAM buffer (representation of a MP3 file, only for sync play)
uint8 *_MusicBuffer;
/// channel played for music. CAN BE -1 while _MusicStream!=NULL in case of Async Loading
sint _MusicChannel;
/// true if the fmod end callback said the stream is ended
bool _CallBackEnded;
/// see stopMusicFader()
std::list<FSOUND_STREAM *> _WaitingForClose;
/// Sound driver that created this
CSoundDriverFMod *_SoundDriver;
public:
/// Constructor
CMusicChannelFMod(CSoundDriverFMod *soundDriver);
virtual ~CMusicChannelFMod();
/// From callback
void markMusicChannelEnded(void *stream);
/// Play async, if bnp give path of bnp and position and size of file inside, else just path to file.
bool playAsync(const std::string &filepath, bool loop, uint fileOffset = 0, uint fileSize = 0);
/// Play from memory.
bool playSync(const std::string &filepath, bool loop);
/// Play the stream
bool playStream();
/// updateWaitingForClose
void update();
/// Close async streams
void updateWaitingForClose();
/** 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);
}; /* class CMusicChannelFMod */
} /* namespace NLSOUND */
#endif /* #ifndef NL_MUSIC_CHANNEL_FMOD_H */
/* end of file */

@ -18,7 +18,6 @@
#include "sound_driver_fmod.h"
#include "listener_fmod.h"
#include "music_channel_fmod.h"
#include "source_fmod.h"
#include "buffer_fmod.h"
@ -133,18 +132,6 @@ CSoundDriverFMod::~CSoundDriverFMod()
{
//nldebug("Destroying FMOD");
// Stop any played music
{
set<CMusicChannelFMod *>::iterator it(_MusicChannels.begin()), end(_MusicChannels.end());
for (; it != end; ++it)
{
nlwarning("CMusicChannelFMod was not deleted by user, deleting now!");
delete *it;
}
_MusicChannels.clear();
}
// Assure that the remaining sources have released all their channels before closing
set<CSourceFMod*>::iterator iter;
for (iter = _Sources.begin(); iter != _Sources.end(); iter++)
@ -152,7 +139,6 @@ CSoundDriverFMod::~CSoundDriverFMod()
(*iter)->release();
}
// Assure that the listener has released all resources before closing down FMod
if (CListenerFMod::getInstance() != 0)
{
@ -341,13 +327,6 @@ void CSoundDriverFMod::removeSource(CSourceFMod *source)
// ******************************************************************
void CSoundDriverFMod::removeMusicChannel(CMusicChannelFMod *musicChannel)
{
_MusicChannels.erase(static_cast<CMusicChannelFMod *>(musicChannel));
}
// ******************************************************************
void CSoundDriverFMod::commit3DChanges()
{
if ( !_FModOk )
@ -383,9 +362,6 @@ void CSoundDriverFMod::commit3DChanges()
// update sources state each frame though
update();
// update the music (XFade etc...)
updateMusic();
// update 3D change in FMod
FSOUND_Update();
}
@ -459,14 +435,6 @@ void CSoundDriverFMod::toFModCoord(const CVector &in, float out[3])
out[2]= in.y;
}
/// Create a music channel
IMusicChannel *CSoundDriverFMod::createMusicChannel()
{
CMusicChannelFMod *music_channel = new CMusicChannelFMod(this);
_MusicChannels.insert(music_channel);
return static_cast<IMusicChannel *>(music_channel);
}
bool getTag (std::string &result, const char *tag, FSOUND_STREAM *stream)
{
void *name;
@ -491,81 +459,4 @@ bool getTag (std::string &result, const char *tag, FSOUND_STREAM *stream)
return false;
}
/** Get music info. Returns false if the song is not found or the function is not implemented.
* \param filepath path to file, CPath::lookup done by driver
* \param artist returns the song artist (empty if not available)
* \param title returns the title (empty if not available)
*/
bool CSoundDriverFMod::getMusicInfo(const std::string &filepath, std::string &artist, std::string &title)
{
/* Open a stream, get the tag if it exists, close the stream */
string pathName = CPath::lookup(filepath, false);
uint32 fileOffset = 0, fileSize = 0;
if (pathName.empty())
{
nlwarning("NLSOUND FMod Driver: Music file %s not found!", filepath.c_str());
return false;
}
// if the file is in a bnp
if (pathName.find('@') != string::npos)
{
if (CBigFile::getInstance().getFileInfo(pathName, fileSize, fileOffset))
{
// set pathname to bnp
pathName = pathName.substr(0, pathName.find('@'));
}
else
{
nlwarning("NLSOUND FMod Driver: BNP BROKEN");
return false;
}
}
FSOUND_STREAM *stream = FSOUND_Stream_Open((const char *)CPath::lookup(filepath, false).c_str(), FSOUND_2D, (sint)fileOffset, (sint)fileSize);
if (stream)
{
getTag(artist, "ARTIST", stream);
getTag(title, "TITLE", stream);
FSOUND_Stream_Close(stream);
return true;
}
artist.clear();
title.clear();
return false;
}
void CSoundDriverFMod::updateMusic()
{
set<CMusicChannelFMod *>::iterator it(_MusicChannels.begin()), end(_MusicChannels.end());
for (; it != end; ++it) (*it)->update();
}
void CSoundDriverFMod::markMusicChannelEnded(void *stream, CMusicChannelFMod *musicChannel)
{
// verify if it exists
set<CMusicChannelFMod *>::iterator it(_MusicChannels.find(musicChannel));
if (it != _MusicChannels.end()) musicChannel->markMusicChannelEnded(stream);
}
/// Get audio/container extensions that are supported natively by the driver implementation.
void CSoundDriverFMod::getMusicExtensions(std::vector<std::string> &extensions) const
{
extensions.push_back("ogg");
extensions.push_back("mp3");
extensions.push_back("mp2");
extensions.push_back("mp1");
extensions.push_back("wav");
extensions.push_back("raw");
}
/// Return if a music extension is supported by the driver's music channel.
bool CSoundDriverFMod::isMusicExtensionSupported(const std::string &extension) const
{
return (extension == "ogg")
|| (extension == "mp3")
|| (extension == "mp2")
|| (extension == "mp1")
|| (extension == "wav")
|| (extension == "raw");
}
} // NLSOUND

@ -108,45 +108,21 @@ public:
bool forceSofwareBuffer() const {return _ForceSoftwareBuffer;}
/// Create a music channel, destroy with destroyMusicChannel
virtual IMusicChannel *createMusicChannel();
/** Get music info. Returns false if the song is not found or the function is not implemented.
* \param filepath path to file, CPath::lookup done by driver
* \param artist returns the song artist (empty if not available)
* \param title returns the title (empty if not available)
*/
virtual bool getMusicInfo(const std::string &filepath, std::string &artist, std::string &title);
// also check that the channel still exist (avoid any free problem)
void markMusicChannelEnded(void *stream, CMusicChannelFMod *musicChannel);
/// (Internal) Remove a buffer (should be called by the destructor of the buffer class)
void removeBuffer(CBufferFMod *buffer);
/// (Internal) Remove a source (should be called by the destructor of the source class)
void removeSource(CSourceFMod *source);
/// (Internal) Remove a music channel (should be called by the destructor of the music channel class)
void removeMusicChannel(CMusicChannelFMod *musicChannel);
/// Get audio/container extensions that are supported natively by the driver implementation.
virtual void getMusicExtensions(std::vector<std::string> &extensions) const;
/// Return if a music extension is supported by the driver's music channel.
virtual bool isMusicExtensionSupported(const std::string &extension) const;
private:
virtual void startBench();
virtual void endBench();
virtual void displayBench(NLMISC::CLog *log);
void updateMusic();
/// The string mapper provided by client code
IStringMapperProvider *_StringMapper;
// Array with the allocated sources
std::set<CSourceFMod*> _Sources;
/// Array with the allocated music channels
std::set<CMusicChannelFMod *> _MusicChannels;
/// if correctly created
bool _FModOk;

@ -1,32 +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/>.
#include "stdsound_lowlevel.h"
#include "nel/sound/driver/music_channel.h"
using namespace std;
namespace NLSOUND {
void dummyToAvoidStupidCompilerWarning_music_channel_cpp()
{
}
} /* namespace NLSOUND */
/* end of file */

@ -145,11 +145,6 @@ public:
/// Remove an effect
void removeEffect(CEffectAL *effect);
/// Get audio/container extensions that are supported natively by the driver implementation.
virtual void getMusicExtensions(std::vector<std::string> & /* extensions */) const { }
/// Return if a music extension is supported by the driver's music channel.
virtual bool isMusicExtensionSupported(const std::string & /* extension */) const { return false; }
protected:
/// Allocate nb new buffers or sources

@ -167,11 +167,6 @@ public:
virtual void startBench();
virtual void endBench();
virtual void displayBench(NLMISC::CLog *log);
/// Get audio/container extensions that are supported natively by the driver implementation.
virtual void getMusicExtensions(std::vector<std::string> & /* extensions */) const { }
/// Return if a music extension is supported by the driver's music channel.
virtual bool isMusicExtensionSupported(const std::string & /* extension */) const { return false; }
/// (Internal) Remove a buffer (should be called by the destructor of the buffer class).
void removeBuffer(CBufferXAudio2 *buffer);

@ -1,9 +1,9 @@
/**
* \file source_music_channel.cpp
* \brief CSourceMusicChannel
* \brief CMusicChannel
* \date 2012-04-11 16:08GMT
* \author Jan Boon (Kaetemi)
* CSourceMusicChannel
* CMusicChannel
*/
/*
@ -26,7 +26,7 @@
*/
#include "stdsound.h"
#include <nel/sound/source_music_channel.h>
#include <nel/sound/music_channel.h>
// STL includes
@ -41,19 +41,19 @@ using namespace std;
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);
delete m_Source;
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
// 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();
}
void CSourceMusicChannel::stop()
void CMusicChannel::stop()
{
// stop but don't delete the source, deleting source may cause waiting for thread
if (m_Source)
m_Source->stop();
}
void CSourceMusicChannel::reset()
void CMusicChannel::reset()
{
// forces the source to be deleted, happens when audio mixer is reset
delete m_Source;
m_Source = NULL;
}
void CSourceMusicChannel::pause()
void CMusicChannel::pause()
{
if (m_Source)
m_Source->pause();
}
void CSourceMusicChannel::resume()
void CMusicChannel::resume()
{
if (m_Source)
m_Source->resume();
}
bool CSourceMusicChannel::isEnded()
bool CMusicChannel::isEnded()
{
if (m_Source)
{
@ -114,21 +114,21 @@ bool CSourceMusicChannel::isEnded()
return true;
}
bool CSourceMusicChannel::isLoadingAsync()
bool CMusicChannel::isLoadingAsync()
{
if (m_Source)
return m_Source->isLoadingAsync();
return false;
}
float CSourceMusicChannel::getLength()
float CMusicChannel::getLength()
{
if (m_Source)
return m_Source->getLength();
return 0.0f;
}
void CSourceMusicChannel::setVolume(float gain)
void CMusicChannel::setVolume(float gain)
{
m_Gain = gain;
if (m_Source)

@ -19,8 +19,7 @@
// Project includes
#include "nel/sound/driver/sound_driver.h"
#include "nel/sound/driver/music_channel.h"
#include "nel/sound/source_music_channel.h"
#include "nel/sound/music_channel.h"
using namespace std;
using namespace NLMISC;
@ -47,19 +46,15 @@ void CMusicChannelFader::init(ISoundDriver *soundDriver)
for (uint i = 0; i < _MaxMusicFader; ++i)
{
nlassert(!_MusicFader[i].MusicChannel);
_MusicFader[i].MusicChannel = _SoundDriver->createMusicChannel();
if (!_MusicFader[i].MusicChannel)
if (_SoundDriver->getOption(ISoundDriver::OptionHasBufferStreaming))
{
if (_SoundDriver->getOption(ISoundDriver::OptionHasBufferStreaming))
{
_MusicFader[i].MusicChannel = new CSourceMusicChannel();
}
else
{
release();
nlwarning("No music channel available!");
return;
}
_MusicFader[i].MusicChannel = new CMusicChannel();
}
else
{
release();
nlwarning("No music channel available!");
return;
}
}
}

Loading…
Cancel
Save