🍑 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

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

Detailed Description

Waveform functions.

Function Documentation

◆ nec_analog_sawtooth()

double nec_analog_sawtooth ( double phase)
inlinenodiscard

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)
inlinenodiscard

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)
inlinenodiscard

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 )
inlinenodiscard

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 )
inlinenodiscard

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 )
inlinenodiscard

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)
inlinenodiscard

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)
inlinenodiscard

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)
inlinenodiscard

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)
inlinenodiscard

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)
inlinenodiscard

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)
inlinenodiscard

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,
const double phase[restrict static len],
double output[restrict static len] )
inline

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,
const float phase[restrict static len],
float output[restrict static len] )
inline

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,
const long double phase[restrict static len],
long double output[restrict static len] )
inline

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,
const double phase[restrict static len],
const double duty[restrict static len],
double output[restrict static len] )
inline

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,
const float phase[restrict static len],
const float duty[restrict static len],
float output[restrict static len] )
inline

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,
const long double phase[restrict static len],
const long double duty[restrict static len],
long double output[restrict static len] )
inline

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,
const double phase[restrict static len],
double output[restrict static len] )
inline

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,
const float phase[restrict static len],
float output[restrict static len] )
inline

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,
const long double phase[restrict static len],
long double output[restrict static len] )
inline

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,
const double phase[restrict static len],
double output[restrict static len] )
inline

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,
const float phase[restrict static len],
float output[restrict static len] )
inline

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,
const long double phase[restrict static len],
long double output[restrict static len] )
inline

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,
const double phase[restrict static len],
double output[restrict static len] )
inline

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,
const float phase[restrict static len],
float output[restrict static len] )
inline

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,
const long double phase[restrict static len],
long double output[restrict static len] )
inline

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,
const double phase[restrict static len],
double output[restrict static len] )
inline

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,
const float phase[restrict static len],
float output[restrict static len] )
inline

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,
const long double phase[restrict static len],
long double output[restrict static len] )
inline

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,
const double phase[restrict static len],
double output[restrict static len] )
inline

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,
const float phase[restrict static len],
float output[restrict static len] )
inline

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,
const long double phase[restrict static len],
long double output[restrict static len] )
inline

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,
const double phase[restrict static len],
const double duty[restrict static len],
double output[restrict static len] )
inline

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,
const float phase[restrict static len],
const float duty[restrict static len],
float output[restrict static len] )
inline

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,
const long double phase[restrict static len],
const long double duty[restrict static len],
long double output[restrict static len] )
inline

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,
const double phase[restrict static len],
double output[restrict static len] )
inline

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,
const float phase[restrict static len],
float output[restrict static len] )
inline

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,
const long double phase[restrict static len],
long double output[restrict static len] )
inline

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,
const double phase[restrict static len],
double output[restrict static len] )
inline

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,
const float phase[restrict static len],
float output[restrict static len] )
inline

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,
const long double phase[restrict static len],
long double output[restrict static len] )
inline

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)
inlinenodiscard

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)
inlinenodiscard

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)
inlinenodiscard

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)
inlinenodiscard

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)
inlinenodiscard

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)
inlinenodiscard

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)
inlinenodiscard

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.

A 2004 DevMaster.net forum thread by a user named "Nick" titled “Fast and accurate sine/cosine” first presents a fast but inaccurate sine/cosine approximation, then demonstrates an error correction method to drastically improve the accuracy. The fast-but-inaccurate version happens to be mathematically identical to nec_parabol() once the range of [0, τ) is remapped to [0, 1).

nec_sin() Uses the error correction method presented in Nick's forum post to greatly refine the accuracy of nec_parabol().

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)
inlinenodiscard

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.

A 2004 DevMaster.net forum thread by a user named "Nick" titled “Fast and accurate sine/cosine” first presents a fast but inaccurate sine/cosine approximation, then demonstrates an error correction method to drastically improve the accuracy. The fast-but-inaccurate version happens to be mathematically identical to nec_parabol() once the range of [0, τ) is remapped to [0, 1).

nec_sin() Uses the error correction method presented in Nick's forum post to greatly refine the accuracy of nec_parabol().

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)
inlinenodiscard

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.

A 2004 DevMaster.net forum thread by a user named "Nick" titled “Fast and accurate sine/cosine” first presents a fast but inaccurate sine/cosine approximation, then demonstrates an error correction method to drastically improve the accuracy. The fast-but-inaccurate version happens to be mathematically identical to nec_parabol() once the range of [0, τ) is remapped to [0, 1).

nec_sin() Uses the error correction method presented in Nick's forum post to greatly refine the accuracy of nec_parabol().

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 )
inlinenodiscard

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 )
inlinenodiscard

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 )
inlinenodiscard

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)
inlinenodiscard

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)
inlinenodiscard

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)
inlinenodiscard

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)
inlinenodiscard

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)
inlinenodiscard

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)
inlinenodiscard

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).