lmms
Cross-platform music production software
Loading...
Searching...
No Matches
lmms::AudioEngine Class Reference

#include <AudioEngine.h>

Inheritance diagram for lmms::AudioEngine:

Classes

class  RequestChangesGuard
 RAII helper for requestChangesInModel. Used by AudioEngine::requestChangesGuard. More...

Signals

void qualitySettingsChanged ()
void sampleRateChanged ()
void nextAudioBuffer (const lmms::SampleFrame *buffer)

Public Member Functions

void initDevices ()
void clear ()
void clearNewPlayHandles ()
bool renderOnly () const
const QString & audioDevName () const
bool audioDevStartFailed () const
void setAudioDevice (AudioDevice *_dev, bool startNow)
void storeAudioDevice ()
void restoreAudioDevice ()
AudioDevice * audioDev ()
void addAudioBusHandle (AudioBusHandle *busHandle)
void removeAudioBusHandle (AudioBusHandle *busHandle)
const QString & midiClientName () const
MidiClient * midiClient ()
bool addPlayHandle (PlayHandle *handle)
void removePlayHandle (PlayHandle *handle)
PlayHandleList & playHandles ()
void removePlayHandlesOfTypes (Track *track, PlayHandle::Types types)
AudioEngineProfiler & profiler ()
int cpuLoad () const
int detailLoad (const AudioEngineProfiler::DetailType type) const
sample_rate_t baseSampleRate () const
sample_rate_t outputSampleRate () const
sample_rate_t inputSampleRate () const
float masterGain () const
void setMasterGain (const float mo)
bool criticalXRuns () const
void pushInputFrames (SampleFrame *_ab, const f_cnt_t _frames)
const SampleFrame * inputBuffer ()
f_cnt_t inputBufferFrames () const
f_cnt_t framesPerPeriod () const
f_cnt_t framesPerAudioBuffer () const
std::span< const SampleFrame > renderNextPeriod ()
 Renders the next audio period.
void renderNextBuffer (InterleavedBufferView< float > dst)
 Renders an audio buffer into dst.
void renderNextBuffer (PlanarBufferView< float > dst)
 Renders an audio buffer into dst.
void requestChangeInModel ()
 Block until a change in model can be done (i.e. wait for audio thread).
void doneChangeInModel ()
RequestChangesGuard requestChangesGuard ()
bool sanitizationEnabled ()
void setSanitizationEnabled (bool enabled)
 Enable/disable sanitization of inf/nan values.

Static Public Member Functions

static sample_t clip (const sample_t s)
static bool isAudioDevNameValid (QString name)
static bool isMidiDevNameValid (QString name)

Private Member Functions

void renderNextBuffer (AudioBufferView< float > auto dst)
 AudioEngine (bool renderOnly)
 ~AudioEngine () override
void startProcessing ()
void stopProcessing ()
AudioDevice * tryAudioDevices ()
MidiClient * tryMidiClients ()
void renderStageNoteSetup ()
void renderStageInstruments ()
void renderStageEffects ()
void renderStageMix ()
void swapBuffers ()
void clearInternal ()
void doSetAudioDevice (AudioDevice *_dev)

Private Attributes

bool m_renderOnly
std::vector< AudioBusHandle * > m_audioBusHandles
f_cnt_t m_framesPerAudioBuffer
f_cnt_t m_framesPerPeriod
sample_rate_t m_baseSampleRate
SampleFrame * m_inputBuffer [2]
f_cnt_t m_inputBufferFrames [2]
f_cnt_t m_inputBufferSize [2]
int m_inputBufferRead
int m_inputBufferWrite
std::unique_ptr< SampleFrame[]> m_outputBufferRead
std::unique_ptr< SampleFrame[]> m_outputBufferWrite
f_cnt_t m_outputBufferReadIndex
std::vector< AudioEngineWorkerThread * > m_workers
int m_numWorkers
PlayHandleList m_playHandles
LocklessList< PlayHandle * > m_newPlayHandles
ConstPlayHandleList m_playHandlesToRemove
float m_masterGain
AudioDevice * m_audioDev
AudioDevice * m_oldAudioDev
QString m_audioDevName
bool m_audioDevStartFailed
MidiClient * m_midiClient
QString m_midiClientName
AudioEngineProfiler m_profiler
bool m_clearSignal
std::atomic< bool > m_sanitizationEnabled = false
std::recursive_mutex m_changeMutex

Friends

class Engine
class AudioEngineWorkerThread
class ProjectRenderer

Constructor & Destructor Documentation

◆ AudioEngine()

lmms::AudioEngine::AudioEngine ( bool renderOnly)
private

◆ ~AudioEngine()

lmms::AudioEngine::~AudioEngine ( )
overrideprivate

Member Function Documentation

◆ addAudioBusHandle()

void lmms::AudioEngine::addAudioBusHandle ( AudioBusHandle * busHandle)
inline

◆ addPlayHandle()

bool lmms::AudioEngine::addPlayHandle ( PlayHandle * handle)

◆ audioDev()

AudioDevice * lmms::AudioEngine::audioDev ( )
inline

◆ audioDevName()

const QString & lmms::AudioEngine::audioDevName ( ) const
inline

◆ audioDevStartFailed()

bool lmms::AudioEngine::audioDevStartFailed ( ) const
inline

◆ baseSampleRate()

sample_rate_t lmms::AudioEngine::baseSampleRate ( ) const
inline

◆ clear()

void lmms::AudioEngine::clear ( )

◆ clearInternal()

void lmms::AudioEngine::clearInternal ( )
private

◆ clearNewPlayHandles()

void lmms::AudioEngine::clearNewPlayHandles ( )

◆ clip()

sample_t lmms::AudioEngine::clip ( const sample_t s)
inlinestatic

◆ cpuLoad()

int lmms::AudioEngine::cpuLoad ( ) const
inline

◆ criticalXRuns()

bool lmms::AudioEngine::criticalXRuns ( ) const

◆ detailLoad()

int lmms::AudioEngine::detailLoad ( const AudioEngineProfiler::DetailType type) const
inline

◆ doneChangeInModel()

void lmms::AudioEngine::doneChangeInModel ( )

◆ doSetAudioDevice()

void lmms::AudioEngine::doSetAudioDevice ( AudioDevice * _dev)
private

◆ framesPerAudioBuffer()

f_cnt_t lmms::AudioEngine::framesPerAudioBuffer ( ) const
inline
Returns
The buffer size used by the configured output audio device. It is in the range of MINIMUM_BUFFER_SIZE and MAXIMUM_BUFFER_SIZE.
Note
This should not be needed for a majority of cases. Currently, it's only being used to set up the audio devices. This member function may be removed in a later refactor.

◆ framesPerPeriod()

f_cnt_t lmms::AudioEngine::framesPerPeriod ( ) const
inline
Returns
The internal buffer size used by audio plugins and other processing done within the audio engine. Its value is DEFAULT_BUFFER_SIZE or framesPerAudioBuffer(), whichever is lower.
See also
renderNextPeriod()

◆ initDevices()

void lmms::AudioEngine::initDevices ( )

◆ inputBuffer()

const SampleFrame * lmms::AudioEngine::inputBuffer ( )
inline

◆ inputBufferFrames()

f_cnt_t lmms::AudioEngine::inputBufferFrames ( ) const
inline

◆ inputSampleRate()

sample_rate_t lmms::AudioEngine::inputSampleRate ( ) const
inline

◆ isAudioDevNameValid()

bool lmms::AudioEngine::isAudioDevNameValid ( QString name)
static

◆ isMidiDevNameValid()

bool lmms::AudioEngine::isMidiDevNameValid ( QString name)
static

◆ masterGain()

float lmms::AudioEngine::masterGain ( ) const
inline

◆ midiClient()

MidiClient * lmms::AudioEngine::midiClient ( )
inline

◆ midiClientName()

const QString & lmms::AudioEngine::midiClientName ( ) const
inline

◆ nextAudioBuffer

void lmms::AudioEngine::nextAudioBuffer ( const lmms::SampleFrame * buffer)
signal

◆ outputSampleRate()

sample_rate_t lmms::AudioEngine::outputSampleRate ( ) const
inline

◆ playHandles()

PlayHandleList & lmms::AudioEngine::playHandles ( )
inline

◆ profiler()

AudioEngineProfiler & lmms::AudioEngine::profiler ( )
inline

◆ pushInputFrames()

void lmms::AudioEngine::pushInputFrames ( SampleFrame * _ab,
const f_cnt_t _frames )

◆ qualitySettingsChanged

void lmms::AudioEngine::qualitySettingsChanged ( )
signal

◆ removeAudioBusHandle()

void lmms::AudioEngine::removeAudioBusHandle ( AudioBusHandle * busHandle)

◆ removePlayHandle()

void lmms::AudioEngine::removePlayHandle ( PlayHandle * handle)

◆ removePlayHandlesOfTypes()

void lmms::AudioEngine::removePlayHandlesOfTypes ( Track * track,
PlayHandle::Types types )

◆ renderNextBuffer() [1/3]

void lmms::AudioEngine::renderNextBuffer ( AudioBufferView< float > auto dst)
inlineprivate

◆ renderNextBuffer() [2/3]

void lmms::AudioEngine::renderNextBuffer ( InterleavedBufferView< float > dst)
inline

Renders an audio buffer into dst.

Renders audio periods into dst. If dst is not a multiple of the period size, the remaining frames are partially rendered (an extra period may be rendered in such cases, which can degrade performance).

If dst has 1 channel, the channels are averaged to mono. If dst has 2 channels, the channels are directly copied. If dst has more than 2 channels, the stereo channels are copied and the rest are zero-filled.

Parameters
dstAn audio buffer view to write into. Both interleaved and planar overloads are provided.

◆ renderNextBuffer() [3/3]

void lmms::AudioEngine::renderNextBuffer ( PlanarBufferView< float > dst)
inline

Renders an audio buffer into dst.

Renders audio periods into dst. If dst is not a multiple of the period size, the remaining frames are partially rendered (an extra period may be rendered in such cases, which can degrade performance).

If dst has 1 channel, the channels are averaged to mono. If dst has 2 channels, the channels are directly copied. If dst has more than 2 channels, the stereo channels are copied and the rest are zero-filled.

Parameters
dstAn audio buffer view to write into. Both interleaved and planar overloads are provided.

◆ renderNextPeriod()

std::span< const SampleFrame > lmms::AudioEngine::renderNextPeriod ( )

Renders the next audio period.

An audio period is a fixed-size chunk of audio the engine generates, and represents a single cycle of the engine's output. The rendering is chunked into smaller periods to timely handle per-buffer updates like non-sample-accurate automation, as well as to improve memory cache performance.

The audio period generated is interleaved and stereo.

Note
The audio period returned is non-owning and will be changed on subsequent calls to renderNextPeriod() and renderNextBuffer(). Callers must copy the data into their own local buffers if they need it to persist.
Returns
A non-owning buffer to the next audio period.

◆ renderOnly()

bool lmms::AudioEngine::renderOnly ( ) const
inline

◆ renderStageEffects()

void lmms::AudioEngine::renderStageEffects ( )
private

◆ renderStageInstruments()

void lmms::AudioEngine::renderStageInstruments ( )
private

◆ renderStageMix()

void lmms::AudioEngine::renderStageMix ( )
private

◆ renderStageNoteSetup()

void lmms::AudioEngine::renderStageNoteSetup ( )
private

◆ requestChangeInModel()

void lmms::AudioEngine::requestChangeInModel ( )

Block until a change in model can be done (i.e. wait for audio thread).

◆ requestChangesGuard()

RequestChangesGuard lmms::AudioEngine::requestChangesGuard ( )
inline

◆ restoreAudioDevice()

void lmms::AudioEngine::restoreAudioDevice ( )

◆ sampleRateChanged

void lmms::AudioEngine::sampleRateChanged ( )
signal

◆ sanitizationEnabled()

bool lmms::AudioEngine::sanitizationEnabled ( )
inline
Returns
true if sanitization of inf/nan values is enabled

◆ setAudioDevice()

void lmms::AudioEngine::setAudioDevice ( AudioDevice * _dev,
bool startNow )

Set new audio device. Old device will be deleted, unless it's stored using storeAudioDevice

◆ setMasterGain()

void lmms::AudioEngine::setMasterGain ( const float mo)
inline

◆ setSanitizationEnabled()

void lmms::AudioEngine::setSanitizationEnabled ( bool enabled)
inline

Enable/disable sanitization of inf/nan values.

◆ startProcessing()

void lmms::AudioEngine::startProcessing ( )
inlineprivate

◆ stopProcessing()

void lmms::AudioEngine::stopProcessing ( )
inlineprivate

◆ storeAudioDevice()

void lmms::AudioEngine::storeAudioDevice ( )

◆ swapBuffers()

void lmms::AudioEngine::swapBuffers ( )
private

◆ tryAudioDevices()

AudioDevice * lmms::AudioEngine::tryAudioDevices ( )
private

◆ tryMidiClients()

MidiClient * lmms::AudioEngine::tryMidiClients ( )
private

◆ AudioEngineWorkerThread

friend class AudioEngineWorkerThread
friend

◆ Engine

friend class Engine
friend

◆ ProjectRenderer

friend class ProjectRenderer
friend

Member Data Documentation

◆ m_audioBusHandles

std::vector<AudioBusHandle*> lmms::AudioEngine::m_audioBusHandles
private

◆ m_audioDev

AudioDevice* lmms::AudioEngine::m_audioDev
private

◆ m_audioDevName

QString lmms::AudioEngine::m_audioDevName
private

◆ m_audioDevStartFailed

bool lmms::AudioEngine::m_audioDevStartFailed
private

◆ m_baseSampleRate

sample_rate_t lmms::AudioEngine::m_baseSampleRate
private

◆ m_changeMutex

std::recursive_mutex lmms::AudioEngine::m_changeMutex
private

◆ m_clearSignal

bool lmms::AudioEngine::m_clearSignal
private

◆ m_framesPerAudioBuffer

f_cnt_t lmms::AudioEngine::m_framesPerAudioBuffer
private

◆ m_framesPerPeriod

f_cnt_t lmms::AudioEngine::m_framesPerPeriod
private

◆ m_inputBuffer

SampleFrame* lmms::AudioEngine::m_inputBuffer[2]
private

◆ m_inputBufferFrames

f_cnt_t lmms::AudioEngine::m_inputBufferFrames[2]
private

◆ m_inputBufferRead

int lmms::AudioEngine::m_inputBufferRead
private

◆ m_inputBufferSize

f_cnt_t lmms::AudioEngine::m_inputBufferSize[2]
private

◆ m_inputBufferWrite

int lmms::AudioEngine::m_inputBufferWrite
private

◆ m_masterGain

float lmms::AudioEngine::m_masterGain
private

◆ m_midiClient

MidiClient* lmms::AudioEngine::m_midiClient
private

◆ m_midiClientName

QString lmms::AudioEngine::m_midiClientName
private

◆ m_newPlayHandles

LocklessList<PlayHandle *> lmms::AudioEngine::m_newPlayHandles
private

◆ m_numWorkers

int lmms::AudioEngine::m_numWorkers
private

◆ m_oldAudioDev

AudioDevice* lmms::AudioEngine::m_oldAudioDev
private

◆ m_outputBufferRead

std::unique_ptr<SampleFrame[]> lmms::AudioEngine::m_outputBufferRead
private

◆ m_outputBufferReadIndex

f_cnt_t lmms::AudioEngine::m_outputBufferReadIndex
private

◆ m_outputBufferWrite

std::unique_ptr<SampleFrame[]> lmms::AudioEngine::m_outputBufferWrite
private

◆ m_playHandles

PlayHandleList lmms::AudioEngine::m_playHandles
private

◆ m_playHandlesToRemove

ConstPlayHandleList lmms::AudioEngine::m_playHandlesToRemove
private

◆ m_profiler

AudioEngineProfiler lmms::AudioEngine::m_profiler
private

◆ m_renderOnly

bool lmms::AudioEngine::m_renderOnly
private

◆ m_sanitizationEnabled

std::atomic<bool> lmms::AudioEngine::m_sanitizationEnabled = false
private

◆ m_workers

std::vector<AudioEngineWorkerThread *> lmms::AudioEngine::m_workers
private

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