полифония!
на данном этапе: 1. 8 полифонических голосов 2. ADSR огибающая для каждого голоса 3. MIDI Note On/Note Off 4. стереовыход 5. Equal-Power Panning 6. случайное распределение голосов по стереополю
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include <iostream>
|
||||
#include "../external/miniaudio.h"
|
||||
#include "../include/synth.hpp"
|
||||
#include "../include/stereo_sample.hpp"
|
||||
|
||||
class AudioEngine{
|
||||
|
||||
|
||||
@@ -42,6 +42,8 @@ class Envelope{
|
||||
void note_off();
|
||||
double process();
|
||||
|
||||
bool is_idle() const;
|
||||
|
||||
private:
|
||||
Condition condition;
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
#ifndef STEREOSAMPLE
|
||||
#define STEREOSAMPLE
|
||||
|
||||
struct StereoSample{
|
||||
double left;
|
||||
double right;
|
||||
};
|
||||
|
||||
#endif
|
||||
+3
-19
@@ -2,24 +2,16 @@
|
||||
#define SYNTH
|
||||
|
||||
#include <cstdint>
|
||||
#include <numbers>
|
||||
#include <cmath>
|
||||
#include <atomic>
|
||||
#include <array>
|
||||
|
||||
#include "../include/envelope.hpp"
|
||||
#include "../include/spsc_queue.hpp"
|
||||
#include "../include/command.hpp"
|
||||
#include "../include/oscillator.hpp"
|
||||
#include "../include/voice.hpp"
|
||||
#include "../include/stereo_sample.hpp"
|
||||
|
||||
class Synth {
|
||||
public:
|
||||
Synth(){
|
||||
current_note = 0;
|
||||
};
|
||||
|
||||
double generate();
|
||||
StereoSample generate();
|
||||
|
||||
void generate_buffer(double* array, int size);
|
||||
void set_frequency(double value);
|
||||
@@ -30,19 +22,11 @@ class Synth {
|
||||
bool note_off(uint8_t note);
|
||||
|
||||
private:
|
||||
/* 1. частота звука в Герцах
|
||||
2. громкость звука, от 0 до 1
|
||||
3. частота дискретизации
|
||||
4. фаза. от 0 до 2 пи*/
|
||||
Voice* find_free_voice();
|
||||
|
||||
Envelope envelope;
|
||||
SpscQueue queue;
|
||||
Oscillator oscillator;
|
||||
|
||||
std::array<Voice, 8> voices;
|
||||
|
||||
|
||||
uint8_t current_note;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
+13
-1
@@ -4,24 +4,31 @@
|
||||
#include <cstdint>
|
||||
#include <numbers>
|
||||
#include <cmath>
|
||||
#include <algorithm>
|
||||
#include <random>
|
||||
|
||||
#include "../include/envelope.hpp"
|
||||
#include "../include/oscillator.hpp"
|
||||
#include "../include/stereo_sample.hpp"
|
||||
|
||||
|
||||
class Voice{
|
||||
public:
|
||||
Voice(){
|
||||
note = 0;
|
||||
pan = 0.0;
|
||||
|
||||
active = false;
|
||||
}
|
||||
|
||||
void note_on(uint8_t note, uint8_t velocity);
|
||||
void note_off();
|
||||
void set_pan(double value);
|
||||
|
||||
double generate();
|
||||
StereoSample generate();
|
||||
|
||||
bool is_active() const;
|
||||
bool is_playing(uint8_t note_) const;
|
||||
|
||||
private:
|
||||
Envelope envelope;
|
||||
@@ -29,8 +36,13 @@ class Voice{
|
||||
|
||||
uint8_t note;
|
||||
|
||||
double envelope_value;
|
||||
double pan;
|
||||
|
||||
bool active;
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user