QtCraft API C++ classes QML types Handbook

QcAudioMixer Class

Software mixer: plays sample buffers as voices with their own gain, stereo position and speed, grouped into buses with a volume each, under a master volume and a mute switch. More...

Header: #include <clientcore/sound/QcAudioMixer.h>

Public Types

struct PlayParameters
struct Voice
VoiceId

Public Functions

float busVolume(QcSoundBus bus) const
void fadeOut(QcAudioMixer::VoiceId id)
bool isMuted() const
bool isPlaying(QcAudioMixer::VoiceId id) const
float masterVolume() const
std::span<const float> mix(int frames)
int outputRate() const
QcAudioMixer::VoiceId play(std::shared_ptr<const QcSampleBuffer> buffer, const QcAudioMixer::PlayParameters &parameters)
void setBusVolume(QcSoundBus bus, float volume)
void setGain(QcAudioMixer::VoiceId id, float gain)
void setMasterVolume(float volume)
void setMuted(bool muted)
void setPan(QcAudioMixer::VoiceId id, float pan)
void stop(QcAudioMixer::VoiceId id)
void stopAll()
int voiceCount() const
const QList<QcAudioMixer::Voice> &voices() const
QcAudioMixer withRate(int outputRate) const
bool wouldPlay(const std::shared_ptr<const QcSampleBuffer> &buffer, float gain) const

Static Public Members

const int fadeOutMilliseconds
float limit(float sample)
const float limiterKnee
const int maxVoices
std::pair<float, float> panGains(float pan)

Detailed Description

Produces interleaved stereo float frames. Not thread-safe; the audio output guards it with a lock.

Member Type Documentation

[alias] QcAudioMixer::VoiceId

Id of a playing voice; 0 is none.

Member Function Documentation

float QcAudioMixer::busVolume(QcSoundBus bus) const

Returns the volume of bus.

See also setBusVolume().

void QcAudioMixer::fadeOut(QcAudioMixer::VoiceId id)

Lets the voice id fall silent over fadeOutMilliseconds, then removes it; it keeps its place until then and ignores setGain.

bool QcAudioMixer::isMuted() const

Returns whether the output is muted.

bool QcAudioMixer::isPlaying(QcAudioMixer::VoiceId id) const

Returns whether voice id is playing (also while it fades out).

[static] float QcAudioMixer::limit(float sample)

Returns sample through a soft limiter: unchanged up to limiterKnee, then bent so that |result| < 1 for any input.

float QcAudioMixer::masterVolume() const

Returns the master volume.

See also setMasterVolume().

std::span<const float> QcAudioMixer::mix(int frames)

Returns the next frames interleaved stereo frames (left, right), mixed into the mixer's own buffer (it keeps its capacity, so mixing allocates nothing once it has grown) and advances all voices; voices that ran out are removed. The view stays valid until the next call.

int QcAudioMixer::outputRate() const

Returns the output rate in frames per second.

[static] std::pair<float, float> QcAudioMixer::panGains(float pan)

Returns the left and right gain of the stereo position pan (constant power: both 1/sqrt(2) in the centre).

QcAudioMixer::VoiceId QcAudioMixer::play(std::shared_ptr<const QcSampleBuffer> buffer, const QcAudioMixer::PlayParameters &parameters)

Starts a voice playing buffer with parameters and returns its id; 0 when the buffer is empty or every voice loops and none can be replaced.

void QcAudioMixer::setBusVolume(QcSoundBus bus, float volume)

Sets the volume of bus to volume (clamped to 0..1; not finite: 0).

See also busVolume().

void QcAudioMixer::setGain(QcAudioMixer::VoiceId id, float gain)

Sets the gain of voice id to gain (at least 0; not finite: 0); ignored while it fades out.

void QcAudioMixer::setMasterVolume(float volume)

Sets the master volume to volume (clamped to 0..1; not finite: 0).

See also masterVolume().

void QcAudioMixer::setMuted(bool muted)

Mutes the output when muted, keeping every voice running.

See also isMuted().

void QcAudioMixer::setPan(QcAudioMixer::VoiceId id, float pan)

Sets the stereo position of voice id to pan (clamped to -1..1; not finite: 0); ignored while it fades out.

void QcAudioMixer::stop(QcAudioMixer::VoiceId id)

Stops the voice id at once.

void QcAudioMixer::stopAll()

Stops every voice at once.

int QcAudioMixer::voiceCount() const

Returns the number of voices.

const QList<QcAudioMixer::Voice> &QcAudioMixer::voices() const

Returns the voices.

QcAudioMixer QcAudioMixer::withRate(int outputRate) const

Returns a mixer at outputRate without voices, with this one's bus and master volumes and mute (for an output device that runs at another rate).

bool QcAudioMixer::wouldPlay(const std::shared_ptr<const QcSampleBuffer> &buffer, float gain) const

Returns whether play() would start a voice for buffer at gain now.

Member Variable Documentation

const int QcAudioMixer::fadeOutMilliseconds

A voice stopped with fadeOut() falls silent over this time instead of cutting off (a click).

const float QcAudioMixer::limiterKnee

Above this level the limiter bends the signal smoothly towards (but never reaching) 1.

const int QcAudioMixer::maxVoices

When all voices are busy, a new sound replaces the quietest one that does not loop.