2026-08-06 00:03:43 +01:00
|
|
|
#ifndef OSCILLATOR_HPP_INCLUDED
|
|
|
|
|
#define OSCILLATOR_HPP_INCLUDED
|
|
|
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
|
|
|
|
|
|
#ifndef M_PI
|
|
|
|
|
#define M_PI 3.14159265358979323846
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
class Oscillator {
|
|
|
|
|
enum WaveShape { kWaveShapeSine, kWaveShapeTriangle, kWaveShapeSquare };
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
Oscillator(float initFreq);
|
|
|
|
|
void process(float *out, uint32_t frames);
|
|
|
|
|
|
|
|
|
|
void setFrequency(float newFreq);
|
|
|
|
|
float getFrequency() const;
|
|
|
|
|
|
|
|
|
|
void setGain(float newGain);
|
|
|
|
|
float getGain() const;
|
|
|
|
|
|
|
|
|
|
void setSampleRate(float newSampleRate);
|
|
|
|
|
float getSampleRate() const;
|
|
|
|
|
|
|
|
|
|
void setWaveShape(WaveShape shape);
|
|
|
|
|
WaveShape getWaveShape() const;
|
|
|
|
|
|
2026-08-12 00:05:50 +01:00
|
|
|
void reset();
|
|
|
|
|
|
2026-08-06 00:03:43 +01:00
|
|
|
private:
|
|
|
|
|
float freq_;
|
|
|
|
|
float gain_;
|
|
|
|
|
WaveShape waveShape_;
|
|
|
|
|
float sampleRate_;
|
|
|
|
|
float phase_;
|
|
|
|
|
float inc_;
|
|
|
|
|
void recalc_();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif // OSCILLATOR_HPP_INCLUDED
|