Skip to content

Instantly share code, notes, and snippets.

@safiire
Last active December 22, 2015 19:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save safiire/6519086 to your computer and use it in GitHub Desktop.
Save safiire/6519086 to your computer and use it in GitHub Desktop.
A Phase Accumulator / Sine wave generator in Faust
import("math.lib");
Tau = 6.283185307179586;
Pi = 3.141592653589793;
Fs = SR;
oscillator(f, amplitude) = phase_accumulator(w) : sinf * amplitude with {
w = f / Fs * Tau;
sinf = ffunction(float sinf(float), <math.h>, "");
};
phase_accumulator(w) = (accumulator(w) ~ _) - w with {
accumulator(w, phase) = output with {
if = (w + phase) >= Tau;
reset = w + phase - Tau;
add = w + phase;
output = (if,add,reset) : select2;
};
};
process = oscillator(440, 0.7) , oscillator(440, 0.7) ;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment