ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

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

#include <mixer_intern.h>

Inheritance diagram for Audio::MixerImpl:
Collaboration diagram for Audio::MixerImpl:

List of all members.

Classes

struct  SoundTypeSettings

Public Member Functions

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

Protected Member Functions

void insertChannel (SoundHandle *handle, Channel *chan)

Private Types

enum  { NUM_CHANNELS = 32 }

Private Attributes

Common::Mutex _mutex
const uint _sampleRate
bool _mixerReady
uint32 _handleSeed
SoundTypeSettings _soundTypeSettings [4]
Channel_channels [NUM_CHANNELS]

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

Definition at line 51 of file mixer_intern.h.


Member Enumeration Documentation

anonymous enum [private]
Enumerator:
NUM_CHANNELS 

Definition at line 53 of file mixer_intern.h.


Constructor & Destructor Documentation

Audio::MixerImpl::MixerImpl ( OSystem system,
uint  sampleRate 
)

Definition at line 177 of file mixer.cpp.

Audio::MixerImpl::~MixerImpl (  ) 

Definition at line 186 of file mixer.cpp.


Member Function Documentation

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

Get the channel balance for the given handle.

Parameters:
handle the sound to affect
Returns:
channel balance

Implements Audio::Mixer.

Definition at line 378 of file mixer.cpp.

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

Get the channel volume for the given handle.

Parameters:
handle the sound to affect
Returns:
channel volume

Implements Audio::Mixer.

Definition at line 360 of file mixer.cpp.

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

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

Implements Audio::Mixer.

Definition at line 390 of file mixer.cpp.

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

Query the system's audio output sample rate.

Returns:
the output sample rate in Hz

Implements Audio::Mixer.

Definition at line 195 of file mixer.cpp.

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

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

Implements Audio::Mixer.

Definition at line 386 of file mixer.cpp.

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

Get the sound ID of handle sound.

Parameters:
handle sound to query
Returns:
sound ID if active

Implements Audio::Mixer.

Definition at line 443 of file mixer.cpp.

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

Query the global volume.

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

Implements Audio::Mixer.

Definition at line 488 of file mixer.cpp.

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:
type the sound type to look for
Returns:
true if any channels of the specified type are active.

Implements Audio::Mixer.

Definition at line 462 of file mixer.cpp.

void Audio::MixerImpl::insertChannel ( SoundHandle handle,
Channel chan 
) [protected]

Definition at line 199 of file mixer.cpp.

virtual bool Audio::MixerImpl::isReady (  )  const [inline, 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?

Implements Audio::Mixer.

Definition at line 79 of file mixer_intern.h.

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

Check if a sound with the given handle is active.

Parameters:
handle sound to query
Returns:
true if the sound is active

Implements Audio::Mixer.

Definition at line 451 of file mixer.cpp.

bool Audio::MixerImpl::isSoundIDActive ( int  id  )  [virtual]

Check if a sound with the given ID is active.

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

Implements Audio::Mixer.

Definition at line 430 of file mixer.cpp.

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

Query the mute state for a given sound type.

Parameters:
type the sound type

Implements Audio::Mixer.

Definition at line 345 of file mixer.cpp.

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:
samples Sample buffer, in which stereo 16-bit samples will be stored.
len Length of the provided buffer to fill (in bytes, should be divisible by 4).
Returns:
number of sample pairs processed (which can still be silence!)

Definition at line 269 of file mixer.cpp.

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

Set the mute state for a given sound type.

Parameters:
type the sound type
mute Whether to mute (= true) or not (= false).

Implements Audio::Mixer.

Definition at line 335 of file mixer.cpp.

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

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

Parameters:
paused true to pause everything, false to unpause

Implements Audio::Mixer.

Definition at line 400 of file mixer.cpp.

void Audio::MixerImpl::pauseHandle ( SoundHandle  handle,
bool  paused 
) [virtual]

Pause/unpause the sound corresponding to the given handle.

Parameters:
handle the sound to affect
paused true to pause the sound, false to unpause it

Implements Audio::Mixer.

Definition at line 419 of file mixer.cpp.

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

Pause/unpause the sound with the given ID.

Parameters:
id the ID of the sound to affect
paused true to pause the sound, false to unpause it

Implements Audio::Mixer.

Definition at line 409 of file mixer.cpp.

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 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:
type the type (voice/sfx/music) of the stream
handle a SoundHandle which can be used to reference and control the stream via suitable mixer methods
stream the actual AudioStream to be played
id a unique id assigned to this stream
volume the volume with which to play the sound, ranging from 0 to 255
balance the balance with which to play the sound, ranging from -127 to 127 (full left to full right), 0 is balanced, -128 is invalid
autofreeStream a flag indicating whether the stream should be freed after playback finished
permanent a flag indicating whether a plain stopAll call should not stop this particular stream
reverseStereo a flag indicating whether left and right channels shall be swapped

Implements Audio::Mixer.

Definition at line 224 of file mixer.cpp.

void Audio::MixerImpl::setChannelBalance ( SoundHandle  handle,
int8  balance 
) [virtual]

Set the channel balance for the given handle.

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

Implements Audio::Mixer.

Definition at line 368 of file mixer.cpp.

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

Set the channel volume for the given handle.

Parameters:
handle the sound to affect
volume the new channel volume (0 - kMaxChannelVolume)

Implements Audio::Mixer.

Definition at line 350 of file mixer.cpp.

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.

Definition at line 191 of file mixer.cpp.

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

Set the volume for the given sound type.

Parameters:
type the sound type
volume the new global volume, 0 - kMaxMixerVolume

Implements Audio::Mixer.

Definition at line 470 of file mixer.cpp.

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

Stop all currently playing sounds.

Implements Audio::Mixer.

Definition at line 303 of file mixer.cpp.

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

Stop playing the sound corresponding to the given handle.

Parameters:
handle the sound to affect

Implements Audio::Mixer.

Definition at line 323 of file mixer.cpp.

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

Stop playing the sound with given ID.

Parameters:
id the ID of the sound to affect

Implements Audio::Mixer.

Definition at line 313 of file mixer.cpp.


Member Data Documentation

Channel* Audio::MixerImpl::_channels[NUM_CHANNELS] [private]

Definition at line 71 of file mixer_intern.h.

Definition at line 61 of file mixer_intern.h.

Definition at line 60 of file mixer_intern.h.

Definition at line 57 of file mixer_intern.h.

Definition at line 59 of file mixer_intern.h.

Definition at line 70 of file mixer_intern.h.


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


Generated on Sat Jan 19 2019 05:05:22 for ResidualVM by doxygen 1.7.1
curved edge   curved edge