Tabula Sonora 0.1.0
A native C++20 implementation of the Roland Sound Canvas VA synth voice
Loading...
Searching...
No Matches
tva_chain.hpp
Go to the documentation of this file.
1#pragma once
2
8
9#include <cstdint>
10#include <optional>
11#include <vector>
12
13namespace ts {
14
25class TvaChain {
26public:
28 static constexpr double amp_scale = 2.0;
29
31 static constexpr int control_tick_hz = 100;
32
35 TvaChain(const TableSet& tables, const EnvelopeMachine& envelope);
36
38 [[nodiscard]] const EnvelopeMachine& envelope() const noexcept { return *envelope_; }
39
46 [[nodiscard]] double amp_of(int level16) const noexcept;
47
53 [[nodiscard]] std::optional<int> partial_level(const PartialParameters& partial,
54 int velocity) const noexcept;
55
57 [[nodiscard]] int base_level(const PartialParameters& partial,
58 int partial_level,
59 int key,
60 int zone_level,
61 int tone_level) const noexcept;
62
80 int velocity,
81 int key,
82 int zone_level = 127,
83 int tone_level = 127,
84 int sample_rate = 32000,
85 double attack_milliseconds = 0.0,
86 std::optional<int> rate_key = std::nullopt,
87 const PartModifiers& modifiers = {}) const;
88
95 [[nodiscard]] std::vector<float> render(const PartialParameters& partial,
96 int velocity,
97 int key,
98 double hold_seconds,
99 double tail_seconds,
100 int zone_level = 127,
101 int tone_level = 127,
102 int sample_rate = 32000,
103 double attack_milliseconds = 0.0,
104 std::optional<int> rate_key = std::nullopt) const;
105
110 [[nodiscard]] static double
111 part_volume_scale(int volume = 127, int expression = 127, int master = 127) noexcept;
112
113private:
114 const EnvelopeMachine* envelope_;
115 std::span<const std::uint16_t> level_curve_;
116 std::span<const std::uint16_t> amp_high_;
117 std::span<const std::uint16_t> amp_low_;
118 std::span<const std::uint8_t> velocity_curve_;
119 std::span<const std::uint8_t> scale_curve_;
120 std::span<const std::uint8_t> level_key_follow_;
121 std::span<const std::uint8_t> rate_key_follow0_;
122 std::span<const std::uint8_t> rate_key_follow1_;
123 std::span<const std::uint8_t> velocity_crossfade_;
124};
125
126} // namespace ts
The segment-rate and segment-shape machine shared by the TVA, TVF and pitch envelopes.
Definition envelope_machine.hpp:22
A zero-copy typed view over one 0x6e-byte partial parameter block inside a tone record.
Definition partial_parameters.hpp:20
A four-segment envelope with a release, evaluated at any sample position.
Definition segment_envelope.hpp:21
The static tables the engine needs, loaded from SCCore.dll or from a directory of extracted ....
Definition table_set.hpp:30
int base_level(const PartialParameters &partial, int partial_level, int key, int zone_level, int tone_level) const noexcept
The 16-bit logarithmic base level for a voice, before the envelope moves it.
static constexpr int control_tick_hz
The control-tick rate, which is the grid note-off is acted on.
Definition tva_chain.hpp:31
std::vector< float > render(const PartialParameters &partial, int velocity, int key, double hold_seconds, double tail_seconds, int zone_level=127, int tone_level=127, int sample_rate=32000, double attack_milliseconds=0.0, std::optional< int > rate_key=std::nullopt) const
Renders the amplitude envelope for one note, or an empty vector when it cannot sound.
const EnvelopeMachine & envelope() const noexcept
The shared segment-rate machine.
Definition tva_chain.hpp:38
SegmentEnvelope create_envelope(const PartialParameters &partial, int velocity, int key, int zone_level=127, int tone_level=127, int sample_rate=32000, double attack_milliseconds=0.0, std::optional< int > rate_key=std::nullopt, const PartModifiers &modifiers={}) const
Builds the amplitude envelope for one note, ready to be evaluated at any sample position.
std::optional< int > partial_level(const PartialParameters &partial, int velocity) const noexcept
The partial's velocity-crossfaded level — the byte the engine keeps at voice+0x164.
static double part_volume_scale(int volume=127, int expression=127, int master=127) noexcept
The part-level volume multiplier, relative to everything at 127.
static constexpr double amp_scale
The engine hands the sampler twice the amplitude the level chain yields.
Definition tva_chain.hpp:28
double amp_of(int level16) const noexcept
Converts a 16-bit logarithmic level to a linear gain in [0, 1].
TvaChain(const TableSet &tables, const EnvelopeMachine &envelope)
Creates the chain over a loaded table set and the shared machine, both of which must outlive it.
Definition control_decode.hpp:7
@ volume
Definition control_decode.hpp:18
@ expression
Definition control_decode.hpp:19
The GS part modify offsets, as the synthesis chains consume them.
Definition part_modifiers.hpp:21