Skip to main content

Crate r8brain_sys

Crate r8brain_sys 

Source
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, and CDSPResampler24, including every public query, streaming processing, and the f64 specialization of the templated one-shot method.
  • Every concrete CDSPProcessor: CDSPBlockConvolver, CDSPHBDownsampler, CDSPHBUpsampler, and CDSPFracInterpolator.
  • CDSPFIRFilter, CDSPFIRFilterCache, CDSPFracDelayFilterBank, and its cache, including explicit reference-management functions.
  • CDSPRealFFTKeeper and all operations on its acquired CDSPRealFFT.
  • CDSPSincFilterGen, its public state, initialization modes, window calculators, and generation methods.
  • CSineGen and 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§

HCDSPBlockConvolver
HCDSPFIRFilter
HCDSPFracDelayFilterBank
HCDSPFracInterpolator
HCDSPHBDownsampler
HCDSPHBUpsampler
HCDSPRealFFTKeeper
HCDSPResampler
HCDSPResampler16
HCDSPResampler24
HCDSPResampler16IR
HCDSPSincFilterGen
HCSineGen

Constants§

fprLinearPhase
Linear-phase response.
fprMinPhase
Minimum-phase response.
wcBlackman
wcBlackmanNuttall
wcGaussian
wcHamming
wcHann
wcKaiser
wcNuttall
wftCosine
Generalized cosine window.
wftGaussian
Gaussian window.
wftKaiser
Kaiser window.

Functions§

besselI0⚠
blockConvolver_clear⚠
blockConvolver_create⚠
Constructs CDSPBlockConvolver and transfers one filter reference to it.
blockConvolver_destroy⚠
blockConvolver_getInLenBeforeOutPos⚠
blockConvolver_getLatency⚠
blockConvolver_getLatencyFrac⚠
blockConvolver_getMaxOutLen⚠
blockConvolver_process⚠
calcFIRFilterGroupDelay⚠
calcFIRFilterResponse⚠
calcMinPhaseTransform⚠
calcSpline2p8Coeffs⚠
calcSpline3p4Coeffs⚠
calcSpline3p6Coeffs⚠
calcSpline3p8Coeffs⚠
clampr⚠
convertResponseToLog⚠
findFIRFilterResponseLevelRtoL⚠
findFIRFilterResponseMaxLtoR⚠
findFIRFilterResponseMinLtoR⚠
findGCD⚠
firFilterCache_getLPFilter⚠
Acquires a reference-counted low-pass FIR filter from the global cache.
firFilterCache_getObjCount⚠
firFilter_getBlockLenBits⚠
firFilter_getKernelBlock⚠
Returns a filter-owned frequency-domain kernel block.
firFilter_getKernelLen⚠
firFilter_getLPMaxAtten⚠
firFilter_getLPMaxTransBand⚠
firFilter_getLPMinAtten⚠
firFilter_getLPMinTransBand⚠
firFilter_getLatency⚠
firFilter_getLatencyFrac⚠
firFilter_isZeroPhase⚠
firFilter_unref⚠
Releases one reference obtained from firFilterCache_getLPFilter.
fracDelayFilterBankCache_getFilterBank⚠
fracDelayFilterBankCache_getObjCount⚠
fracDelayFilterBank_create⚠
fracDelayFilterBank_destroy⚠
Deletes a directly constructed bank; do not use for cached banks.
fracDelayFilterBank_getFilter⚠
Returns the first coefficient of the indexed filter entry.
fracDelayFilterBank_getFilterFracs⚠
fracDelayFilterBank_getFilterLen⚠
fracDelayFilterBank_roundReqAtten⚠
fracDelayFilterBank_unref⚠
Releases a non-static cached bank reference.
fracInterpolator_clear⚠
fracInterpolator_create⚠
fracInterpolator_destroy⚠
fracInterpolator_getInLenBeforeOutPos⚠
fracInterpolator_getLatency⚠
fracInterpolator_getLatencyFrac⚠
fracInterpolator_getMaxOutLen⚠
fracInterpolator_process⚠
gauss⚠
getBitOccupancy⚠
getWholeStepping⚠
hbDownsampler_clear⚠
hbDownsampler_create⚠
hbDownsampler_destroy⚠
hbDownsampler_getInLenBeforeOutPos⚠
hbDownsampler_getLatency⚠
hbDownsampler_getLatencyFrac⚠
hbDownsampler_getMaxOutLen⚠
hbDownsampler_process⚠
hbUpsampler_clear⚠
hbUpsampler_create⚠
hbUpsampler_destroy⚠
hbUpsampler_getHBFilter⚠
Returns a pointer to static half-band filter data.
hbUpsampler_getHBFilterThird⚠
Returns a pointer to static one-third-band filter data.
hbUpsampler_getInLenBeforeOutPos⚠
hbUpsampler_getLatency⚠
hbUpsampler_getLatencyFrac⚠
hbUpsampler_getMaxOutLen⚠
hbUpsampler_process⚠
normalizeFIRFilter⚠
pow_a⚠
r8b_asinh⚠
Namespaced form of r8brain’s asinh helper, avoiding a libm symbol collision.
realFFTKeeper_convertToZP⚠
realFFTKeeper_create⚠
realFFTKeeper_createWithLen⚠
Acquires an FFT of length 1 << LenBits. PFFFT backends additionally require a transform length supported by PFFFT (32 is the safe minimum).
realFFTKeeper_destroy⚠
realFFTKeeper_forward⚠
Performs an in-place forward transform. PFFFT backends require the block pointer to be at least 16-byte aligned.
realFFTKeeper_getInvMulConst⚠
realFFTKeeper_getLen⚠
realFFTKeeper_getLenBits⚠
realFFTKeeper_init⚠
realFFTKeeper_inverse⚠
Performs an in-place inverse transform. PFFFT backends require the block pointer to be at least 16-byte aligned.
realFFTKeeper_multiplyBlocks⚠
realFFTKeeper_multiplyBlocksInplace⚠
realFFTKeeper_multiplyBlocksZP⚠
realFFTKeeper_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_getInLenBeforeOutPos⚠
Returns the input length before the requested output position.
resampler16IR_getInLenBeforeOutStart⚠
Iterative legacy version of getInLenBeforeOutPos; clears the object.
resampler16IR_getInputRequiredForOutput⚠
Returns the input required to produce at least this many outputs.
resampler16IR_getLatency⚠
Returns whole-sample output latency.
resampler16IR_getLatencyFrac⚠
Returns fractional output latency.
resampler16IR_getMaxOutLen⚠
Returns the maximum output length for a processing call.
resampler16IR_oneshot⚠
Performs exact-length one-shot f64 resampling 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_getInLenBeforeOutPos⚠
Returns the input length before the requested output position.
resampler16_getInLenBeforeOutStart⚠
Iterative legacy version of getInLenBeforeOutPos; clears the object.
resampler16_getInputRequiredForOutput⚠
Returns the input required to produce at least this many outputs.
resampler16_getLatency⚠
Returns whole-sample output latency.
resampler16_getLatencyFrac⚠
Returns fractional output latency.
resampler16_getMaxOutLen⚠
Returns the maximum output length for a processing call.
resampler16_oneshot⚠
Performs exact-length one-shot f64 resampling 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_getInLenBeforeOutPos⚠
Returns the input length before the requested output position.
resampler24_getInLenBeforeOutStart⚠
Iterative legacy version of getInLenBeforeOutPos; clears the object.
resampler24_getInputRequiredForOutput⚠
Returns the input required to produce at least this many outputs.
resampler24_getLatency⚠
Returns whole-sample output latency.
resampler24_getLatencyFrac⚠
Returns fractional output latency.
resampler24_getMaxOutLen⚠
Returns the maximum output length for a processing call.
resampler24_oneshot⚠
Performs exact-length one-shot f64 resampling 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::CDSPResampler with explicit filter parameters.
resampler_destroy⚠
Destroys the C++ resampler object.
resampler_getInLenBeforeOutPos⚠
Returns the input length before the requested output position.
resampler_getInLenBeforeOutStart⚠
Iterative legacy version of getInLenBeforeOutPos; clears the object.
resampler_getInputRequiredForOutput⚠
Returns the input required to produce at least this many outputs.
resampler_getLatency⚠
Returns whole-sample output latency.
resampler_getLatencyFrac⚠
Returns fractional output latency.
resampler_getMaxOutLen⚠
Returns the maximum output length for a processing call.
resampler_oneshot⚠
Performs exact-length one-shot f64 resampling and clears the object.
resampler_process⚠
Processes a streaming input block and updates the borrowed output pointer.
sincFilterGen_calcWindow⚠
sincFilterGen_calcWindowBlackman⚠
sincFilterGen_calcWindowBlackmanNuttall⚠
sincFilterGen_calcWindowGaussian⚠
sincFilterGen_calcWindowHamming⚠
sincFilterGen_calcWindowHann⚠
sincFilterGen_calcWindowKaiser⚠
sincFilterGen_calcWindowNuttall⚠
sincFilterGen_create⚠
sincFilterGen_destroy⚠
sincFilterGen_generateBand⚠
sincFilterGen_generateFrac⚠
sincFilterGen_generateHilbert⚠
sincFilterGen_generateWindow⚠
sincFilterGen_getFracDelay⚠
sincFilterGen_getFreq1⚠
sincFilterGen_getFreq2⚠
sincFilterGen_getHalfKernelLen⚠
sincFilterGen_getKernelLen⚠
sincFilterGen_getLen2⚠
sincFilterGen_initBand⚠
sincFilterGen_initFrac⚠
sincFilterGen_initHilbert⚠
sincFilterGen_initWindow⚠
sincFilterGen_setFracDelay⚠
sincFilterGen_setFreq1⚠
sincFilterGen_setFreq2⚠
sincFilterGen_setLen2⚠
sineGen_create⚠
sineGen_createUnity⚠
sineGen_createWithGain⚠
sineGen_destroy⚠
sineGen_generate⚠
sineGen_init⚠
sineGen_initWithGain⚠
sqr⚠
updateScanStep⚠

Type Aliases§

EDSPFilterPhaseResponse
ABI type corresponding to r8brain’s EDSPFilterPhaseResponse.
EWindowCalculator
C-compatible selector for CDSPSincFilterGen’s public window-calculation member functions.
EWindowFunctionType
ABI type corresponding to CDSPSincFilterGen::EWindowFunctionType.