r8brain-sys 7.3.0

Raw bindings to `r8brain`, a sample rate converter designed by Aleksey Vaneev of Voxengo.
Documentation
use core::ffi::c_int;

use crate::EDSPFilterPhaseResponse;

macro_rules! opaque {
    ($($name:ident),+ $(,)?) => {$(
        #[repr(C)]
        #[derive(Debug)]
        pub struct $name {
            _unused: [u8; 0],
        }
    )+};
}

opaque!(
    HCDSPResampler,
    HCDSPResampler16,
    HCDSPResampler16IR,
    HCDSPResampler24,
);

unsafe extern "C" {
    /// Constructs `r8b::CDSPResampler` with explicit filter parameters.
    pub fn resampler_create(
        SrcSampleRate: f64,
        DstSampleRate: f64,
        MaxInLen: c_int,
        ReqTransBand: f64,
        ReqAtten: f64,
        ReqPhase: EDSPFilterPhaseResponse,
    ) -> *mut HCDSPResampler;

    /// Constructs the 16-bit linear-phase preset.
    pub fn resampler16_create(
        SrcSampleRate: f64,
        DstSampleRate: f64,
        MaxInLen: c_int,
        ReqTransBand: f64,
    ) -> *mut HCDSPResampler16;

    /// Constructs the 16-bit impulse-response preset.
    pub fn resampler16IR_create(
        SrcSampleRate: f64,
        DstSampleRate: f64,
        MaxInLen: c_int,
        ReqTransBand: f64,
    ) -> *mut HCDSPResampler16IR;

    /// Constructs the 24-bit/32-bit-floating-point linear-phase preset.
    pub fn resampler24_create(
        SrcSampleRate: f64,
        DstSampleRate: f64,
        MaxInLen: c_int,
        ReqTransBand: f64,
    ) -> *mut HCDSPResampler24;
}

macro_rules! declare_resampler_methods {
    ($handle:ty; $destroy:ident, $clear:ident, $before_pos:ident,
     $before_start:ident, $required:ident, $latency:ident, $latency_frac:ident,
     $max_out:ident, $process:ident, $oneshot:ident) => {
        unsafe extern "C" {
            /// Destroys the C++ resampler object.
            pub fn $destroy(resampler: *mut $handle);
            /// Restores the object to its post-construction state.
            pub fn $clear(resampler: *mut $handle);
            /// Returns the input length before the requested output position.
            pub fn $before_pos(resampler: *mut $handle, ReqOutPos: c_int) -> c_int;
            /// Iterative legacy version of `getInLenBeforeOutPos`; clears the object.
            pub fn $before_start(resampler: *mut $handle, ReqOutPos: c_int) -> c_int;
            /// Returns the input required to produce at least this many outputs.
            pub fn $required(resampler: *mut $handle, ReqOutSamples: c_int) -> c_int;
            /// Returns whole-sample output latency.
            pub fn $latency(resampler: *mut $handle) -> c_int;
            /// Returns fractional output latency.
            pub fn $latency_frac(resampler: *mut $handle) -> f64;
            /// Returns the maximum output length for a processing call.
            pub fn $max_out(resampler: *mut $handle, MaxInLen: c_int) -> c_int;
            /// Processes a streaming input block and updates the borrowed output pointer.
            pub fn $process(
                resampler: *mut $handle,
                input: *mut f64,
                InputLen: c_int,
                output: *mut *mut f64,
            ) -> c_int;
            /// Performs exact-length one-shot `f64` resampling and clears the object.
            ///
            /// r8brain 7.3 permits this operation to use the input as temporary
            /// storage, so the input pointer must refer to writable memory.
            pub fn $oneshot(
                resampler: *mut $handle,
                input: *mut f64,
                InputLen: c_int,
                output: *mut f64,
                OutputLen: c_int,
            );
        }
    };
}

declare_resampler_methods!(HCDSPResampler;
    resampler_destroy, resampler_clear, resampler_getInLenBeforeOutPos,
    resampler_getInLenBeforeOutStart, resampler_getInputRequiredForOutput,
    resampler_getLatency, resampler_getLatencyFrac, resampler_getMaxOutLen,
    resampler_process, resampler_oneshot);
declare_resampler_methods!(HCDSPResampler16;
    resampler16_destroy, resampler16_clear, resampler16_getInLenBeforeOutPos,
    resampler16_getInLenBeforeOutStart,
    resampler16_getInputRequiredForOutput, resampler16_getLatency,
    resampler16_getLatencyFrac, resampler16_getMaxOutLen,
    resampler16_process, resampler16_oneshot);
declare_resampler_methods!(HCDSPResampler16IR;
    resampler16IR_destroy, resampler16IR_clear,
    resampler16IR_getInLenBeforeOutPos, resampler16IR_getInLenBeforeOutStart,
    resampler16IR_getInputRequiredForOutput, resampler16IR_getLatency,
    resampler16IR_getLatencyFrac, resampler16IR_getMaxOutLen,
    resampler16IR_process, resampler16IR_oneshot);
declare_resampler_methods!(HCDSPResampler24;
    resampler24_destroy, resampler24_clear, resampler24_getInLenBeforeOutPos,
    resampler24_getInLenBeforeOutStart,
    resampler24_getInputRequiredForOutput, resampler24_getLatency,
    resampler24_getLatencyFrac, resampler24_getMaxOutLen,
    resampler24_process, resampler24_oneshot);