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.
|
2014-02-18 01:34:17 +00:00
|
|
|
*
|
2002-04-21 17:46:42 +00:00
|
|
|
* 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.
|
2014-02-18 01:34:17 +00:00
|
|
|
*
|
2002-04-21 17:46:42 +00:00
|
|
|
* 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
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2011-10-28 10:27:50 +00:00
|
|
|
#ifndef AUDIO_MIXER_H
|
|
|
|
#define AUDIO_MIXER_H
|
2002-04-14 18:13:08 +00:00
|
|
|
|
2021-06-21 06:42:27 +00:00
|
|
|
#include "common/mutex.h"
|
2010-01-08 22:09:43 +00:00
|
|
|
#include "common/types.h"
|
2010-06-08 01:07:10 +00:00
|
|
|
#include "common/noncopyable.h"
|
2003-09-07 20:23:38 +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;
|
2011-04-24 08:34:27 +00:00
|
|
|
class Timestamp;
|
2005-05-11 00:01:44 +00:00
|
|
|
|
2007-02-03 19:05:53 +00:00
|
|
|
/**
|
2020-11-30 01:54:01 +00:00
|
|
|
* @defgroup audio_mixer Mixer
|
|
|
|
* @ingroup audio
|
|
|
|
*
|
|
|
|
* @brief Mixer class used for playing audio streams.
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A SoundHandle instance corresponds to a specific sound
|
|
|
|
* being played using the mixer. It can be used to control that
|
2007-02-03 19:05:53 +00:00
|
|
|
* sound (pause it, stop it, etc.).
|
2020-11-30 01:54:01 +00:00
|
|
|
* @see Mixer
|
2007-02-03 19:05:53 +00:00
|
|
|
*/
|
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
|
|
|
/**
|
2020-11-30 01:54:01 +00:00
|
|
|
* The main audio mixer that handles mixing of an arbitrary number of
|
2010-04-29 21:54:39 +00:00
|
|
|
* audio streams (in the form of AudioStream instances).
|
2007-02-03 19:05:53 +00:00
|
|
|
*/
|
2010-06-08 01:07:10 +00:00
|
|
|
class Mixer : Common::NonCopyable {
|
2003-06-15 01:56:47 +00:00
|
|
|
public:
|
2020-11-30 01:54:01 +00:00
|
|
|
/** Sound types. */
|
2004-12-27 00:27:00 +00:00
|
|
|
enum SoundType {
|
2020-11-30 01:54:01 +00:00
|
|
|
kPlainSoundType = 0, /*!< Plain sound. */
|
2004-12-27 00:27:00 +00:00
|
|
|
|
2020-11-30 01:54:01 +00:00
|
|
|
kMusicSoundType = 1, /*!< Music. */
|
|
|
|
kSFXSoundType = 2, /*!< Sound effects. */
|
|
|
|
kSpeechSoundType = 3 /*!< Speech. */
|
2004-12-27 00:27:00 +00:00
|
|
|
};
|
2020-11-30 01:54:01 +00:00
|
|
|
/** Max volumes. */
|
2004-12-27 23:33:19 +00:00
|
|
|
enum {
|
2020-11-30 01:54:01 +00:00
|
|
|
kMaxChannelVolume = 255, /*!< Max channel volume. */
|
|
|
|
kMaxMixerVolume = 256 /*!< Max global volume. */
|
2004-12-27 23:33:19 +00:00
|
|
|
};
|
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
|
|
|
/**
|
2020-11-30 01:54:01 +00:00
|
|
|
* Check whether the mixer is ready and set up.
|
|
|
|
*
|
|
|
|
* The mixer might not be set up on systems that do not support
|
|
|
|
* digital sound output. In such case, the mixer processing might
|
|
|
|
* never be called. That, in turn, can cause breakage in games that try to
|
|
|
|
* sync with an audio stream. In particular, the AdLib MIDI emulation.
|
2004-11-27 15:58:18 +00:00
|
|
|
*
|
2020-11-30 01:54:01 +00:00
|
|
|
* @return Whether the mixer is ready and set up.
|
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
|
|
|
|
2021-06-21 06:42:27 +00:00
|
|
|
/**
|
|
|
|
* Return the mixer's internal mutex so that audio players can use it.
|
|
|
|
*/
|
|
|
|
virtual Common::Mutex &mutex() = 0;
|
2004-11-27 15:58:18 +00:00
|
|
|
|
|
|
|
/**
|
2010-04-29 21:54:39 +00:00
|
|
|
* Start playing the given audio stream.
|
2007-02-03 19:05:53 +00:00
|
|
|
*
|
2020-11-30 01:54:01 +00:00
|
|
|
* Note that the sound ID assigned here is unique. At most, one stream
|
|
|
|
* with the given ID can play at any given time. Trying to play a sound
|
|
|
|
* with an ID that is already in use causes the new sound to not be played.
|
2007-02-03 19:05:53 +00:00
|
|
|
*
|
2020-11-30 01:54:01 +00:00
|
|
|
* @param type Type of the stream - voice/SFX/music.
|
|
|
|
* @param handle A SoundHandle instance that can be used to reference and control
|
|
|
|
* the stream using suitable mixer methods.
|
|
|
|
* @param stream The actual AudioStream to be played.
|
|
|
|
* @param id Unique ID assigned to this stream.
|
|
|
|
* @param volume Volume with which to play the sound, ranging from 0 to 255.
|
|
|
|
* @param balance Balance with which to play the sound, ranging from -127 to 127 (full left to full right).
|
|
|
|
* 0 is balanced, -128 is invalid.
|
2021-05-04 08:45:03 +00:00
|
|
|
* @param autofreeStream If set, the stream will be freed after the playback is finished.
|
|
|
|
* @param permanent If set, a plain stopAll call will not stop this particular stream.
|
2020-11-30 01:54:01 +00:00
|
|
|
* @param reverseStereo If set, left and right channels will be swapped.
|
2004-11-27 15:58:18 +00:00
|
|
|
*/
|
2010-04-12 09:14:17 +00:00
|
|
|
virtual void playStream(
|
2007-02-03 19:05:53 +00:00
|
|
|
SoundType type,
|
|
|
|
SoundHandle *handle,
|
2010-04-29 21:54:39 +00:00
|
|
|
AudioStream *stream,
|
2010-01-19 11:20:58 +00:00
|
|
|
int id = -1,
|
|
|
|
byte volume = kMaxChannelVolume,
|
|
|
|
int8 balance = 0,
|
2010-01-08 22:09:43 +00:00
|
|
|
DisposeAfterUse::Flag autofreeStream = DisposeAfterUse::YES,
|
2007-03-02 14:49:07 +00:00
|
|
|
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
|
|
|
/**
|
2020-11-30 01:54:01 +00:00
|
|
|
* Stop playing the sound with the given ID.
|
2004-11-27 15:58:18 +00:00
|
|
|
*
|
2020-11-30 01:54:01 +00:00
|
|
|
* @param id ID of the sound.
|
2004-11-27 15:58:18 +00:00
|
|
|
*/
|
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.
|
|
|
|
*
|
2020-11-30 01:54:01 +00:00
|
|
|
* @param handle The sound to stop playing.
|
2004-11-27 15:58:18 +00:00
|
|
|
*/
|
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
|
|
|
|
|
|
|
|
|
|
|
/**
|
2020-11-30 01:54:01 +00:00
|
|
|
* Pause or unpause all sounds, including all regular and permanent
|
|
|
|
* channels.
|
2004-11-27 15:58:18 +00:00
|
|
|
*
|
2020-11-30 01:54:01 +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
|
|
|
/**
|
2020-11-30 01:54:01 +00:00
|
|
|
* Pause or unpause the sound with the given ID.
|
2004-11-27 15:58:18 +00:00
|
|
|
*
|
2020-11-30 01:54:01 +00:00
|
|
|
* @param id ID of the sound.
|
|
|
|
* @param paused True to pause the sound, false to unpause it.
|
2004-11-27 15:58:18 +00:00
|
|
|
*/
|
2008-06-28 15:28:29 +00:00
|
|
|
virtual void pauseID(int id, bool paused) = 0;
|
2004-11-27 15:58:18 +00:00
|
|
|
|
|
|
|
/**
|
2020-11-30 01:54:01 +00:00
|
|
|
* Pause or unpause the sound corresponding to the given handle.
|
2004-11-27 15:58:18 +00:00
|
|
|
*
|
2020-11-30 01:54:01 +00:00
|
|
|
* @param handle The sound to pause or unpause.
|
|
|
|
* @param paused True to pause the sound, false to unpause it.
|
2004-11-27 15:58:18 +00:00
|
|
|
*/
|
2008-06-28 15:28:29 +00:00
|
|
|
virtual void pauseHandle(SoundHandle handle, bool paused) = 0;
|
2004-11-27 15:58:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2020-11-30 01:54:01 +00:00
|
|
|
* Check whether a sound with the given ID is active.
|
2004-11-27 15:58:18 +00:00
|
|
|
*
|
2020-11-30 01:54:01 +00:00
|
|
|
* @param id ID of the sound to query.
|
|
|
|
*
|
|
|
|
* @return True if the sound is active.
|
2004-11-27 15:58:18 +00:00
|
|
|
*/
|
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
|
|
|
/**
|
2020-11-30 01:54:01 +00:00
|
|
|
* Get the sound ID for the given handle.
|
|
|
|
*
|
|
|
|
* @param handle The sound to query.
|
2005-04-04 11:43:25 +00:00
|
|
|
*
|
2020-11-30 01:54:01 +00:00
|
|
|
* @return Sound ID if the sound is active.
|
2005-04-04 11:43:25 +00:00
|
|
|
*/
|
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
|
|
|
/**
|
2020-11-30 01:54:01 +00:00
|
|
|
* Check whether a sound with the given handle is active.
|
2005-03-12 18:56:09 +00:00
|
|
|
*
|
2020-11-30 01:54:01 +00:00
|
|
|
* @param handle The sound to query.
|
|
|
|
*
|
|
|
|
* @return True if the sound is active.
|
2005-03-12 18:56:09 +00:00
|
|
|
*/
|
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
|
|
|
|
2011-03-20 22:44:46 +00:00
|
|
|
/**
|
|
|
|
* Set the mute state for a given sound type.
|
|
|
|
*
|
2020-11-30 01:54:01 +00:00
|
|
|
* @param type Sound type. See @ref SoundType.
|
2011-04-16 16:20:37 +00:00
|
|
|
* @param mute Whether to mute (= true) or not (= false).
|
2011-03-20 22:44:46 +00:00
|
|
|
*/
|
2011-04-16 16:20:37 +00:00
|
|
|
virtual void muteSoundType(SoundType type, bool mute) = 0;
|
2011-03-20 22:44:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Query the mute state for a given sound type.
|
|
|
|
*
|
2020-11-30 01:54:01 +00:00
|
|
|
* @param type Sound type. See @ref SoundType.
|
2011-03-20 22:44:46 +00:00
|
|
|
*/
|
2011-04-16 16:20:37 +00:00
|
|
|
virtual bool isSoundTypeMuted(SoundType type) const = 0;
|
2003-09-02 13:48:20 +00:00
|
|
|
|
2004-11-27 15:58:18 +00:00
|
|
|
/**
|
|
|
|
* Set the channel volume for the given handle.
|
|
|
|
*
|
2020-11-30 01:54:01 +00:00
|
|
|
* @param handle The sound to affect.
|
|
|
|
* @param volume The new channel volume, in the range 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
|
|
|
|
2011-06-11 11:08:21 +00:00
|
|
|
/**
|
|
|
|
* Get the channel volume for the given handle.
|
|
|
|
*
|
2020-11-30 01:54:01 +00:00
|
|
|
* @param handle The sound to affect.
|
|
|
|
*
|
|
|
|
* @return The channel volume.
|
2011-06-11 11:08:21 +00:00
|
|
|
*/
|
|
|
|
virtual byte getChannelVolume(SoundHandle handle) = 0;
|
|
|
|
|
2004-11-27 15:58:18 +00:00
|
|
|
/**
|
|
|
|
* Set the channel balance for the given handle.
|
|
|
|
*
|
2020-11-30 01:54:01 +00:00
|
|
|
* @param handle The sound to affect.
|
|
|
|
* @param balance The new channel balance:
|
|
|
|
* (-127 ... 0 ... 127) corresponds to (left ... center ... right)
|
2004-11-27 15:58:18 +00:00
|
|
|
*/
|
2008-06-28 15:28:29 +00:00
|
|
|
virtual void setChannelBalance(SoundHandle handle, int8 balance) = 0;
|
2003-08-31 20:26:21 +00:00
|
|
|
|
2011-06-11 11:08:21 +00:00
|
|
|
/**
|
|
|
|
* Get the channel balance for the given handle.
|
|
|
|
*
|
2020-11-30 01:54:01 +00:00
|
|
|
* @param handle The sound to affect.
|
|
|
|
*
|
|
|
|
* @return The channel balance.
|
2011-06-11 11:08:21 +00:00
|
|
|
*/
|
|
|
|
virtual int8 getChannelBalance(SoundHandle handle) = 0;
|
|
|
|
|
2004-11-27 15:58:18 +00:00
|
|
|
/**
|
2020-11-30 01:54:01 +00:00
|
|
|
* Get an approximation of for how long the channel has been playing.
|
2004-11-27 15:58:18 +00:00
|
|
|
*/
|
2008-06-28 15:28:29 +00:00
|
|
|
virtual uint32 getSoundElapsedTime(SoundHandle handle) = 0;
|
2004-02-12 16:25:28 +00:00
|
|
|
|
2010-01-09 22:37:10 +00:00
|
|
|
/**
|
2020-11-30 01:54:01 +00:00
|
|
|
* Get an approximation of for how long the channel has been playing.
|
2010-01-09 22:37:10 +00:00
|
|
|
*/
|
|
|
|
virtual Timestamp getElapsedTime(SoundHandle handle) = 0;
|
|
|
|
|
2021-08-12 05:46:39 +00:00
|
|
|
/**
|
|
|
|
* Replace the channel's stream with a version that loops indefinitely.
|
|
|
|
*/
|
|
|
|
virtual void loopChannel(SoundHandle handle) = 0;
|
|
|
|
|
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.
|
2020-11-30 01:54:01 +00:00
|
|
|
*
|
2004-12-27 00:27:00 +00:00
|
|
|
* For example, this can be used to check whether any SFX sound
|
2020-11-30 01:54:01 +00:00
|
|
|
* is currently playing by checking for type kSFXSoundType.
|
2004-11-27 15:58:18 +00:00
|
|
|
*
|
2020-11-30 01:54:01 +00:00
|
|
|
* @param type The sound type to query.
|
|
|
|
*
|
|
|
|
* @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
|
|
|
*
|
2020-11-30 01:54:01 +00:00
|
|
|
* @param type Sound type.
|
|
|
|
* @param volume The new global volume, in the range 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
|
|
|
/**
|
2020-11-30 01:54:01 +00:00
|
|
|
* Check what the global volume is for a sound type.
|
|
|
|
*
|
|
|
|
* @param type Sound type.
|
2004-11-27 15:58:18 +00:00
|
|
|
*
|
2020-11-30 01:54:01 +00:00
|
|
|
* @return The global volume, in the range 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
|
|
|
/**
|
2020-11-30 01:54:01 +00:00
|
|
|
* Return the output sample rate of the system.
|
2004-11-27 15:58:18 +00:00
|
|
|
*
|
2020-11-30 01:54:01 +00:00
|
|
|
* @return The output sample rate in Hz.
|
2004-11-27 15:58:18 +00:00
|
|
|
*/
|
2008-06-28 15:28:29 +00:00
|
|
|
virtual uint getOutputRate() const = 0;
|
2002-04-14 18:13:08 +00:00
|
|
|
};
|
|
|
|
|
2020-11-30 01:54:01 +00:00
|
|
|
/** @} */
|
2005-05-10 23:48:48 +00:00
|
|
|
} // End of namespace Audio
|
|
|
|
|
2002-08-18 16:10:38 +00:00
|
|
|
#endif
|