добавлено управление Pitch Bend и Vibrato через MIDI

реализовано:
1. обработка MIDI Pitch Bend
2. управление глубиной вибрато через Mod Wheel (CC1)
3. реализован LFO на основе синусоидальной волны
4. добавлена частотная модуляция голосов с помощью LFO
5. реализовано совместное применение Pitch Bend и Vibrato без взаимного перезаписывания эффектов
6. добавлен пересчет частоты осциллятора с учетом всех множителей
This commit is contained in:
2026-11-15 12:35:20 +06:00
parent 6773949803
commit 9b01cf0480
10 changed files with 121 additions and 29 deletions
+3 -1
View File
@@ -7,7 +7,8 @@ enum class CommandType{
None,
NoteOn,
NoteOff,
PitchBend
PitchBend,
ModWheel
};
struct Command{
@@ -15,6 +16,7 @@ struct Command{
uint8_t note = 0;
uint8_t velocity = 0;
uint16_t pitch_bend = 8192;
uint8_t mod_wheel = 0;
};
#endif
+28
View File
@@ -0,0 +1,28 @@
#ifndef LFO
#define LFO
#include <cstdint>
#include <numbers>
#include <cmath>
class Lfo{
public:
Lfo(){
sample = 0.0;
frequency = 5.0;
phase = 0.0;
sample_rate = 48000;
}
double generate();
void set_frequency(double value);
private:
double sample;
double frequency;
double phase;
uint32_t sample_rate;
};
#endif
+2
View File
@@ -14,6 +14,7 @@ class MidiInput{
public:
MidiInput(Synth& synth) : synth_(synth){
pitch = 8192;
mod_wheel = 0;
}
void list_ports();
@@ -25,6 +26,7 @@ class MidiInput{
Synth& synth_;
uint16_t pitch;
uint8_t mod_wheel;
};
+9 -3
View File
@@ -9,6 +9,7 @@
#include "../include/command.hpp"
#include "../include/voice.hpp"
#include "../include/stereo_sample.hpp"
#include "../include/lfo.hpp"
class Synth {
public:
@@ -17,19 +18,21 @@ class Synth {
pitch_bend_range = 2.0;
pitch_semitones = 0.0;
pitch_multiplier = 1.0;
vibrato_depth_ = 0.0;
mod_wheel = 0;
stolen_voices = 0;
}
StereoSample 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);
void set_mod_wheel(uint8_t value);
void pitch_bend(uint16_t value);
double pitch_to_semitones(uint16_t value);
double semitones_to_multiplier(double semitones);
double mod_wheel_to_depth(uint8_t value);
bool note_on(uint8_t note, uint8_t velocity);
bool note_off(uint8_t note);
@@ -39,11 +42,14 @@ class Synth {
Voice* find_quietest_voice();
SpscQueue queue;
Lfo lfo;
double pitch_bend_range;
double pitch_semitones;
double pitch_multiplier;
double vibrato_depth_;
uint8_t mod_wheel;
uint64_t stolen_voices;
std::array<Voice, 8> voices;
+6 -2
View File
@@ -20,7 +20,8 @@ class Voice{
envelope_value = 0.0;
pan = 0.0;
base_frequency = 440.0;
multiplier_ = 1.0;
pitch_bend = 1.0;
vibrato = 1.0;
active = false;
}
@@ -29,6 +30,8 @@ class Voice{
void note_off();
void set_pan(double value);
void set_pitch_bend(double multiplier);
void set_vibrato(double multiplier);
void update_frequency();
StereoSample generate();
@@ -47,7 +50,8 @@ class Voice{
double envelope_value;
double pan;
double base_frequency;
double multiplier_;
double pitch_bend;
double vibrato;
bool active;
};