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

myst3/sound.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 AUTHORS
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 SOUND_H_
00024 #define SOUND_H_
00025 
00026 #include "audio/audiostream.h"
00027 #include "audio/mixer.h"
00028 
00029 #include "common/str.h"
00030 
00031 namespace Myst3 {
00032 
00033 class Myst3Engine;
00034 
00035 enum SoundType {
00036     kAny,
00037     kAmbient,
00038     kCue,
00039     kEffect,
00040     kMusic
00041 };
00042 
00043 enum SoundNextCommand {
00044     kRandom,
00045     kNext,
00046     kRandomIfOtherStarting,
00047     kNextIfOtherStarting
00048 };
00049 
00050 class SoundChannel {
00051 public:
00052     SoundChannel(Myst3Engine *vm);
00053     virtual ~SoundChannel();
00054 
00055     void play(uint32 id, uint32 volume, uint16 heading, uint16 attenuation, bool loop, SoundType type);
00056     void setVolume3D(uint32 volume, uint16 heading, uint16 attenuation);
00057     void fade(uint32 targetVolume, int32 targetHeading, int32 targetAttenuation, uint32 fadeDelay);
00058     void fadeOut(uint32 fadeDelay);
00059     void update();
00060     void stop();
00061     void age(uint32 maxAge);
00062     uint32 playedFrames();
00063     uint32 adjustVolume(uint32 volume);
00064 
00065     uint32 _id;
00066     bool _playing;
00067     bool _stopWhenSilent;
00068     bool _fading;
00069     SoundType _type;
00070     uint32 _age;
00071     uint32 _ambientFadeOutDelay;
00072 
00073     uint _fadeLastTick;
00074     int32 _fadeDuration; // In frames (@30 fps)
00075     int32 _fadePosition;
00076 
00077     int32 _fadeSourceVolume;
00078     int32 _fadeTargetVolume;
00079     int32 _fadeSourceHeading;
00080     int32 _fadeTargetHeading;
00081     int32 _fadeSourceAttenuation;
00082     int32 _fadeTargetAttenuation;
00083 
00084     bool _hasFadeArray;
00085     uint32 _fadeArrayPosition;
00086     uint32 _fadeDurations[4];
00087     uint32 _fadeVolumes[4];
00088 
00089 private:
00090     Myst3Engine *_vm;
00091 
00092     Common::String _name;
00093 
00094     uint32 _volume;
00095     int32 _heading;
00096     uint32 _headingAngle;
00097 
00098     Audio::AudioStream *_stream;
00099     Audio::SoundHandle _handle;
00100     Audio::Timestamp _length;
00101 
00102     Audio::RewindableAudioStream *makeAudioStream(const Common::String &name) const;
00103     void updateFading();
00104     Audio::Mixer::SoundType mixerSoundType();
00105 };
00106 
00107 class Sound {
00108 public:
00109     Sound(Myst3Engine *vm);
00110     virtual ~Sound();
00111 
00112     SoundChannel *getChannelForSound(uint32 id, SoundType type, bool *found = nullptr);
00113 
00114     void playEffect(uint32 id, uint32 volume, uint16 heading = 0, uint16 attenuation = 0);
00115     void playEffectLooping(uint32 id, uint32 volume, uint16 heading = 0, uint16 attenuation = 0);
00116     void playEffectFadeInOut(uint32 id, uint32 volume, uint16 heading, uint16 attenuation,
00117             uint32 fadeInDuration, uint32 playDuration, uint32 fadeOutDuration);
00118     void stopEffect(uint32 id, uint32 fadeDuration);
00119 
00120     void playCue(uint32 id, uint32 volume, uint16 heading, uint16 attenuation);
00121     void stopCue(uint32 fadeDelay);
00122 
00123     void stopMusic(uint32 fadeDelay);
00124 
00125     bool isPlaying(uint32 id);
00126     int32 playedFrames(uint32 id);
00127 
00128     void update();
00129     void age();
00130 
00131     void fadeOutOldSounds(uint32 fadeDelay);
00132 
00133     void computeVolumeBalance(int32 volume, int32 heading, uint attenuation, int32 *mixerVolume, int32 *balance);
00134 
00135     void setupNextSound(SoundNextCommand command, int16 controlVar, int16 startSoundId, int16 soundCount,
00136                         int32 soundMinDelay, int32 soundMaxDelay, int32 controlSoundId = 0, int32 controlSoundMaxPosition = 0);
00137     void resetSoundVars();
00138 private:
00139     static const uint kNumChannels = 14;
00140 
00141     Myst3Engine *_vm;
00142     SoundChannel *_channels[kNumChannels];
00143 
00144     void compute3DVolumes(int32 heading, uint angle, int32 *left, int32 *right);
00145 };
00146 
00147 } // End of namespace Myst3
00148 
00149 #endif // SOUND_H_


Generated on Sat Mar 16 2019 05:01:54 for ResidualVM by doxygen 1.7.1
curved edge   curved edge