ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

emisound.h

Go to the documentation of this file.
00001 /* ResidualVM - A 3D game interpreter
00002  *
00003  * ResidualVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #ifndef GRIM_MSS_H
00024 #define GRIM_MSS_H
00025 
00026 #include "audio/mixer.h"
00027 #include "common/str.h"
00028 #include "common/stack.h"
00029 #include "common/mutex.h"
00030 #include "common/hashmap.h"
00031 #include "math/vector3d.h"
00032 
00033 namespace Grim {
00034 
00035 class SoundTrack;
00036 class SaveGame;
00037 
00038 struct MusicEntry {
00039     int _x;
00040     int _y;
00041     int _sync;
00042     int _trim;
00043     int _id;
00044     Common::String _type;
00045     Common::String _name;
00046     Common::String _filename;
00047 };
00048 
00049 // Currently this class only implements the exact functions called in iMuse
00050 // from Actor, to allow for splitting that into EMI-sound and iMuse without
00051 // changing iMuse.
00052 class EMISound {
00053 public:
00054     EMISound(int fps);
00055     ~EMISound();
00056     bool startVoice(const Common::String &soundName, int volume = static_cast<int>(Audio::Mixer::kMaxChannelVolume), int pan = 64);
00057     bool startSfx(const Common::String &soundName, int volume = static_cast<int>(Audio::Mixer::kMaxChannelVolume), int pan = 64);
00058     bool startSfxFrom(const Common::String &soundName, const Math::Vector3d &pos, int volume = static_cast<int>(Audio::Mixer::kMaxChannelVolume));
00059     bool getSoundStatus(const Common::String &soundName);
00060     void stopSound(const Common::String &soundName);
00061     int32 getPosIn16msTicks(const Common::String &soundName);
00062 
00063     void setVolume(const Common::String &soundName, int volume);
00064     void setPan(const Common::String &soundName, int pan); /* pan: 0 .. 127 */
00065 
00066     bool loadSfx(const Common::String &soundName, int &id);
00067     void playLoadedSound(int id, bool looping);
00068     void playLoadedSoundFrom(int id, const Math::Vector3d &pos, bool looping);
00069     void setLoadedSoundLooping(int id, bool looping);
00070     void stopLoadedSound(int id);
00071     void freeLoadedSound(int id);
00072     void setLoadedSoundVolume(int id, int volume);
00073     void setLoadedSoundPan(int id, int pan);
00074     void setLoadedSoundPosition(int id, const Math::Vector3d &pos);
00075     bool getLoadedSoundStatus(int id);
00076     int getLoadedSoundVolume(int id);
00077 
00078     void setMusicState(int stateId);
00079     void selectMusicSet(int setId);
00080 
00081     bool stateHasLooped(int stateId);
00082     bool stateHasEnded(int stateId);
00083 
00084     void restoreState(SaveGame *savedState);
00085     void saveState(SaveGame *savedState);
00086 
00087     void pushStateToStack();
00088     void popStateFromStack();
00089     void flushStack();
00090     void pause(bool paused);
00091     void flushTracks();
00092 
00093     uint32 getMsPos(int stateId);
00094 
00095     void updateSoundPositions();
00096 
00097 private:
00098     struct StackEntry {
00099         int _state;
00100         SoundTrack *_track;
00101     };
00102 
00103     typedef Common::List<SoundTrack *> TrackList;
00104     TrackList _playingTracks;
00105     SoundTrack *_musicTrack;
00106     MusicEntry *_musicTable;
00107     Common::String _musicPrefix;
00108     Common::Stack<StackEntry> _stateStack;
00109     // A mutex to avoid concurrent modification of the sound channels by the engine thread
00110     // and the timer callback, which may run in a different thread.
00111     Common::Mutex _mutex;
00112 
00113     typedef Common::HashMap<int, SoundTrack *> TrackMap;
00114     TrackMap _preloadedTrackMap;
00115 
00116     int _curMusicState;
00117     int _numMusicStates;
00118     int _callbackFps;
00119     int _curTrackId;
00120 
00121     static void timerHandler(void *refConf);
00122     void removeItem(SoundTrack *item);
00123     TrackList::iterator getPlayingTrackByName(const Common::String &name);
00124     void freeChannel(int32 channel);
00125     void initMusicTable();
00126 
00127     void callback();
00128     void updateTrack(SoundTrack *track);
00129     void freePlayingSounds();
00130     void freeLoadedSounds();
00131     SoundTrack *initTrack(const Common::String &soundName, Audio::Mixer::SoundType soundType, const Audio::Timestamp *start = nullptr) const;
00132     SoundTrack *restartTrack(SoundTrack *track);
00133     bool startSound(const Common::String &soundName, Audio::Mixer::SoundType soundType, int volume, int pan);
00134     bool startSoundFrom(const Common::String &soundName, Audio::Mixer::SoundType soundType, const Math::Vector3d &pos, int volume);
00135     void saveTrack(SoundTrack *track, SaveGame *savedState);
00136     SoundTrack *restoreTrack(SaveGame *savedState);
00137     MusicEntry *initMusicTableDemo(const Common::String &filename);
00138     MusicEntry *initMusicTableRetail(MusicEntry *table, const Common::String &filename);
00139 };
00140 
00141 extern EMISound *g_emiSound;
00142 
00143 }
00144 
00145 #endif


Generated on Sat Feb 16 2019 05:00:50 for ResidualVM by doxygen 1.7.1
curved edge   curved edge