SquidgeDSP/core/Oscillator.hpp

41 lines
779 B
C++
Raw Permalink Normal View History

#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();
private:
float freq_;
float gain_;
WaveShape waveShape_;
float sampleRate_;
float phase_;
float inc_;
void recalc_();
};
#endif // OSCILLATOR_HPP_INCLUDED