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

Per-track recording state with a lock-free SPSC queue. More...

#include <src/controllers/audio_recording_session.h>

Public Types

enum class  State : uint8_t { Armed , Capturing , Finalizing }

Public Member Functions

 AudioRecordingSession (units::sample_u32_t max_block_length)
void prepare_for_processing (units::sample_u32_t block_length)
 Prepares internal buffers for processing at the given block length.
void write_samples (units::sample_t timeline_position, bool transport_recording, std::span< const float > l_data, std::span< const float > r_data) noexcept
 RT-safe: writes audio data into the ring buffer.
std::vector< RecordingAudioPacketdrain_pending ()
 Non-RT: drains all pending packets from the ring buffer.
auto state () const
void finalize () noexcept
 Transitions to Finalizing state, rejecting further writes.
void reset ()
 Resets the session to Armed state for reuse.
uint64_t dropped_packets () const
 Returns the number of packets dropped due to fifo overflow.

Static Public Attributes

static constexpr size_t kFifoCapacity = 1024

Detailed Description

Per-track recording state with a lock-free SPSC queue.

The RT thread writes audio into pre-allocated slots and pushes slot indices onto a farbot SPSC fifo. The non-RT timer drains pending indices and reads the corresponding slot data into RecordingAudioPacket objects.

Thread contracts:

Definition at line 43 of file audio_recording_session.h.

Member Enumeration Documentation

◆ State

enum class zrythm::controllers::AudioRecordingSession::State : uint8_t
strong

Definition at line 46 of file audio_recording_session.h.

Member Function Documentation

◆ drain_pending()

std::vector< RecordingAudioPacket > zrythm::controllers::AudioRecordingSession::drain_pending ( )
nodiscard

Non-RT: drains all pending packets from the ring buffer.

Called from the timer thread. Reads slot indices from the SPSC fifo and copies the slot data into RecordingAudioPacket objects.

◆ dropped_packets()

uint64_t zrythm::controllers::AudioRecordingSession::dropped_packets ( ) const
inlinenodiscard

Returns the number of packets dropped due to fifo overflow.

Definition at line 120 of file audio_recording_session.h.

◆ finalize()

void zrythm::controllers::AudioRecordingSession::finalize ( )
noexcept

Transitions to Finalizing state, rejecting further writes.

Safe to call while write_samples() is in progress on another thread — this only sets an atomic flag. Any in-flight writes will complete normally; subsequent audio callbacks will see Finalizing and skip.

◆ prepare_for_processing()

void zrythm::controllers::AudioRecordingSession::prepare_for_processing ( units::sample_u32_t block_length)

Prepares internal buffers for processing at the given block length.

Buffers are only grown, never shrunk, so a decrease in block length is safe (existing large buffers are kept). Must be called before audio processing starts (not concurrently with write_samples() or drain_pending()).

◆ reset()

void zrythm::controllers::AudioRecordingSession::reset ( )

Resets the session to Armed state for reuse.

Must only be called when neither write_samples() nor drain_pending() are active. Clears all buffered data, recorded regions, and counters.

◆ state()

auto zrythm::controllers::AudioRecordingSession::state ( ) const
inlinenodiscard

Definition at line 95 of file audio_recording_session.h.

◆ write_samples()

void zrythm::controllers::AudioRecordingSession::write_samples ( units::sample_t timeline_position,
bool transport_recording,
std::span< const float > l_data,
std::span< const float > r_data )
noexcept

RT-safe: writes audio data into the ring buffer.

Called from the audio thread. No allocations — copies data into pre-allocated slot memory and pushes the slot index onto the SPSC fifo. If the fifo is full, the slot is overwritten with the latest data but the index is not queued and the dropped counter is incremented. The next call reuses the same slot, so once the consumer drains enough entries the most recent audio is always captured.

Field Documentation

◆ kFifoCapacity

size_t zrythm::controllers::AudioRecordingSession::kFifoCapacity = 1024
staticconstexpr

Definition at line 58 of file audio_recording_session.h.


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