Deepnote Synthesizer Voice Library v1.0.0
A C++14 header-only library implementing the THX Deep Note effect
Loading...
Searching...
No Matches
frequencytable.hpp
Go to the documentation of this file.
1
34#pragma once
35
36#include "oscfrequency.hpp"
37#include "ranges/range.hpp"
38#include <array>
39#include <functional>
40
41namespace deepnote
42{
43namespace nt
44{
45using FrequencyTableIndex = NamedType<unsigned int, struct FrequencyTableIndexTag>;
46using VoiceIndex = NamedType<unsigned int, struct VoiceIndexTag>;
47} // namespace nt
48
49using FrequencyFunc = std::function<nt::OscillatorFrequency()>;
50
51template <unsigned int TABLE_HEIGHT, unsigned int TABLE_WIDTH> struct FrequencyTable
52{
53 // the table is a 2D array of functions that return a frequency
54 using TableType = std::array<std::array<FrequencyFunc, TABLE_WIDTH>, TABLE_HEIGHT>;
55
56 explicit FrequencyTable(const TableType &table)
57 : freq_functions(table)
58 {
59 }
60
61 FrequencyTable(const FrequencyTable<TABLE_HEIGHT, TABLE_WIDTH> &other) = default;
62 FrequencyTable(FrequencyTable<TABLE_HEIGHT, TABLE_WIDTH> &&other) = default;
63 FrequencyTable<TABLE_HEIGHT, TABLE_WIDTH> &
64 operator=(const FrequencyTable<TABLE_HEIGHT, TABLE_WIDTH> &other) = default;
65 ~FrequencyTable() = default;
66
67 nt::OscillatorFrequency get(const nt::FrequencyTableIndex table_index, const nt::VoiceIndex voice_index) const
68 {
69 // ensure that table_index and voice_index are within the bounds of the table
70 // values will wrap around if they are out of bounds
71 return freq_functions[table_index.get() % TABLE_HEIGHT][voice_index.get() % TABLE_WIDTH]();
72 }
73
74 private:
75 TableType freq_functions;
76};
77
78} // namespace deepnote
Oscillator frequency calculation utilities for the Deep Note synthesizer.
Range constraint and validation utilities for the Deep Note synthesizer.