No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

sineosc.c 390B

12345678910111213141516171819
  1. #include <math.h>
  2. #include "sineosc.h"
  3. #include "config.h"
  4. void sine_osc_init(struct SineOsc *osc) {
  5. osc->s0 = 1.0;
  6. osc->s1 = 0.0;
  7. }
  8. void sine_osc_set_freq(struct SineOsc *osc, float freq) {
  9. osc->a = 2.0 * sinf(M_PI * freq / SAMPLE_RATE);
  10. }
  11. float sine_osc_sample(struct SineOsc *osc) {
  12. osc->s0 = osc->s0 - osc->a * osc->s1;
  13. osc->s1 = osc->s1 + osc->a * osc->s0;
  14. return osc->s0;
  15. }