Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
forge_wavetable_catalog.hpp
Go to the documentation of this file.
1#pragma once
2
3// Wavetable — Forge-facing bake-layer catalog nodes.
4//
5// This pack exposes the shipped WavetableBank as a fixed four-table source.
6// Table construction allocates and therefore happens in the node instance's
7// control-thread lifetime; prepare and process only update scalar state.
8
12
13#include <algorithm>
14#include <cmath>
15#include <cstddef>
16#include <vector>
17
19
20inline constexpr const char* kTypeId = "wavetable.oscillator";
21
22inline constexpr state::ParamID kFrequencyHz = 1;
23inline constexpr state::ParamID kPosition = 2;
24inline constexpr state::ParamID kLevelDb = 3;
25
37
40 t.type_id = kTypeId;
41 t.version = 1;
42 t.num_input_ports = 0;
43 t.num_output_ports = 1;
44 t.default_name = "Wavetable Oscillator";
45 t.lowerable = true;
46
47 t.create = []() -> void* { return new Instance{}; };
48 t.destroy = [](void* p) { delete static_cast<Instance*>(p); };
49 t.prepare = [](void* p, double sample_rate, int /*max_block*/) {
50 auto* s = static_cast<Instance*>(p);
51 s->bank.set_sample_rate(static_cast<float>(sample_rate));
52 s->bank.set_frequency_immediate(220.0f);
53 s->bank.reset();
54 };
55 t.reset = [](void* p) { static_cast<Instance*>(p)->bank.reset(); };
56
57 t.baked_params.push_back({kFrequencyHz, 20.0f, 20000.0f, 220.0f});
58 t.baked_params.push_back({kPosition, 0.0f, 1.0f, 0.0f});
59 t.baked_params.push_back({kLevelDb, -60.0f, 0.0f, -12.0f});
60
61 t.process_instance_baked_param = [](void* p, audio::BufferView<float>& out,
62 const audio::BufferView<const float>& /*in*/, int n,
63 const BakedParamView& params) {
64 auto* s = static_cast<Instance*>(p);
65 float* output = out.channel_ptr(0);
66 for (int k = 0; k < n; ++k) {
67 const auto offset = static_cast<std::int32_t>(k);
68 s->bank.set_frequency(params.value_at(kFrequencyHz, offset));
69 s->bank.set_position(params.value_at(kPosition, offset));
70 const float gain = std::pow(10.0f, params.value_at(kLevelDb, offset) / 20.0f);
71 output[static_cast<std::size_t>(k)] = s->bank.next() * gain;
72 }
73 };
74 return t;
75}
76
78 return {
79 "wavetable_oscillator",
80 "Wavetable Oscillator",
81 "An oscillator that morphs continuously across sine, saw, square, and triangle tables.",
82 {},
83 {{"default", kTypeId}},
84 {
85 {"frequency_hz", kFrequencyHz, "Frequency", "Hz",
86 "Oscillator frequency.", ForgeParamKind::continuous,
88 {"position", kPosition, "Position", "%",
89 "Morph position across the wavetable bank.", ForgeParamKind::continuous,
91 {"level_db", kLevelDb, "Level", "dB",
92 "Oscillator output level.", ForgeParamKind::continuous,
94 },
95 };
96}
97
98inline constexpr float worst_case_gain() {
99 return 1.0f;
100}
101
102} // namespace pulp::host::wavetable
Non-owning view over multi-channel audio sample data.
Definition buffer.hpp:30
Definition custom_node_type.hpp:51
static WavetableT make_saw(std::size_t bands=10, std::size_t table_length=2048, float reference_sample_rate=float{48000.0f})
static WavetableT make_triangle(std::size_t bands=10, std::size_t table_length=2048, float reference_sample_rate=float{48000.0f})
static WavetableT make_square(std::size_t bands=10, std::size_t table_length=2048, float reference_sample_rate=float{48000.0f})
static WavetableT make_sine(std::size_t table_length=2048, float reference_sample_rate=float{48000.0f})
Definition forge_wavetable_catalog.hpp:18
constexpr state::ParamID kPosition
Definition forge_wavetable_catalog.hpp:23
CustomNodeType make_wavetable_oscillator_node()
Definition forge_wavetable_catalog.hpp:38
constexpr float worst_case_gain()
Definition forge_wavetable_catalog.hpp:98
constexpr const char * kTypeId
Definition forge_wavetable_catalog.hpp:20
constexpr state::ParamID kLevelDb
Definition forge_wavetable_catalog.hpp:24
constexpr state::ParamID kFrequencyHz
Definition forge_wavetable_catalog.hpp:22
ForgeNodeDescriptor descriptor()
Definition forge_wavetable_catalog.hpp:77
@ continuous
Definition forge_param_descriptor.hpp:25
@ logarithmic
Definition forge_param_descriptor.hpp:29
@ linear
Definition forge_param_descriptor.hpp:29
Definition additive_bank.hpp:218
WavetableBankT< float > WavetableBank
Definition wavetable.hpp:308
uint32_t ParamID
Unique parameter identifier, stable across plugin versions.
Definition parameter.hpp:55
STL namespace.
Definition custom_node_type.hpp:90
Definition forge_param_descriptor.hpp:127
Definition forge_wavetable_catalog.hpp:26
signal::WavetableBank bank
Definition forge_wavetable_catalog.hpp:27
Instance()
Definition forge_wavetable_catalog.hpp:29
Wavetable oscillator with band-switching + bank morphing.