scummvm/engines/myst3/sound.h

125 lines
3.2 KiB
C
Raw Normal View History

2012-01-26 12:11:43 +00:00
/* ResidualVM - A 3D game interpreter
*
* ResidualVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the AUTHORS
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* 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 General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#ifndef SOUND_H_
#define SOUND_H_
#include "common/str.h"
namespace Myst3 {
class Myst3Engine;
2012-03-10 13:35:27 +00:00
enum SoundType {
2014-03-02 19:46:36 +00:00
kAny,
kAmbient,
2014-03-01 08:09:54 +00:00
kCue,
2012-03-10 13:35:27 +00:00
kEffect,
kMusic
};
2012-01-26 12:11:43 +00:00
class SoundChannel {
public:
SoundChannel(Myst3Engine *vm);
virtual ~SoundChannel();
2014-03-01 13:43:44 +00:00
void play(uint32 id, uint32 volume, uint16 heading, uint16 attenuation, bool loop, SoundType type);
void setVolume3D(uint32 volume, uint16 heading, uint16 attenuation);
2014-03-01 08:09:54 +00:00
void fade(uint32 targetVolume, int32 targetHeading, int32 targetAttenuation, uint32 fadeDelay);
void fadeOut(uint32 fadeDelay);
2012-01-26 12:11:43 +00:00
void update();
2014-03-01 08:09:54 +00:00
void stop();
void age(uint32 maxAge);
2012-01-26 12:11:43 +00:00
uint32 _id;
2012-03-10 13:35:27 +00:00
bool _playing;
2014-03-02 19:46:36 +00:00
bool _stopWhenSilent;
2014-03-02 10:24:56 +00:00
bool _fading;
2012-03-10 13:35:27 +00:00
SoundType _type;
uint32 _age;
uint32 _ambientFadeOutDelay;
2012-01-26 12:11:43 +00:00
2014-03-02 19:46:36 +00:00
int32 _fadeDuration; // In frames (@30 fps)
int32 _fadePosition;
int32 _fadeSourceVolume;
int32 _fadeTargetVolume;
int32 _fadeSourceHeading;
int32 _fadeTargetHeading;
int32 _fadeSourceAttenuation;
int32 _fadeTargetAttenuation;
bool _hasFadeArray;
uint32 _fadeArrayPosition;
uint32 _fadeDurations[4];
uint32 _fadeVolumes[4];
2012-01-26 12:11:43 +00:00
private:
Myst3Engine *_vm;
Common::String _name;
2014-03-02 10:24:56 +00:00
2012-01-26 12:11:43 +00:00
uint32 _volume;
2014-03-02 10:24:56 +00:00
int32 _heading;
uint32 _headingAngle;
Audio::AudioStream *_stream;
2012-01-26 12:11:43 +00:00
Audio::SoundHandle _handle;
Audio::RewindableAudioStream *makeAudioStream(const Common::String &name) const;
2014-03-02 19:46:36 +00:00
void updateFading();
2012-01-26 12:11:43 +00:00
};
class Sound {
public:
Sound(Myst3Engine *vm);
virtual ~Sound();
SoundChannel *getChannelForSound(uint32 id, SoundType type, bool *found = nullptr);
2012-03-10 13:35:27 +00:00
void playEffect(uint32 id, uint32 volume, uint16 heading = 0, uint16 attenuation = 0);
void playEffectLooping(uint32 id, uint32 volume, uint16 heading = 0, uint16 attenuation = 0);
void stopEffect(uint32 id, uint32 fadeDuration);
2014-03-01 08:09:54 +00:00
void playCue(uint32 id, uint32 volume, uint16 heading, uint16 attenuation);
void stopCue(uint32 fadeDelay);
void stopMusic(uint32 fadeDelay);
2012-01-26 12:11:43 +00:00
void update();
void age();
void fadeOutOldSounds(uint32 fadeDelay);
2012-01-26 12:11:43 +00:00
2014-03-02 11:18:16 +00:00
void computeVolumeBalance(int32 volume, int32 heading, uint attenuation, int32 *mixerVolume, int32 *balance);
2012-01-26 12:11:43 +00:00
private:
2014-03-01 08:09:54 +00:00
static const uint kNumChannels = 14;
2012-01-26 12:11:43 +00:00
Myst3Engine *_vm;
SoundChannel *_channels[kNumChannels];
2014-03-02 11:18:16 +00:00
void compute3DVolumes(int32 heading, uint angle, int32 *left, int32 *right);
2012-01-26 12:11:43 +00:00
};
} /* namespace Myst3 */
#endif /* SOUND_H_ */