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
fixed.hpp
Go to the documentation of this file.
1// sbl/dsp/fixed.hpp — Fixed-point constants and audio sample types
2//
3// Phase convention: uint32_t full range [0, 2^32) = one cycle
4
5#ifndef SBL_DSP_TYPES_FIXED_HPP_
6#define SBL_DSP_TYPES_FIXED_HPP_
7
8#include <cstdint>
9
10namespace sbl::dsp::types {
11
12// Master sample rate. All DSP coefficient math reads this directly — no per-
13// component sample_rate_ members. Set once at audio init, never changes at
14// runtime. Tests can modify between batch runs (tear down DSP graph, set new
15// rate, rebuild, run all tests again).
16inline uint32_t SAMPLE_RATE = 48000;
17inline float SAMPLE_RATE_F = 48000.0f;
18
19// 24-bit audio sample range (matches SAI/I2S int32 format)
20inline constexpr int32_t SAMPLE_MAX_24 = 8388607; // 2^23 - 1
21inline constexpr int32_t SAMPLE_MIN_24 = -8388607; // -(2^23 - 1), symmetric
22
23/// Clamp value to 24-bit audio range
24inline constexpr int32_t saturate_24(int32_t x) {
25 return (x > SAMPLE_MAX_24) ? SAMPLE_MAX_24
27 : x;
28}
29
30} // namespace sbl::dsp::types
31
32#endif // SBL_DSP_TYPES_FIXED_HPP_
Sample rate, sample formats, blocks and frames.
Definition block.hpp:20
constexpr int32_t saturate_24(int32_t x)
Clamp value to 24-bit audio range.
Definition fixed.hpp:24
float SAMPLE_RATE_F
Definition fixed.hpp:17
constexpr int32_t SAMPLE_MIN_24
Definition fixed.hpp:21
constexpr int32_t SAMPLE_MAX_24
Definition fixed.hpp:20
uint32_t SAMPLE_RATE
Definition fixed.hpp:16