ScummVM API documentation
Audio::MixerImpl Class Reference

#include <mixer_intern.h>

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

Public Member Functions

 MixerImpl (uint sampleRate, bool stereo=true, uint outBufSize=0)
 
bool isReady () const override
 
Common::Mutexmutex () override
 
void playStream (SoundType type, SoundHandle *handle, AudioStream *input, int id, byte volume, int8 balance, DisposeAfterUse::Flag autofreeStream, bool permanent, bool reverseStereo) override
 
void stopAll () override
 
void stopID (int id) override
 
void stopHandle (SoundHandle handle) override
 
void pauseAll (bool paused) override
 
void pauseID (int id, bool paused) override
 
void pauseHandle (SoundHandle handle, bool paused) override
 
bool isSoundIDActive (int id) override
 
int getSoundID (SoundHandle handle) override
 
bool isSoundHandleActive (SoundHandle handle) override
 
void muteSoundType (SoundType type, bool mute) override
 
bool isSoundTypeMuted (SoundType type) const override
 
void setChannelVolume (SoundHandle handle, byte volume) override
 
byte getChannelVolume (SoundHandle handle) override
 
void setChannelBalance (SoundHandle handle, int8 balance) override
 
int8 getChannelBalance (SoundHandle handle) override
 
void setChannelFaderL (SoundHandle handle, uint8 scaleL) override
 
uint8 getChannelFaderL (SoundHandle handle) override
 
void setChannelFaderR (SoundHandle handle, uint8 scaleR) override
 
uint8 getChannelFaderR (SoundHandle handle) override
 
void setChannelRate (SoundHandle handle, uint32 rate) override
 
uint32 getChannelRate (SoundHandle handle) override
 
void resetChannelRate (SoundHandle handle) override
 
uint32 getSoundElapsedTime (SoundHandle handle) override
 
Timestamp getElapsedTime (SoundHandle handle) override
 
void loopChannel (SoundHandle handle) override
 
bool hasActiveChannelOfType (SoundType type) override
 
void setVolumeForSoundType (SoundType type, int volume) override
 
int getVolumeForSoundType (SoundType type) const override
 
uint getOutputRate () const override
 
bool getOutputStereo () const override
 
uint getOutputBufSize () const override
 
int mixCallback (byte *samples, uint len)
 
void setReady (bool ready)
 

Protected Member Functions

void insertChannel (SoundHandle *handle, Channel *chan)
 

Additional Inherited Members

- Public Types inherited from Audio::Mixer
enum  SoundType { kPlainSoundType = 0, kMusicSoundType = 1, kSFXSoundType = 2, kSpeechSoundType = 3 }
 
enum  { kMaxChannelVolume = 255, kMaxMixerVolume = 256 }
 

Detailed Description

The (default) implementation of the ScummVM audio mixing subsystem.

Backends are responsible for allocating (and later releasing) an instance of this class, which engines can access via OSystem::getMixer().

Initialisation of instances of this class usually happens as follows: 1) Creat a new Audio::MixerImpl instance. 2) Set the hardware output sample rate via the setSampleRate() method. 3) Hook up the mixCallback() in a suitable audio processing thread/callback. 4) Change the mixer into ready mode via setReady(true). 5) Start audio processing (e.g. by resuming the audio thread, if applicable).

In the future, we might make it possible for backends to provide (partial) alternative implementations of the mixer, e.g. to make better use of native sound mixing support on low-end devices.

See also
OSystem::getMixer()

Member Function Documentation

◆ isReady()

bool Audio::MixerImpl::isReady ( ) const
inlineoverridevirtual

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.

Implements Audio::Mixer.

◆ mutex()

Common::Mutex& Audio::MixerImpl::mutex ( )
inlineoverridevirtual

Return the mixer's internal mutex so that audio players can use it.

Implements Audio::Mixer.

◆ playStream()

void Audio::MixerImpl::playStream ( SoundType  type,
SoundHandle handle,
AudioStream stream,
int  id,
byte  volume,
int8  balance,
DisposeAfterUse::Flag  autofreeStream,
bool  permanent,
bool  reverseStereo 
)
overridevirtual

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.

Implements Audio::Mixer.

◆ stopAll()

void Audio::MixerImpl::stopAll ( )
overridevirtual

Stop all currently playing sounds.

Implements Audio::Mixer.

◆ stopID()

void Audio::MixerImpl::stopID ( int  id)
overridevirtual

Stop playing the sound with the given ID.

Parameters
idID of the sound.

Implements Audio::Mixer.

◆ stopHandle()

void Audio::MixerImpl::stopHandle ( SoundHandle  handle)
overridevirtual

Stop playing the sound corresponding to the given handle.

Parameters
handleThe sound to stop playing.

Implements Audio::Mixer.

◆ pauseAll()

void Audio::MixerImpl::pauseAll ( bool  paused)
overridevirtual

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

Parameters
pausedTrue to pause everything, false to unpause.

Implements Audio::Mixer.

◆ pauseID()

void Audio::MixerImpl::pauseID ( int  id,
bool  paused 
)
overridevirtual

Pause or unpause the sound with the given ID.

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

Implements Audio::Mixer.

◆ pauseHandle()

void Audio::MixerImpl::pauseHandle ( SoundHandle  handle,
bool  paused 
)
overridevirtual

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.

Implements Audio::Mixer.

◆ isSoundIDActive()

bool Audio::MixerImpl::isSoundIDActive ( int  id)
overridevirtual

Check whether a sound with the given ID is active.

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

Implements Audio::Mixer.

◆ getSoundID()

int Audio::MixerImpl::getSoundID ( SoundHandle  handle)
overridevirtual

Get the sound ID for the given handle.

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

Implements Audio::Mixer.

◆ isSoundHandleActive()

bool Audio::MixerImpl::isSoundHandleActive ( SoundHandle  handle)
overridevirtual

Check whether a sound with the given handle is active.

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

Implements Audio::Mixer.

◆ muteSoundType()

void Audio::MixerImpl::muteSoundType ( SoundType  type,
bool  mute 
)
overridevirtual

Set the mute state for a given sound type.

Parameters
typeSound type. See SoundType.
muteWhether to mute (= true) or not (= false).

Implements Audio::Mixer.

◆ isSoundTypeMuted()

bool Audio::MixerImpl::isSoundTypeMuted ( SoundType  type) const
overridevirtual

Query the mute state for a given sound type.

Parameters
typeSound type. See SoundType.

Implements Audio::Mixer.

◆ setChannelVolume()

void Audio::MixerImpl::setChannelVolume ( SoundHandle  handle,
byte  volume 
)
overridevirtual

Set the channel volume for the given handle.

Parameters
handleThe sound to affect.
volumeThe new channel volume, in the range 0 - kMaxChannelVolume.

Implements Audio::Mixer.

◆ getChannelVolume()

byte Audio::MixerImpl::getChannelVolume ( SoundHandle  handle)
overridevirtual

Get the channel volume for the given handle.

Parameters
handleThe sound to affect.
Returns
The channel volume.

Implements Audio::Mixer.

◆ setChannelBalance()

void Audio::MixerImpl::setChannelBalance ( SoundHandle  handle,
int8  balance 
)
overridevirtual

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)

Implements Audio::Mixer.

◆ getChannelBalance()

int8 Audio::MixerImpl::getChannelBalance ( SoundHandle  handle)
overridevirtual

Get the channel balance for the given handle.

Parameters
handleThe sound to affect.
Returns
The channel balance.

Implements Audio::Mixer.

◆ setChannelFaderL()

void Audio::MixerImpl::setChannelFaderL ( SoundHandle  handle,
uint8  faderL 
)
overridevirtual

Set the channel's left fader level for the given handle.

Parameters
handleThe sound to affect.
faderLThe channel's new left fader level, in the range of 0-255.

Implements Audio::Mixer.

◆ getChannelFaderL()

uint8 Audio::MixerImpl::getChannelFaderL ( SoundHandle  handle)
overridevirtual

Get the channel's left fader level for the given handle.

Parameters
handleThe sound to affect.
Returns
The channel's left fader level.

Implements Audio::Mixer.

◆ setChannelFaderR()

void Audio::MixerImpl::setChannelFaderR ( SoundHandle  handle,
uint8  faderR 
)
overridevirtual

Set the channel's right fader level for the given handle.

Parameters
handleThe sound to affect.
faderRThe channel's new right fader level, in the range of 0-255.

Implements Audio::Mixer.

◆ getChannelFaderR()

uint8 Audio::MixerImpl::getChannelFaderR ( SoundHandle  handle)
overridevirtual

Get the channel's right fader level for the given handle.

Parameters
handleThe sound to affect.
Returns
The channel's right fader level.

Implements Audio::Mixer.

◆ setChannelRate()

void Audio::MixerImpl::setChannelRate ( SoundHandle  handle,
uint32  rate 
)
overridevirtual

Set the sample rate for the given handle.

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

Implements Audio::Mixer.

◆ getChannelRate()

uint32 Audio::MixerImpl::getChannelRate ( SoundHandle  handle)
overridevirtual

Get the sample rate for the given handle.

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

Implements Audio::Mixer.

◆ resetChannelRate()

void Audio::MixerImpl::resetChannelRate ( SoundHandle  handle)
overridevirtual

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

Parameters
handleThe sound to affect.

Implements Audio::Mixer.

◆ getSoundElapsedTime()

uint32 Audio::MixerImpl::getSoundElapsedTime ( SoundHandle  handle)
overridevirtual

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

Implements Audio::Mixer.

◆ getElapsedTime()

Timestamp Audio::MixerImpl::getElapsedTime ( SoundHandle  handle)
overridevirtual

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

Implements Audio::Mixer.

◆ loopChannel()

void Audio::MixerImpl::loopChannel ( SoundHandle  handle)
overridevirtual

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

Implements Audio::Mixer.

◆ hasActiveChannelOfType()

bool Audio::MixerImpl::hasActiveChannelOfType ( SoundType  type)
overridevirtual

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.

Implements Audio::Mixer.

◆ setVolumeForSoundType()

void Audio::MixerImpl::setVolumeForSoundType ( SoundType  type,
int  volume 
)
overridevirtual

Set the volume for the given sound type.

Parameters
typeSound type.
volumeThe new global volume, in the range 0 - kMaxMixerVolume.

Implements Audio::Mixer.

◆ getVolumeForSoundType()

int Audio::MixerImpl::getVolumeForSoundType ( SoundType  type) const
overridevirtual

Check what the global volume is for a sound type.

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

Implements Audio::Mixer.

◆ getOutputRate()

uint Audio::MixerImpl::getOutputRate ( ) const
overridevirtual

Return the output sample rate of the system.

Returns
The output sample rate in Hz.

Implements Audio::Mixer.

◆ getOutputStereo()

bool Audio::MixerImpl::getOutputStereo ( ) const
overridevirtual

Check whether the output is stereo.

Returns
true if output is stereo, false if not.

Implements Audio::Mixer.

◆ getOutputBufSize()

uint Audio::MixerImpl::getOutputBufSize ( ) const
overridevirtual

Return the output sample buffer size of the system.

The return value is measured in frame units instead of bytes. It can be converted to bytes by multiplying it with the sample size and the number of channels. For example, for 16-bit stereo output it should be multiplied by 4.

Returns
The number of samples processed at each audio callback.

Implements Audio::Mixer.

◆ mixCallback()

int Audio::MixerImpl::mixCallback ( byte *  samples,
uint  len 
)

The mixer callback function, to be called at regular intervals by the backend (e.g. from an audio mixing thread). All the actual mixing work is done from here.

Parameters
samplesSample buffer, in which stereo 16-bit samples will be stored.
lenLength of the provided buffer to fill (in bytes, should be divisible by 4).
Returns
number of sample pairs processed (which can still be silence!)

◆ setReady()

void Audio::MixerImpl::setReady ( bool  ready)

Set the internal 'is ready' flag of the mixer. Backends should invoke Mixer::setReady(true) once initialisation of their audio system has been completed.


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