ScummVM API documentation
Audio::Mixer Class Referenceabstract

#include <mixer.h>

Inheritance diagram for Audio::Mixer:
Common::NonCopyable Audio::MixerImpl

Public Types

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

Public Member Functions

virtual bool isReady () const =0
 
virtual Common::Mutexmutex ()=0
 
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
 
virtual void stopAll ()=0
 
virtual void stopID (int id)=0
 
virtual void stopHandle (SoundHandle handle)=0
 
virtual void pauseAll (bool paused)=0
 
virtual void pauseID (int id, bool paused)=0
 
virtual void pauseHandle (SoundHandle handle, bool paused)=0
 
virtual bool isSoundIDActive (int id)=0
 
virtual int getSoundID (SoundHandle handle)=0
 
virtual bool isSoundHandleActive (SoundHandle handle)=0
 
virtual void muteSoundType (SoundType type, bool mute)=0
 
virtual bool isSoundTypeMuted (SoundType type) const =0
 
virtual void setChannelVolume (SoundHandle handle, byte volume)=0
 
virtual byte getChannelVolume (SoundHandle handle)=0
 
virtual void setChannelBalance (SoundHandle handle, int8 balance)=0
 
virtual int8 getChannelBalance (SoundHandle handle)=0
 
virtual void setChannelRate (SoundHandle handle, uint32 rate)=0
 
virtual uint32 getChannelRate (SoundHandle handle)=0
 
virtual void resetChannelRate (SoundHandle handle)=0
 
virtual uint32 getSoundElapsedTime (SoundHandle handle)=0
 
virtual Timestamp getElapsedTime (SoundHandle handle)=0
 
virtual void loopChannel (SoundHandle handle)=0
 
virtual bool hasActiveChannelOfType (SoundType type)=0
 
virtual void setVolumeForSoundType (SoundType type, int volume)=0
 
virtual int getVolumeForSoundType (SoundType type) const =0
 
virtual uint getOutputRate () const =0
 
virtual bool getOutputStereo () const =0
 
virtual uint getOutputBufSize () const =0
 

Detailed Description

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

Member Enumeration Documentation

◆ SoundType

Sound types.

Enumerator
kPlainSoundType 

Plain sound.

kMusicSoundType 

Music.

kSFXSoundType 

Sound effects.

kSpeechSoundType 

Speech.

◆ anonymous enum

anonymous enum

Max volumes.

Enumerator
kMaxChannelVolume 

Max channel volume.

kMaxMixerVolume 

Max global volume.

Member Function Documentation

◆ isReady()

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

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.

Returns
Whether the mixer is ready and set up.

Implemented in Audio::MixerImpl.

◆ mutex()

virtual Common::Mutex& Audio::Mixer::mutex ( )
pure virtual

Return the mixer's internal mutex so that audio players can use 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 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.

Parameters
typeType of the stream - voice/SFX/music.
handleA SoundHandle instance that can be used to reference and control the stream using suitable mixer methods.
streamThe actual AudioStream to be played.
idUnique ID assigned to this stream.
volumeVolume with which to play the sound, ranging from 0 to 255.
balanceBalance with which to play the sound, ranging from -127 to 127 (full left to full right). 0 is balanced, -128 is invalid.
autofreeStreamIf set, the stream will be freed after the playback is finished.
permanentIf set, a plain stopAll call will not stop this particular stream.
reverseStereoIf set, left and right channels will be swapped.

Implemented in Audio::MixerImpl.

◆ stopAll()

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

Stop all currently playing sounds.

Implemented in Audio::MixerImpl.

◆ stopID()

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

Stop playing the sound with the given ID.

Parameters
idID of the sound.

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

Implemented in Audio::MixerImpl.

◆ pauseAll()

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

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

Parameters
pausedTrue to pause everything, false to unpause.

Implemented in Audio::MixerImpl.

◆ pauseID()

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

Pause or unpause the sound with the given ID.

Parameters
idID of the sound.
pausedTrue to pause the sound, false to unpause it.

Implemented in Audio::MixerImpl.

◆ pauseHandle()

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

Pause or unpause the sound corresponding to the given handle.

Parameters
handleThe sound to pause or unpause.
pausedTrue to pause the sound, false to unpause it.

Implemented in Audio::MixerImpl.

◆ isSoundIDActive()

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

Check whether a sound with the given ID is active.

Parameters
idID of the sound to query.
Returns
True if the sound is active.

Implemented in Audio::MixerImpl.

◆ getSoundID()

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

Get the sound ID for the given handle.

Parameters
handleThe sound to query.
Returns
Sound ID if the sound is active.

Implemented in Audio::MixerImpl.

◆ isSoundHandleActive()

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

Check whether a sound with the given handle is active.

Parameters
handleThe sound to query.
Returns
True if the sound is active.

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
typeSound type. See SoundType.
muteWhether to mute (= true) or not (= false).

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
typeSound type. See SoundType.

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, in the range 0 - kMaxChannelVolume.

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
The channel volume.

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.

◆ getChannelBalance()

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

Get the channel balance for the given handle.

Parameters
handleThe sound to affect.
Returns
The channel balance.

Implemented in Audio::MixerImpl.

◆ setChannelRate()

virtual void Audio::Mixer::setChannelRate ( SoundHandle  handle,
uint32  rate 
)
pure virtual

Set the sample rate for the given handle.

Parameters
handleThe sound to affect.
rateThe new sample rate. Must be less than 131072

Implemented in Audio::MixerImpl.

◆ getChannelRate()

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

Get the sample rate for the given handle.

Parameters
handleThe sound to affect.
Returns
The current sample rate of the channel.

Implemented in Audio::MixerImpl.

◆ resetChannelRate()

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

Reset the sample rate of the channel back to its AudioStream's native rate.

Parameters
handleThe sound to affect.

Implemented in Audio::MixerImpl.

◆ getSoundElapsedTime()

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

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

Implemented in Audio::MixerImpl.

◆ getElapsedTime()

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

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

Implemented in Audio::MixerImpl.

◆ loopChannel()

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

Replace the channel's stream with a version that loops indefinitely.

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 query.
Returns
True if any channels of the specified type are active.

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
typeSound type.
volumeThe new global volume, in the range 0 - kMaxMixerVolume.

Implemented in Audio::MixerImpl.

◆ getVolumeForSoundType()

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

Check what the global volume is for a sound type.

Parameters
typeSound type.
Returns
The global volume, in the range 0 - kMaxMixerVolume.

Implemented in Audio::MixerImpl.

◆ getOutputRate()

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

Return the output sample rate of the system.

Returns
The output sample rate in Hz.

Implemented in Audio::MixerImpl.

◆ getOutputStereo()

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

Check whether the output is stereo.

Returns
true if output is stereo, false if not.

Implemented in Audio::MixerImpl.

◆ getOutputBufSize()

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

Return the output sample buffer size of the system.

Returns
The number of samples processed at each audio callback.

Implemented in Audio::MixerImpl.


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