add oscillator class

This commit is contained in:
2026-01-16 22:55:28 -06:00
parent 2e8953e489
commit 198b7f0dde
4 changed files with 122 additions and 58 deletions

View File

@@ -1,4 +1,50 @@
# pragma once
#pragma once
// placeholder
#include <cstdint>
#include <cmath>
#include <array>
#ifndef M_PI // I hate my stupid chungus life
#define M_PI 3.14159265358979323846
#endif
// TODO: you get it, also in a yml config
#define SYNTH_PITCH_STANDARD 440.0f // frequency of home pitch
#define SYNTH_MIDI_HOME 69 // midi note index of home pitch
#define SYNTH_NOTES_PER_OCTAVE 12
#define SYNTH_WAVETABLE_SIZE 2048
class Oscillator {
public:
Oscillator() = default;
~Oscillator() = default;
void setWavetable(uint8_t waveTableId);
void setSampleRate(float sampleRate);
float frequency();
float process(uint8_t note, bool& scopeTrigger);
float process(float frequency, bool& scopeTrigger);
private:
float sampleRate_ = 44100.0f;
inline float noteToFrequency(uint8_t note);
// internal state tracking
float phase_ = 0.0f;
uint8_t activeWavetable_;
float frequency_ = 220.0f;
// TODO: implement
// TODO: wavetable class that can load from files
// TODO: wavetables should be shared among the entire synth
std::array<float, SYNTH_WAVETABLE_SIZE> wavetable1_;
std::array<float, SYNTH_WAVETABLE_SIZE> wavetable2_;
std::array<float, SYNTH_WAVETABLE_SIZE> wavetable3_;
std::array<float, SYNTH_WAVETABLE_SIZE> wavetable4_;
};