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
block.hpp
Go to the documentation of this file.
1// sbl/dsp/types/block.hpp — Statically-allocated audio buffer types
2//
3// MonoBlock<N> and StereoBlock<N> are simple buffer-owning types for
4// passing audio data between processing stages. They are data types,
5// not processing units — no DSP, just buffer ownership with clean
6// accessors.
7//
8// Usage:
9// MonoBlock<48> mono;
10// osc.process(mono.buf(), mono.size());
11//
12// StereoBlock<48> stereo;
13// delay.process(stereo.buf_l(), stereo.buf_r(), stereo.size());
14
15#ifndef SBL_DSP_TYPES_BLOCK_HPP_
16#define SBL_DSP_TYPES_BLOCK_HPP_
17
18#include <cstdint>
19
20namespace sbl::dsp::types {
21
22/// Mono audio buffer with static allocation.
23template <uint16_t N>
24struct MonoBlock {
25 float data[N] = {};
26
27 float* buf() { return data; }
28 const float* buf() const { return data; }
29
30 static constexpr uint16_t size() { return N; }
31
32 void clear() {
33 for (uint16_t i = 0; i < N; ++i) data[i] = 0.0f;
34 }
35
36 void clear(uint16_t n) {
37 for (uint16_t i = 0; i < n; ++i) data[i] = 0.0f;
38 }
39};
40
41/// Stereo audio buffer with static allocation.
42template <uint16_t N>
44 float left[N] = {};
45 float right[N] = {};
46
47 float* buf_l() { return left; }
48 float* buf_r() { return right; }
49 const float* buf_l() const { return left; }
50 const float* buf_r() const { return right; }
51
52 static constexpr uint16_t size() { return N; }
53
54 void clear() {
55 for (uint16_t i = 0; i < N; ++i) {
56 left[i] = 0.0f;
57 right[i] = 0.0f;
58 }
59 }
60
61 void clear(uint16_t n) {
62 for (uint16_t i = 0; i < n; ++i) {
63 left[i] = 0.0f;
64 right[i] = 0.0f;
65 }
66 }
67};
68
69} // namespace sbl::dsp::types
70
71#endif // SBL_DSP_TYPES_BLOCK_HPP_
Sample rate, sample formats, blocks and frames.
Definition block.hpp:20
Mono audio buffer with static allocation.
Definition block.hpp:24
static constexpr uint16_t size()
Definition block.hpp:30
void clear(uint16_t n)
Definition block.hpp:36
const float * buf() const
Definition block.hpp:28
Stereo audio buffer with static allocation.
Definition block.hpp:43
void clear(uint16_t n)
Definition block.hpp:61
const float * buf_r() const
Definition block.hpp:50
const float * buf_l() const
Definition block.hpp:49
static constexpr uint16_t size()
Definition block.hpp:52