|
Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
|
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< RecordingAudioPacket > | drain_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 |
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.
|
strong |
Definition at line 46 of file audio_recording_session.h.
|
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.
|
inlinenodiscard |
Returns the number of packets dropped due to fifo overflow.
Definition at line 120 of file audio_recording_session.h.
|
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.
| 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()).
| 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.
|
inlinenodiscard |
Definition at line 95 of file audio_recording_session.h.
|
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.
|
staticconstexpr |
Definition at line 58 of file audio_recording_session.h.