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