JUCE wrapper for libsamplerate
aka Secret Rabbit Code. Provides
SRCAudioSource class as an alternative for juce::ResamplingAudioSource.
#include "juce_libsamplerate/juce_libsamplerate.h"
auto resampler = std::make_unique<SRCAudioSource> (
inputSource,
/* deleteInputWhenDeleted = */ true,
/* numChannels = */ 2,
/* quality = */ SRCQuality::MediumSinc);
// samplesInPerOutputSample: 1.0 = passthrough, >1.0 = speed up, <1.0 = slow down
resampler->setResamplingRatio (2.0);
resampler->prepareToPlay (512, 48000.0);
// ... use it as a normal juce::AudioSource ...Internal buffer is preallocated and its size is capped by MaxRatio = 32.0 which avoids resizing
during playback but may limit some use cases.
SRCQuality |
libsamplerate converter |
|---|---|
BestSinc |
SRC_SINC_BEST_QUALITY |
MediumSinc |
SRC_SINC_MEDIUM_QUALITY |
FastestSinc |
SRC_SINC_FASTEST |
ZeroOrder |
SRC_ZERO_ORDER_HOLD |
Linear |
SRC_LINEAR |
See the libsamplerate docs for more info.
libsamplerate is not bundled with the module and must be added by the user.
git submodule add https://github.com/libsndfile/libsamplerate.git vendor/libsamplerate
git submodule add https://github.com/antonvasin/juce_libsamplerate.git modules/libsamplerate
git submodule update --init
Then add libsamplerate and juce_libsamplerate to your CMake project:
add_subdirectory(vendor/libsamplerate)
juce_add_module(modules/juce_libsamplerate)
target_link_libraries(juce_libsamplerate INTERFACE SampleRate::samplerate)
target_link_libraries(MyPlugin PRIVATE juce_libsamplerate)include(CPM)
CPMAddPackage(
NAME libsamplerate
GITHUB_REPOSITORY libsndfile/libsamplerate
GIT_TAG 0.2.2
)
CPMAddPackage(
NAME juce_libsamplerate
GITHUB_REPOSITORY antonvasin/juce_libsamplerate
SOURCE_DIR modules/juce_libsamplerate
)
juce_add_module(modules/juce_libsamplerate)
target_link_libraries(juce_libsamplerate INTERFACE SampleRate::samplerate)
target_link_libraries(MyPlugin PRIVATE juce_libsamplerate)- JUCE 7 or newer (depends on
juce_audio_formats). - libsamplerate 0.2.x.
- A C++20 compiler