Tabula Sonora 0.1.0
A native C++20 implementation of the Roland Sound Canvas VA synth voice
Loading...
Searching...
No Matches
wave_rom.hpp
Go to the documentation of this file.
1#pragma once
2
4
5#include <cstdint>
6#include <optional>
7#include <vector>
8
9namespace ts {
10
16 std::vector<std::uint8_t> delta;
26 std::vector<std::uint8_t> preamble_delta;
29 std::vector<std::uint8_t> scale;
31 std::int32_t sample_count = 0;
33 std::int32_t data_start = 0;
40 std::int32_t scale_phase = 0;
41};
42
49class WaveRom {
50public:
52 static constexpr std::int32_t region_size = 0x100000;
53
55 static constexpr std::int32_t max_sample_count = 2'000'000;
56
67 static constexpr int bank_a_region_count = 16;
68
75 static constexpr int bank_b_region_count = 8;
76
78 [[nodiscard]] static constexpr int region_count(int bank) noexcept
79 {
81 }
82
84 struct SplitRegion {
85 int bank = 0;
87 };
88
89 [[nodiscard]] static constexpr SplitRegion split_region(int region) noexcept
90 {
91 const int bank = (region >> 4) & 1;
92 return SplitRegion{bank, region - (16 * bank)};
93 }
94
96 explicit WaveRom(const RomImage& rom);
97
99 [[nodiscard]] std::int64_t bank_base(int bank) const noexcept
100 {
101 return bank == 0 ? bank_a_base_ : bank_b_base_;
102 }
103
105 [[nodiscard]] std::int64_t region_base(int region) const noexcept;
106
122 [[nodiscard]] std::optional<WaveStreams> read_streams(int region, int loop, int start) const;
123
124private:
125 const RomImage* rom_;
126 std::int64_t bank_a_base_ = 0;
127 std::int64_t bank_b_base_ = 0;
128};
129
130} // namespace ts
Read-only access to SCCore.dll as a data file.
Definition rom_image.hpp:39
WaveRom(const RomImage &rom)
Creates a wave-ROM view over an open image, which must outlive it.
std::int64_t bank_base(int bank) const noexcept
File offset of the first byte of a bank.
Definition wave_rom.hpp:99
std::int64_t region_base(int region) const noexcept
File offset of the base of a region, from a descriptor's region byte.
static constexpr int region_count(int bank) noexcept
Number of regions of real ROM data in a bank: 0 for bank A, 1 for bank B.
Definition wave_rom.hpp:78
static constexpr std::int32_t max_sample_count
Largest wave this class will attempt to read, as a sanity bound.
Definition wave_rom.hpp:55
static constexpr int bank_b_region_count
Regions of real ROM data in bank B — eight, not twelve.
Definition wave_rom.hpp:75
static constexpr int bank_a_region_count
Regions bank A spans: sixteen, the full width of the region nibble.
Definition wave_rom.hpp:67
static constexpr std::int32_t region_size
Size of one addressable ROM region, 1 MB.
Definition wave_rom.hpp:52
std::optional< WaveStreams > read_streams(int region, int loop, int start) const
Reads the delta and scale streams for one wave.
static constexpr SplitRegion split_region(int region) noexcept
Definition wave_rom.hpp:89
Definition control_decode.hpp:7
@ bank
Definition control_decode.hpp:26
@ loop
Forward loop. Rewinds the delta index and keeps the predictor.
Definition sampler.hpp:20
Splits a descriptor's region byte into a bank and a bank-relative region index.
Definition wave_rom.hpp:84
int bank
Definition wave_rom.hpp:85
int effective_region
Definition wave_rom.hpp:86
The two raw streams that make up one wave: a signed delta per sample, and a shift exponent per 16-sam...
Definition wave_rom.hpp:13
std::vector< std::uint8_t > delta
One signed byte per sample, sample_count + 1 long — the ping-pong sampler turns around on index sampl...
Definition wave_rom.hpp:16
std::vector< std::uint8_t > preamble_delta
The deltas between the 32-sample exponent-block boundary and the data start — scale_phase of them,...
Definition wave_rom.hpp:26
std::int32_t scale_phase
Where data_start falls inside its 32-sample exponent block, i.e.
Definition wave_rom.hpp:40
std::int32_t sample_count
Number of decodable samples.
Definition wave_rom.hpp:31
std::int32_t data_start
The descriptor's data start, exactly as given — not rounded to a block.
Definition wave_rom.hpp:33
std::vector< std::uint8_t > scale
Shift-exponent nibbles: byte i >> 5 holds the exponents for samples i, with the low nibble used when ...
Definition wave_rom.hpp:29