Advertisement
Guest User

Untitled

a guest
Feb 20th, 2020
110
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #pragma once
  2.  
  3. class Osc {
  4. public:
  5.     Osc() { phase = 0; }
  6.  
  7.     void setSampleRate(float sr) {
  8.         sampleRate = sr;
  9.         srDiv = 2.f / sampleRate;
  10.     }
  11.  
  12.     void setFreq(float f) {
  13.         freq = f;
  14.         inc = srDiv * freq;
  15.     }
  16.  
  17.     float getFreq() { return freq; }
  18.  
  19.     void run() {
  20.         phase += inc;
  21.         if (phase > 1.f)
  22.             phase -= 2.f;
  23.     }
  24.  
  25.     float getSin() {
  26.         return sin(phase * MathConstants<float>::pi);
  27.     }
  28.  
  29. private:
  30.     float sampleRate, srDiv, freq, inc, phase;
  31. };
Advertisement
RAW Paste Data Copied
Advertisement