b0a75e98db
вайбкод потому что мне в моменте стало понятно. что проще было сразу писать на фреймворке JUCE, чем адаптировать консольное приложение на MiniAudio. обновляться данный репозиторий не будет. СmakeLists адаптирован онли под linux.
128 lines
3.7 KiB
C++
128 lines
3.7 KiB
C++
#ifndef SYNTH
|
|
#define SYNTH
|
|
|
|
#include <cstdint>
|
|
#include <array>
|
|
#include <cmath>
|
|
|
|
#include "../include/spsc_queue.hpp"
|
|
#include "../include/command.hpp"
|
|
#include "../include/voice.hpp"
|
|
#include "../include/stereo_sample.hpp"
|
|
#include "../include/lfo.hpp"
|
|
|
|
class Synth {
|
|
public:
|
|
|
|
Synth(){
|
|
|
|
sin_wavetable.generate_sin(32);
|
|
saw_wavetable.generate_saw(32);
|
|
square_wavetable.generate_square(28);
|
|
triangle_wavetable.generate_triangle(40);
|
|
|
|
pitch_bend_range = 2.0;
|
|
pitch_semitones = 0.0;
|
|
pitch_multiplier = 1.0;
|
|
vibrato_depth_ = 0.0;
|
|
|
|
mod_wheel = 0;
|
|
stolen_voices = 0;
|
|
sample_rate = 48000.0;
|
|
|
|
set_wavetable(&saw_wavetable);
|
|
set_wavetable2(&square_wavetable);
|
|
}
|
|
|
|
void prepare(double sample_rate_);
|
|
void render_block(float* left, float* right, int num_samples);
|
|
|
|
StereoSample generate();
|
|
|
|
void generate_buffer(double* array, int size);
|
|
void set_mod_wheel(uint8_t value);
|
|
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_wavetable2(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();
|
|
void pitch_bend(uint16_t value);
|
|
|
|
void set_attack(double value);
|
|
void set_decay(double value);
|
|
void set_sustain(double value);
|
|
void set_release(double value);
|
|
void set_lfo_frequency(double value);
|
|
void set_pitch_bend_range(double value);
|
|
|
|
void apply_unison_voices(int value);
|
|
void apply_unison_gain(double value);
|
|
void apply_stereo_spread(double value);
|
|
void apply_detune_amount(double value);
|
|
void apply_waveform(int index);
|
|
void apply_waveform2(int index);
|
|
void apply_osc1_enabled(bool enabled);
|
|
void apply_osc2_enabled(bool enabled);
|
|
void apply_osc1_level(double value);
|
|
void apply_osc2_level(double value);
|
|
void apply_filter_type(int index);
|
|
void apply_filter_cutoff(double value);
|
|
void apply_filter_resonance(double value);
|
|
void apply_mod_wheel(uint8_t value);
|
|
void apply_pitch_bend(uint16_t value);
|
|
|
|
Wavetable* get_wavetable(int index);
|
|
Wavetable* get_wavetable2(int index);
|
|
|
|
void note_on_direct(uint8_t note, uint8_t velocity);
|
|
void note_off_direct(uint8_t note);
|
|
void all_notes_off();
|
|
|
|
double pitch_to_semitones(uint16_t value);
|
|
double semitones_to_multiplier(double semitones);
|
|
double mod_wheel_to_depth(uint8_t value);
|
|
|
|
bool note_on(uint8_t note, uint8_t velocity);
|
|
bool note_off(uint8_t note);
|
|
|
|
private:
|
|
Voice* find_free_voice();
|
|
Voice* find_quietest_voice();
|
|
|
|
SpscQueue midi_queue;
|
|
SpscQueue gui_queue;
|
|
|
|
Lfo lfo;
|
|
|
|
Tables tables;
|
|
|
|
Wavetable sin_wavetable;
|
|
Wavetable saw_wavetable;
|
|
Wavetable square_wavetable;
|
|
Wavetable triangle_wavetable;
|
|
|
|
double pitch_bend_range;
|
|
double pitch_semitones;
|
|
double pitch_multiplier;
|
|
double vibrato_depth_;
|
|
|
|
uint8_t mod_wheel;
|
|
uint64_t stolen_voices;
|
|
double sample_rate;
|
|
|
|
std::array<Voice, 8> voices;
|
|
};
|
|
|
|
#endif
|