Jef 20d28e80a5 Initial community commit | 2 mesi fa | |
---|---|---|
.. | ||
CDSPBlockConvolver.h | 2 mesi fa | |
CDSPFIRFilter.h | 2 mesi fa | |
CDSPFracInterpolator.h | 2 mesi fa | |
CDSPHBDownsampler.h | 2 mesi fa | |
CDSPHBUpsampler.h | 2 mesi fa | |
CDSPHBUpsampler.inc | 2 mesi fa | |
CDSPProcessor.h | 2 mesi fa | |
CDSPRealFFT.h | 2 mesi fa | |
CDSPResampler.h | 2 mesi fa | |
CDSPSincFilterGen.h | 2 mesi fa | |
LICENSE | 2 mesi fa | |
OpenMPT.txt | 2 mesi fa | |
README.md | 2 mesi fa | |
fft4g.h | 2 mesi fa | |
r8bbase.cpp | 2 mesi fa | |
r8bbase.h | 2 mesi fa | |
r8bconf.h | 2 mesi fa | |
r8butil.h | 2 mesi fa |
Open source (under the MIT license) high-quality professional audio sample rate converter (SRC) / resampler C++ library. Features routines for SRC, both up- and downsampling, to/from any sample rate, including non-integer sample rates: it can be also used for conversion to/from SACD/DSD sample rates, and even go beyond that. SRC routines were implemented in a multi-platform C++ code, and have a high level of optimality. Also suitable for fast general-purpose 1D time-series resampling / interpolation (with relaxed filter parameters).
The structure of this library's objects is such that they can be frequently created and destroyed in large applications with a minimal performance impact due to a high level of reusability of its most "initialization-expensive" objects: the fast Fourier transform and FIR filter objects.
The SRC algorithm at first produces 2X oversampled (relative to the source sample rate, or the destination sample rate if the downsampling is performed) signal, then performs interpolation using a bank of short (8 to 30 taps, depending on the required precision) polynomial-interpolated sinc function-based fractional delay filters. This puts the algorithm into the league of the fastest among the most precise SRC algorithms. The more precise alternative being only the whole number-factored SRC, which can be slower.
P.S. Please credit the creator of this library in your documentation in the following way: "Sample rate converter designed by Aleksey Vaneev of Voxengo".
C++ compiler and system with the "double" floating point type (53-bit mantissa) support. No explicit code for the "float" type is present in this library, because as practice has shown the "float"-based code performs considerably slower on a modern processor, at least in this library. This library does not have dependencies beside the standard C library, the "windows.h" on Windows and the "pthread.h" on macOS and Linux.
The sample rate converter (resampler) is represented by the r8b::CDSPResampler class, which is a single front-end class for the whole library. You do not basically need to use nor understand any other classes beside this class. Several derived classes that have varying levels of precision are also available (for full-resolution 16-bit and 24-bit resampling).
The code of the library resides in the "r8b" C++ namespace, effectively isolating it from all other code. The code is thread-safe. A separate resampler object should be created for each audio channel or stream being processed concurrently.
Note that you will need to compile the "r8bbase.cpp" source file and include the resulting object file into your application build. This source file includes definitions of several global static objects used by the library. You may also need to include to your project: the "Kernel32" library (on Windows) and the "pthread" library on macOS and Linux.
The library is able to process signal of any scale and loudness: it is not limited to just a "usual" -1.0 to 1.0 range.
By defining the R8B_IPP
configuration macro it is possible to enable Intel
IPP back-end for FFT functions, instead of the default Ooura FFT. IPP FFT
makes sample rate conversion faster by 23% on average.
#define R8B_IPP 1
If a larger initial processing delay and a very minor sample timing error are
not an issue, for the most efficiency you can define these macros at
the beginning of the r8bconf.h
file, or during compilation:
#define R8B_IPP 1
#define R8B_FASTTIMING 1
#define R8B_EXTFFT 1
If you do not have access to the Intel IPP then you may consider enabling the
PFFFT which is only slightly slower than Intel IPP FFT in performance. There
are two macros available: R8B_PFFFT
and R8B_PFFFT_DOUBLE
. The first macro
enables PFFFT that works in single-precision resolution, thus limiting the
overall resampler's precision to 24-bit sample rate conversions (for
mission-critical professional audio applications, using the R8B_PFFFT
macro
is not recommended as its peak error is quite large). The second macro
enables PFFFT implementation that works in double-precision resolution, making
use of SSE2, AVX, and NEON intrinsics, yielding precision that is equal to
both Intel IPP and Ooura FFT implementations.
To use the PFFFT, define the R8B_PFFFT
or R8B_PFFFT_DOUBLE
macro, compile
and include the supplied pffft.cpp
or pffft_double/pffft_double.c
file to
your project build.
#define R8B_PFFFT 1
or
#define R8B_PFFFT_DOUBLE 1
The code of this library was commented in the Doxygen
style. To generate the documentation locally you may run the
doxygen ./other/r8bdoxy.txt
command from the library's folder.
Preliminary tests show that the r8b::CDSPResampler24 resampler class achieves
31.8*n_cores
Mrops (44*n_cores
for Intel IPP FFT) when converting 1
channel of 24-bit audio from 44100 to 96000 sample rate (2% transition band),
on a Ryzen 3700X processor-based 64-bit system. This approximately translates
to a real-time resampling of 720*n_cores
(1000*n_cores
) audio streams, at
100% CPU load. Speed performance when converting to other sample rates may
vary greatly. When comparing performance of this resampler library to another
library make sure that the competing library is also tuned to produce a fully
linear-phase response, has similar stop-band characteristics and similar
sample timing precision.
The functions of this SRC library are also accessible in simplified form via the DLL file on Windows, requiring a processor with SSE2 support (Win64 version includes AVX2 auto-dispatch code). Delphi Pascal interface unit file for the DLL file is available. DLL and C LIB files are distributed in the DLL folder on the project's homepage. On non-Windows systems it is preferrable to use the C++ library directly. Note that the DLL was compiled with the Intel IPP enabled.
The resampler class of this library was designed as an asynchronous processor: it may produce any number of output samples, depending on the input sample data length and the resampling parameters. The resampler must be fed with the input sample data until enough output sample data were produced, with any excess output samples used before feeding the resampler with more input data. A "relief" factor here is that the resampler removes the initial processing latency automatically, and that after initial moments of processing the output becomes steady, with only minor output sample data length fluctuations.
So, while for an off-line resampling a "push" method can be used,
demonstrated in the example.cpp
file, for a real-time resampling a "pull"
method should be used which calls the resampling process until the output
buffer is filled.
When using the r8b::CDSPResampler class directly, you may select the transition band/steepness of the low-pass (reconstruction) filter, expressed as a percentage of the full spectral bandwidth of the input signal (or the output signal if the downsampling is performed), and the desired stop-band attenuation in decibel.
The transition band is specified as the normalized spectral space of the input signal (or the output signal if the downsampling is performed) between the low-pass filter's -3 dB point and the Nyquist frequency, and ranges from 0.5% to 45%. Stop-band attenuation can be specified in the range from 49 to 218 decibel. Both the transition band and stop-band attenuation affect resampler's overall speed performance and initial output delay. For your information, transition frequency range spans 175% of the specified transition band, which means that for 2% transition band, frequency response below 0.965*Nyquist is linear.
This SRC library also implements a much faster "power of 2" resampling (e.g. 2X, 4X, 8X, 16X, 3X, 3*2X, 3*4X, 3*8X, etc. upsampling and downsampling), which is engaged automatically if the resampling parameters permit.
This library was tested for compatibility with GNU C++, Microsoft Visual C++, LLVM and Intel C++ compilers, on 32- and 64-bit Windows, macOS, and CentOS Linux.
Most code is "inline", without the need to compile many source files. The memory footprint is quite modest.
r8brain-free-src is bundled with the following code:
This library is used by:
Please send me a note via [email protected] and I will include a link to your software product to this list of users. This list is important in maintaining confidence in this library among the interested parties. The inclusion into this list is not mandatory.
Version 5.6:
CDSPHBUpsampler
yielding 15%
performance improvement of power-of-2 upsampling.CDSPRealFFT::multiplyBlocksZP
function, for 2-3% performance improvement.aDoConsumeLatency
parameter to CDSPHBUpsampler
constructor,
for "inline" DSP uses of the class.Version 5.5:
CDSPSincFilterGen
class.__ARM_NEON
macro to NEON availability detection.Version 5.4:
Version 5.3:
Version 5.2:
PFFFT
and PFFFT DOUBLE
conditional pre-processor directives to
always enable NEON on aarch64
/arm64
(this includes code built for
Apple M1).Version 5.1:
CFixedBuffer
class to 64 bytes. This improves AVX
performance of the PFFFT DOUBLE
implementation by a few percent.pffft_double
folder, integrated the
pffft_common.c
file into the pffft_double.c
file.Version 5.0:
r8bconf.h
file.pf_sse2_double.h
file
as per PFFFT DOUBLE author's suggestion, to allow SSE2 intrinsics in most
compilers.Version 4.10:
PFFFT DOUBLE
implementation support. Now available via the
R8B_PFFFT_DOUBLE
definition macro.Version 4.9:
Version 4.8:
Version 4.7:
#ifndef _USE_MATH_DEFINES
to pffft.cpp
.#include "pffft.h"
to CDSPRealFFT.h
.Version 4.6:
MaxInLen
parameter from the oneshot()
function.Version 4.5:
Version 4.4:
Version 4.3:
Version 4.2:
r8bfreesrc
bench tool. The
tool is now compiled with the R8B_IPP 1
and R8B_EXTFFT 1
macros to
demonstrate the maximal achievable performance.Version 4.1:
Version 4.0:
Version 3.7:
Version 3.6:
Version 3.5:
r8bfreesrc
benchmark tool to support RF64 WAV files.Version 3.4:
Version 3.3:
Version 3.2:
Version 3.1:
Version 3.0:
float
buffer types.Version 2.1:
Version 2.0:
Version 1.9:
R8B_EXTFFT
configuration option.Version 1.8:
R8B_FASTTIMING
configuration option.Version 1.7:
bench
tools.