#include <mixer_intern.h>
Public Member Functions | |
| MixerImpl (uint sampleRate, bool stereo=true, uint outBufSize=0) | |
| bool | isReady () const override |
| Common::Mutex & | mutex () 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 } |
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.
|
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.
Implements Audio::Mixer.
|
inlineoverridevirtual |
Return the mixer's internal mutex so that audio players can use it.
Implements Audio::Mixer.
|
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.
| 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.
|
overridevirtual |
Stop all currently playing sounds.
Implements Audio::Mixer.
|
overridevirtual |
|
overridevirtual |
Stop playing the sound corresponding to the given handle.
| handle | The sound to stop playing. |
Implements Audio::Mixer.
|
overridevirtual |
Pause or unpause all sounds, including all regular and permanent channels.
| paused | True to pause everything, false to unpause. |
Implements Audio::Mixer.
|
overridevirtual |
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.
|
overridevirtual |
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.
|
overridevirtual |
Check whether a sound with the given ID is active.
| id | ID of the sound to query. |
Implements Audio::Mixer.
|
overridevirtual |
Get the sound ID for the given handle.
| handle | The sound to query. |
Implements Audio::Mixer.
|
overridevirtual |
Check whether a sound with the given handle is active.
| handle | The sound to query. |
Implements Audio::Mixer.
|
overridevirtual |
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.
|
overridevirtual |
Query the mute state for a given sound type.
| type | Sound type. See SoundType. |
Implements Audio::Mixer.
|
overridevirtual |
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.
|
overridevirtual |
Get the channel volume for the given handle.
| handle | The sound to affect. |
Implements Audio::Mixer.
|
overridevirtual |
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.
|
overridevirtual |
Get the channel balance for the given handle.
| handle | The sound to affect. |
Implements Audio::Mixer.
|
overridevirtual |
Set the channel's left fader level for the given handle.
| handle | The sound to affect. |
| faderL | The channel's new left fader level, in the range of 0-255. |
Implements Audio::Mixer.
|
overridevirtual |
Get the channel's left fader level for the given handle.
| handle | The sound to affect. |
Implements Audio::Mixer.
|
overridevirtual |
Set the channel's right fader level for the given handle.
| handle | The sound to affect. |
| faderR | The channel's new right fader level, in the range of 0-255. |
Implements Audio::Mixer.
|
overridevirtual |
Get the channel's right fader level for the given handle.
| handle | The sound to affect. |
Implements Audio::Mixer.
|
overridevirtual |
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.
|
overridevirtual |
Get the sample rate for the given handle.
| handle | The sound to affect. |
Implements Audio::Mixer.
|
overridevirtual |
Reset the sample rate of the channel back to its AudioStream's native rate.
| handle | The sound to affect. |
Implements Audio::Mixer.
|
overridevirtual |
Get an approximation of for how long the channel has been playing.
Implements Audio::Mixer.
|
overridevirtual |
Get an approximation of for how long the channel has been playing.
Implements Audio::Mixer.
|
overridevirtual |
Replace the channel's stream with a version that loops indefinitely.
Implements Audio::Mixer.
|
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.
| type | The sound type to query. |
Implements Audio::Mixer.
|
overridevirtual |
Set the volume for the given sound type.
| type | Sound type. |
| volume | The new global volume, in the range 0 - kMaxMixerVolume. |
Implements Audio::Mixer.
|
overridevirtual |
Check what the global volume is for a sound type.
| type | Sound type. |
Implements Audio::Mixer.
|
overridevirtual |
Return the output sample rate of the system.
Implements Audio::Mixer.
|
overridevirtual |
Check whether the output is stereo.
Implements Audio::Mixer.
|
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.
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.