2026-11-14 15:15:00 +06:00
|
|
|
#ifndef VOICE
|
|
|
|
|
#define VOICE
|
|
|
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
|
#include <numbers>
|
|
|
|
|
#include <cmath>
|
2026-11-14 20:37:48 +06:00
|
|
|
#include <algorithm>
|
|
|
|
|
#include <random>
|
2026-11-14 15:15:00 +06:00
|
|
|
|
|
|
|
|
#include "../include/envelope.hpp"
|
|
|
|
|
#include "../include/oscillator.hpp"
|
2026-11-14 20:37:48 +06:00
|
|
|
#include "../include/stereo_sample.hpp"
|
|
|
|
|
|
2026-11-14 15:15:00 +06:00
|
|
|
|
|
|
|
|
class Voice{
|
|
|
|
|
public:
|
|
|
|
|
Voice(){
|
|
|
|
|
note = 0;
|
2026-11-15 00:47:07 +06:00
|
|
|
|
|
|
|
|
envelope_value = 0.0;
|
2026-11-14 20:37:48 +06:00
|
|
|
pan = 0.0;
|
2026-11-15 00:47:07 +06:00
|
|
|
base_frequency = 440.0;
|
2026-11-15 12:35:20 +06:00
|
|
|
pitch_bend = 1.0;
|
|
|
|
|
vibrato = 1.0;
|
2026-11-14 15:15:00 +06:00
|
|
|
|
|
|
|
|
active = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void note_on(uint8_t note, uint8_t velocity);
|
|
|
|
|
void note_off();
|
2026-11-14 20:37:48 +06:00
|
|
|
void set_pan(double value);
|
2026-11-15 00:47:07 +06:00
|
|
|
void set_pitch_bend(double multiplier);
|
2026-11-15 12:35:20 +06:00
|
|
|
void set_vibrato(double multiplier);
|
|
|
|
|
void update_frequency();
|
2026-11-14 15:15:00 +06:00
|
|
|
|
2026-11-14 20:37:48 +06:00
|
|
|
StereoSample generate();
|
2026-11-14 15:15:00 +06:00
|
|
|
|
2026-11-15 00:47:07 +06:00
|
|
|
double get_volume() const;
|
|
|
|
|
|
2026-11-14 15:15:00 +06:00
|
|
|
bool is_active() const;
|
2026-11-14 20:37:48 +06:00
|
|
|
bool is_playing(uint8_t note_) const;
|
2026-11-15 00:47:07 +06:00
|
|
|
bool is_released() const;
|
2026-11-14 15:15:00 +06:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
Envelope envelope;
|
|
|
|
|
Oscillator oscillator;
|
|
|
|
|
|
|
|
|
|
uint8_t note;
|
|
|
|
|
|
2026-11-14 20:37:48 +06:00
|
|
|
double envelope_value;
|
|
|
|
|
double pan;
|
2026-11-15 00:47:07 +06:00
|
|
|
double base_frequency;
|
2026-11-15 12:35:20 +06:00
|
|
|
double pitch_bend;
|
|
|
|
|
double vibrato;
|
2026-11-14 20:37:48 +06:00
|
|
|
|
2026-11-14 15:15:00 +06:00
|
|
|
bool active;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif
|