r8brain-free-src

repository·master·Indexed 20 days ago

https://github.com/avaneev/r8brain-free-src

A high-performance, professional-grade C++ library for audio sample rate conversion (SRC). It supports high-quality upsampling and downsampling to any sample rate, including non-integer and SACD/DSD rates. The library features a 2X oversampling algorithm with polynomial-interpolated sinc function-based fractional delay filters and provides the r8b::CDSPResampler class as its primary interface. It is thread-safe and supports optional FFT back-ends such as Intel IPP and PFFFT for optimized performance.

Tokens
995
Snippets
1
Records
5
Agent score
22%

What's inside r8brain-free-src

  1. Introduction to r8brain-free-src

    master

    r8brain-free-src is a high-quality, professional-grade C++ library for audio sample rate conversion (SRC) and resampling. It supports both upsampling and downsampling to any sample rate, including non-integer rates and SACD/DSD rates.

    Key characteristics:

    • High Performance: Uses a 2X oversampling algorithm with polynomial-interpolated sinc function-based fractional delay filters, making it one of the fastest precise SRC algorithms.
    • Thread-Safe: The library is thread-safe; however, you must create a separate resampler object for each audio channel or stream being processed concurrently.
    • Flexible Precision: Offers various classes for different precision requirements, including full-resolution 16-bit and 24-bit resampling.
    • Scale Independent: Can process signals of any scale and loudness (not limited to the -1.0 to 1.0 range).
  2. Requirements for using r8brain-free-src

    master

    To use this library, your environment must meet the following requirements:

    • C++ Compiler: Supports standard C++.
    • Floating-Point Support: Requires a system with "double" floating-point type (53-bit mantissa) support. Note that the library does not use "float" for core routines as it is often slower on modern processors.
    • Dependencies: The library is primarily header-only and depends only on the standard C++ library.

    Pre-C++11 Compiler Requirements: If you are using a compiler older than C++11, you must include the following in your build:

    • Windows: Kernel32 library.
    • macOS/Linux: pthread.h and the pthread library.
  3. Configure FFT back-ends via macros

    master

    You can optimize the performance of the FFT functions by defining specific configuration macros. These should be defined at the beginning of the r8bconf.h file or during compilation.

    Intel IPP (Fastest)

    Enables the Intel IPP back-end, which increases resampling speed by approximately 23% on average.

    #define R8B_IPP 1

    PFFFT (Alternative to IPP)

    If Intel IPP is unavailable, you can use PFFFT. You must define the macro and include the corresponding source file (fft/pffft.c or fft/pffft_double.c) in your project build.

    • Single-precision PFFFT: Limits precision to 24-bit conversions. Not recommended for professional audio due to large peak error.
      #define R8B_PFFFT 1
    • Double-precision PFFFT: Uses SSE2, AVX, and NEON intrinsics. Provides precision equal to Intel IPP and Ooura FFT.
      #define R8B_PFFFT_DOUBLE 1

    High Efficiency Mode

    For maximum efficiency (at the cost of larger initial processing delay and minor sample-timing error), define these macros:

    #define R8B_IPP 1
    #define R8B_FASTTIMING 1
    #define R8B_EXTFFT 1
  4. Use the r8b::CDSPResampler class

    master

    The r8b::CDSPResampler class is the primary front-end interface for the library. Most users only need to interact with this class.

    Resampling Parameters

    When using r8b::CDSPResampler, you can configure:

    • Transition Band: The steepness of the low-pass (reconstruction) filter, expressed as a percentage of the full spectral bandwidth (0.5% to 45%).
    • Stop-band Attenuation: Specified in decibels (49 to 218 dB).

    Note: Increasing these values improves quality but increases initial output delay and affects performance.

    Real-Time vs. Off-line Processing

    • Off-line (Push method): Feed input data and collect all available output. See example.cpp for implementation details.
    • Real-time (Pull method): The resampler is an asynchronous processor. In real-time applications, you should use a "pull" method, calling the resampling process until the output buffer is filled. The resampler automatically handles initial processing latency and stabilizes output after the initial moments.
  5. Calculate input requirements for real-time output

    master
    In real-time applications, you can determine how much input data is required to produce a specific amount of output data using the CDSPResampler::getInputRequiredForOutput() function. This is essential for managing buffers in a "pull" based processing loop.