QtCraft API C++ classes QML types Handbook

QcAudioOutput Class

Plays the mixer through the default audio output of a QcAudioPlatform (the system's, QcSystemAudio, unless a test passes another). More...

Header: #include <audio/QcAudioOutput.h>
Inherits: QObject

Public Functions

QcAudioOutput(QObject *parent = nullptr)
QcAudioOutput(std::unique_ptr<QcAudioPlatform> platform, QObject *parent = nullptr)
QcAudioOutput(const QcAudioOutput &)
QcAudioOutput(QcAudioOutput &&)
QByteArray deviceId() const
QString error() const
qint64 framesRendered() const
bool isActive() const
int sampleRate() const
void setRetryDelay(std::chrono::milliseconds delay)
bool start()
void stop()
void withMixer(const std::function<void (QcAudioMixer &)> &change)
QcAudioOutput &operator=(QcAudioOutput &&)
QcAudioOutput &operator=(const QcAudioOutput &)

Signals

void mixerReset()

Static Public Members

const int maxRetries
const std::chrono::milliseconds retryDelay
const qint64 stableMilliseconds

Detailed Description

The sink pulls the mixer on the audio thread, so every access to the mixer goes through withMixer(). Without a usable device the output stays inactive and the game is silent. From start() on it follows the system's devices (QcAudioRoute): a new default output, the current one going away or a first device appearing moves the sound to the default output, keeping the mixer with its voices when the new device takes the mixer's rate. A sink that fails while playing (a device invalidated by a format or profile change, which keeps the same default device) is opened again after retryDelay, at most maxRetries times in a row.

Member Function Documentation

[explicit] QcAudioOutput::QcAudioOutput(QObject *parent = nullptr)

An output on the system's audio (QcSystemAudio), child of parent.

[explicit] QcAudioOutput::QcAudioOutput(std::unique_ptr<QcAudioPlatform> platform, QObject *parent = nullptr)

An output on platform (tests pass a fake one), child of parent.

[delete] QcAudioOutput::QcAudioOutput(const QcAudioOutput &)

Copy-constructs an instance of QcAudioOutput. This function is deleted.

[delete] QcAudioOutput::QcAudioOutput(QcAudioOutput &&)

Move-constructs an instance of QcAudioOutput. This function is deleted.

QByteArray QcAudioOutput::deviceId() const

Returns the id of the device playing now; empty while none is open.

QString QcAudioOutput::error() const

Returns why the last start or switch of the device failed; empty after a success.

qint64 QcAudioOutput::framesRendered() const

Returns the stereo frames rendered so far; readable from any thread.

bool QcAudioOutput::isActive() const

Returns whether a device plays.

[signal] void QcAudioOutput::mixerReset()

The mixer was replaced by a silent one at a new rate (the first device opened, or one that does not take the old rate): sounds rendered for the old rate should be rendered again.

int QcAudioOutput::sampleRate() const

Returns the rate of the mixer in frames per second.

void QcAudioOutput::setRetryDelay(std::chrono::milliseconds delay)

Sets the pause before opening the output again after a sink error to delay (tests shorten it).

bool QcAudioOutput::start()

Opens the default output device and follows device changes from now on. Returns false and keeps silent when there is none or it cannot be opened (until a usable device appears); the reason is in error() and logged.

void QcAudioOutput::stop()

Closes the device and stops following device changes.

void QcAudioOutput::withMixer(const std::function<void (QcAudioMixer &)> &change)

Runs change with the mixer locked against the audio thread.

[delete] QcAudioOutput &QcAudioOutput::operator=(QcAudioOutput &&)

Move-assigns other to this QcAudioOutput instance. This function is deleted.

[delete] QcAudioOutput &QcAudioOutput::operator=(const QcAudioOutput &)

Copy-assigns other to this QcAudioOutput instance. This function is deleted.

Member Variable Documentation

const int QcAudioOutput::maxRetries

Attempts to open the output again after a sink error before giving up until the devices change.

const std::chrono::milliseconds QcAudioOutput::retryDelay

The pause before opening the output again after a sink error.

const qint64 QcAudioOutput::stableMilliseconds

A sink that played this long before it failed starts a new series of retries.