🍑 nectarine
Audio synthesis tools for C23
Loading...
Searching...
No Matches
waveforms.h File Reference

Waveform functions. More...

#include <stddef.h>
#include <math.h>
#include "vendor/prelude/hint.h"

Go to the source code of this file.

Functions

static long double nec_wrapl (long double phase)
 Maps an arbitrary phase into the domain [0, 1).
static double nec_wrap (double phase)
 Maps an arbitrary phase into the domain [0, 1).
static float nec_wrapf (float phase)
 Maps an arbitrary phase into the domain [0, 1).
static void nec_fill_wrapl (size_t len, long double phase[const restrict static len], long double output[restrict static len])
 Maps a buffer of arbitrary phases into the domain [0, 1).
static void nec_fill_wrap (size_t len, double phase[const restrict static len], double output[restrict static len])
 Maps a buffer of arbitrary phases into the domain [0, 1).
static void nec_fill_wrapf (size_t len, float phase[const restrict static len], float output[restrict static len])
 Maps a buffer of arbitrary phases into the domain [0, 1).
static long double nec_analog_sawtoothl (long double phase)
 Analog-like sawtooth waveform.
static double nec_analog_sawtooth (double phase)
 Analog-like sawtooth waveform.
static float nec_analog_sawtoothf (float phase)
 Analog-like sawtooth waveform.
static void nec_fill_analog_sawtoothl (size_t len, long double phase[const restrict static len], long double output[restrict static len])
 Fills a buffer with an analog-like sawtooth waveform.
static void nec_fill_analog_sawtooth (size_t len, double phase[const restrict static len], double output[restrict static len])
 Fills a buffer with an analog-like sawtooth waveform.
static void nec_fill_analog_sawtoothf (size_t len, float phase[const restrict static len], float output[restrict static len])
 Fills a buffer with an analog-like sawtooth waveform.
static long double nec_analog_squarel (long double phase, long double duty)
 Analog-like square waveform.
static double nec_analog_square (double phase, double duty)
 Analog-like square waveform.
static float nec_analog_squaref (float phase, float duty)
 Analog-like square waveform.
static void nec_fill_analog_squarel (size_t len, long double phase[const restrict static len], long double duty[const restrict static len], long double output[restrict static len])
 Fills a buffer with an analog-like square waveform.
static void nec_fill_analog_square (size_t len, double phase[const restrict static len], double duty[const restrict static len], double output[restrict static len])
 Fills a buffer with an analog-like square waveform.
static void nec_fill_analog_squaref (size_t len, float phase[const restrict static len], float duty[const restrict static len], float output[restrict static len])
 Fills a buffer with an analog-like square waveform.
static long double nec_analog_trianglel (long double phase)
 Analog-like triangle waveform.
static double nec_analog_triangle (double phase)
 Analog-like triangle waveform.
static float nec_analog_trianglef (float phase)
 Analog-like triangle waveform.
static void nec_fill_analog_trianglel (size_t len, long double phase[const restrict static len], long double output[restrict static len])
 Fills a buffer with an analog-like triangle waveform.
static void nec_fill_analog_triangle (size_t len, double phase[const restrict static len], double output[restrict static len])
 Fills a buffer with an analog-like triangle waveform.
static void nec_fill_analog_trianglef (size_t len, float phase[const restrict static len], float output[restrict static len])
 Fills a buffer with an analog-like triangle waveform.
static long double nec_paraboll (long double phase)
 Fast sine approximation waveform.
static double nec_parabol (double phase)
 Fast sine approximation waveform.
static float nec_parabolf (float phase)
 Fast sine approximation waveform.
static void nec_fill_paraboll (size_t len, long double phase[const restrict static len], long double output[restrict static len])
 Fills a buffer with a fast sine approximation waveform.
static void nec_fill_parabol (size_t len, double phase[const restrict static len], double output[restrict static len])
 Fills a buffer with a fast sine approximation waveform.
static void nec_fill_parabolf (size_t len, float phase[const restrict static len], float output[restrict static len])
 Fills a buffer with a fast sine approximation waveform.
static long double nec_sinl (long double phase)
 Accurate sine approximation waveform.
static double nec_sin (double phase)
 Accurate sine approximation waveform.
static float nec_sinf (float phase)
 Accurate sine approximation waveform.
static void nec_fill_sinl (size_t len, long double phase[const restrict static len], long double output[restrict static len])
 Fills a buffer with an accurate sine approximation waveform.
static void nec_fill_sin (size_t len, double phase[const restrict static len], double output[restrict static len])
 Fills a buffer with an accurate sine approximation waveform.
static void nec_fill_sinf (size_t len, float phase[const restrict static len], float output[restrict static len])
 Fills a buffer with an accurate sine approximation waveform.
static long double nec_circlel (long double phase)
 Circle waveform function.
static double nec_circle (double phase)
 Circle waveform function.
static float nec_circlef (float phase)
 Circle waveform function.
static void nec_fill_circlel (size_t len, long double phase[const restrict static len], long double output[restrict static len])
 Fills a buffer with a circle waveform.
static void nec_fill_circle (size_t len, double phase[const restrict static len], double output[restrict static len])
 Fills a buffer with a circle waveform.
static void nec_fill_circlef (size_t len, float phase[const restrict static len], float output[restrict static len])
 Fills a buffer with a circle waveform.
static long double nec_sawtoothl (long double phase)
 Basic sawtooth waveform.
static double nec_sawtooth (double phase)
 Basic sawtooth waveform.
static float nec_sawtoothf (float phase)
 Basic sawtooth waveform.
static void nec_fill_sawtoothl (size_t len, long double phase[const restrict static len], long double output[restrict static len])
 Fills a buffer with a sawtooth waveform.
static void nec_fill_sawtooth (size_t len, double phase[const restrict static len], double output[restrict static len])
 Fills a buffer with a sawtooth waveform.
static void nec_fill_sawtoothf (size_t len, float phase[const restrict static len], float output[restrict static len])
 Fills a buffer with a sawtooth waveform.
static long double nec_squarel (long double phase, long double duty)
 Basic square waveform.
static double nec_square (double phase, double duty)
 Basic square waveform.
static float nec_squaref (float phase, float duty)
 Basic square waveform.
static void nec_fill_squarel (size_t len, long double phase[const restrict static len], long double duty[const restrict static len], long double output[restrict static len])
 Fills a buffer with a square waveform.
static void nec_fill_square (size_t len, double phase[const restrict static len], double duty[const restrict static len], double output[restrict static len])
 Fills a buffer with a square waveform.
static void nec_fill_squaref (size_t len, float phase[const restrict static len], float duty[const restrict static len], float output[restrict static len])
 Fills a buffer with a square waveform.
static long double nec_trianglel (long double phase)
 Basic triangle waveform.
static double nec_triangle (double phase)
 Basic triangle waveform.
static float nec_trianglef (float phase)
 Basic triangle waveform.
static void nec_fill_trianglel (size_t len, long double phase[const restrict static len], long double output[restrict static len])
 Fills a buffer with a triangle waveform.
static void nec_fill_triangle (size_t len, double phase[const restrict static len], double output[restrict static len])
 Fills a buffer with a triangle waveform.
static void nec_fill_trianglef (size_t len, float phase[const restrict static len], float output[restrict static len])
 Fills a buffer with a triangle waveform.

Variables

static constexpr long double NECTARINE_SINE_ERR_CORRECTION_WEIGHT = 0.225l
 Error correction term used to increase the accuracy of nec_sin.

Detailed Description

Waveform functions.

Function Documentation

◆ nec_analog_sawtooth()

double nec_analog_sawtooth ( double phase)
inlinestaticnodiscard

Analog-like sawtooth waveform.

This sawtooth waveform changes with an exponential curve to emulate a discharging capacitor (or charging, when inverted).

To be more precise, it approximates the exponential curve \(\frac{2e}{e-1}\left(e^{-x}-1\right)+1\) using a rational function.

Parameters
phaseThe input phase of the waveform, in domain [0, 1).
Returns
A sample of a sawtooth waveform, with range [-1, 1].

◆ nec_analog_sawtoothf()

float nec_analog_sawtoothf ( float phase)
inlinestaticnodiscard

Analog-like sawtooth waveform.

This sawtooth waveform changes with an exponential curve to emulate a discharging capacitor (or charging, when inverted).

To be more precise, it approximates the exponential curve \(\frac{2e}{e-1}\left(e^{-x}-1\right)+1\) using a rational function.

Parameters
phaseThe input phase of the waveform, in domain [0, 1).
Returns
A sample of a sawtooth waveform, with range [-1, 1].

◆ nec_analog_sawtoothl()

long double nec_analog_sawtoothl ( long double phase)
inlinestaticnodiscard

Analog-like sawtooth waveform.

This sawtooth waveform changes with an exponential curve to emulate a discharging capacitor (or charging, when inverted).

To be more precise, it approximates the exponential curve \(\frac{2e}{e-1}\left(e^{-x}-1\right)+1\) using a rational function.

Parameters
phaseThe input phase of the waveform, in domain [0, 1).
Returns
A sample of a sawtooth waveform, with range [-1, 1].

◆ nec_analog_square()

double nec_analog_square ( double phase,
double duty )
inlinestaticnodiscard

Analog-like square waveform.

This square waveform decays with an exponential curve to emulate a discharging capacitor.

To be more precise, it approximates the exponential curve \(\frac{e}{2\left(e-1\right)}\left(e^{-x}-1\right)+1\) using a rational function.

Parameters
phaseThe input phase of the waveform, in domain [0, 1).
dutyThe duty cycle of the waveform, in domain [0, 1].
Returns
A sample of a square waveform, with range [-1, 1].

◆ nec_analog_squaref()

float nec_analog_squaref ( float phase,
float duty )
inlinestaticnodiscard

Analog-like square waveform.

This square waveform decays with an exponential curve to emulate a discharging capacitor.

To be more precise, it approximates the exponential curve \(\frac{e}{2\left(e-1\right)}\left(e^{-x}-1\right)+1\) using a rational function.

Parameters
phaseThe input phase of the waveform, in domain [0, 1).
dutyThe duty cycle of the waveform, in domain [0, 1].
Returns
A sample of a square waveform, with range [-1, 1].

◆ nec_analog_squarel()

long double nec_analog_squarel ( long double phase,
long double duty )
inlinestaticnodiscard

Analog-like square waveform.

This square waveform decays with an exponential curve to emulate a discharging capacitor.

To be more precise, it approximates the exponential curve \(\frac{e}{2\left(e-1\right)}\left(e^{-x}-1\right)+1\) using a rational function.

Parameters
phaseThe input phase of the waveform, in domain [0, 1).
dutyThe duty cycle of the waveform, in domain [0, 1].
Returns
A sample of a square waveform, with range [-1, 1].

◆ nec_analog_triangle()

double nec_analog_triangle ( double phase)
inlinestaticnodiscard

Analog-like triangle waveform.

This triangle waveform changes with an exponential curve to emulate a charging and discharging capacitor.

To be more precise, it approximates the exponential curve \(\frac{2e}{e-1}\left(e^{-x}-1\right)+1\) using a rational function.

Parameters
phaseThe input phase of the waveform, in domain [0, 1).
Returns
A sample of a triangle waveform, with range [-1, 1].

◆ nec_analog_trianglef()

float nec_analog_trianglef ( float phase)
inlinestaticnodiscard

Analog-like triangle waveform.

This triangle waveform changes with an exponential curve to emulate a charging and discharging capacitor.

To be more precise, it approximates the exponential curve \(\frac{2e}{e-1}\left(e^{-x}-1\right)+1\) using a rational function.

Parameters
phaseThe input phase of the waveform, in domain [0, 1).
Returns
A sample of a triangle waveform, with range [-1, 1].

◆ nec_analog_trianglel()

long double nec_analog_trianglel ( long double phase)
inlinestaticnodiscard

Analog-like triangle waveform.

This triangle waveform changes with an exponential curve to emulate a charging and discharging capacitor.

To be more precise, it approximates the exponential curve \(\frac{2e}{e-1}\left(e^{-x}-1\right)+1\) using a rational function.

Parameters
phaseThe input phase of the waveform, in domain [0, 1).
Returns
A sample of a triangle waveform, with range [-1, 1].

◆ nec_circle()

double nec_circle ( double phase)
inlinestaticnodiscard

Circle waveform function.

This waveform looks like an alternating semicircle.

Parameters
phaseThe input phase of the waveform, in domain [0, 1).
Returns
A sample of circle waveform, with range [-1, 1].

◆ nec_circlef()

float nec_circlef ( float phase)
inlinestaticnodiscard

Circle waveform function.

This waveform looks like an alternating semicircle.

Parameters
phaseThe input phase of the waveform, in domain [0, 1).
Returns
A sample of circle waveform, with range [-1, 1].

◆ nec_circlel()

long double nec_circlel ( long double phase)
inlinestaticnodiscard

Circle waveform function.

This waveform looks like an alternating semicircle.

Parameters
phaseThe input phase of the waveform, in domain [0, 1).
Returns
A sample of circle waveform, with range [-1, 1].

◆ nec_fill_analog_sawtooth()

void nec_fill_analog_sawtooth ( size_t len,
double phase[const restrict static len],
double output[restrict static len] )
inlinestatic

Fills a buffer with an analog-like sawtooth waveform.

See also
nec_analog_sawtooth()
Parameters
[in]lenThe length of the input and output buffers, phase and output. Must be at least 1.
[in]phaseA buffer full of input phases in domain [0, 1).
[out]outputA buffer to be filled with samples of a sawtooth waveform, with range [-1, 1].

◆ nec_fill_analog_sawtoothf()

void nec_fill_analog_sawtoothf ( size_t len,
float phase[const restrict static len],
float output[restrict static len] )
inlinestatic

Fills a buffer with an analog-like sawtooth waveform.

See also
nec_analog_sawtooth()
Parameters
[in]lenThe length of the input and output buffers, phase and output. Must be at least 1.
[in]phaseA buffer full of input phases in domain [0, 1).
[out]outputA buffer to be filled with samples of a sawtooth waveform, with range [-1, 1].

◆ nec_fill_analog_sawtoothl()

void nec_fill_analog_sawtoothl ( size_t len,
long double phase[const restrict static len],
long double output[restrict static len] )
inlinestatic

Fills a buffer with an analog-like sawtooth waveform.

See also
nec_analog_sawtooth()
Parameters
[in]lenThe length of the input and output buffers, phase and output. Must be at least 1.
[in]phaseA buffer full of input phases in domain [0, 1).
[out]outputA buffer to be filled with samples of a sawtooth waveform, with range [-1, 1].

◆ nec_fill_analog_square()

void nec_fill_analog_square ( size_t len,
double phase[const restrict static len],
double duty[const restrict static len],
double output[restrict static len] )
inlinestatic

Fills a buffer with an analog-like square waveform.

See also
nec_analog_square()
Parameters
[in]lenThe length of the input and output buffers, phase and output. Must be at least 1.
[in]phaseA buffer full of input phases in domain [0, 1).
[in]dutyA buffer full of duty cycles in domain [0, 1].
[out]outputA buffer to be filled with samples of a square waveform, with range [-1, 1].

◆ nec_fill_analog_squaref()

void nec_fill_analog_squaref ( size_t len,
float phase[const restrict static len],
float duty[const restrict static len],
float output[restrict static len] )
inlinestatic

Fills a buffer with an analog-like square waveform.

See also
nec_analog_square()
Parameters
[in]lenThe length of the input and output buffers, phase and output. Must be at least 1.
[in]phaseA buffer full of input phases in domain [0, 1).
[in]dutyA buffer full of duty cycles in domain [0, 1].
[out]outputA buffer to be filled with samples of a square waveform, with range [-1, 1].

◆ nec_fill_analog_squarel()

void nec_fill_analog_squarel ( size_t len,
long double phase[const restrict static len],
long double duty[const restrict static len],
long double output[restrict static len] )
inlinestatic

Fills a buffer with an analog-like square waveform.

See also
nec_analog_square()
Parameters
[in]lenThe length of the input and output buffers, phase and output. Must be at least 1.
[in]phaseA buffer full of input phases in domain [0, 1).
[in]dutyA buffer full of duty cycles in domain [0, 1].
[out]outputA buffer to be filled with samples of a square waveform, with range [-1, 1].

◆ nec_fill_analog_triangle()

void nec_fill_analog_triangle ( size_t len,
double phase[const restrict static len],
double output[restrict static len] )
inlinestatic

Fills a buffer with an analog-like triangle waveform.

See also
nec_analog_triangle()
Parameters
[in]lenThe length of the input and output buffers, phase and output. Must be at least 1.
[in]phaseA buffer full of input phases in domain [0, 1).
[out]outputA buffer to be filled with samples of a triangle waveform, with range [-1, 1].

◆ nec_fill_analog_trianglef()

void nec_fill_analog_trianglef ( size_t len,
float phase[const restrict static len],
float output[restrict static len] )
inlinestatic

Fills a buffer with an analog-like triangle waveform.

See also
nec_analog_triangle()
Parameters
[in]lenThe length of the input and output buffers, phase and output. Must be at least 1.
[in]phaseA buffer full of input phases in domain [0, 1).
[out]outputA buffer to be filled with samples of a triangle waveform, with range [-1, 1].

◆ nec_fill_analog_trianglel()

void nec_fill_analog_trianglel ( size_t len,
long double phase[const restrict static len],
long double output[restrict static len] )
inlinestatic

Fills a buffer with an analog-like triangle waveform.

See also
nec_analog_triangle()
Parameters
[in]lenThe length of the input and output buffers, phase and output. Must be at least 1.
[in]phaseA buffer full of input phases in domain [0, 1).
[out]outputA buffer to be filled with samples of a triangle waveform, with range [-1, 1].

◆ nec_fill_circle()

void nec_fill_circle ( size_t len,
double phase[const restrict static len],
double output[restrict static len] )
inlinestatic

Fills a buffer with a circle waveform.

See also
nec_circle()
Parameters
[in]lenThe length of the input and output buffers, phase and output. Must be at least 1.
[in]phaseA buffer full of input phases in domain [0, 1).
[out]outputA buffer to be filled with samples of a circle waveform, with range [-1, 1].

◆ nec_fill_circlef()

void nec_fill_circlef ( size_t len,
float phase[const restrict static len],
float output[restrict static len] )
inlinestatic

Fills a buffer with a circle waveform.

See also
nec_circle()
Parameters
[in]lenThe length of the input and output buffers, phase and output. Must be at least 1.
[in]phaseA buffer full of input phases in domain [0, 1).
[out]outputA buffer to be filled with samples of a circle waveform, with range [-1, 1].

◆ nec_fill_circlel()

void nec_fill_circlel ( size_t len,
long double phase[const restrict static len],
long double output[restrict static len] )
inlinestatic

Fills a buffer with a circle waveform.

See also
nec_circle()
Parameters
[in]lenThe length of the input and output buffers, phase and output. Must be at least 1.
[in]phaseA buffer full of input phases in domain [0, 1).
[out]outputA buffer to be filled with samples of a circle waveform, with range [-1, 1].

◆ nec_fill_parabol()

void nec_fill_parabol ( size_t len,
double phase[const restrict static len],
double output[restrict static len] )
inlinestatic

Fills a buffer with a fast sine approximation waveform.

See also
nec_parabol()
Parameters
[in]lenThe length of the input and output buffers, phase and output. Must be at least 1.
[in]phaseA buffer full of input phases in domain [0, 1).
[out]outputA buffer to be filled with samples of an approximated sine waveform, with range [-1, 1].

◆ nec_fill_parabolf()

void nec_fill_parabolf ( size_t len,
float phase[const restrict static len],
float output[restrict static len] )
inlinestatic

Fills a buffer with a fast sine approximation waveform.

See also
nec_parabol()
Parameters
[in]lenThe length of the input and output buffers, phase and output. Must be at least 1.
[in]phaseA buffer full of input phases in domain [0, 1).
[out]outputA buffer to be filled with samples of an approximated sine waveform, with range [-1, 1].

◆ nec_fill_paraboll()

void nec_fill_paraboll ( size_t len,
long double phase[const restrict static len],
long double output[restrict static len] )
inlinestatic

Fills a buffer with a fast sine approximation waveform.

See also
nec_parabol()
Parameters
[in]lenThe length of the input and output buffers, phase and output. Must be at least 1.
[in]phaseA buffer full of input phases in domain [0, 1).
[out]outputA buffer to be filled with samples of an approximated sine waveform, with range [-1, 1].

◆ nec_fill_sawtooth()

void nec_fill_sawtooth ( size_t len,
double phase[const restrict static len],
double output[restrict static len] )
inlinestatic

Fills a buffer with a sawtooth waveform.

See also
nec_sawtooth()
Parameters
[in]lenThe length of the input and output buffers, phase and output. Must be at least 1.
[in]phaseA buffer full of input phases in domain [0, 1).
[out]outputA buffer to be filled with samples of a sawtooth waveform, with range [-1, 1].

◆ nec_fill_sawtoothf()

void nec_fill_sawtoothf ( size_t len,
float phase[const restrict static len],
float output[restrict static len] )
inlinestatic

Fills a buffer with a sawtooth waveform.

See also
nec_sawtooth()
Parameters
[in]lenThe length of the input and output buffers, phase and output. Must be at least 1.
[in]phaseA buffer full of input phases in domain [0, 1).
[out]outputA buffer to be filled with samples of a sawtooth waveform, with range [-1, 1].

◆ nec_fill_sawtoothl()

void nec_fill_sawtoothl ( size_t len,
long double phase[const restrict static len],
long double output[restrict static len] )
inlinestatic

Fills a buffer with a sawtooth waveform.

See also
nec_sawtooth()
Parameters
[in]lenThe length of the input and output buffers, phase and output. Must be at least 1.
[in]phaseA buffer full of input phases in domain [0, 1).
[out]outputA buffer to be filled with samples of a sawtooth waveform, with range [-1, 1].

◆ nec_fill_sin()

void nec_fill_sin ( size_t len,
double phase[const restrict static len],
double output[restrict static len] )
inlinestatic

Fills a buffer with an accurate sine approximation waveform.

See also
nec_sin()
Parameters
[in]lenThe length of the input and output buffers, phase and output. Must be at least 1.
[in]phaseA buffer full of input phases in domain [0, 1).
[out]outputA buffer to be filled with samples of a sine waveform, with range [-1, 1].

◆ nec_fill_sinf()

void nec_fill_sinf ( size_t len,
float phase[const restrict static len],
float output[restrict static len] )
inlinestatic

Fills a buffer with an accurate sine approximation waveform.

See also
nec_sin()
Parameters
[in]lenThe length of the input and output buffers, phase and output. Must be at least 1.
[in]phaseA buffer full of input phases in domain [0, 1).
[out]outputA buffer to be filled with samples of a sine waveform, with range [-1, 1].

◆ nec_fill_sinl()

void nec_fill_sinl ( size_t len,
long double phase[const restrict static len],
long double output[restrict static len] )
inlinestatic

Fills a buffer with an accurate sine approximation waveform.

See also
nec_sin()
Parameters
[in]lenThe length of the input and output buffers, phase and output. Must be at least 1.
[in]phaseA buffer full of input phases in domain [0, 1).
[out]outputA buffer to be filled with samples of a sine waveform, with range [-1, 1].

◆ nec_fill_square()

void nec_fill_square ( size_t len,
double phase[const restrict static len],
double duty[const restrict static len],
double output[restrict static len] )
inlinestatic

Fills a buffer with a square waveform.

See also
nec_square()
Parameters
[in]lenThe length of the input and output buffers, phase and output. Must be at least 1.
[in]phaseA buffer full of input phases in domain [0, 1).
[in]dutyA buffer full of duty cycles in domain [0, 1].
[out]outputA buffer to be filled with samples of a square waveform, with range [-1, 1].

◆ nec_fill_squaref()

void nec_fill_squaref ( size_t len,
float phase[const restrict static len],
float duty[const restrict static len],
float output[restrict static len] )
inlinestatic

Fills a buffer with a square waveform.

See also
nec_square()
Parameters
[in]lenThe length of the input and output buffers, phase and output. Must be at least 1.
[in]phaseA buffer full of input phases in domain [0, 1).
[in]dutyA buffer full of duty cycles in domain [0, 1].
[out]outputA buffer to be filled with samples of a square waveform, with range [-1, 1].

◆ nec_fill_squarel()

void nec_fill_squarel ( size_t len,
long double phase[const restrict static len],
long double duty[const restrict static len],
long double output[restrict static len] )
inlinestatic

Fills a buffer with a square waveform.

See also
nec_square()
Parameters
[in]lenThe length of the input and output buffers, phase and output. Must be at least 1.
[in]phaseA buffer full of input phases in domain [0, 1).
[in]dutyA buffer full of duty cycles in domain [0, 1].
[out]outputA buffer to be filled with samples of a square waveform, with range [-1, 1].

◆ nec_fill_triangle()

void nec_fill_triangle ( size_t len,
double phase[const restrict static len],
double output[restrict static len] )
inlinestatic

Fills a buffer with a triangle waveform.

See also
nec_triangle()
Parameters
[in]lenThe length of the input and output buffers, phase and output. Must be at least 1.
[in]phaseA buffer full of input phases in domain [0, 1).
[out]outputA buffer to be filled with samples of a triangle waveform, with range [-1, 1].

◆ nec_fill_trianglef()

void nec_fill_trianglef ( size_t len,
float phase[const restrict static len],
float output[restrict static len] )
inlinestatic

Fills a buffer with a triangle waveform.

See also
nec_triangle()
Parameters
[in]lenThe length of the input and output buffers, phase and output. Must be at least 1.
[in]phaseA buffer full of input phases in domain [0, 1).
[out]outputA buffer to be filled with samples of a triangle waveform, with range [-1, 1].

◆ nec_fill_trianglel()

void nec_fill_trianglel ( size_t len,
long double phase[const restrict static len],
long double output[restrict static len] )
inlinestatic

Fills a buffer with a triangle waveform.

See also
nec_triangle()
Parameters
[in]lenThe length of the input and output buffers, phase and output. Must be at least 1.
[in]phaseA buffer full of input phases in domain [0, 1).
[out]outputA buffer to be filled with samples of a triangle waveform, with range [-1, 1].

◆ nec_fill_wrap()

void nec_fill_wrap ( size_t len,
double phase[const restrict static len],
double output[restrict static len] )
inlinestatic

Maps a buffer of arbitrary phases into the domain [0, 1).

See also
nec_wrap()
Parameters
[in]lenThe length of the input and output buffers, phase and output. Must be at least 1.
[in]phaseA buffer full of arbitrary input phases.
[out]outputA buffer to be filled with equivalent phases to the contents of phase, but within the domain [0, 1).

◆ nec_fill_wrapf()

void nec_fill_wrapf ( size_t len,
float phase[const restrict static len],
float output[restrict static len] )
inlinestatic

Maps a buffer of arbitrary phases into the domain [0, 1).

See also
nec_wrap()
Parameters
[in]lenThe length of the input and output buffers, phase and output. Must be at least 1.
[in]phaseA buffer full of arbitrary input phases.
[out]outputA buffer to be filled with equivalent phases to the contents of phase, but within the domain [0, 1).

◆ nec_fill_wrapl()

void nec_fill_wrapl ( size_t len,
long double phase[const restrict static len],
long double output[restrict static len] )
inlinestatic

Maps a buffer of arbitrary phases into the domain [0, 1).

See also
nec_wrap()
Parameters
[in]lenThe length of the input and output buffers, phase and output. Must be at least 1.
[in]phaseA buffer full of arbitrary input phases.
[out]outputA buffer to be filled with equivalent phases to the contents of phase, but within the domain [0, 1).

◆ nec_parabol()

double nec_parabol ( double phase)
inlinestaticnodiscard

Fast sine approximation waveform.

This function generates a fast approximation of a sine waveform. It has a maximum absolute error of ±0.05601, which is quite large and produces audible harmonics, so it is intended for use in oscillators where these harmonics are desirable or LFOs where they aren't perceptible.

Parameters
phaseThe input phase of the waveform, in domain [0, 1).
Returns
A sample of an approximated sine waveform, with range [-1, 1].

◆ nec_parabolf()

float nec_parabolf ( float phase)
inlinestaticnodiscard

Fast sine approximation waveform.

This function generates a fast approximation of a sine waveform. It has a maximum absolute error of ±0.05601, which is quite large and produces audible harmonics, so it is intended for use in oscillators where these harmonics are desirable or LFOs where they aren't perceptible.

Parameters
phaseThe input phase of the waveform, in domain [0, 1).
Returns
A sample of an approximated sine waveform, with range [-1, 1].

◆ nec_paraboll()

long double nec_paraboll ( long double phase)
inlinestaticnodiscard

Fast sine approximation waveform.

This function generates a fast approximation of a sine waveform. It has a maximum absolute error of ±0.05601, which is quite large and produces audible harmonics, so it is intended for use in oscillators where these harmonics are desirable or LFOs where they aren't perceptible.

Parameters
phaseThe input phase of the waveform, in domain [0, 1).
Returns
A sample of an approximated sine waveform, with range [-1, 1].

◆ nec_sawtooth()

double nec_sawtooth ( double phase)
inlinestaticnodiscard

Basic sawtooth waveform.

Parameters
phaseThe input phase of the waveform, in domain [0, 1).
Returns
A sample of a sawtooth waveform, with range [-1, 1].

◆ nec_sawtoothf()

float nec_sawtoothf ( float phase)
inlinestaticnodiscard

Basic sawtooth waveform.

Parameters
phaseThe input phase of the waveform, in domain [0, 1).
Returns
A sample of a sawtooth waveform, with range [-1, 1].

◆ nec_sawtoothl()

long double nec_sawtoothl ( long double phase)
inlinestaticnodiscard

Basic sawtooth waveform.

Parameters
phaseThe input phase of the waveform, in domain [0, 1).
Returns
A sample of a sawtooth waveform, with range [-1, 1].

◆ nec_sin()

double nec_sin ( double phase)
inlinestaticnodiscard

Accurate sine approximation waveform.

This function generates a sine approximation. It has a maximum absolute error of ±0.0010903. This error does produce harmonics, but they are very quiet.

Parameters
phaseThe input phase of the waveform, in domain [0, 1).
Returns
A sample of sine waveform, with range [-1, 1].

◆ nec_sinf()

float nec_sinf ( float phase)
inlinestaticnodiscard

Accurate sine approximation waveform.

This function generates a sine approximation. It has a maximum absolute error of ±0.0010903. This error does produce harmonics, but they are very quiet.

Parameters
phaseThe input phase of the waveform, in domain [0, 1).
Returns
A sample of sine waveform, with range [-1, 1].

◆ nec_sinl()

long double nec_sinl ( long double phase)
inlinestaticnodiscard

Accurate sine approximation waveform.

This function generates a sine approximation. It has a maximum absolute error of ±0.0010903. This error does produce harmonics, but they are very quiet.

Parameters
phaseThe input phase of the waveform, in domain [0, 1).
Returns
A sample of sine waveform, with range [-1, 1].

◆ nec_square()

double nec_square ( double phase,
double duty )
inlinestaticnodiscard

Basic square waveform.

Parameters
phaseThe input phase of the waveform, in domain [0, 1).
dutyThe duty cycle of the waveform, in domain [0, 1].
Returns
A sample of a square waveform, with range [-1, 1].

◆ nec_squaref()

float nec_squaref ( float phase,
float duty )
inlinestaticnodiscard

Basic square waveform.

Parameters
phaseThe input phase of the waveform, in domain [0, 1).
dutyThe duty cycle of the waveform, in domain [0, 1].
Returns
A sample of a square waveform, with range [-1, 1].

◆ nec_squarel()

long double nec_squarel ( long double phase,
long double duty )
inlinestaticnodiscard

Basic square waveform.

Parameters
phaseThe input phase of the waveform, in domain [0, 1).
dutyThe duty cycle of the waveform, in domain [0, 1].
Returns
A sample of a square waveform, with range [-1, 1].

◆ nec_triangle()

double nec_triangle ( double phase)
inlinestaticnodiscard

Basic triangle waveform.

Parameters
phaseThe input phase of the waveform, in domain [0, 1).
Returns
A sample of a triangle waveform, with range [-1, 1].

◆ nec_trianglef()

float nec_trianglef ( float phase)
inlinestaticnodiscard

Basic triangle waveform.

Parameters
phaseThe input phase of the waveform, in domain [0, 1).
Returns
A sample of a triangle waveform, with range [-1, 1].

◆ nec_trianglel()

long double nec_trianglel ( long double phase)
inlinestaticnodiscard

Basic triangle waveform.

Parameters
phaseThe input phase of the waveform, in domain [0, 1).
Returns
A sample of a triangle waveform, with range [-1, 1].

◆ nec_wrap()

double nec_wrap ( double phase)
inlinestaticnodiscard

Maps an arbitrary phase into the domain [0, 1).

All of nectarine's waveform functions require an input phase within the domain [0, 1) and misbehave outside that domain. This function can be used to produce an equivalent input phase within that domain.

This is desirable when storing an oscillator's phase also, since long-running oscillators can accumulate floating point precision error as the phase increases further and further away from zero. Wrapping an oscillator's stored phase periodically can help prevent this.

Parameters
phaseAn arbitrary input phase.
Returns
An equivalent phase to phase, but within the domain [0, 1).

◆ nec_wrapf()

float nec_wrapf ( float phase)
inlinestaticnodiscard

Maps an arbitrary phase into the domain [0, 1).

All of nectarine's waveform functions require an input phase within the domain [0, 1) and misbehave outside that domain. This function can be used to produce an equivalent input phase within that domain.

This is desirable when storing an oscillator's phase also, since long-running oscillators can accumulate floating point precision error as the phase increases further and further away from zero. Wrapping an oscillator's stored phase periodically can help prevent this.

Parameters
phaseAn arbitrary input phase.
Returns
An equivalent phase to phase, but within the domain [0, 1).

◆ nec_wrapl()

long double nec_wrapl ( long double phase)
inlinestaticnodiscard

Maps an arbitrary phase into the domain [0, 1).

All of nectarine's waveform functions require an input phase within the domain [0, 1) and misbehave outside that domain. This function can be used to produce an equivalent input phase within that domain.

This is desirable when storing an oscillator's phase also, since long-running oscillators can accumulate floating point precision error as the phase increases further and further away from zero. Wrapping an oscillator's stored phase periodically can help prevent this.

Parameters
phaseAn arbitrary input phase.
Returns
An equivalent phase to phase, but within the domain [0, 1).

Variable Documentation

◆ NECTARINE_SINE_ERR_CORRECTION_WEIGHT

long double NECTARINE_SINE_ERR_CORRECTION_WEIGHT = 0.225l
staticconstexpr

Error correction term used to increase the accuracy of nec_sin.

Found this old forum thread for a fast sin() approximation. Turns out the code given in the thread is equivalent to nec_parabol once the domain is remapped to [0, 1). nec_sin uses the error correction shown in the thread to improve upon nec_parabol.

See also
nec_parabol()
nec_sin()
https://web.archive.org/web/20060503192740/http://www.devmaster.net/forums/showthread.php?t=5784