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
cam.hpp
Go to the documentation of this file.
1// sbl/control/cam.hpp — Cam profile evaluation
2//
3// Evaluates LUTE-generated cam transfer function tables.
4// A cam table maps [0, 1] input to arbitrary float output via precomputed
5// breakpoint-interpolated lookup tables.
6//
7// Rate-agnostic: works at control rate (200 Hz knob updates) or audio rate
8// (48 kHz modulation reshaping). Cost is ~5-8 cycles per evaluation on M7.
9//
10// Usage:
11// #include <sbl/control/cam.hpp>
12// #include "davis_jr/cam/k4_delay_drive_256.hpp"
13//
14// float v = sbl::control::cam_evaluate(
15// davis_jr::cam::k4_delay_drive_256, 256, knob_value);
16
17#ifndef SBL_CONTROL_CAM_HPP_
18#define SBL_CONTROL_CAM_HPP_
19
20#include <cstdint>
21
22namespace sbl::control {
23
24/// Evaluate a cam table at a single input position.
25/// Input clamped to [0, 1]. Returns linearly interpolated table value.
26/// Table must have at least 1 guard point (size + 1 entries).
27inline float cam_evaluate(const float* table, uint16_t size, float input) {
28 float clamped = input < 0.0f ? 0.0f : (input > 1.0f ? 1.0f : input);
29 float pos = clamped * static_cast<float>(size - 1);
30 uint16_t idx = static_cast<uint16_t>(pos);
31 float frac = pos - static_cast<float>(idx);
32 return table[idx] + (table[idx + 1] - table[idx]) * frac;
33}
34
35/// Evaluate a cam table across a buffer.
36inline void cam_evaluate_block(const float* table, uint16_t size,
37 const float* in, float* out, uint16_t n) {
38 for (uint16_t i = 0; i < n; ++i) {
39 out[i] = cam_evaluate(table, size, in[i]);
40 }
41}
42
43} // namespace sbl::control
44
45#endif // SBL_CONTROL_CAM_HPP_
Control Stack v2: scheduler, event queue, merge, CC mapping, calibration, presets.
void cam_evaluate_block(const float *table, uint16_t size, const float *in, float *out, uint16_t n)
Evaluate a cam table across a buffer.
Definition cam.hpp:36
float cam_evaluate(const float *table, uint16_t size, float input)
Definition cam.hpp:27