Sound Byte Libs uses a structured namespace hierarchy to separate generated code from static implementations.
Namespace Overview
| Namespace | Purpose | Location |
sbl::driver:: | MCU driver implementations | sbl-hardware/mcu/*/driver/ |
sbl::hw:: | Generated hardware configuration | build/generated/sbl/hw/config/ |
sbl::hw::gpio:: | Generated GPIO handles | build/generated/sbl/hw/config/gpio.hpp |
sbl::hw::adc:: | Generated ADC handles | build/generated/sbl/hw/config/adc.hpp |
sbl::hw::uart:: | Generated UART handles | build/generated/sbl/hw/config/uart.hpp |
sbl::hw::mcu:: | MCU metadata | build/generated/sbl/hw/config/mcu.hpp |
sbl::hw::Board | Generated Board abstraction | build/generated/sbl/hw/config/board.hpp |
sbl::gpio:: | GPIO types (PinMode) | src/sbl/hal/gpio/types.hpp |
sbl::adc:: | ADC convenience functions | src/sbl/hal/adc/driver.hpp, src/sbl/hal/adc/scan.hpp |
sbl::cv:: | CV input convenience functions | src/sbl/hal/cv/input.hpp |
sbl::audio:: | Audio output convenience | src/sbl/hal/audio/driver.hpp |
sbl::button:: | Button HAL convenience | src/sbl/hal/button/input.hpp |
sbl::encoder:: | Encoder HAL convenience | src/sbl/hal/encoder/input.hpp |
sbl::led:: | RGB LED HAL convenience | src/sbl/hal/led/output.hpp |
sbl::pot:: | Potentiometer HAL convenience | src/sbl/hal/pot/input.hpp |
sbl::voct:: | V/Oct HAL convenience | src/sbl/hal/cv/voct.hpp |
sbl::dsp:: | DSP atoms (phase, filters, delay, fast_math) | src/sbl/dsp/ |
sbl::dsp::lut:: | Lookup table functions | src/sbl/dsp/lut.hpp |
sbl::signal:: | Signal composition (Frame, exp_mod) | src/sbl/signal/ |
sbl::midi:: | MIDI parser and input | src/sbl/midi/ |
sbl::widgets::source:: | Sound sources (oscillators, noise) | src/sbl/widgets/source/ |
sbl::widgets::proc:: | Processing (SVF, VCA, Delay, PlateReverb) | src/sbl/widgets/proc/ |
sbl::widgets::mod:: | Modulation (envelope, LFO) | src/sbl/widgets/mod/ |
sbl::log:: | Logging utilities (Logger, Level) | src/sbl/log/ |
sbl::defaults:: | Sensible buffer size constants | src/sbl/common/defaults.hpp |
sbl::version:: | Library version info (CMake-generated) | build/include/sbl/version.hpp |
sbl::meta:: | Hardware metadata (sloth-generated) | build/generated/sbl/hw/meta.hpp |
sbl:: | Non-generated types (handles) | src/sbl/types.hpp |
<tt>sbl::driver::</tt> - MCU Drivers
MCU-specific driver implementations. These are static files maintained in the sbl-hardware repository and included via CMake.
sbl::driver::init();
sbl::driver::Gpio::set_mode(sbl::hw::gpio::status_led, sbl::gpio::PinMode::Output);
sbl::driver::Gpio::write(sbl::hw::gpio::status_led, true);
sbl::driver::Gpio::toggle(sbl::hw::gpio::status_led);
sbl::driver::Timer::busy_wait_ms(500);
sbl::driver::Uart<>::init(sbl::hw::uart::debug);
sbl::driver::Uart<>::write_byte('A');
sbl::driver::Uart<1>::init_rx(sbl::hw::uart::midi);
Uber-umbrella header for all target-specific code.
Individual driver headers are also available:
#include <sbl/hw/driver/gpio.hpp>
#include <sbl/hw/driver/timer.hpp>
#include <sbl/hw/driver/uart.hpp>
#include <sbl/hw/driver/adc.hpp>
#include <sbl/hw/driver/sai.hpp>
#include <sbl/hw/driver/dma.hpp>
#include <sbl/hw/driver/dma_buffer.hpp>
#include <sbl/hw/driver/init.hpp>
Contents:
Gpio - GPIO read/write/mode/toggle operations (handle-first API)
Timer - Delay functions and millis counter
Uart<N> - Multi-instance UART (template on instance index, default 0)
Adc - ADC initialization, polling reads, and DMA scan mode (STM32H7)
Sai - SAI/I2S full-duplex audio with DMA (STM32H7)
init() - MCU initialization
init_audio() - Audio subsystem init: PLL2, SAI GPIO, codec reset (STM32H7)
<tt>sbl::adc::</tt> - ADC Convenience Functions
Convenience namespace for ADC operations:
uint16_t value = sbl::adc::read<sbl::driver::Adc>(sbl::hw::adc::knob1);
ADC driver interface - canonical types for MCU driver implementations.
DMA-based continuous multi-channel scanning:
#include <sbl/hw/driver/dma_buffer.hpp>
SBL_DMA_BUFFER static uint16_t adc_buf[2];
const sbl::AdcHandle channels[] = { sbl::hw::adc::knob1, sbl::hw::adc::knob2 };
sbl::adc::start_scan<sbl::driver::Adc>(channels, 2, adc_buf);
sbl::adc::stop_scan<sbl::driver::Adc>();
ADC DMA scan interface — continuous multi-channel acquisition.
<tt>sbl::cv::</tt> - CV Input Convenience Functions
Composes ADC reads with CvInput smoothing in a single call:
sbl::cv::read<sbl::driver::Adc>(knob, handle, adc::SampleTime::Slow);
uint16_t read_dma(CvInput &input, const uint16_t *buffer, uint8_t channel_index)
Read from DMA scan buffer and feed into CvInput filter.
<tt>sbl::audio::</tt> - Audio Output Convenience
Portable audio output that wraps driver-specific details:
void my_callback(int32_t* tx, const int32_t* rx, uint16_t frames) { }
sbl::audio::start<sbl::driver::Sai>(my_callback);
Audio driver interface - canonical types and convenience functions.
<tt>sbl::button::</tt> - Button HAL Convenience
sbl::button::read<sbl::driver::Gpio>(btn, sbl::hw::gpio::button1);
<tt>sbl::encoder::</tt> - Encoder HAL Convenience
sbl::encoder::read<sbl::driver::Gpio>(enc, sbl::hw::gpio::encoder_a, sbl::hw::gpio::encoder_b);
Quadrature encoder with Gray code state machine and position tracking.
<tt>sbl::led::</tt> - RGB LED HAL Convenience
sbl::led::write<sbl::driver::Gpio>(led, sbl::hw::gpio::led1_r, sbl::hw::gpio::led1_g, sbl::hw::gpio::led1_b);
RGB LED state holder with 8-bit per-channel duty cycle.
RGB LED output convenience functions.
<tt>sbl::pot::</tt> - Potentiometer HAL Convenience
Potentiometer with EWMA smoothing, deadband, and change detection.
uint16_t read_dma(Pot &pot, const uint16_t *buffer, uint8_t channel_index)
Read from DMA scan buffer and feed into Pot.
<tt>sbl::voct::</tt> - V/Oct HAL Convenience
V/Oct input convenience functions.
void read_dma(VoctInput &input, const uint16_t *buffer, uint8_t channel_index)
Read from DMA scan buffer and feed into VoctInput.
<tt>sbl::dsp::</tt> - DSP Atoms (Audio Stack)
Single-concern signal processing primitives. Each atom manipulates one property of sound. No hardware dependencies.
phase.set_frequency(440000);
void advance()
Advance phase by one sample.
uint16_t lookup_linear(const uint16_t *table, uint32_t phase)
constexpr float sin_1024[1026]
float fast_tan_pif(float f)
float note_to_frequency(float midi_note)
MIDI note to frequency in Hz. A4 = 440 Hz.
float semitones_to_ratio(float semitones)
float fast_exp2f(float x)
<tt>sbl::signal::</tt> - Signal Composition (Audio Stack)
Composed building blocks that eliminate boilerplate in audio callbacks. Sits between atoms and widgets in the Audio Stack.
uint16_t n = frame.
begin(frames);
void exp_mod_block(const float *mod, float *freq_out, uint16_t n, float base, float depth, float lo=20.0f, float hi=20000.0f)
float exp_mod(float base, float mod, float depth, float lo=20.0f, float hi=20000.0f)
uint16_t begin(uint16_t requested)
void end(int32_t *tx, uint16_t n) const
void scale(float gain, uint16_t n)
Design principle: Signals follow [-1.0, 1.0]. Configuration uses engineering units. exp_mod() bridges the gap at the modulation point — exactly as in analog hardware.
<tt>sbl::midi::</tt> - MIDI Parser & Input
Stream-based MIDI parser with running status, real-time passthrough, and channel filtering:
sbl::midi::poll<MidiUart>(parser);
MIDI byte stream parser — state machine with running status.
void set_callback(MidiCallback cb)
Set the callback for parsed MIDI events.
void set_channel(uint8_t ch)
Set channel filter.
<tt>sbl::widgets::</tt> - Widgets (Audio Stack)
User-facing audio components — "module on a panel" abstractions:
<tt>sbl::gpio::</tt> - GPIO Types
GPIO-related types defined in src/sbl/hal/gpio/types.hpp:
sbl::gpio::PinMode::Output
sbl::gpio::PinMode::Input
sbl::gpio::PinMode::InputPullup
sbl::gpio::PinMode::InputPulldown
<tt>sbl::hw::</tt> - Generated Hardware Configuration
Build-time generated headers containing hardware-specific constants resolved from manifests by sloth.
Generated files in build/generated/sbl/hw/config/:
gpio.hpp - GPIO handles
adc.hpp - ADC handles (if any ADC claims)
uart.hpp - UART handles (if any UART claims)
board.hpp - Board abstraction (if components defined)
mcu.hpp - MCU metadata
system.hpp - System configuration
meta.hpp - Target/MCU metadata
constexpr auto led = sbl::hw::gpio::status_led;
constexpr auto midi = sbl::hw::uart::midi;
Sub-namespaces:
sbl::hw::gpio:: - GPIO handles (e.g., status_led)
sbl::hw::adc:: - ADC handles (e.g., knob1, knob2)
sbl::hw::uart:: - UART handles (e.g., debug, midi)
sbl::hw::system:: - Configuration values (e.g., sysclk_mhz)
sbl::hw::mcu:: - MCU metadata (e.g., name, family)
sbl::hw::Board - Board struct with typed component members (e.g., board.knob1, board.button1)
<tt>sbl::</tt> - Non-Generated Types
Handle types defined in static headers for IDE/LSP support. These types are used by both generated and driver code.
GPIO pin handle with port, pin number, and polarity.
Common types for SBL hardware abstraction.
Handles are passed directly to driver functions (handle-first API):
sbl::driver::Gpio::write(sbl::hw::gpio::status_led, true);
sbl::driver::Gpio::toggle(sbl::hw::gpio::status_led);
Optional Aliases
For shorter code, include <sbl/aliases.hpp>:
sbl::Gpio::set_mode(pin, sbl::PinMode::Output);
sbl::Timer::busy_wait_ms(500);
sbl::init();
Optional convenience aliases for SBL namespaces.
This is opt-in. The explicit sbl::driver:: form is recommended for clarity in embedded code.
<tt>sbl::defaults::</tt> - Sensible Buffer Defaults
Pre-defined buffer size constants for embedded contexts:
Sensible default constants for embedded systems.
constexpr std::size_t LOG_MESSAGE
Maximum log message length.
constexpr std::size_t LARGE_BUFFER
Large buffer size for log messages, etc.
constexpr std::size_t SMALL_BUFFER
Small buffer size for number formatting, etc.
constexpr std::size_t MEDIUM_BUFFER
Medium buffer size for string operations.
<tt>sbl::version::</tt> - Library Version
CMake-generated version info from git tags:
#include <sbl/version.hpp>
sbl::version::major
sbl::version::minor
sbl::version::patch
sbl::version::string
sbl::version::full_string
sbl::version::git_hash
sbl::version::git_dirty
sbl::version::number
sbl::version::is_at_least(0, 1, 5)
<tt>sbl::meta::</tt> - Hardware Metadata
sloth-generated metadata about the target hardware:
#include <sbl/hw/meta.hpp>
sbl::meta::manifest_schema
sbl::meta::target::name
sbl::meta::target::manifest_version
sbl::meta::target::hw_revision
sbl::meta::mcu::name
sbl::meta::mcu::manifest_version
<tt>sbl::log::</tt> - Logging System
Lightweight, zero-overhead logging for embedded development:
struct UartOutput {
static void write(const char* str) { sbl::driver::Uart<>::write_string(str); }
};
struct Timestamp {
static uint32_t now() { return sbl::driver::Timer::millis(); }
};
#define SBL_LOG_OUTPUT UartOutput
#define SBL_LOG_TIMESTAMP Timestamp
#define SBL_LOG_LEVEL SBL_LOG_LEVEL_INFO
Logging system umbrella header.
Zero-overhead logging macros with file/line capture.
#define SBL_LOG_INFO(...)
#define SBL_LOG_DEBUG(...)
#define SBL_LOG_ERROR(...)
Main logging macros with compile-time level filtering.
Log levels (compile-time constants for #if compatibility):
SBL_LOG_LEVEL_OFF (0) - Disable all logging
SBL_LOG_LEVEL_ERROR (1)
SBL_LOG_LEVEL_WARN (2)
SBL_LOG_LEVEL_INFO (3)
SBL_LOG_LEVEL_DEBUG (4)
SBL_LOG_LEVEL_TRACE (5)
Output format: I 12345 main.cpp:42| Message