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

virtual bool Audio::MixerImpl::isReady ( ) const
inlinevirtual

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()

virtual Common::Mutex& Audio::MixerImpl::mutex ( )
inlinevirtual

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

Implements Audio::Mixer.

◆ playStream()

virtual void Audio::MixerImpl::playStream ( SoundType  type,
SoundHandle handle,
AudioStream stream,
int  id,
byte  volume,
int8  balance,
DisposeAfterUse::Flag  autofreeStream,
bool  permanent,
bool  reverseStereo 
)
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.

Implements Audio::Mixer.

◆ stopAll()

virtual void Audio::MixerImpl::stopAll ( )
virtual

Stop all currently playing sounds.

Implements Audio::Mixer.

◆ stopID()

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

Stop playing the sound with the given ID.

Parameters
idID of the sound.

Implements Audio::Mixer.

◆ stopHandle()

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

Stop playing the sound corresponding to the given handle.

Parameters
handleThe sound to stop playing.

Implements Audio::Mixer.

◆ pauseAll()

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

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

Parameters
pausedTrue to pause everything, false to unpause.

Implements Audio::Mixer.

◆ pauseID()

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

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()

virtual void Audio::MixerImpl::pauseHandle ( SoundHandle  handle,
bool  paused 
)
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.

Implements Audio::Mixer.

◆ isSoundIDActive()

virtual bool Audio::MixerImpl::isSoundIDActive ( int  id)
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.

Implements Audio::Mixer.

◆ getSoundID()

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

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()

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

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()

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

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()

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

Query the mute state for a given sound type.

Parameters
typeSound type. See SoundType.

Implements Audio::Mixer.

◆ setChannelVolume()

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

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()

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

Get the channel volume for the given handle.

Parameters
handleThe sound to affect.
Returns
The channel volume.

Implements Audio::Mixer.

◆ setChannelBalance()

virtual void Audio::MixerImpl::setChannelBalance ( SoundHandle  handle,
int8  balance 
)
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)

Implements Audio::Mixer.

◆ getChannelBalance()

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

Get the channel balance for the given handle.

Parameters
handleThe sound to affect.
Returns
The channel balance.

Implements Audio::Mixer.

◆ setChannelRate()

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

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()

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

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()

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

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

Parameters
handleThe sound to affect.

Implements Audio::Mixer.

◆ getSoundElapsedTime()

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

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

Implements Audio::Mixer.

◆ getElapsedTime()

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

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

Implements Audio::Mixer.

◆ loopChannel()

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

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

Implements Audio::Mixer.

◆ hasActiveChannelOfType()

virtual bool Audio::MixerImpl::hasActiveChannelOfType ( SoundType  type)
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.

Implements Audio::Mixer.

◆ setVolumeForSoundType()

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

Set the volume for the given sound type.

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

Implements Audio::Mixer.

◆ getVolumeForSoundType()

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

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()

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

Return the output sample rate of the system.

Returns
The output sample rate in Hz.

Implements Audio::Mixer.

◆ getOutputStereo()

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

Check whether the output is stereo.

Returns
true if output is stereo, false if not.

Implements Audio::Mixer.

◆ getOutputBufSize()

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

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: