Last active
January 1, 2023 12:39
-
-
Save Jacajack/6d54c9d8fde24ed8c02c9a964ddcf44e to your computer and use it in GitHub Desktop.
PolyBLEP oscillators vs Faust standard library oscillators
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import("stdfaust.lib"); | |
//----------`(os.)polyblep`---------- | |
// PolyBLEP residual function - used for smoothing steps in the audio signal. | |
// | |
// #### Usage | |
// | |
// ``` | |
// polyblep(Q, phase) : _ | |
// ``` | |
// | |
// Where: | |
// | |
// * `Q`: smoothing factor between 0 and 0.5. Determines how far from the ends of the phase interval the quadratic function is used. | |
// * `phase`: normalised phase (between 0 and 1) | |
//------------------------------------------------------------ | |
// Author: Jacek Wieczorek | |
polyblep( Q, phase ) = ( 0, L( phase / Q ), R( ( phase - 1 ) / Q ) ) : select3( sel ) | |
with | |
{ | |
sel = ( phase < Q ) + 2*( phase > 1 - Q ); | |
L(x) = 2*x - x*x - 1; // Used near the left end of the interval | |
R(x) = 2*x + x*x + 1; // Used near the right end of the interval | |
}; | |
//----------`(os.)polyblep_saw`---------- | |
// Sawtooth oscillator with suppressed aliasing (using polyBLEP) | |
// | |
// #### Usage | |
// | |
// ``` | |
// polyblep_saw(f) : _ | |
// ``` | |
// | |
// Where: | |
// | |
// * `f`: frequency in Hz | |
//------------------------------------------------------------ | |
// Author: Jacek Wieczorek | |
polyblep_saw( f ) = naive - polyblep( Q , phase ) | |
with | |
{ | |
phase = os.phasor( 1, f ); | |
naive = 2 * phase - 1; | |
Q = f / ma.SR; | |
}; | |
//----------`(os.)polyblep_square`---------- | |
// Square wave oscillator with suppressed aliasing (using polyBLEP) | |
// | |
// #### Usage | |
// | |
// ``` | |
// polyblep_square(f) : _ | |
// ``` | |
// | |
// Where: | |
// | |
// * `f`: frequency in Hz | |
//------------------------------------------------------------ | |
// Author: Jacek Wieczorek | |
polyblep_square( f ) = naive - polyblep( Q, phase ) + polyblep( Q, ma.modulo( phase + 0.5, 1 ) ) | |
with | |
{ | |
phase = os.phasor( 1, f ); | |
naive = 2 * ( phase * 2 : int ) - 1; | |
Q = f / ma.SR; | |
}; | |
// PolyBLEP triangle (square through a leaky integrator) | |
polyblep_triangle( f ) = polyblep_square( f ) : fi.pole( 0.999 ) : *(4 * f / ma.SR); | |
f = hslider( "f", 100, 20, 8000, 0.001 ); | |
wave_select = hslider( "wave", 0, 0, 2, 1 ); | |
use_polyblep = checkbox( "PolyBLEP" ); | |
polyblep_wave = ( polyblep_saw( f ), polyblep_square( f ), polyblep_triangle( f ) ) : select3( wave_select ); | |
faust_wave = ( os.sawtooth( f ), os.square( f ), os.triangle( f ) ) : select3( wave_select ); | |
process = ( faust_wave, polyblep_wave ) : select2( use_polyblep ); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment