2026-11-12 16:34:18 +06:00
|
|
|
#ifndef SYNTH
|
|
|
|
|
#define SYNTH
|
|
|
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
|
#include <numbers>
|
|
|
|
|
#include <cmath>
|
2026-11-13 18:31:07 +06:00
|
|
|
#include <atomic>
|
|
|
|
|
|
2026-11-13 02:02:50 +06:00
|
|
|
#include "../include/envelope.hpp"
|
2026-11-13 18:31:07 +06:00
|
|
|
#include "../include/spsc_queue.hpp"
|
|
|
|
|
#include "../include/command.hpp"
|
2026-11-12 16:34:18 +06:00
|
|
|
|
|
|
|
|
class Synth {
|
|
|
|
|
public:
|
2026-11-12 20:19:00 +06:00
|
|
|
Synth(){
|
|
|
|
|
frequency = 440;
|
|
|
|
|
amplitude = 0.5;
|
|
|
|
|
sample_rate = 48000;
|
|
|
|
|
phase = 0.0;
|
|
|
|
|
};
|
|
|
|
|
|
2026-11-12 16:34:18 +06:00
|
|
|
double generate();
|
2026-11-12 22:37:00 +06:00
|
|
|
|
2026-11-12 16:34:18 +06:00
|
|
|
void generate_buffer(double* array, int size);
|
|
|
|
|
void set_frequency(double value);
|
|
|
|
|
void set_amplitude(double value);
|
|
|
|
|
|
2026-11-13 18:31:07 +06:00
|
|
|
bool note_on();
|
|
|
|
|
bool note_off();
|
2026-11-12 22:37:00 +06:00
|
|
|
|
2026-11-12 16:34:18 +06:00
|
|
|
private:
|
2026-11-12 22:37:00 +06:00
|
|
|
/* 1. частота звука в Герцах
|
|
|
|
|
2. громкость звука, от 0 до 1
|
|
|
|
|
3. частота дискретизации
|
|
|
|
|
4. фаза. от 0 до 2 пи*/
|
2026-11-13 02:02:50 +06:00
|
|
|
|
|
|
|
|
Envelope envelope;
|
2026-11-13 18:31:07 +06:00
|
|
|
SpscQueue queue;
|
2026-11-13 02:02:50 +06:00
|
|
|
|
2026-11-12 20:19:00 +06:00
|
|
|
double frequency;
|
|
|
|
|
double amplitude;
|
|
|
|
|
double phase;
|
2026-11-13 02:02:50 +06:00
|
|
|
|
|
|
|
|
uint32_t sample_rate;
|
2026-11-12 16:34:18 +06:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif
|