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
switched_exciter.hpp
Go to the documentation of this file.
1// sbl/dsp/pm/switched_exciter.hpp — One of two exciters, chosen per block (Physical modeling — composition)
2//
3// An app that lets a player switch bow models owns two exciters and this:
4// the string sees one Exciter and never learns there are two. The choice is
5// read at advance(), once a block, so the sample loop has no branch in it;
6// the exciter switched to starts from rest.
7
8#ifndef SBL_DSP_PM_SWITCHED_EXCITER_HPP_
9#define SBL_DSP_PM_SWITCHED_EXCITER_HPP_
10
11#include <cstdint>
12
15
16namespace sbl::dsp::pm {
17
18template<typename A, typename B>
20 static_assert(is_exciter_v<A> && is_exciter_v<B>, "both sides are Exciters (physical-modeling.md §4.2)");
21
22public:
23 /// @note All public methods are ISR-safe — bounded computation, no I/O.
24
25 SwitchedExciter(A& a, B& b) : a_(a), b_(b) {}
26
27 /// Which one plays: false the first, true the second. Takes effect at the next block.
28 void select(bool second) { pending_ = second; }
29 bool second() const { return use_b_; }
30
31 void advance(uint16_t n) {
32 if (pending_ != use_b_) {
33 use_b_ = pending_;
34 if (use_b_) b_.reset(); else a_.reset();
35 }
36 if (use_b_) b_.advance(n); else a_.advance(n);
37 }
38
39 float excite(const JunctionState& j) { return use_b_ ? b_.excite(j) : a_.excite(j); }
40 float energy() const { return use_b_ ? b_.energy() : a_.energy(); }
41
42 void reset() {
43 a_.reset();
44 b_.reset();
45 }
46
47 diagram::Ports describe(diagram::Graph& g, uint8_t group, const char* name = "exciter") const {
48 return use_b_ ? b_.describe(g, group, name) : a_.describe(g, group, name);
49 }
50
51private:
52 A& a_;
53 B& b_;
54 bool use_b_ = false;
55 bool pending_ = false;
56};
57
58} // namespace sbl::dsp::pm
59
60#endif // SBL_DSP_PM_SWITCHED_EXCITER_HPP_
float excite(const JunctionState &j)
diagram::Ports describe(diagram::Graph &g, uint8_t group, const char *name="exciter") const
void select(bool second)
Which one plays: false the first, true the second. Takes effect at the next block.
What a load, an exciter, a termination and a friction law provide (Physical modeling — cross-cutting)
A model's wiring, as data (AP-037)
Physical modeling: laws, bows, junctions, loads, resonators, strings (docs/conventions/physical-model...
Definition bow.hpp:31
The ports a component exposes after describing itself, so an owner can wire them.
Definition graph.hpp:130
What the guide reports at an excitation point, each sample.
Definition contracts.hpp:43