..
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
#ifndef OSCILLATOR
|
||||
#define OSCILLATOR
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
struct Oscillator{
|
||||
double frequency = 440.0;
|
||||
double amplitude = 0.5;
|
||||
double phase = 0.0;
|
||||
|
||||
uint32_t sample_rate = 48000;
|
||||
};
|
||||
|
||||
#endif
|
||||
+6
-8
@@ -5,18 +5,17 @@
|
||||
#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"
|
||||
|
||||
class Synth {
|
||||
public:
|
||||
Synth(){
|
||||
frequency = 440.0;
|
||||
amplitude = 0.5;
|
||||
sample_rate = 48000;
|
||||
phase = 0.0;
|
||||
current_note = 0;
|
||||
};
|
||||
|
||||
@@ -38,12 +37,11 @@ class Synth {
|
||||
|
||||
Envelope envelope;
|
||||
SpscQueue queue;
|
||||
Oscillator oscillator;
|
||||
|
||||
std::array<Voice, 8> voices;
|
||||
|
||||
double frequency;
|
||||
double amplitude;
|
||||
double phase;
|
||||
|
||||
uint32_t sample_rate;
|
||||
uint8_t current_note;
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
#ifndef VOICE
|
||||
#define VOICE
|
||||
|
||||
#include <cstdint>
|
||||
#include <numbers>
|
||||
#include <cmath>
|
||||
|
||||
#include "../include/envelope.hpp"
|
||||
#include "../include/oscillator.hpp"
|
||||
|
||||
class Voice{
|
||||
public:
|
||||
Voice(){
|
||||
note = 0;
|
||||
|
||||
active = false;
|
||||
}
|
||||
|
||||
void note_on(uint8_t note, uint8_t velocity);
|
||||
void note_off();
|
||||
|
||||
double generate();
|
||||
|
||||
bool is_active() const;
|
||||
|
||||
private:
|
||||
Envelope envelope;
|
||||
Oscillator oscillator;
|
||||
|
||||
uint8_t note;
|
||||
|
||||
bool active;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user