2007-05-30 21:56:52 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
2002-04-21 17:46:42 +00:00
|
|
|
*
|
|
|
|
* 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
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2002-04-21 17:46:42 +00:00
|
|
|
*
|
2006-02-11 10:05:31 +00:00
|
|
|
* $URL$
|
|
|
|
* $Id$
|
2002-04-21 17:46:42 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2003-08-05 23:03:42 +00:00
|
|
|
#ifndef SOUND_MIXER_H
|
|
|
|
#define SOUND_MIXER_H
|
2002-04-14 18:13:08 +00:00
|
|
|
|
2003-09-07 20:23:38 +00:00
|
|
|
#include "common/scummsys.h"
|
2005-01-10 22:06:49 +00:00
|
|
|
#include "common/mutex.h"
|
2003-09-07 20:23:38 +00:00
|
|
|
|
2003-06-15 01:56:47 +00:00
|
|
|
|
2005-01-10 22:06:49 +00:00
|
|
|
class OSystem;
|
2002-04-17 20:23:45 +00:00
|
|
|
|
2005-05-11 00:01:44 +00:00
|
|
|
|
|
|
|
namespace Audio {
|
|
|
|
|
2006-04-29 22:33:31 +00:00
|
|
|
class AudioStream;
|
2005-05-11 00:01:44 +00:00
|
|
|
class Channel;
|
|
|
|
class Mixer;
|
2008-06-28 15:28:29 +00:00
|
|
|
class MixerImpl;
|
2005-05-11 00:01:44 +00:00
|
|
|
|
2007-02-03 19:05:53 +00:00
|
|
|
/**
|
|
|
|
* A SoundHandle instances corresponds to a specific sound
|
|
|
|
* being played via the mixer. It can be used to control that
|
|
|
|
* sound (pause it, stop it, etc.).
|
|
|
|
* @see The Mixer class
|
|
|
|
*/
|
2005-03-22 18:29:02 +00:00
|
|
|
class SoundHandle {
|
2006-10-21 12:44:10 +00:00
|
|
|
friend class Channel;
|
2008-06-28 15:28:29 +00:00
|
|
|
friend class MixerImpl;
|
2005-03-22 18:29:02 +00:00
|
|
|
uint32 _val;
|
|
|
|
public:
|
|
|
|
inline SoundHandle() : _val(0xFFFFFFFF) {}
|
|
|
|
};
|
|
|
|
|
2007-02-03 19:05:53 +00:00
|
|
|
/**
|
|
|
|
* The main audio mixer handles mixing of an arbitrary number of
|
|
|
|
* input audio streams (in the form of AudioStream instances).
|
|
|
|
*/
|
2005-05-10 23:48:48 +00:00
|
|
|
class Mixer {
|
2003-06-15 01:56:47 +00:00
|
|
|
public:
|
2007-03-02 15:22:38 +00:00
|
|
|
/**
|
|
|
|
* Various flags which can be bit-ORed and then passed to
|
|
|
|
* Mixer::playRaw resp. makeLinearInputStream to control their
|
|
|
|
* behavior.
|
|
|
|
*
|
2007-03-02 17:49:08 +00:00
|
|
|
* Engine authors are advised not to rely on a certain value or
|
|
|
|
* order of these flags (in particular, do not store them verbatim
|
|
|
|
* in savestates).
|
2007-03-02 15:22:38 +00:00
|
|
|
*/
|
|
|
|
enum RawFlags {
|
2004-11-27 16:26:54 +00:00
|
|
|
/** unsigned samples (default: signed) */
|
|
|
|
FLAG_UNSIGNED = 1 << 0,
|
|
|
|
|
|
|
|
/** sound is 16 bits wide (default: 8bit) */
|
|
|
|
FLAG_16BITS = 1 << 1,
|
|
|
|
|
2007-03-02 15:22:38 +00:00
|
|
|
/** samples are little endian (default: big endian) */
|
2004-11-27 16:26:54 +00:00
|
|
|
FLAG_LITTLE_ENDIAN = 1 << 2,
|
|
|
|
|
|
|
|
/** sound is in stereo (default: mono) */
|
|
|
|
FLAG_STEREO = 1 << 3,
|
|
|
|
|
|
|
|
/** reverse the left and right stereo channel */
|
|
|
|
FLAG_REVERSE_STEREO = 1 << 4,
|
|
|
|
|
|
|
|
/** sound buffer is freed automagically at the end of playing */
|
|
|
|
FLAG_AUTOFREE = 1 << 5,
|
|
|
|
|
|
|
|
/** loop the audio */
|
|
|
|
FLAG_LOOP = 1 << 6
|
2003-07-25 01:19:14 +00:00
|
|
|
};
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2004-12-27 00:27:00 +00:00
|
|
|
enum SoundType {
|
2005-03-09 18:12:54 +00:00
|
|
|
kPlainSoundType = 0,
|
2004-12-27 00:27:00 +00:00
|
|
|
|
2005-03-09 18:12:54 +00:00
|
|
|
kMusicSoundType = 1,
|
|
|
|
kSFXSoundType = 2,
|
|
|
|
kSpeechSoundType = 3
|
2004-12-27 00:27:00 +00:00
|
|
|
};
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2004-12-27 23:33:19 +00:00
|
|
|
enum {
|
|
|
|
kMaxChannelVolume = 255,
|
|
|
|
kMaxMixerVolume = 256
|
|
|
|
};
|
2003-07-25 01:19:14 +00:00
|
|
|
|
2003-06-15 01:56:47 +00:00
|
|
|
public:
|
2008-06-28 15:28:29 +00:00
|
|
|
Mixer() {}
|
|
|
|
virtual ~Mixer() {}
|
2002-08-18 21:42:22 +00:00
|
|
|
|
2004-11-27 15:58:18 +00:00
|
|
|
|
|
|
|
|
2003-12-24 17:42:22 +00:00
|
|
|
/**
|
|
|
|
* Is the mixer ready and setup? This may not be the case on systems which
|
|
|
|
* don't support digital sound output. In that case, the mixer proc may
|
2007-02-20 18:50:17 +00:00
|
|
|
* never be called. That in turn can cause breakage in games which try to
|
|
|
|
* sync with an audio stream. In particular, the Adlib MIDI emulation...
|
2004-11-27 15:58:18 +00:00
|
|
|
*
|
|
|
|
* @return whether the mixer is ready and setup
|
2008-06-28 15:28:29 +00:00
|
|
|
*
|
|
|
|
* @todo get rid of this?
|
2003-12-24 17:42:22 +00:00
|
|
|
*/
|
2008-06-28 15:28:29 +00:00
|
|
|
virtual bool isReady() const = 0;
|
2003-09-05 20:48:32 +00:00
|
|
|
|
2004-11-27 15:58:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Start playing the given raw sound data.
|
|
|
|
* Internally, this simply creates an audio input stream wrapping the data
|
|
|
|
* (using the makeLinearInputStream factory function), which is then
|
|
|
|
* passed on to playInputStream.
|
|
|
|
*/
|
2008-06-28 15:28:29 +00:00
|
|
|
virtual void playRaw(
|
2007-02-03 19:05:53 +00:00
|
|
|
SoundType type,
|
|
|
|
SoundHandle *handle,
|
|
|
|
void *sound, uint32 size, uint rate, byte flags,
|
2008-06-11 11:29:34 +00:00
|
|
|
int id = -1, byte volume = kMaxChannelVolume, int8 balance = 0,
|
2008-06-28 15:28:29 +00:00
|
|
|
uint32 loopStart = 0, uint32 loopEnd = 0) = 0;
|
2002-04-14 18:13:08 +00:00
|
|
|
|
2004-11-27 15:58:18 +00:00
|
|
|
/**
|
|
|
|
* Start playing the given audio input stream.
|
2007-02-03 19:05:53 +00:00
|
|
|
*
|
|
|
|
* Note that the sound id assigned below is unique. At most one stream
|
2009-02-27 23:38:37 +00:00
|
|
|
* with a given id can play at any given time. Trying to play a sound
|
2007-02-03 19:05:53 +00:00
|
|
|
* with an id that is already in use causes the new sound to be not played.
|
|
|
|
*
|
|
|
|
* @param type the type (voice/sfx/music) of the stream
|
|
|
|
* @param handle a SoundHandle which can be used to reference and control
|
|
|
|
* the stream via suitable mixer methods
|
|
|
|
* @param input the actual AudioStream to be played
|
|
|
|
* @param id a unique id assigned to this stream
|
|
|
|
* @param volume the volume with which to play the sound, ranging from 0 to 255
|
|
|
|
* @param balance the balance with which to play the sound, ranging from -128 to 127
|
|
|
|
* @param autofreeStream a flag indicating whether the stream should be
|
|
|
|
* freed after playback finished
|
|
|
|
* @param permanent a flag indicating whether a plain stopAll call should
|
|
|
|
* not stop this particular stream
|
2007-03-02 14:49:07 +00:00
|
|
|
* @param reverseStereo a flag indicating whether left and right channels shall be swapped
|
2004-11-27 15:58:18 +00:00
|
|
|
*/
|
2008-06-28 15:28:29 +00:00
|
|
|
virtual void playInputStream(
|
2007-02-03 19:05:53 +00:00
|
|
|
SoundType type,
|
|
|
|
SoundHandle *handle,
|
|
|
|
AudioStream *input,
|
2008-06-11 11:29:34 +00:00
|
|
|
int id = -1, byte volume = kMaxChannelVolume, int8 balance = 0,
|
2007-03-02 14:49:07 +00:00
|
|
|
bool autofreeStream = true,
|
|
|
|
bool permanent = false,
|
2008-06-28 15:28:29 +00:00
|
|
|
bool reverseStereo = false) = 0;
|
2003-12-19 00:32:47 +00:00
|
|
|
|
|
|
|
|
2004-11-27 15:58:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Stop all currently playing sounds.
|
|
|
|
*/
|
2008-06-28 15:28:29 +00:00
|
|
|
virtual void stopAll() = 0;
|
2002-04-14 18:13:08 +00:00
|
|
|
|
2004-11-27 15:58:18 +00:00
|
|
|
/**
|
|
|
|
* Stop playing the sound with given ID.
|
|
|
|
*
|
|
|
|
* @param id the ID of the sound to affect
|
|
|
|
*/
|
2008-06-28 15:28:29 +00:00
|
|
|
virtual void stopID(int id) = 0;
|
2003-03-18 21:46:44 +00:00
|
|
|
|
2004-11-27 15:58:18 +00:00
|
|
|
/**
|
|
|
|
* Stop playing the sound corresponding to the given handle.
|
|
|
|
*
|
|
|
|
* @param handle the sound to affect
|
|
|
|
*/
|
2008-06-28 15:28:29 +00:00
|
|
|
virtual void stopHandle(SoundHandle handle) = 0;
|
2003-07-14 20:09:14 +00:00
|
|
|
|
2004-11-27 15:58:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2007-09-19 08:40:12 +00:00
|
|
|
* Pause/unpause all sounds, including all regular and permanent
|
2007-02-20 18:50:17 +00:00
|
|
|
* channels
|
2004-11-27 15:58:18 +00:00
|
|
|
*
|
2007-02-03 19:05:53 +00:00
|
|
|
* @param paused true to pause everything, false to unpause
|
2004-11-27 15:58:18 +00:00
|
|
|
*/
|
2008-06-28 15:28:29 +00:00
|
|
|
virtual void pauseAll(bool paused) = 0;
|
2003-09-05 20:48:32 +00:00
|
|
|
|
2004-11-27 15:58:18 +00:00
|
|
|
/**
|
|
|
|
* Pause/unpause the sound with the given ID.
|
|
|
|
*
|
|
|
|
* @param id the ID of the sound to affect
|
|
|
|
* @param paused true to pause the sound, false to unpause it
|
|
|
|
*/
|
2008-06-28 15:28:29 +00:00
|
|
|
virtual void pauseID(int id, bool paused) = 0;
|
2004-11-27 15:58:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Pause/unpause the sound corresponding to the given handle.
|
|
|
|
*
|
|
|
|
* @param handle the sound to affect
|
|
|
|
* @param paused true to pause the sound, false to unpause it
|
|
|
|
*/
|
2008-06-28 15:28:29 +00:00
|
|
|
virtual void pauseHandle(SoundHandle handle, bool paused) = 0;
|
2004-11-27 15:58:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if a sound with the given ID is active.
|
|
|
|
*
|
|
|
|
* @param id the ID of the sound to query
|
|
|
|
* @return true if the sound is active
|
|
|
|
*/
|
2008-06-28 15:28:29 +00:00
|
|
|
virtual bool isSoundIDActive(int id) = 0;
|
2004-09-19 12:22:47 +00:00
|
|
|
|
2005-04-04 11:43:25 +00:00
|
|
|
/**
|
|
|
|
* Get the sound ID of handle sound
|
|
|
|
*
|
|
|
|
* @param handle sound to query
|
|
|
|
* @return sound ID if active
|
|
|
|
*/
|
2008-06-28 15:28:29 +00:00
|
|
|
virtual int getSoundID(SoundHandle handle) = 0;
|
2005-04-04 11:43:25 +00:00
|
|
|
|
2005-03-12 18:56:09 +00:00
|
|
|
/**
|
2007-02-03 19:05:53 +00:00
|
|
|
* Check if a sound with the given handle is active.
|
2005-03-12 18:56:09 +00:00
|
|
|
*
|
2005-04-04 11:43:25 +00:00
|
|
|
* @param handle sound to query
|
2005-03-12 18:56:09 +00:00
|
|
|
* @return true if the sound is active
|
|
|
|
*/
|
2008-06-28 15:28:29 +00:00
|
|
|
virtual bool isSoundHandleActive(SoundHandle handle) = 0;
|
2005-03-12 18:56:09 +00:00
|
|
|
|
2003-09-02 13:48:20 +00:00
|
|
|
|
|
|
|
|
2004-11-27 15:58:18 +00:00
|
|
|
/**
|
|
|
|
* Set the channel volume for the given handle.
|
|
|
|
*
|
|
|
|
* @param handle the sound to affect
|
2008-06-11 11:29:34 +00:00
|
|
|
* @param volume the new channel volume (0 - kMaxChannelVolume)
|
2004-11-27 15:58:18 +00:00
|
|
|
*/
|
2008-06-28 15:28:29 +00:00
|
|
|
virtual void setChannelVolume(SoundHandle handle, byte volume) = 0;
|
2003-08-31 20:26:21 +00:00
|
|
|
|
2004-11-27 15:58:18 +00:00
|
|
|
/**
|
|
|
|
* Set the channel balance for the given handle.
|
|
|
|
*
|
|
|
|
* @param handle the sound to affect
|
|
|
|
* @param balance the new channel balance:
|
|
|
|
* (-127 ... 0 ... 127) corresponds to (left ... center ... right)
|
|
|
|
*/
|
2008-06-28 15:28:29 +00:00
|
|
|
virtual void setChannelBalance(SoundHandle handle, int8 balance) = 0;
|
2003-08-31 20:26:21 +00:00
|
|
|
|
2004-11-27 15:58:18 +00:00
|
|
|
/**
|
|
|
|
* Get approximation of for how long the channel has been playing.
|
|
|
|
*/
|
2008-06-28 15:28:29 +00:00
|
|
|
virtual uint32 getSoundElapsedTime(SoundHandle handle) = 0;
|
2004-02-12 16:25:28 +00:00
|
|
|
|
2004-11-27 15:58:18 +00:00
|
|
|
/**
|
2004-12-27 00:27:00 +00:00
|
|
|
* Check whether any channel of the given sound type is active.
|
|
|
|
* For example, this can be used to check whether any SFX sound
|
2005-03-09 18:12:54 +00:00
|
|
|
* is currently playing, by checking for type kSFXSoundType.
|
2004-11-27 15:58:18 +00:00
|
|
|
*
|
2004-12-27 00:27:00 +00:00
|
|
|
* @param type the sound type to look for
|
|
|
|
* @return true if any channels of the specified type are active.
|
2004-11-27 15:58:18 +00:00
|
|
|
*/
|
2008-06-28 15:28:29 +00:00
|
|
|
virtual bool hasActiveChannelOfType(SoundType type) = 0;
|
2003-11-08 23:05:04 +00:00
|
|
|
|
2004-11-27 15:58:18 +00:00
|
|
|
/**
|
2004-12-27 00:27:00 +00:00
|
|
|
* Set the volume for the given sound type.
|
2004-11-27 15:58:18 +00:00
|
|
|
*
|
2005-05-05 15:59:24 +00:00
|
|
|
* @param type the sound type
|
2008-06-11 11:29:34 +00:00
|
|
|
* @param volume the new global volume, 0 - kMaxMixerVolume
|
2004-11-27 15:58:18 +00:00
|
|
|
*/
|
2008-06-28 15:28:29 +00:00
|
|
|
virtual void setVolumeForSoundType(SoundType type, int volume) = 0;
|
2003-11-08 23:05:04 +00:00
|
|
|
|
2004-11-27 15:58:18 +00:00
|
|
|
/**
|
|
|
|
* Query the global volume.
|
|
|
|
*
|
2005-05-05 15:59:24 +00:00
|
|
|
* @param type the sound type
|
2008-06-11 11:29:34 +00:00
|
|
|
* @return the global music volume, 0 - kMaxMixerVolume
|
2004-11-27 15:58:18 +00:00
|
|
|
*/
|
2008-06-28 15:28:29 +00:00
|
|
|
virtual int getVolumeForSoundType(SoundType type) const = 0;
|
2003-11-08 23:05:04 +00:00
|
|
|
|
2004-11-27 15:58:18 +00:00
|
|
|
/**
|
|
|
|
* Query the system's audio output sample rate. This returns
|
|
|
|
* the same value as OSystem::getOutputSampleRate().
|
|
|
|
*
|
|
|
|
* @return the output sample rate in Hz
|
|
|
|
*/
|
2008-06-28 15:28:29 +00:00
|
|
|
virtual uint getOutputRate() const = 0;
|
2002-04-14 18:13:08 +00:00
|
|
|
};
|
|
|
|
|
2005-05-10 23:48:48 +00:00
|
|
|
|
|
|
|
} // End of namespace Audio
|
|
|
|
|
2002-08-18 16:10:38 +00:00
|
|
|
#endif
|