ScummVM
Audio::Mixer Class Referenceabstract

The main audio mixer handles mixing of an arbitrary number of audio streams (in the form of AudioStream instances). More...

#include <mixer.h>

Inheritance diagram for Audio::Mixer:
Collaboration diagram for Audio::Mixer:

Public Types

enum  SoundType { kPlainSoundType = 0, kMusicSoundType = 1, kSFXSoundType = 2, kSpeechSoundType = 3 }
 
enum  { kMaxChannelVolume = 255, kMaxMixerVolume = 256 }
 

Public Member Functions

 Mixer ()
 
virtual ~Mixer ()
 
virtual bool isReady () const =0
 Is the mixer ready and setup? This may not be the case on systems which don't support digital sound output. More...
 
virtual void playStream (SoundType type, SoundHandle *handle, AudioStream *stream, int id=-1, byte volume=kMaxChannelVolume, int8 balance=0, DisposeAfterUse::Flag autofreeStream=DisposeAfterUse::YES, bool permanent=false, bool reverseStereo=false)=0
 Start playing the given audio stream. More...
 
virtual void stopAll ()=0
 Stop all currently playing sounds. More...
 
virtual void stopID (int id)=0
 Stop playing the sound with given ID. More...
 
virtual void stopHandle (SoundHandle handle)=0
 Stop playing the sound corresponding to the given handle. More...
 
virtual void pauseAll (bool paused)=0
 Pause/unpause all sounds, including all regular and permanent channels. More...
 
virtual void pauseID (int id, bool paused)=0
 Pause/unpause the sound with the given ID. More...
 
virtual void pauseHandle (SoundHandle handle, bool paused)=0
 Pause/unpause the sound corresponding to the given handle. More...
 
virtual bool isSoundIDActive (int id)=0
 Check if a sound with the given ID is active. More...
 
virtual int getSoundID (SoundHandle handle)=0
 Get the sound ID of handle sound. More...
 
virtual bool isSoundHandleActive (SoundHandle handle)=0
 Check if a sound with the given handle is active. More...
 
virtual void muteSoundType (SoundType type, bool mute)=0
 Set the mute state for a given sound type. More...
 
virtual bool isSoundTypeMuted (SoundType type) const =0
 Query the mute state for a given sound type. More...
 
virtual void setChannelVolume (SoundHandle handle, byte volume)=0
 Set the channel volume for the given handle. More...
 
virtual byte getChannelVolume (SoundHandle handle)=0
 Get the channel volume for the given handle. More...
 
virtual void setChannelBalance (SoundHandle handle, int8 balance)=0
 Set the channel balance for the given handle. More...
 
virtual int8 getChannelBalance (SoundHandle handle)=0
 Get the channel balance for the given handle. More...
 
virtual uint32 getSoundElapsedTime (SoundHandle handle)=0
 Get approximation of for how long the channel has been playing. More...
 
virtual Timestamp getElapsedTime (SoundHandle handle)=0
 Get approximation of for how long the channel has been playing. More...
 
virtual bool hasActiveChannelOfType (SoundType type)=0
 Check whether any channel of the given sound type is active. More...
 
virtual void setVolumeForSoundType (SoundType type, int volume)=0
 Set the volume for the given sound type. More...
 
virtual int getVolumeForSoundType (SoundType type) const =0
 Query the global volume. More...
 
virtual uint getOutputRate () const =0
 Query the system's audio output sample rate. More...
 

Additional Inherited Members

- Private Member Functions inherited from Common::NonCopyable
 NonCopyable ()
 

Detailed Description

The main audio mixer handles mixing of an arbitrary number of audio streams (in the form of AudioStream instances).

Definition at line 53 of file mixer.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
kMaxChannelVolume 
kMaxMixerVolume 

Definition at line 63 of file mixer.h.

◆ SoundType

Enumerator
kPlainSoundType 
kMusicSoundType 
kSFXSoundType 
kSpeechSoundType 

Definition at line 55 of file mixer.h.

Constructor & Destructor Documentation

◆ Mixer()

Audio::Mixer::Mixer ( )
inline

Definition at line 69 of file mixer.h.

◆ ~Mixer()

virtual Audio::Mixer::~Mixer ( )
inlinevirtual

Definition at line 70 of file mixer.h.

Member Function Documentation

◆ getChannelBalance()

virtual int8 Audio::Mixer::getChannelBalance ( SoundHandle  handle)
pure virtual

Get the channel balance for the given handle.

Parameters
handlethe sound to affect
Returns
channel balance

Implemented in Audio::MixerImpl.

◆ getChannelVolume()

virtual byte Audio::Mixer::getChannelVolume ( SoundHandle  handle)
pure virtual

Get the channel volume for the given handle.

Parameters
handlethe sound to affect
Returns
channel volume

Implemented in Audio::MixerImpl.

◆ getElapsedTime()

virtual Timestamp Audio::Mixer::getElapsedTime ( SoundHandle  handle)
pure virtual

Get approximation of for how long the channel has been playing.

Implemented in Audio::MixerImpl.

◆ getOutputRate()

virtual uint Audio::Mixer::getOutputRate ( ) const
pure virtual

Query the system's audio output sample rate.

Returns
the output sample rate in Hz

Implemented in Audio::MixerImpl.

◆ getSoundElapsedTime()

virtual uint32 Audio::Mixer::getSoundElapsedTime ( SoundHandle  handle)
pure virtual

Get approximation of for how long the channel has been playing.

Implemented in Audio::MixerImpl.

◆ getSoundID()

virtual int Audio::Mixer::getSoundID ( SoundHandle  handle)
pure virtual

Get the sound ID of handle sound.

Parameters
handlesound to query
Returns
sound ID if active

Implemented in Audio::MixerImpl.

◆ getVolumeForSoundType()

virtual int Audio::Mixer::getVolumeForSoundType ( SoundType  type) const
pure virtual

Query the global volume.

Parameters
typethe sound type
Returns
the global music volume, 0 - kMaxMixerVolume

Implemented in Audio::MixerImpl.

◆ hasActiveChannelOfType()

virtual bool Audio::Mixer::hasActiveChannelOfType ( SoundType  type)
pure virtual

Check whether any channel of the given sound type is active.

For example, this can be used to check whether any SFX sound is currently playing, by checking for type kSFXSoundType.

Parameters
typethe sound type to look for
Returns
true if any channels of the specified type are active.

Implemented in Audio::MixerImpl.

◆ isReady()

virtual bool Audio::Mixer::isReady ( ) const
pure virtual

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 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...

Returns
whether the mixer is ready and setup
Todo:
get rid of this?

Implemented in Audio::MixerImpl.

◆ isSoundHandleActive()

virtual bool Audio::Mixer::isSoundHandleActive ( SoundHandle  handle)
pure virtual

Check if a sound with the given handle is active.

Parameters
handlesound to query
Returns
true if the sound is active

Implemented in Audio::MixerImpl.

◆ isSoundIDActive()

virtual bool Audio::Mixer::isSoundIDActive ( int  id)
pure virtual

Check if a sound with the given ID is active.

Parameters
idthe ID of the sound to query
Returns
true if the sound is active

Implemented in Audio::MixerImpl.

◆ isSoundTypeMuted()

virtual bool Audio::Mixer::isSoundTypeMuted ( SoundType  type) const
pure virtual

Query the mute state for a given sound type.

Parameters
typethe sound type

Implemented in Audio::MixerImpl.

◆ muteSoundType()

virtual void Audio::Mixer::muteSoundType ( SoundType  type,
bool  mute 
)
pure virtual

Set the mute state for a given sound type.

Parameters
typethe sound type
muteWhether to mute (= true) or not (= false).

Implemented in Audio::MixerImpl.

◆ pauseAll()

virtual void Audio::Mixer::pauseAll ( bool  paused)
pure virtual

Pause/unpause all sounds, including all regular and permanent channels.

Parameters
pausedtrue to pause everything, false to unpause

Implemented in Audio::MixerImpl.

◆ pauseHandle()

virtual void Audio::Mixer::pauseHandle ( SoundHandle  handle,
bool  paused 
)
pure virtual

Pause/unpause the sound corresponding to the given handle.

Parameters
handlethe sound to affect
pausedtrue to pause the sound, false to unpause it

Implemented in Audio::MixerImpl.

◆ pauseID()

virtual void Audio::Mixer::pauseID ( int  id,
bool  paused 
)
pure virtual

Pause/unpause the sound with the given ID.

Parameters
idthe ID of the sound to affect
pausedtrue to pause the sound, false to unpause it

Implemented in Audio::MixerImpl.

◆ playStream()

virtual void Audio::Mixer::playStream ( SoundType  type,
SoundHandle handle,
AudioStream stream,
int  id = -1,
byte  volume = kMaxChannelVolume,
int8  balance = 0,
DisposeAfterUse::Flag  autofreeStream = DisposeAfterUse::YES,
bool  permanent = false,
bool  reverseStereo = false 
)
pure virtual

Start playing the given audio stream.

Note that the sound id assigned below is unique. At most one stream with a 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 be not played.

Parameters
typethe type (voice/sfx/music) of the stream
handlea SoundHandle which can be used to reference and control the stream via suitable mixer methods
streamthe actual AudioStream to be played
ida unique id assigned to this stream
volumethe volume with which to play the sound, ranging from 0 to 255
balancethe balance with which to play the sound, ranging from -127 to 127 (full left to full right), 0 is balanced, -128 is invalid
autofreeStreama flag indicating whether the stream should be freed after playback finished
permanenta flag indicating whether a plain stopAll call should not stop this particular stream
reverseStereoa flag indicating whether left and right channels shall be swapped

Implemented in Audio::MixerImpl.

◆ setChannelBalance()

virtual void Audio::Mixer::setChannelBalance ( SoundHandle  handle,
int8  balance 
)
pure virtual

Set the channel balance for the given handle.

Parameters
handlethe sound to affect
balancethe new channel balance: (-127 ... 0 ... 127) corresponds to (left ... center ... right)

Implemented in Audio::MixerImpl.

◆ setChannelVolume()

virtual void Audio::Mixer::setChannelVolume ( SoundHandle  handle,
byte  volume 
)
pure virtual

Set the channel volume for the given handle.

Parameters
handlethe sound to affect
volumethe new channel volume (0 - kMaxChannelVolume)

Implemented in Audio::MixerImpl.

◆ setVolumeForSoundType()

virtual void Audio::Mixer::setVolumeForSoundType ( SoundType  type,
int  volume 
)
pure virtual

Set the volume for the given sound type.

Parameters
typethe sound type
volumethe new global volume, 0 - kMaxMixerVolume

Implemented in Audio::MixerImpl.

◆ stopAll()

virtual void Audio::Mixer::stopAll ( )
pure virtual

Stop all currently playing sounds.

Implemented in Audio::MixerImpl.

◆ stopHandle()

virtual void Audio::Mixer::stopHandle ( SoundHandle  handle)
pure virtual

Stop playing the sound corresponding to the given handle.

Parameters
handlethe sound to affect

Implemented in Audio::MixerImpl.

◆ stopID()

virtual void Audio::Mixer::stopID ( int  id)
pure virtual

Stop playing the sound with given ID.

Parameters
idthe ID of the sound to affect

Implemented in Audio::MixerImpl.


The documentation for this class was generated from the following file: