Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
zrythm::dsp::AudioEngine Class Reference

The audio engine. More...

#include <src/dsp/engine.h>

Inheritance diagram for zrythm::dsp::AudioEngine:
Collaboration diagram for zrythm::dsp::AudioEngine:

Data Structures

struct  EngineState

Public Types

enum class  State : std::uint8_t { Uninitialized , Initialized , Active }
enum class  ProcessReturnStatus : std::uint8_t { ProcessCompleted , ProcessSkipped , ProcessFailed }

Public Member Functions

 AudioEngine (dsp::Transport &transport, IHardwareAudioInterface &hw_interface, dsp::DspGraphDispatcher &graph_dispatcher, const dsp::TempoMap &tempo_map, QObject *parent=nullptr)
 Create a new audio engine.
 ~AudioEngine () override
 Closes any connections and free's data.
Q_INVOKABLE int xRunCount () const
Q_INVOKABLE double loadPercentage () const
int sampleRate () const
 Current sample rate from the hardware interface (QML-friendly).
int blockLength () const
 Current block length from the hardware interface (QML-friendly).
Q_SIGNAL void sampleRateChanged (int sampleRate)
Q_SIGNAL void blockLengthChanged (int blockLength)
units::sample_rate_t sample_rate () const
 Current sample rate as a unit type.
units::sample_u32_t block_length () const
 Current block length as a unit type.
utils::Utf8String device_name () const
 Current audio device name from the hardware interface.
void wait_for_pause (EngineState &state, bool force_pause, bool with_fadeout)
void resume (const EngineState &state)
Q_INVOKABLE void activate ()
 Activate the engine if not already active.
Q_INVOKABLE void deactivate ()
 Deactivates the engine if active.
bool process_prepare (dsp::Transport::TransportSnapshot &transport_snapshot, units::sample_u32_t nframes, SemaphoreRAII< moodycamel::LightweightSemaphore > &sem) noexcept
 To be called by each implementation to prepare the structures before processing.
auto process (const dsp::PlayheadProcessingGuard &playhead_guard, units::sample_u32_t total_frames_to_process) noexcept -> ProcessReturnStatus
 Processes current cycle.
void advance_playhead_after_processing (dsp::Transport::TransportSnapshot &transport_snapshot, const dsp::PlayheadProcessingGuard &playhead_guard, units::sample_u32_t roll_nframes, units::sample_u32_t nframes) noexcept
 Advances the playhead if transport is rolling.
auto & get_monitor_out_port ()
auto * midi_panic_processor () const
auto * audio_input_processor () const
 Returns the audio input processor, or nullptr if no audio device has started.
void panic_all ()
 Queues MIDI note off to event queues.
bool activated () const
bool running () const
void set_running (bool run)
auto & graph_dispatcher ()
bool exporting () const
void set_exporting (bool exporting)
auto get_processing_lock ()
void execute_function_with_paused_processing_synchronously (const std::function< void()> &func, bool recalculate_graph)
 Executes the given function after pausing processing and then resumes processing.

Properties

int sampleRate
int blockLength

Detailed Description

The audio engine.

Definition at line 24 of file engine.h.

Member Enumeration Documentation

◆ ProcessReturnStatus

enum class zrythm::dsp::AudioEngine::ProcessReturnStatus : std::uint8_t
strong

Definition at line 145 of file engine.h.

◆ State

enum class zrythm::dsp::AudioEngine::State : std::uint8_t
strong

Definition at line 33 of file engine.h.

Constructor & Destructor Documentation

◆ AudioEngine()

zrythm::dsp::AudioEngine::AudioEngine ( dsp::Transport & transport,
IHardwareAudioInterface & hw_interface,
dsp::DspGraphDispatcher & graph_dispatcher,
const dsp::TempoMap & tempo_map,
QObject * parent = nullptr )

Create a new audio engine.

This only initializes the engine and does not connect to any backend.

Member Function Documentation

◆ activate()

Q_INVOKABLE void zrythm::dsp::AudioEngine::activate ( )

Activate the engine if not already active.

This method is idempotent.

◆ activated()

bool zrythm::dsp::AudioEngine::activated ( ) const
inline

Definition at line 196 of file engine.h.

◆ advance_playhead_after_processing()

void zrythm::dsp::AudioEngine::advance_playhead_after_processing ( dsp::Transport::TransportSnapshot & transport_snapshot,
const dsp::PlayheadProcessingGuard & playhead_guard,
units::sample_u32_t roll_nframes,
units::sample_u32_t nframes )
noexcept

Advances the playhead if transport is rolling.

Parameters
roll_nframesFrames to roll (add to the playhead - if transport rolling).
nframesTotal frames for this processing cycle.

◆ audio_input_processor()

auto * zrythm::dsp::AudioEngine::audio_input_processor ( ) const
inline

Returns the audio input processor, or nullptr if no audio device has started.

Definition at line 186 of file engine.h.

◆ deactivate()

Q_INVOKABLE void zrythm::dsp::AudioEngine::deactivate ( )

Deactivates the engine if active.

This method is idempotent.

◆ execute_function_with_paused_processing_synchronously()

void zrythm::dsp::AudioEngine::execute_function_with_paused_processing_synchronously ( const std::function< void()> & func,
bool recalculate_graph )

Executes the given function after pausing processing and then resumes processing.

Parameters
recalculate_graphWhether to also recreate the processing graph before resuming processing.

◆ exporting()

bool zrythm::dsp::AudioEngine::exporting ( ) const
inline

Definition at line 201 of file engine.h.

◆ get_monitor_out_port()

auto & zrythm::dsp::AudioEngine::get_monitor_out_port ( )
inline

Definition at line 178 of file engine.h.

◆ get_processing_lock()

auto zrythm::dsp::AudioEngine::get_processing_lock ( )
inline

Definition at line 204 of file engine.h.

◆ graph_dispatcher()

auto & zrythm::dsp::AudioEngine::graph_dispatcher ( )
inline

Definition at line 199 of file engine.h.

◆ loadPercentage()

Q_INVOKABLE double zrythm::dsp::AudioEngine::loadPercentage ( ) const
inline

Definition at line 74 of file engine.h.

◆ midi_panic_processor()

auto * zrythm::dsp::AudioEngine::midi_panic_processor ( ) const
inline

Definition at line 180 of file engine.h.

◆ process()

auto zrythm::dsp::AudioEngine::process ( const dsp::PlayheadProcessingGuard & playhead_guard,
units::sample_u32_t total_frames_to_process ) -> ProcessReturnStatus
noexcept

Processes current cycle.

To be called by each implementation in its callback.

◆ process_prepare()

bool zrythm::dsp::AudioEngine::process_prepare ( dsp::Transport::TransportSnapshot & transport_snapshot,
units::sample_u32_t nframes,
SemaphoreRAII< moodycamel::LightweightSemaphore > & sem )
noexcept

To be called by each implementation to prepare the structures before processing.

Clears buffers, marks all as unprocessed, etc.

Parameters
semSemamphoreRAII to check if acquired. If not acquired before calling this function, it will only clear output buffers and return true.
Returns
Whether the cycle should be skipped.

◆ running()

bool zrythm::dsp::AudioEngine::running ( ) const
inline

Definition at line 197 of file engine.h.

◆ set_exporting()

void zrythm::dsp::AudioEngine::set_exporting ( bool exporting)
inline

Definition at line 202 of file engine.h.

◆ set_running()

void zrythm::dsp::AudioEngine::set_running ( bool run)
inline

Definition at line 198 of file engine.h.

◆ wait_for_pause()

void zrythm::dsp::AudioEngine::wait_for_pause ( EngineState & state,
bool force_pause,
bool with_fadeout )
Parameters
force_pauseWhether to force transport pause, otherwise for engine to process and handle the pause request.

◆ xRunCount()

Q_INVOKABLE int zrythm::dsp::AudioEngine::xRunCount ( ) const
inline

Definition at line 73 of file engine.h.

Property Documentation

◆ blockLength

int zrythm::dsp::AudioEngine::blockLength
read

Definition at line 28 of file engine.h.

◆ sampleRate

int zrythm::dsp::AudioEngine::sampleRate
read

Definition at line 27 of file engine.h.


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