summaryrefslogblamecommitdiffstats
path: root/src/osc_saw.c
blob: bc2fd930fb99595fac33c327d8e6afe6fa075669 (plain) (tree)
1
2
3
4
5
6
7





                                               
            




















                                                                                  
#include "osc.h"

osc_t OSC_saw = MAKE_OSC("f_saw", 20000, WAVE);

OSC_COMMON(saw)

static float
sawX(float sm, int offset, int len)
{
  float dOutput = 0.0;
  for (float n = 1.0; n < sm; n++)
    dOutput += (sinf(n * 2.0 * M_PI * offset / len)) / n;
  return 0.5 * dOutput;
}

float
osc_saw(float offset)
{
  return osc_interpolate(offset,
                         sawX(25, (int)offset, OSC_saw.len),
                         sawX(25, osc_next_index(&OSC_saw, offset), OSC_saw.len));
}

float
osc_saw_next(float f, float offset)
{
  return osc_next_offset(&OSC_saw, f, offset);
}