#include <mixer_intern.h>
Public Member Functions | |
MixerImpl (uint sampleRate, bool stereo=true, uint outBufSize=0) | |
virtual bool | isReady () const |
virtual Common::Mutex & | mutex () |
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 } |
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.
|
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.
Implements Audio::Mixer.
|
inlinevirtual |
Return the mixer's internal mutex so that audio players can use it.
Implements Audio::Mixer.
|
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.
type | Type of the stream - voice/SFX/music. |
handle | A SoundHandle instance that can be used to reference and control the stream using suitable mixer methods. |
stream | The actual AudioStream to be played. |
id | Unique ID assigned to this stream. |
volume | Volume with which to play the sound, ranging from 0 to 255. |
balance | Balance with which to play the sound, ranging from -127 to 127 (full left to full right). 0 is balanced, -128 is invalid. |
autofreeStream | If set, the stream will be freed after the playback is finished. |
permanent | If set, a plain stopAll call will not stop this particular stream. |
reverseStereo | If set, left and right channels will be swapped. |
Implements Audio::Mixer.
|
virtual |
Stop all currently playing sounds.
Implements Audio::Mixer.
|
virtual |
|
virtual |
Stop playing the sound corresponding to the given handle.
handle | The sound to stop playing. |
Implements Audio::Mixer.
|
virtual |
Pause or unpause all sounds, including all regular and permanent channels.
paused | True to pause everything, false to unpause. |
Implements Audio::Mixer.
|
virtual |
Pause or unpause the sound with the given ID.
id | ID of the sound. |
paused | True to pause the sound, false to unpause it. |
Implements Audio::Mixer.
|
virtual |
Pause or unpause the sound corresponding to the given handle.
handle | The sound to pause or unpause. |
paused | True to pause the sound, false to unpause it. |
Implements Audio::Mixer.
|
virtual |
Check whether a sound with the given ID is active.
id | ID of the sound to query. |
Implements Audio::Mixer.
|
virtual |
Get the sound ID for the given handle.
handle | The sound to query. |
Implements Audio::Mixer.
|
virtual |
Check whether a sound with the given handle is active.
handle | The sound to query. |
Implements Audio::Mixer.
|
virtual |
Set the mute state for a given sound type.
type | Sound type. See SoundType. |
mute | Whether to mute (= true) or not (= false). |
Implements Audio::Mixer.
|
virtual |
Query the mute state for a given sound type.
type | Sound type. See SoundType. |
Implements Audio::Mixer.
|
virtual |
Set the channel volume for the given handle.
handle | The sound to affect. |
volume | The new channel volume, in the range 0 - kMaxChannelVolume. |
Implements Audio::Mixer.
|
virtual |
Get the channel volume for the given handle.
handle | The sound to affect. |
Implements Audio::Mixer.
|
virtual |
Set the channel balance for the given handle.
handle | The sound to affect. |
balance | The new channel balance: (-127 ... 0 ... 127) corresponds to (left ... center ... right) |
Implements Audio::Mixer.
|
virtual |
Get the channel balance for the given handle.
handle | The sound to affect. |
Implements Audio::Mixer.
|
virtual |
Set the sample rate for the given handle.
handle | The sound to affect. |
rate | The new sample rate. Must be less than 131072 |
Implements Audio::Mixer.
|
virtual |
Get the sample rate for the given handle.
handle | The sound to affect. |
Implements Audio::Mixer.
|
virtual |
Reset the sample rate of the channel back to its AudioStream's native rate.
handle | The sound to affect. |
Implements Audio::Mixer.
|
virtual |
Get an approximation of for how long the channel has been playing.
Implements Audio::Mixer.
|
virtual |
Get an approximation of for how long the channel has been playing.
Implements Audio::Mixer.
|
virtual |
Replace the channel's stream with a version that loops indefinitely.
Implements Audio::Mixer.
|
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.
type | The sound type to query. |
Implements Audio::Mixer.
|
virtual |
Set the volume for the given sound type.
type | Sound type. |
volume | The new global volume, in the range 0 - kMaxMixerVolume. |
Implements Audio::Mixer.
|
virtual |
Check what the global volume is for a sound type.
type | Sound type. |
Implements Audio::Mixer.
|
virtual |
Return the output sample rate of the system.
Implements Audio::Mixer.
|
virtual |
Check whether the output is stereo.
Implements Audio::Mixer.
|
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.
Implements Audio::Mixer.
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.
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). |
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.