r8brain-sys 7.3.0

Raw bindings to `r8brain`, a sample rate converter designed by Aleksey Vaneev of Voxengo.
Documentation
#include "dsp-extern.h"

#include "CDSPBlockConvolver.h"
#include "CDSPFracInterpolator.h"
#include "CDSPHBDownsampler.h"
#include "CDSPHBUpsampler.h"

using r8b::CDSPBlockConvolver;
using r8b::CDSPFIRFilter;
using r8b::CDSPFracInterpolator;
using r8b::CDSPHBDownsampler;
using r8b::CDSPHBUpsampler;

#define DEFINE_PROCESSOR_METHODS(prefix, handle_type, cpp_type) \
    void prefix##_destroy(handle_type* const processor) \
    { \
        delete reinterpret_cast<cpp_type*>(processor); \
    } \
    int prefix##_getInLenBeforeOutPos(handle_type* const processor, \
        const int req_out_pos) \
    { \
        return reinterpret_cast<cpp_type*>(processor) \
            ->getInLenBeforeOutPos(req_out_pos); \
    } \
    int prefix##_getLatency(handle_type* const processor) \
    { \
        return reinterpret_cast<cpp_type*>(processor)->getLatency(); \
    } \
    double prefix##_getLatencyFrac(handle_type* const processor) \
    { \
        return reinterpret_cast<cpp_type*>(processor)->getLatencyFrac(); \
    } \
    int prefix##_getMaxOutLen(handle_type* const processor, \
        const int max_in_len) \
    { \
        return reinterpret_cast<cpp_type*>(processor) \
            ->getMaxOutLen(max_in_len); \
    } \
    void prefix##_clear(handle_type* const processor) \
    { \
        reinterpret_cast<cpp_type*>(processor)->clear(); \
    } \
    int prefix##_process(handle_type* const processor, double* const input, \
        const int input_len, double** const output) \
    { \
        return reinterpret_cast<cpp_type*>(processor) \
            ->process(input, input_len, *output); \
    }

extern "C" {

HCDSPBlockConvolver* blockConvolver_create(HCDSPFIRFilter* const filter,
    const int up_factor, const int down_factor, const double prev_latency,
    const int do_consume_latency)
{
    return reinterpret_cast<HCDSPBlockConvolver*>(new CDSPBlockConvolver(
        *reinterpret_cast<CDSPFIRFilter*>(filter), up_factor, down_factor,
        prev_latency, do_consume_latency != 0));
}

DEFINE_PROCESSOR_METHODS(
    blockConvolver, HCDSPBlockConvolver, CDSPBlockConvolver)

HCDSPHBDownsampler* hbDownsampler_create(const double req_attenuation,
    const int steep_index, const int is_third, const double prev_latency)
{
    return reinterpret_cast<HCDSPHBDownsampler*>(new CDSPHBDownsampler(
        req_attenuation, steep_index, is_third != 0, prev_latency));
}

DEFINE_PROCESSOR_METHODS(
    hbDownsampler, HCDSPHBDownsampler, CDSPHBDownsampler)

void hbUpsampler_getHBFilter(const double req_attenuation,
    const int steep_index, const double** const filter,
    int* const filter_len, double* const actual_attenuation)
{
    CDSPHBUpsampler::getHBFilter(req_attenuation, steep_index, *filter,
        *filter_len, *actual_attenuation);
}

void hbUpsampler_getHBFilterThird(const double req_attenuation,
    const int steep_index, const double** const filter,
    int* const filter_len, double* const actual_attenuation)
{
    CDSPHBUpsampler::getHBFilterThird(req_attenuation, steep_index, *filter,
        *filter_len, *actual_attenuation);
}

HCDSPHBUpsampler* hbUpsampler_create(const double req_attenuation,
    const int steep_index, const int is_third, const double prev_latency,
    const int do_consume_latency)
{
    return reinterpret_cast<HCDSPHBUpsampler*>(new CDSPHBUpsampler(
        req_attenuation, steep_index, is_third != 0, prev_latency,
        do_consume_latency != 0));
}

DEFINE_PROCESSOR_METHODS(hbUpsampler, HCDSPHBUpsampler, CDSPHBUpsampler)

HCDSPFracInterpolator* fracInterpolator_create(
    const double src_sample_rate, const double dst_sample_rate,
    const double req_attenuation, const int is_third,
    const double prev_latency)
{
    return reinterpret_cast<HCDSPFracInterpolator*>(new CDSPFracInterpolator(
        src_sample_rate, dst_sample_rate, req_attenuation, is_third != 0,
        prev_latency));
}

DEFINE_PROCESSOR_METHODS(
    fracInterpolator, HCDSPFracInterpolator, CDSPFracInterpolator)

} // extern "C"