From 39976ad9031ea279a67bc41e69c119adce264fad Mon Sep 17 00:00:00 2001 From: kaetemi Date: Fri, 27 Sep 2013 21:28:33 +0200 Subject: [PATCH] Remove legacy music channel interface from sound drivers. Breaks music support for FMod driver completely. --HG-- branch : sound --- .../include/nel/sound/driver/music_channel.h | 77 ----- .../include/nel/sound/driver/sound_driver.h | 16 - .../include/nel/sound/music_channel_fader.h | 4 +- .../include/nel/sound/source_music_channel.h | 4 +- .../stream_ogg_vorbis/stream_ogg_vorbis.cpp | 2 +- code/nel/src/sound/audio_mixer_user.cpp | 23 +- .../sound/driver/dsound/sound_driver_dsound.h | 6 - .../sound/driver/fmod/music_channel_fmod.cpp | 319 ------------------ .../sound/driver/fmod/music_channel_fmod.h | 118 ------- .../sound/driver/fmod/sound_driver_fmod.cpp | 109 ------ .../src/sound/driver/fmod/sound_driver_fmod.h | 24 -- code/nel/src/sound/driver/music_channel.cpp | 32 -- .../src/sound/driver/openal/sound_driver_al.h | 5 - .../driver/xaudio2/sound_driver_xaudio2.h | 5 - code/nel/src/sound/music_channel_fader.cpp | 21 +- 15 files changed, 15 insertions(+), 750 deletions(-) delete mode 100644 code/nel/include/nel/sound/driver/music_channel.h delete mode 100644 code/nel/src/sound/driver/fmod/music_channel_fmod.cpp delete mode 100644 code/nel/src/sound/driver/fmod/music_channel_fmod.h delete mode 100644 code/nel/src/sound/driver/music_channel.cpp diff --git a/code/nel/include/nel/sound/driver/music_channel.h b/code/nel/include/nel/sound/driver/music_channel.h deleted file mode 100644 index 83968a32e..000000000 --- a/code/nel/include/nel/sound/driver/music_channel.h +++ /dev/null @@ -1,77 +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_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 */ diff --git a/code/nel/include/nel/sound/driver/sound_driver.h b/code/nel/include/nel/sound/driver/sound_driver.h index b5549e5bf..7ebe1360a 100644 --- a/code/nel/include/nel/sound/driver/sound_driver.h +++ b/code/nel/include/nel/sound/driver/sound_driver.h @@ -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 &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; diff --git a/code/nel/include/nel/sound/music_channel_fader.h b/code/nel/include/nel/sound/music_channel_fader.h index 9c2b2f379..4fa11b635 100644 --- a/code/nel/include/nel/sound/music_channel_fader.h +++ b/code/nel/include/nel/sound/music_channel_fader.h @@ -33,7 +33,7 @@ namespace NLSOUND { class ISoundDriver; - class IMusicChannel; + class CSourceMusicChannel; /** * \brief CMusicChannelFader @@ -47,7 +47,7 @@ private: struct _CMusicFader { _CMusicFader() : MusicChannel(NULL), XFadeVolume(0.f), XFadeDVolume(0.f), Playing(false), Fade(false) { } - IMusicChannel *MusicChannel; + CSourceMusicChannel *MusicChannel; float XFadeVolume; // 0--1 float XFadeDVolume; // delta bool Playing; diff --git a/code/nel/include/nel/sound/source_music_channel.h b/code/nel/include/nel/sound/source_music_channel.h index ea742c2c7..c0e0e1f6d 100644 --- a/code/nel/include/nel/sound/source_music_channel.h +++ b/code/nel/include/nel/sound/source_music_channel.h @@ -32,7 +32,6 @@ // STL includes // NeL includes -#include #include // Project includes @@ -45,8 +44,9 @@ namespace NLSOUND { * \date 2012-04-11 16:08GMT * \author Jan Boon (Kaetemi) * CSourceMusicChannel + * TODO_DEPRECATED */ -class CSourceMusicChannel : public IMusicChannel +class CSourceMusicChannel { public: CSourceMusicChannel(); diff --git a/code/nel/samples/sound/stream_ogg_vorbis/stream_ogg_vorbis.cpp b/code/nel/samples/sound/stream_ogg_vorbis/stream_ogg_vorbis.cpp index 1f491b21c..f82e49209 100644 --- a/code/nel/samples/sound/stream_ogg_vorbis/stream_ogg_vorbis.cpp +++ b/code/nel/samples/sound/stream_ogg_vorbis/stream_ogg_vorbis.cpp @@ -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; diff --git a/code/nel/src/sound/audio_mixer_user.cpp b/code/nel/src/sound/audio_mixer_user.cpp index 3a75433f4..86e01900c 100644 --- a/code/nel/src/sound/audio_mixer_user.cpp +++ b/code/nel/src/sound/audio_mixer_user.cpp @@ -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 &extensions) { - _SoundDriver->getMusicExtensions(extensions); + extensions.push_back("ogg"); } /// Add a reverb environment diff --git a/code/nel/src/sound/driver/dsound/sound_driver_dsound.h b/code/nel/src/sound/driver/dsound/sound_driver_dsound.h index 14872c1e1..87c20478e 100644 --- a/code/nel/src/sound/driver/dsound/sound_driver_dsound.h +++ b/code/nel/src/sound/driver/dsound/sound_driver_dsound.h @@ -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 & /* 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; diff --git a/code/nel/src/sound/driver/fmod/music_channel_fmod.cpp b/code/nel/src/sound/driver/fmod/music_channel_fmod.cpp deleted file mode 100644 index 3640869b6..000000000 --- a/code/nel/src/sound/driver/fmod/music_channel_fmod.cpp +++ /dev/null @@ -1,319 +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 . - -#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(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(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::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); - } -} - -} diff --git a/code/nel/src/sound/driver/fmod/music_channel_fmod.h b/code/nel/src/sound/driver/fmod/music_channel_fmod.h deleted file mode 100644 index 28ffef6ce..000000000 --- a/code/nel/src/sound/driver/fmod/music_channel_fmod.h +++ /dev/null @@ -1,118 +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 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 _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 */ diff --git a/code/nel/src/sound/driver/fmod/sound_driver_fmod.cpp b/code/nel/src/sound/driver/fmod/sound_driver_fmod.cpp index 6ca480ce7..e7770aabf 100644 --- a/code/nel/src/sound/driver/fmod/sound_driver_fmod.cpp +++ b/code/nel/src/sound/driver/fmod/sound_driver_fmod.cpp @@ -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::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::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(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(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::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::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 &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 diff --git a/code/nel/src/sound/driver/fmod/sound_driver_fmod.h b/code/nel/src/sound/driver/fmod/sound_driver_fmod.h index 8beabe562..ab457378a 100644 --- a/code/nel/src/sound/driver/fmod/sound_driver_fmod.h +++ b/code/nel/src/sound/driver/fmod/sound_driver_fmod.h @@ -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 &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 _Sources; - /// Array with the allocated music channels - std::set _MusicChannels; /// if correctly created bool _FModOk; diff --git a/code/nel/src/sound/driver/music_channel.cpp b/code/nel/src/sound/driver/music_channel.cpp deleted file mode 100644 index 2cf87099c..000000000 --- a/code/nel/src/sound/driver/music_channel.cpp +++ /dev/null @@ -1,32 +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 . - -#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 */ diff --git a/code/nel/src/sound/driver/openal/sound_driver_al.h b/code/nel/src/sound/driver/openal/sound_driver_al.h index a58d5418e..ecce801b8 100644 --- a/code/nel/src/sound/driver/openal/sound_driver_al.h +++ b/code/nel/src/sound/driver/openal/sound_driver_al.h @@ -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 & /* 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 diff --git a/code/nel/src/sound/driver/xaudio2/sound_driver_xaudio2.h b/code/nel/src/sound/driver/xaudio2/sound_driver_xaudio2.h index e3c999b26..e8f150967 100644 --- a/code/nel/src/sound/driver/xaudio2/sound_driver_xaudio2.h +++ b/code/nel/src/sound/driver/xaudio2/sound_driver_xaudio2.h @@ -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 & /* 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); diff --git a/code/nel/src/sound/music_channel_fader.cpp b/code/nel/src/sound/music_channel_fader.cpp index 67e39bcf8..e2072a4da 100644 --- a/code/nel/src/sound/music_channel_fader.cpp +++ b/code/nel/src/sound/music_channel_fader.cpp @@ -19,7 +19,6 @@ // Project includes #include "nel/sound/driver/sound_driver.h" -#include "nel/sound/driver/music_channel.h" #include "nel/sound/source_music_channel.h" using namespace std; @@ -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 CSourceMusicChannel(); + } + else + { + release(); + nlwarning("No music channel available!"); + return; } } }