Sound Byte Libs 0.5.1-340-gab5b79a
C++ firmware library for audio applications on 32-bit ARM Cortex-M processors
Loading...
Searching...
No Matches
sbl::diagnostics::AudioCapture< MaxFrames > Class Template Reference

Always-on audio capture ring buffer for host-side analysis. More...

Detailed Description

template<uint16_t MaxFrames = 4096>
class sbl::diagnostics::AudioCapture< MaxFrames >

Always-on audio capture ring buffer for host-side analysis.

Continuously records the last MaxFrames of audio into a circular buffer. No arming needed - the buffer always has the latest audio. To read:

  1. Freeze the buffer (via SWD write or app trigger) - audio keeps playing
  2. Read pos_ to know the ring head position
  3. Read buf_left_/buf_right_ via sbl-debugger
  4. Unfreeze to resume capture
  5. Unroll the ring: [pos_..MaxFrames) then [0..pos_) = chronological order

The sbl-debugger audio_capture tool handles all of this automatically.

Example:

void audio_callback(int32_t* tx, const int32_t* rx, uint16_t frames) {
render(left_buf, right_buf, frames);
audio_capture.feed(left_buf, right_buf, frames);
sbl::dsp::types::interleave_from_float(left_buf, right_buf, tx, frames);
}
Always-on audio capture ring buffer for host-side analysis.
void feed(const float *left, const float *right, uint16_t frames)
Write one block into the ring; a no-op when frozen.
void interleave_from_float(const float *left, const float *right, S24RjI32 *interleaved, uint16_t frames)
Interleave float L/R buffers into stereo codec words.
Definition convert.hpp:93

When frozen, feed() is a single branch.

Template parameter MaxFrames controls buffer size and capture duration:

2048 -> 16 KB stereo, 42.7 ms @ 48kHz
4096 -> 32 KB stereo, 85.3 ms @ 48kHz (default)
8192 -> 64 KB stereo, 170.7 ms @ 48kHz
16384 -> 128 KB stereo, 341.3 ms @ 48kHz

Definition at line 54 of file audio_capture.hpp.

#include <audio_capture.hpp>

Public Member Functions

void feed (const float *left, const float *right, uint16_t frames)
 Write one block into the ring; a no-op when frozen.
 
void freeze ()
 Freeze the buffer: feed() stops writing; the audio callback runs on.
 
void unfreeze ()
 Resume writing after a freeze.
 

Public Attributes

volatile bool frozen_ = false
 
volatile bool ready_ = false
 
volatile uint16_t pos_ = 0
 
volatile uint32_t written_ = 0
 
float buf_left_ [MaxFrames] = {}
 
float buf_right_ [MaxFrames] = {}
 

Static Public Attributes

static constexpr uint16_t MAX_FRAMES = MaxFrames
 

Member Function Documentation

◆ feed()

template<uint16_t MaxFrames = 4096>
void sbl::diagnostics::AudioCapture< MaxFrames >::feed ( const float *  left,
const float *  right,
uint16_t  frames 
)
inline

Write one block into the ring; a no-op when frozen.

Parameters
leftLeft channel samples
rightRight channel samples
framesFrames in each channel
Context
The audio callback, every block.

Definition at line 63 of file audio_capture.hpp.

References sbl::diagnostics::AudioCapture< MaxFrames >::buf_left_, sbl::diagnostics::AudioCapture< MaxFrames >::buf_right_, sbl::diagnostics::AudioCapture< MaxFrames >::frozen_, sbl::diagnostics::AudioCapture< MaxFrames >::pos_, sbl::diagnostics::AudioCapture< MaxFrames >::ready_, and sbl::diagnostics::AudioCapture< MaxFrames >::written_.

◆ freeze()

template<uint16_t MaxFrames = 4096>
void sbl::diagnostics::AudioCapture< MaxFrames >::freeze ( )
inline

Freeze the buffer: feed() stops writing; the audio callback runs on.

Context
Any context; a debugger may also write frozen_ over SWD.

Definition at line 88 of file audio_capture.hpp.

References sbl::diagnostics::AudioCapture< MaxFrames >::frozen_.

◆ unfreeze()

template<uint16_t MaxFrames = 4096>
void sbl::diagnostics::AudioCapture< MaxFrames >::unfreeze ( )
inline

Resume writing after a freeze.

Definition at line 91 of file audio_capture.hpp.

References sbl::diagnostics::AudioCapture< MaxFrames >::frozen_.

Member Data Documentation

◆ frozen_

template<uint16_t MaxFrames = 4096>
volatile bool sbl::diagnostics::AudioCapture< MaxFrames >::frozen_ = false

◆ ready_

template<uint16_t MaxFrames = 4096>
volatile bool sbl::diagnostics::AudioCapture< MaxFrames >::ready_ = false

True once the buffer has been fully written

Definition at line 163 of file audio_capture.hpp.

Referenced by sbl::diagnostics::AudioCapture< MaxFrames >::feed().

◆ pos_

template<uint16_t MaxFrames = 4096>
volatile uint16_t sbl::diagnostics::AudioCapture< MaxFrames >::pos_ = 0

Ring head: next write position

Definition at line 164 of file audio_capture.hpp.

Referenced by sbl::diagnostics::AudioCapture< MaxFrames >::feed().

◆ written_

template<uint16_t MaxFrames = 4096>
volatile uint32_t sbl::diagnostics::AudioCapture< MaxFrames >::written_ = 0

Total frames written (for ready_ detection)

Definition at line 165 of file audio_capture.hpp.

Referenced by sbl::diagnostics::AudioCapture< MaxFrames >::feed().

◆ buf_left_

template<uint16_t MaxFrames = 4096>
float sbl::diagnostics::AudioCapture< MaxFrames >::buf_left_[MaxFrames] = {}

Left channel ring

Definition at line 169 of file audio_capture.hpp.

Referenced by sbl::diagnostics::AudioCapture< MaxFrames >::feed().

◆ buf_right_

template<uint16_t MaxFrames = 4096>
float sbl::diagnostics::AudioCapture< MaxFrames >::buf_right_[MaxFrames] = {}

Right channel ring

Definition at line 170 of file audio_capture.hpp.

Referenced by sbl::diagnostics::AudioCapture< MaxFrames >::feed().

◆ MAX_FRAMES

template<uint16_t MaxFrames = 4096>
constexpr uint16_t sbl::diagnostics::AudioCapture< MaxFrames >::MAX_FRAMES = MaxFrames
staticconstexpr

Ring length in frames

Definition at line 173 of file audio_capture.hpp.


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