51 lines
1.1 KiB
C++
51 lines
1.1 KiB
C++
#ifndef SYNTH
|
|
#define SYNTH
|
|
|
|
#include <cstdint>
|
|
#include <numbers>
|
|
#include <cmath>
|
|
#include <atomic>
|
|
|
|
#include "../include/envelope.hpp"
|
|
#include "../include/spsc_queue.hpp"
|
|
#include "../include/command.hpp"
|
|
|
|
class Synth {
|
|
public:
|
|
Synth(){
|
|
frequency = 440.0;
|
|
amplitude = 0.5;
|
|
sample_rate = 48000;
|
|
phase = 0.0;
|
|
current_note = 0;
|
|
};
|
|
|
|
double generate();
|
|
|
|
void generate_buffer(double* array, int size);
|
|
void set_frequency(double value);
|
|
void set_amplitude(double value);
|
|
void set_midi_note(uint8_t note);
|
|
|
|
bool note_on(uint8_t note, uint8_t velocity);
|
|
bool note_off(uint8_t note);
|
|
|
|
private:
|
|
/* 1. частота звука в Герцах
|
|
2. громкость звука, от 0 до 1
|
|
3. частота дискретизации
|
|
4. фаза. от 0 до 2 пи*/
|
|
|
|
Envelope envelope;
|
|
SpscQueue queue;
|
|
|
|
double frequency;
|
|
double amplitude;
|
|
double phase;
|
|
|
|
uint32_t sample_rate;
|
|
uint8_t current_note;
|
|
};
|
|
|
|
#endif
|