теперь работает MIDI Pitch Bend с диапазоном +- 2 полутона

This commit is contained in:
2026-11-15 00:47:07 +06:00
parent 2cff003e4b
commit 6773949803
9 changed files with 139 additions and 39 deletions
+6 -4
View File
@@ -6,13 +6,15 @@
enum class CommandType{
None,
NoteOn,
NoteOff
NoteOff,
PitchBend
};
struct Command{
CommandType type;
uint8_t note;
uint8_t velocity;
CommandType type = CommandType::None;
uint8_t note = 0;
uint8_t velocity = 0;
uint16_t pitch_bend = 8192;
};
#endif
+2
View File
@@ -40,9 +40,11 @@ class Envelope{
void note_on();
void note_off();
double process();
bool is_idle() const;
bool is_release() const;
private:
Condition condition;
+3 -1
View File
@@ -13,7 +13,7 @@ class MidiInput{
public:
MidiInput(Synth& synth) : synth_(synth){
pitch = 8192;
}
void list_ports();
@@ -24,6 +24,8 @@ class MidiInput{
RtMidiIn midiIn;
Synth& synth_;
uint16_t pitch;
};
#endif
+20
View File
@@ -3,6 +3,7 @@
#include <cstdint>
#include <array>
#include <cmath>
#include "../include/spsc_queue.hpp"
#include "../include/command.hpp"
@@ -11,21 +12,40 @@
class Synth {
public:
Synth(){
pitch_bend_range = 2.0;
pitch_semitones = 0.0;
pitch_multiplier = 1.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 pitch_bend(uint16_t value);
double pitch_to_semitones(uint16_t value);
double semitones_to_multiplier(double semitones);
bool note_on(uint8_t note, uint8_t velocity);
bool note_off(uint8_t note);
private:
Voice* find_free_voice();
Voice* find_quietest_voice();
SpscQueue queue;
double pitch_bend_range;
double pitch_semitones;
double pitch_multiplier;
uint64_t stolen_voices;
std::array<Voice, 8> voices;
};
+10 -3
View File
@@ -16,7 +16,11 @@ class Voice{
public:
Voice(){
note = 0;
envelope_value = 0.0;
pan = 0.0;
base_frequency = 440.0;
multiplier_ = 1.0;
active = false;
}
@@ -24,11 +28,15 @@ class Voice{
void note_on(uint8_t note, uint8_t velocity);
void note_off();
void set_pan(double value);
void set_pitch_bend(double multiplier);
StereoSample generate();
double get_volume() const;
bool is_active() const;
bool is_playing(uint8_t note_) const;
bool is_released() const;
private:
Envelope envelope;
@@ -38,11 +46,10 @@ class Voice{
double envelope_value;
double pan;
double base_frequency;
double multiplier_;
bool active;
};
#endif