scaffold new classes
This commit is contained in:
@@ -47,6 +47,10 @@ add_library(sonobulus_core STATIC
|
|||||||
src/synth/KeyboardController.cpp
|
src/synth/KeyboardController.cpp
|
||||||
src/synth/MidiController.cpp
|
src/synth/MidiController.cpp
|
||||||
src/synth/NoteQueue.cpp
|
src/synth/NoteQueue.cpp
|
||||||
|
src/synth/Scope.cpp
|
||||||
|
src/synth/Synth.cpp
|
||||||
|
src/synth/Voice.cpp
|
||||||
|
src/synth/Instrument.cpp
|
||||||
)
|
)
|
||||||
target_link_libraries(sonobulus_core PRIVATE
|
target_link_libraries(sonobulus_core PRIVATE
|
||||||
Qt6::Core
|
Qt6::Core
|
||||||
|
|||||||
0
src/synth/Instrument.cpp
Normal file
0
src/synth/Instrument.cpp
Normal file
15
src/synth/Instrument.hpp
Normal file
15
src/synth/Instrument.hpp
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
// an instrument is our state space model. it calculates discrete samples as a function of time, the current states, and the inputs
|
||||||
|
// an instrumeent is owned by a voice
|
||||||
|
class Instrument {
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
Instrument() = default;
|
||||||
|
~Instrument() = default;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
};
|
||||||
0
src/synth/Scope.cpp
Normal file
0
src/synth/Scope.cpp
Normal file
27
src/synth/Scope.hpp
Normal file
27
src/synth/Scope.hpp
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <atomic>
|
||||||
|
|
||||||
|
class ScopeBuffer {
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
ScopeBuffer(size_t size);
|
||||||
|
~ScopeBuffer() = default;
|
||||||
|
|
||||||
|
void push(float sample);
|
||||||
|
void read(std::vector<float>& out);
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
std::vector<float> buffer_;
|
||||||
|
std::atomic<size_t> writeIndex_{0};
|
||||||
|
|
||||||
|
size_t trigger_ = 0;
|
||||||
|
uint32_t wavelgnth = 400;
|
||||||
|
|
||||||
|
bool spinLock_ = false;
|
||||||
|
|
||||||
|
};
|
||||||
0
src/synth/Synth.cpp
Normal file
0
src/synth/Synth.cpp
Normal file
35
src/synth/Synth.hpp
Normal file
35
src/synth/Synth.hpp
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "ConfigService.hpp"
|
||||||
|
#include "LoggerService.hpp"
|
||||||
|
#include "NoteQueue.hpp"
|
||||||
|
#include "Voice.hpp"
|
||||||
|
#include "Scope.hpp"
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
class Synth {
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
Synth(ConfigService* config, LoggerService* logger, ScopeBuffer* scope);
|
||||||
|
~Synth();
|
||||||
|
|
||||||
|
void process(float* out, size_t nFrames, uint32_t sampleRate);
|
||||||
|
void handleNoteEvent(const NoteEvent& event);
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
Voice* findFreeVoice();
|
||||||
|
Voice* findVoiceByNote(uint8_t note);
|
||||||
|
|
||||||
|
std::vector<uint8_t> sustainedNotes_;
|
||||||
|
|
||||||
|
// voices
|
||||||
|
static constexpr size_t MAX_VOICES = 32;
|
||||||
|
std::array<Voice, MAX_VOICES> voices_;
|
||||||
|
|
||||||
|
ScopeBuffer* scope_ = nullptr;
|
||||||
|
|
||||||
|
}
|
||||||
0
src/synth/Voice.cpp
Normal file
0
src/synth/Voice.cpp
Normal file
36
src/synth/Voice.hpp
Normal file
36
src/synth/Voice.hpp
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include "Instrument.hpp"
|
||||||
|
|
||||||
|
// a voice is a tone generator that the synth uses for polyphony
|
||||||
|
// the synth mixes multiple voices together into a polyphonic audio. calculations for samples are handled in the instrument
|
||||||
|
class Voice {
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
Voice() = default;
|
||||||
|
~Voice() = default;
|
||||||
|
|
||||||
|
void noteOn(int8_t midiNote, float velocity);
|
||||||
|
void noteOff();
|
||||||
|
bool isActive();
|
||||||
|
|
||||||
|
float process(bool& scopeTrigger);
|
||||||
|
uint8_t note() { return note_; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
float sampleRate_ = 44100.0f;
|
||||||
|
|
||||||
|
inline float noteToFrequency(uint8_t note);
|
||||||
|
|
||||||
|
uint8_t note_ = 0;
|
||||||
|
float velocity_ = 1.0f;
|
||||||
|
bool active_ = false;
|
||||||
|
|
||||||
|
Instrument* instrument;
|
||||||
|
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user