Expand description
§r8brain-sys
Raw Rust bindings to the public C++ API of r8brain-free-src, Aleksey Vaneev’s high-quality sample-rate converter.
The default build feature compiles r8brain’s 6.5 source.
use std::ptr;
use r8brain_sys::*;
unsafe {
let resampler = resampler24_create(44_100.0, 48_000.0, 1024, 2.0);
assert!(!resampler.is_null());
let mut input = vec![0.0; 1024];
let mut output = ptr::null_mut();
let output_len = resampler24_process(
resampler,
input.as_mut_ptr(),
input.len() as i32,
&mut output,
);
let output = std::slice::from_raw_parts(output, output_len as usize);
// Consume `output` before calling a mutating function on `resampler`.
resampler24_destroy(resampler);
}§Exposed C++ surface
CDSPResampler,CDSPResampler16,CDSPResampler16IR, andCDSPResampler24, including every public query, streaming processing, and thef64specialization of the templated one-shot method.- Every concrete
CDSPProcessor:CDSPBlockConvolver,CDSPHBDownsampler,CDSPHBUpsampler, andCDSPFracInterpolator. CDSPFIRFilter,CDSPFIRFilterCache,CDSPFracDelayFilterBank, and its cache, including explicit reference-management functions.CDSPRealFFTKeeperand all operations on its acquiredCDSPRealFFT.CDSPSincFilterGen, its public state, initialization modes, window calculators, and generation methods.CSineGenand r8brain’s documented FIR, spline, minimum-phase, stepping, response-scanning, and mathematical utility functions.
Allocator, synchronization, and ownership-helper templates remain internal
implementation details. C++ overloads have distinct C names, and APIs that
take C++ bool use c_int (0 is false, nonzero is true). The sinc
generator’s member-function pointer parameters use the wc* selector
constants. Direct FFT buffers must satisfy the active backend’s alignment
requirements (at least 16-byte alignment for the bundled PFFFT backends).
§Safety and ownership
As a -sys crate, all functions are raw and unsafe. Constructor preconditions and buffer sizes
documented by r8brain must be upheld. In particular, an input block passed to
a resampler must not exceed the MaxInLen supplied at construction.
Streaming resamplers return a borrowed pointer that may alias the input or
resampler-owned storage. It must not be freed and must be consumed before the
same object is mutated again. Other CDSPProcessor implementations expect
the caller to initialize the output pointer to storage sized using that
processor’s getMaxOutLen function.
Objects acquired from firFilterCache_getLPFilter must be released with
firFilter_unref, unless their reference is transferred to
blockConvolver_create, which inherits and releases it. Non-static filter
banks acquired from the cache must be released with
fracDelayFilterBank_unref; directly constructed banks use
fracDelayFilterBank_destroy.
Optional r8b_pffft and r8b_pffft_double features select the bundled PFFFT
FFT backends. If both are enabled, the double-precision backend takes
precedence.
The r8b_fasttiming and r8b_extfft Cargo features enable r8brain’s corresponding R8B_FASTTIMING and R8B_EXTFFT compile-time options, respectively.
Disabling default features skips compilation of the bundled C++ source; the final application must then provide every referenced shim symbol.
Structs§
- HCDSP
Block Convolver - HCDSPFIR
Filter - HCDSP
Frac Delay Filter Bank - HCDSP
Frac Interpolator - HCDSPHB
Downsampler - HCDSPHB
Upsampler - HCDSP
RealFFT Keeper - HCDSP
Resampler - HCDSP
Resampler16 - HCDSP
Resampler24 - HCDSP
Resampler16IR - HCDSP
Sinc Filter Gen - HCSine
Gen
Constants§
- fprLinear
Phase - Linear-phase response.
- fprMin
Phase - Minimum-phase response.
- wcBlackman
- wcBlackman
Nuttall - wcGaussian
- wcHamming
- wcHann
- wcKaiser
- wcNuttall
- wftCosine
- Generalized cosine window.
- wftGaussian
- Gaussian window.
- wftKaiser
- Kaiser window.
Functions§
- bessel
I0 ⚠ - block
Convolver_ ⚠clear - block
Convolver_ ⚠create - Constructs
CDSPBlockConvolverand transfers one filter reference to it. - block
Convolver_ ⚠destroy - block
Convolver_ ⚠getIn LenBefore OutPos - block
Convolver_ ⚠getLatency - block
Convolver_ ⚠getLatency Frac - block
Convolver_ ⚠getMax OutLen - block
Convolver_ ⚠process - calcFIR
Filter ⚠Group Delay - calcFIR
Filter ⚠Response - calc
MinPhase ⚠Transform - calc
Spline2p8 ⚠Coeffs - calc
Spline3p4 ⚠Coeffs - calc
Spline3p6 ⚠Coeffs - calc
Spline3p8 ⚠Coeffs - clampr⚠
- convert
Response ⚠ToLog - findFIR
Filter ⚠Response Level RtoL - findFIR
Filter ⚠Response MaxLtoR - findFIR
Filter ⚠Response MinLtoR - findGCD⚠
- firFilter
Cache_ ⚠getLP Filter - Acquires a reference-counted low-pass FIR filter from the global cache.
- firFilter
Cache_ ⚠getObj Count - firFilter_
getBlock ⚠LenBits - firFilter_
getKernel ⚠Block - Returns a filter-owned frequency-domain kernel block.
- firFilter_
getKernel ⚠Len - firFilter_
getLP ⚠MaxAtten - firFilter_
getLP ⚠MaxTrans Band - firFilter_
getLP ⚠MinAtten - firFilter_
getLP ⚠MinTrans Band - firFilter_
getLatency ⚠ - firFilter_
getLatency ⚠Frac - firFilter_
isZero ⚠Phase - firFilter_
unref ⚠ - Releases one reference obtained from
firFilterCache_getLPFilter. - frac
Delay ⚠Filter Bank Cache_ getFilter Bank - frac
Delay ⚠Filter Bank Cache_ getObj Count - frac
Delay ⚠Filter Bank_ create - frac
Delay ⚠Filter Bank_ destroy - Deletes a directly constructed bank; do not use for cached banks.
- frac
Delay ⚠Filter Bank_ getFilter - Returns the first coefficient of the indexed filter entry.
- frac
Delay ⚠Filter Bank_ getFilter Fracs - frac
Delay ⚠Filter Bank_ getFilter Len - frac
Delay ⚠Filter Bank_ round ReqAtten - frac
Delay ⚠Filter Bank_ unref - Releases a non-static cached bank reference.
- frac
Interpolator_ ⚠clear - frac
Interpolator_ ⚠create - frac
Interpolator_ ⚠destroy - frac
Interpolator_ ⚠getIn LenBefore OutPos - frac
Interpolator_ ⚠getLatency - frac
Interpolator_ ⚠getLatency Frac - frac
Interpolator_ ⚠getMax OutLen - frac
Interpolator_ ⚠process - gauss⚠
- getBit
Occupancy ⚠ - getWhole
Stepping ⚠ - hbDownsampler_
clear ⚠ - hbDownsampler_
create ⚠ - hbDownsampler_
destroy ⚠ - hbDownsampler_
getIn ⚠LenBefore OutPos - hbDownsampler_
getLatency ⚠ - hbDownsampler_
getLatency ⚠Frac - hbDownsampler_
getMax ⚠OutLen - hbDownsampler_
process ⚠ - hbUpsampler_
clear ⚠ - hbUpsampler_
create ⚠ - hbUpsampler_
destroy ⚠ - hbUpsampler_
getHB ⚠Filter - Returns a pointer to static half-band filter data.
- hbUpsampler_
getHB ⚠Filter Third - Returns a pointer to static one-third-band filter data.
- hbUpsampler_
getIn ⚠LenBefore OutPos - hbUpsampler_
getLatency ⚠ - hbUpsampler_
getLatency ⚠Frac - hbUpsampler_
getMax ⚠OutLen - hbUpsampler_
process ⚠ - normalizeFIR
Filter ⚠ - pow_a⚠
- r8b_
asinh ⚠ - Namespaced form of r8brain’s
asinhhelper, avoiding a libm symbol collision. - realFFT
Keeper_ ⚠convert ToZP - realFFT
Keeper_ ⚠create - realFFT
Keeper_ ⚠create With Len - Acquires an FFT of length
1 << LenBits. PFFFT backends additionally require a transform length supported by PFFFT (32 is the safe minimum). - realFFT
Keeper_ ⚠destroy - realFFT
Keeper_ ⚠forward - Performs an in-place forward transform. PFFFT backends require the block pointer to be at least 16-byte aligned.
- realFFT
Keeper_ ⚠getInv MulConst - realFFT
Keeper_ ⚠getLen - realFFT
Keeper_ ⚠getLen Bits - realFFT
Keeper_ ⚠init - realFFT
Keeper_ ⚠inverse - Performs an in-place inverse transform. PFFFT backends require the block pointer to be at least 16-byte aligned.
- realFFT
Keeper_ ⚠multiply Blocks - realFFT
Keeper_ ⚠multiply Blocks Inplace - realFFT
Keeper_ ⚠multiply BlocksZP - realFFT
Keeper_ ⚠reset - resampler16IR_
clear ⚠ - Restores the object to its post-construction state.
- resampler16IR_
create ⚠ - Constructs the 16-bit impulse-response preset.
- resampler16IR_
destroy ⚠ - Destroys the C++ resampler object.
- resampler16IR_
getIn ⚠LenBefore OutPos - Returns the input length before the requested output position.
- resampler16IR_
getIn ⚠LenBefore OutStart - Iterative legacy version of
getInLenBeforeOutPos; clears the object. - resampler16IR_
getInput ⚠Required ForOutput - Returns the input required to produce at least this many outputs.
- resampler16IR_
getLatency ⚠ - Returns whole-sample output latency.
- resampler16IR_
getLatency ⚠Frac - Returns fractional output latency.
- resampler16IR_
getMax ⚠OutLen - Returns the maximum output length for a processing call.
- resampler16IR_
oneshot ⚠ - Performs exact-length one-shot
f64resampling and clears the object. - resampler16IR_
process ⚠ - Processes a streaming input block and updates the borrowed output pointer.
- resampler16_
clear ⚠ - Restores the object to its post-construction state.
- resampler16_
create ⚠ - Constructs the 16-bit linear-phase preset.
- resampler16_
destroy ⚠ - Destroys the C++ resampler object.
- resampler16_
getIn ⚠LenBefore OutPos - Returns the input length before the requested output position.
- resampler16_
getIn ⚠LenBefore OutStart - Iterative legacy version of
getInLenBeforeOutPos; clears the object. - resampler16_
getInput ⚠Required ForOutput - Returns the input required to produce at least this many outputs.
- resampler16_
getLatency ⚠ - Returns whole-sample output latency.
- resampler16_
getLatency ⚠Frac - Returns fractional output latency.
- resampler16_
getMax ⚠OutLen - Returns the maximum output length for a processing call.
- resampler16_
oneshot ⚠ - Performs exact-length one-shot
f64resampling and clears the object. - resampler16_
process ⚠ - Processes a streaming input block and updates the borrowed output pointer.
- resampler24_
clear ⚠ - Restores the object to its post-construction state.
- resampler24_
create ⚠ - Constructs the 24-bit/32-bit-floating-point linear-phase preset.
- resampler24_
destroy ⚠ - Destroys the C++ resampler object.
- resampler24_
getIn ⚠LenBefore OutPos - Returns the input length before the requested output position.
- resampler24_
getIn ⚠LenBefore OutStart - Iterative legacy version of
getInLenBeforeOutPos; clears the object. - resampler24_
getInput ⚠Required ForOutput - Returns the input required to produce at least this many outputs.
- resampler24_
getLatency ⚠ - Returns whole-sample output latency.
- resampler24_
getLatency ⚠Frac - Returns fractional output latency.
- resampler24_
getMax ⚠OutLen - Returns the maximum output length for a processing call.
- resampler24_
oneshot ⚠ - Performs exact-length one-shot
f64resampling and clears the object. - resampler24_
process ⚠ - Processes a streaming input block and updates the borrowed output pointer.
- resampler_
clear ⚠ - Restores the object to its post-construction state.
- resampler_
create ⚠ - Constructs
r8b::CDSPResamplerwith explicit filter parameters. - resampler_
destroy ⚠ - Destroys the C++ resampler object.
- resampler_
getIn ⚠LenBefore OutPos - Returns the input length before the requested output position.
- resampler_
getIn ⚠LenBefore OutStart - Iterative legacy version of
getInLenBeforeOutPos; clears the object. - resampler_
getInput ⚠Required ForOutput - Returns the input required to produce at least this many outputs.
- resampler_
getLatency ⚠ - Returns whole-sample output latency.
- resampler_
getLatency ⚠Frac - Returns fractional output latency.
- resampler_
getMax ⚠OutLen - Returns the maximum output length for a processing call.
- resampler_
oneshot ⚠ - Performs exact-length one-shot
f64resampling and clears the object. - resampler_
process ⚠ - Processes a streaming input block and updates the borrowed output pointer.
- sinc
Filter ⚠Gen_ calc Window - sinc
Filter ⚠Gen_ calc Window Blackman - sinc
Filter ⚠Gen_ calc Window Blackman Nuttall - sinc
Filter ⚠Gen_ calc Window Gaussian - sinc
Filter ⚠Gen_ calc Window Hamming - sinc
Filter ⚠Gen_ calc Window Hann - sinc
Filter ⚠Gen_ calc Window Kaiser - sinc
Filter ⚠Gen_ calc Window Nuttall - sinc
Filter ⚠Gen_ create - sinc
Filter ⚠Gen_ destroy - sinc
Filter ⚠Gen_ generate Band - sinc
Filter ⚠Gen_ generate Frac - sinc
Filter ⚠Gen_ generate Hilbert - sinc
Filter ⚠Gen_ generate Window - sinc
Filter ⚠Gen_ getFrac Delay - sinc
Filter ⚠Gen_ getFreq1 - sinc
Filter ⚠Gen_ getFreq2 - sinc
Filter ⚠Gen_ getHalf Kernel Len - sinc
Filter ⚠Gen_ getKernel Len - sinc
Filter ⚠Gen_ getLen2 - sinc
Filter ⚠Gen_ init Band - sinc
Filter ⚠Gen_ init Frac - sinc
Filter ⚠Gen_ init Hilbert - sinc
Filter ⚠Gen_ init Window - sinc
Filter ⚠Gen_ setFrac Delay - sinc
Filter ⚠Gen_ setFreq1 - sinc
Filter ⚠Gen_ setFreq2 - sinc
Filter ⚠Gen_ setLen2 - sine
Gen_ ⚠create - sine
Gen_ ⚠create Unity - sine
Gen_ ⚠create With Gain - sine
Gen_ ⚠destroy - sine
Gen_ ⚠generate - sine
Gen_ ⚠init - sine
Gen_ ⚠init With Gain - sqr⚠
- update
Scan ⚠Step
Type Aliases§
- EDSP
Filter Phase Response - ABI type corresponding to r8brain’s
EDSPFilterPhaseResponse. - EWindow
Calculator - C-compatible selector for
CDSPSincFilterGen’s public window-calculation member functions. - EWindow
Function Type - ABI type corresponding to
CDSPSincFilterGen::EWindowFunctionType.