Files
osc/include/voice.hpp
T

60 lines
1.2 KiB
C++
Raw Normal View History

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;
envelope_value = 0.0;
2026-11-14 20:37:48 +06:00
pan = 0.0;
base_frequency = 440.0;
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);
void set_pitch_bend(double multiplier);
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
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;
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;
double base_frequency;
double pitch_bend;
double vibrato;
2026-11-14 20:37:48 +06:00
2026-11-14 15:15:00 +06:00
bool active;
};
#endif