2026-11-12 16:34:18 +06:00
|
|
|
#ifndef SYNTH
|
|
|
|
|
#define SYNTH
|
|
|
|
|
|
|
|
|
|
#include <cstdint>
|
2026-11-14 15:15:00 +06:00
|
|
|
#include <array>
|
2026-11-15 00:47:07 +06:00
|
|
|
#include <cmath>
|
2026-11-13 18:31:07 +06:00
|
|
|
|
|
|
|
|
#include "../include/spsc_queue.hpp"
|
|
|
|
|
#include "../include/command.hpp"
|
2026-11-14 15:15:00 +06:00
|
|
|
#include "../include/voice.hpp"
|
2026-11-14 20:37:48 +06:00
|
|
|
#include "../include/stereo_sample.hpp"
|
2026-11-15 12:35:20 +06:00
|
|
|
#include "../include/lfo.hpp"
|
2026-11-12 16:34:18 +06:00
|
|
|
|
|
|
|
|
class Synth {
|
|
|
|
|
public:
|
2026-11-15 00:47:07 +06:00
|
|
|
|
|
|
|
|
Synth(){
|
2026-11-16 00:49:29 +06:00
|
|
|
|
|
|
|
|
sin_wavetable.generate_sin(32);
|
|
|
|
|
saw_wavetable.generate_saw(32);
|
|
|
|
|
square_wavetable.generate_square(28);
|
|
|
|
|
triangle_wavetable.generate_triangle(40);
|
|
|
|
|
|
2026-11-15 00:47:07 +06:00
|
|
|
pitch_bend_range = 2.0;
|
|
|
|
|
pitch_semitones = 0.0;
|
|
|
|
|
pitch_multiplier = 1.0;
|
2026-11-15 12:35:20 +06:00
|
|
|
vibrato_depth_ = 0.0;
|
|
|
|
|
|
|
|
|
|
mod_wheel = 0;
|
2026-11-15 00:47:07 +06:00
|
|
|
stolen_voices = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-14 20:37:48 +06:00
|
|
|
StereoSample generate();
|
2026-11-12 22:37:00 +06:00
|
|
|
|
2026-11-12 16:34:18 +06:00
|
|
|
void generate_buffer(double* array, int size);
|
2026-11-15 12:35:20 +06:00
|
|
|
void set_mod_wheel(uint8_t value);
|
2026-11-16 00:49:29 +06:00
|
|
|
void set_unison_voices(uint8_t value);
|
|
|
|
|
void set_unison_gain(double value);
|
|
|
|
|
void set_stereo_spread(double value);
|
|
|
|
|
void set_detune_amount(double value);
|
|
|
|
|
void set_wavetable(Wavetable* wavetable);
|
|
|
|
|
void set_wavetable_sin();
|
|
|
|
|
void set_wavetable_saw();
|
|
|
|
|
void set_wavetable_square();
|
|
|
|
|
void set_wavetable_triangle();
|
|
|
|
|
void set_filter_cutoff(double value);
|
|
|
|
|
void set_filter_resonance(double value);
|
|
|
|
|
void set_filter_off();
|
|
|
|
|
void set_hpf();
|
|
|
|
|
void set_bpf();
|
|
|
|
|
void set_lpf();
|
2026-11-15 00:47:07 +06:00
|
|
|
void pitch_bend(uint16_t value);
|
|
|
|
|
|
|
|
|
|
double pitch_to_semitones(uint16_t value);
|
|
|
|
|
double semitones_to_multiplier(double semitones);
|
2026-11-15 12:35:20 +06:00
|
|
|
double mod_wheel_to_depth(uint8_t value);
|
2026-11-12 16:34:18 +06:00
|
|
|
|
2026-11-13 23:59:25 +06:00
|
|
|
bool note_on(uint8_t note, uint8_t velocity);
|
|
|
|
|
bool note_off(uint8_t note);
|
2026-11-12 22:37:00 +06:00
|
|
|
|
2026-11-12 16:34:18 +06:00
|
|
|
private:
|
2026-11-14 20:37:48 +06:00
|
|
|
Voice* find_free_voice();
|
2026-11-15 00:47:07 +06:00
|
|
|
Voice* find_quietest_voice();
|
2026-11-13 02:02:50 +06:00
|
|
|
|
2026-11-16 00:49:29 +06:00
|
|
|
SpscQueue midi_queue;
|
|
|
|
|
SpscQueue gui_queue;
|
|
|
|
|
|
2026-11-15 12:35:20 +06:00
|
|
|
Lfo lfo;
|
2026-11-14 15:15:00 +06:00
|
|
|
|
2026-11-16 00:49:29 +06:00
|
|
|
Tables tables;
|
|
|
|
|
|
|
|
|
|
Wavetable sin_wavetable;
|
|
|
|
|
Wavetable saw_wavetable;
|
|
|
|
|
Wavetable square_wavetable;
|
|
|
|
|
Wavetable triangle_wavetable;
|
|
|
|
|
|
2026-11-15 00:47:07 +06:00
|
|
|
double pitch_bend_range;
|
|
|
|
|
double pitch_semitones;
|
|
|
|
|
double pitch_multiplier;
|
2026-11-15 12:35:20 +06:00
|
|
|
double vibrato_depth_;
|
2026-11-15 00:47:07 +06:00
|
|
|
|
2026-11-15 12:35:20 +06:00
|
|
|
uint8_t mod_wheel;
|
2026-11-15 00:47:07 +06:00
|
|
|
uint64_t stolen_voices;
|
|
|
|
|
|
2026-11-14 15:15:00 +06:00
|
|
|
std::array<Voice, 8> voices;
|
2026-11-12 16:34:18 +06:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif
|