|
🍑 nectarine
Audio synthesis tools for C23
|
Type-generic waveform functions. More...
#include "waveforms.h"Go to the source code of this file.
Macros | |
| #define | nec_wrap(phase) |
| Maps an arbitrary phase into the domain [0, 1). | |
| #define | nec_fill_wrap(len, phase, output) |
| Maps a buffer of arbitrary phases into the domain [0, 1). | |
| #define | nec_analog_sawtooth(phase) |
| Analog-like sawtooth waveform. | |
| #define | nec_fill_analog_sawtooth(len, phase, output) |
| Fills a buffer with an analog-like sawtooth waveform. | |
| #define | nec_analog_square(phase, duty) |
| Analog-like square waveform. | |
| #define | nec_fill_analog_square(len, phase, duty, output) |
| Fills a buffer with an analog-like square waveform. | |
| #define | nec_analog_triangle(phase) |
| Analog-like triangle waveform. | |
| #define | nec_fill_analog_triangle(len, phase, output) |
| Fills a buffer with an analog-like triangle waveform. | |
| #define | nec_parabol(phase) |
| Fast sine approximation waveform. | |
| #define | nec_fill_parabol(len, phase, output) |
| Fills a buffer with a fast sine approximation waveform. | |
| #define | nec_sin(phase) |
| Accurate sine approximation waveform. | |
| #define | nec_fill_sin(len, phase, output) |
| Fills a buffer with an accurate sine approximation waveform. | |
| #define | nec_circle(phase) |
| Circle waveform function. | |
| #define | nec_fill_circle(len, phase, output) |
| Fills a buffer with a circle waveform. | |
| #define | nec_sawtooth(phase) |
| Basic sawtooth waveform. | |
| #define | nec_fill_sawtooth(len, phase, output) |
| Fills a buffer with a sawtooth waveform. | |
| #define | nec_square(phase, duty) |
| Basic square waveform. | |
| #define | nec_fill_square(len, phase, duty, output) |
| Fills a buffer with a square waveform. | |
| #define | nec_triangle(phase) |
| Basic triangle waveform. | |
| #define | nec_fill_triangle(len, phase, output) |
| Fills a buffer with a triangle waveform. | |
Type-generic waveform functions.
| #define nec_analog_sawtooth | ( | phase | ) |
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.
| phase | The input phase of the waveform, in domain [0, 1). |
| #define nec_analog_square | ( | phase, | |
| duty ) |
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.
| phase | The input phase of the waveform, in domain [0, 1). |
| duty | The duty cycle of the waveform, in domain [0, 1]. |
| #define nec_analog_triangle | ( | phase | ) |
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.
| phase | The input phase of the waveform, in domain [0, 1). |
| #define nec_circle | ( | phase | ) |
Circle waveform function.
This waveform looks like an alternating semicircle.
| phase | The input phase of the waveform, in domain [0, 1). |
| #define nec_fill_analog_sawtooth | ( | len, | |
| phase, | |||
| output ) |
Fills a buffer with an analog-like sawtooth waveform.
| [in] | len | The length of the input and output buffers, phase and output. Must be at least 1. |
| [in] | phase | A buffer full of input phases in domain [0, 1). |
| [out] | output | A buffer to be filled with samples of a sawtooth waveform, with range [-1, 1]. |
| #define nec_fill_analog_square | ( | len, | |
| phase, | |||
| duty, | |||
| output ) |
Fills a buffer with an analog-like square waveform.
| [in] | len | The length of the input and output buffers, phase and output. Must be at least 1. |
| [in] | phase | A buffer full of input phases in domain [0, 1). |
| [in] | duty | A buffer full of duty cycles in domain [0, 1]. |
| [out] | output | A buffer to be filled with samples of a square waveform, with range [-1, 1]. |
| #define nec_fill_analog_triangle | ( | len, | |
| phase, | |||
| output ) |
Fills a buffer with an analog-like triangle waveform.
| [in] | len | The length of the input and output buffers, phase and output. Must be at least 1. |
| [in] | phase | A buffer full of input phases in domain [0, 1). |
| [out] | output | A buffer to be filled with samples of a triangle waveform, with range [-1, 1]. |
| #define nec_fill_circle | ( | len, | |
| phase, | |||
| output ) |
Fills a buffer with a circle waveform.
| [in] | len | The length of the input and output buffers, phase and output. Must be at least 1. |
| [in] | phase | A buffer full of input phases in domain [0, 1). |
| [out] | output | A buffer to be filled with samples of a circle waveform, with range [-1, 1]. |
| #define nec_fill_parabol | ( | len, | |
| phase, | |||
| output ) |
Fills a buffer with a fast sine approximation waveform.
| [in] | len | The length of the input and output buffers, phase and output. Must be at least 1. |
| [in] | phase | A buffer full of input phases in domain [0, 1). |
| [out] | output | A buffer to be filled with samples of an approximated sine waveform, with range [-1, 1]. |
| #define nec_fill_sawtooth | ( | len, | |
| phase, | |||
| output ) |
Fills a buffer with a sawtooth waveform.
| [in] | len | The length of the input and output buffers, phase and output. Must be at least 1. |
| [in] | phase | A buffer full of input phases in domain [0, 1). |
| [out] | output | A buffer to be filled with samples of a sawtooth waveform, with range [-1, 1]. |
| #define nec_fill_sin | ( | len, | |
| phase, | |||
| output ) |
Fills a buffer with an accurate sine approximation waveform.
| [in] | len | The length of the input and output buffers, phase and output. Must be at least 1. |
| [in] | phase | A buffer full of input phases in domain [0, 1). |
| [out] | output | A buffer to be filled with samples of a sine waveform, with range [-1, 1]. |
| #define nec_fill_square | ( | len, | |
| phase, | |||
| duty, | |||
| output ) |
Fills a buffer with a square waveform.
| [in] | len | The length of the input and output buffers, phase and output. Must be at least 1. |
| [in] | phase | A buffer full of input phases in domain [0, 1). |
| [in] | duty | A buffer full of duty cycles in domain [0, 1]. |
| [out] | output | A buffer to be filled with samples of a square waveform, with range [-1, 1]. |
| #define nec_fill_triangle | ( | len, | |
| phase, | |||
| output ) |
Fills a buffer with a triangle waveform.
| [in] | len | The length of the input and output buffers, phase and output. Must be at least 1. |
| [in] | phase | A buffer full of input phases in domain [0, 1). |
| [out] | output | A buffer to be filled with samples of a triangle waveform, with range [-1, 1]. |
| #define nec_fill_wrap | ( | len, | |
| phase, | |||
| output ) |
Maps a buffer of arbitrary phases into the domain [0, 1).
| [in] | len | The length of the input and output buffers, phase and output. Must be at least 1. |
| [in] | phase | A buffer full of arbitrary input phases. |
| [out] | output | A buffer to be filled with equivalent phases to the contents of phase, but within the domain [0, 1). |
| #define nec_parabol | ( | phase | ) |
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.
| phase | The input phase of the waveform, in domain [0, 1). |
| #define nec_sawtooth | ( | phase | ) |
Basic sawtooth waveform.
| phase | The input phase of the waveform, in domain [0, 1). |
| #define nec_sin | ( | phase | ) |
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.
| phase | The input phase of the waveform, in domain [0, 1). |
| #define nec_square | ( | phase, | |
| duty ) |
Basic square waveform.
| phase | The input phase of the waveform, in domain [0, 1). |
| duty | The duty cycle of the waveform, in domain [0, 1]. |
| #define nec_triangle | ( | phase | ) |
Basic triangle waveform.
| phase | The input phase of the waveform, in domain [0, 1). |
| #define nec_wrap | ( | phase | ) |
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.
| phase | An arbitrary input phase. |
phase, but within the domain [0, 1).