|
Gin
|
Anti-aliased bitcrusher with independent bit depth and sample rate reduction. More...
#include <gin_bitcrusher.h>
Public Member Functions | |
| BitCrusher (int maxChannels_=2, int maxBlockSize_=4096) | |
| void | setSampleRate (double sr) |
| Sets the sample rate. | |
| void | setParams (float bitDepth, float rateHz, bool dirtyMode) |
| Sets the parameters. | |
| void | reset () |
| Resets all internal state. | |
| int | getLatencySamples () const |
| Latency in samples for the current mode. | |
| void | process (juce::AudioSampleBuffer &buffer) |
| Processes a buffer of audio. | |
Anti-aliased bitcrusher with independent bit depth and sample rate reduction.
BitCrusher combines two classic lo-fi effects with optional anti-aliasing:
Bit depth reduction quantizes the amplitude of the signal to a reduced number of bits (1 to 16). Quantization is a static nonlinearity that generates harmonics which alias back into the audible range, so the quantizer runs inside a 4x juce::dsp::Oversampling stage - the signal is upsampled, quantized at the oversampled rate, then filtered and decimated back down.
Sample rate reduction resamples the signal to a lower rate (e.g. 500Hz to 48kHz) with a sample & hold driven by a phase accumulator, like a sync'd oscillator. Each hold transition is a step discontinuity which would normally cause fold-back aliasing. Instead of naively holding values, a polyBLEP correction is injected around each discontinuity (across the samples before and after the step, via a one sample delay line), giving a band-limited step that keeps the audible stepped character without the harsh fold-back. The held value is sampled at the exact step instant by linear interpolation of the input.
Signal chain: oversample -> quantize -> decimate -> BLEP sample & hold. The sample & hold runs last, at the project rate, since the BLEP correction band-limits the steps relative to the output Nyquist, and holding after quantization keeps the steps exactly on the bit grid.
Dirty mode bypasses all anti-aliasing (naive quantization and naive hold, zero latency) for the raw aliased sound of a classic bitcrusher.
Key Features:
Usage:
References setSampleRate(), and ValueSmoother< T >::setTime().
Sets the sample rate.
Resets the effect.
References reset(), setParams(), and ValueSmoother< T >::setSampleRate().
Referenced by BitCrusher().
Sets the parameters.
| bitDepth | Bits of amplitude resolution (1 to 16) |
| rateHz | Target sample & hold rate in Hz. At or above the project rate the signal passes through unheld. |
| dirtyMode | true bypasses all anti-aliasing for the classic raw aliased sound |
References ValueSmoother< T >::setValue().
Referenced by setSampleRate().
| void BitCrusher::reset | ( | ) |
Resets all internal state.
References ValueSmoother< T >::snapToValue().
Referenced by setSampleRate().
| int BitCrusher::getLatencySamples | ( | ) | const |
Latency in samples for the current mode.
Zero in dirty mode, otherwise the oversampling filter latency plus one sample for the BLEP delay. Changes when dirty mode is toggled.
| void BitCrusher::process | ( | juce::AudioSampleBuffer & | buffer | ) |
Processes a buffer of audio.
Channels beyond maxChannels are left untouched. Buffers larger than maxBlockSize are processed in chunks.