Sound Byte Libs 29c5ff3
C++ firmware library for audio applications on 32-bit ARM Cortex-M processors
Loading...
Searching...
No Matches
fixed.hpp
Go to the documentation of this file.
1// sbl/dsp/fixed.hpp — Fixed-point constants for the DSP layer
2//
3// Q16 conventions used throughout sbl::dsp:
4// - Phase: uint32_t full range [0, 2^32) = one cycle
5// - Normalized uint16_t: 0 = 0.0, 65535 = ~1.0
6// - Fractional mask: lower 16 bits after index extraction
7
8#pragma once
9
10#include <cstdint>
11
12namespace sbl::dsp {
13
14// Q16 fixed-point: 1.0 represented as 65536 (one past uint16_t range)
15inline constexpr uint32_t Q16_ONE = 65536u;
16
17// Maximum uint16_t value — end of normalized [0, 65535] range
18inline constexpr uint16_t U16_MAX = 65535u;
19
20// Midpoint of uint16_t range — "linear" / center value for curve parameter
21inline constexpr uint16_t U16_MID = 32768u;
22
23// 16-bit fractional mask for phase extraction
24inline constexpr uint16_t FRAC16_MASK = 0xffff;
25
26// 24-bit audio sample range (matches SAI/I2S int32 format)
27inline constexpr int32_t SAMPLE_MAX_24 = 8388607; // 2^23 - 1
28inline constexpr int32_t SAMPLE_MIN_24 = -8388607; // -(2^23 - 1), symmetric
29
30/// Clamp value to 24-bit audio range
31inline constexpr int32_t saturate_24(int32_t x) {
32 return (x > SAMPLE_MAX_24) ? SAMPLE_MAX_24
34 : x;
35}
36
37} // namespace sbl::dsp
DSP atoms for audio signal processing.
Definition allpass.hpp:22
constexpr uint16_t FRAC16_MASK
Definition fixed.hpp:24
constexpr uint16_t U16_MID
Definition fixed.hpp:21
constexpr int32_t SAMPLE_MIN_24
Definition fixed.hpp:28
constexpr int32_t SAMPLE_MAX_24
Definition fixed.hpp:27
constexpr uint16_t U16_MAX
Definition fixed.hpp:18
constexpr uint32_t Q16_ONE
Definition fixed.hpp:15
constexpr int32_t saturate_24(int32_t x)
Clamp value to 24-bit audio range.
Definition fixed.hpp:31