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

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: static sbl::diagnostics::AudioCapture<4096> s_audio_capture;

void audio_callback(int32_t* tx, const int32_t* rx, uint16_t frames) { render(left_buf, right_buf, frames); s_audio_capture.feed(left_buf, right_buf, frames); sbl::dsp::types::interleave_from_float(left_buf, right_buf, tx, frames); }

Cost: ~1us per 48-frame block when active. Single branch when frozen.

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 43 of file audio_capture.hpp.

#include <audio_capture.hpp>

Public Member Functions

void feed (const float *left, const float *right, uint16_t frames)
 
void freeze ()
 
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

◆ freeze()

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

Freeze the buffer — stops writing. Audio callback continues normally. Safe to call from any context (ISR, main loop, SWD write to frozen_).

Definition at line 65 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 68 of file audio_capture.hpp.

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

Member Data Documentation

◆ frozen_

◆ ready_

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

◆ pos_

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

◆ written_

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

◆ buf_left_

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

◆ buf_right_

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

◆ max_frames

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

Definition at line 138 of file audio_capture.hpp.


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