|
Sound Byte Libs 0.5.1-121-g3358a44
C++ firmware library for audio applications on 32-bit ARM Cortex-M processors
|
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:
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 |
|
inline |
Call from audio callback every block. Always-on ring buffer write. No-op when frozen. ~1us for 48 stereo frames.
Definition at line 47 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_.
|
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_.
|
inline |
Resume writing after a freeze.
Definition at line 68 of file audio_capture.hpp.
References sbl::diagnostics::AudioCapture< MaxFrames >::frozen_.
| volatile bool sbl::diagnostics::AudioCapture< MaxFrames >::frozen_ = false |
Definition at line 128 of file audio_capture.hpp.
Referenced by sbl::diagnostics::AudioCapture< MaxFrames >::feed(), sbl::diagnostics::AudioCapture< MaxFrames >::freeze(), and sbl::diagnostics::AudioCapture< MaxFrames >::unfreeze().
| volatile bool sbl::diagnostics::AudioCapture< MaxFrames >::ready_ = false |
Definition at line 129 of file audio_capture.hpp.
Referenced by sbl::diagnostics::AudioCapture< MaxFrames >::feed().
| volatile uint16_t sbl::diagnostics::AudioCapture< MaxFrames >::pos_ = 0 |
Definition at line 130 of file audio_capture.hpp.
Referenced by sbl::diagnostics::AudioCapture< MaxFrames >::feed().
| volatile uint32_t sbl::diagnostics::AudioCapture< MaxFrames >::written_ = 0 |
Definition at line 131 of file audio_capture.hpp.
Referenced by sbl::diagnostics::AudioCapture< MaxFrames >::feed().
| float sbl::diagnostics::AudioCapture< MaxFrames >::buf_left_[MaxFrames] = {} |
Definition at line 135 of file audio_capture.hpp.
Referenced by sbl::diagnostics::AudioCapture< MaxFrames >::feed().
| float sbl::diagnostics::AudioCapture< MaxFrames >::buf_right_[MaxFrames] = {} |
Definition at line 136 of file audio_capture.hpp.
Referenced by sbl::diagnostics::AudioCapture< MaxFrames >::feed().
|
staticconstexpr |
Definition at line 138 of file audio_capture.hpp.