Skip to content

Commit d3e790f

Browse files
committed
Setup convolver file resampling via r8brain
Signed-off-by: falkTX <falktx@falktx.com>
1 parent 26ca598 commit d3e790f

File tree

6 files changed

+51
-8
lines changed

6 files changed

+51
-8
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@
1010
[submodule "3rd-party/pffft"]
1111
path = 3rd-party/pffft
1212
url = https://github.com/marton78/pffft.git
13+
[submodule "3rd-party/r8brain"]
14+
path = 3rd-party/r8brain
15+
url = https://github.com/avaneev/r8brain-free-src.git

3rd-party/pffft

Submodule pffft deleted from 08f5ed2

3rd-party/pffft

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
r8brain

3rd-party/r8brain

Submodule r8brain added at 8ce873a

plugins/ConvolutionReverb/3rd-party.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* DISTRHO OneKnob Convolution Reverb
3-
* Copyright (C) 2022 Filipe Coelho <falktx@falktx.com>
3+
* Copyright (C) 2022-2023 Filipe Coelho <falktx@falktx.com>
44
*
55
* Permission to use, copy, modify, and/or distribute this software for any purpose with
66
* or without fee is hereby granted, provided that the above copyright notice and this
@@ -20,5 +20,5 @@
2020
#define DR_WAV_IMPLEMENTATION
2121
#include "dr_wav.h"
2222

23-
#include "pffft/pffft.c"
24-
#include "pffft/pffft_common.c"
23+
#include "r8brain/pffft.cpp"
24+
#include "r8brain/r8bbase.cpp"

plugins/ConvolutionReverb/Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,21 @@ FILES_UI = \
3333

3434
include ../../dpf/Makefile.plugins.mk
3535

36+
BUILD_CXX_FLAGS += -DAUDIOFFT_PFFFT
37+
BUILD_CXX_FLAGS += -DR8B_FASTTIMING
38+
BUILD_CXX_FLAGS += -DR8B_R8B_PFFFT
3639
BUILD_CXX_FLAGS += -I../common
3740
BUILD_CXX_FLAGS += -I../../3rd-party
3841
BUILD_CXX_FLAGS += -I../../3rd-party/FFTConvolver
42+
BUILD_CXX_FLAGS += -I../../3rd-party/r8brain
3943
BUILD_CXX_FLAGS += -I../../dpf-widgets/opengl
4044
BUILD_CXX_FLAGS += -pthread
4145
LINK_FLAGS += $(SHARED_MEMORY_LIBS)
4246

4347
# BUILD_CXX_FLAGS += -DAUDIOFFT_FFTW3 $(shell $(PKG_CONFIG) --cflags fftw3f)
4448
# LINK_FLAGS += $(shell $(PKG_CONFIG) --libs fftw3f)
4549

46-
BUILD_CXX_FLAGS += -DAUDIOFFT_PFFFT -DPFFFT_ENABLE_NEON -Ipffft
50+
# BUILD_CXX_FLAGS += -DAUDIOFFT_PFFFT -DPFFFT_ENABLE_NEON -Ipffft
4751

4852
# --------------------------------------------------------------
4953
# Enable all possible plugin types

plugins/ConvolutionReverb/OneKnobPlugin.cpp

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@
2626
#include "extra/ScopedPointer.hpp"
2727
#include "extra/Thread.hpp"
2828

29-
#include "FFTConvolver/TwoStageFFTConvolver.h"
3029
#include "dr_flac.h"
3130
#include "dr_wav.h"
31+
// -Wunused-variable
32+
#include "r8brain/CDSPResampler.h"
33+
#include "FFTConvolver/TwoStageFFTConvolver.h"
3234

3335
START_NAMESPACE_DISTRHO
3436

@@ -317,9 +319,20 @@ class OneKnobConvolutionReverbPlugin : public OneKnobPlugin
317319
unsigned int channels;
318320
unsigned int sampleRate;
319321
drwav_uint64 numFrames;
322+
const size_t valuelen = std::strlen(value);
323+
324+
ScopedPointer<TwoStageThreadedConvolver> newConvolverL, newConvolverR;
325+
326+
if (valuelen <= 5)
327+
{
328+
const MutexLocker cml(mutex);
329+
convolverL.swapWith(newConvolverL);
330+
convolverR.swapWith(newConvolverR);
331+
return;
332+
}
320333

321334
float* ir;
322-
if (::strncasecmp(value + (std::max(size_t(0), std::strlen(value) - 5u)), ".flac", 5) == 0)
335+
if (::strncasecmp(value + (std::max(size_t(0), valuelen - 5u)), ".flac", 5) == 0)
323336
ir = drflac_open_file_and_read_pcm_frames_f32(value, &channels, &sampleRate, &numFrames, nullptr);
324337
else
325338
ir = drwav_open_file_and_read_pcm_frames_f32(value, &channels, &sampleRate, &numFrames, nullptr);
@@ -363,7 +376,29 @@ class OneKnobConvolutionReverbPlugin : public OneKnobPlugin
363376
break;
364377
}
365378

366-
ScopedPointer<TwoStageThreadedConvolver> newConvolverL, newConvolverR;
379+
if (sampleRate != getSampleRate())
380+
{
381+
r8b::CDSPResampler16IR resampler(sampleRate, getSampleRate(), numFrames);
382+
const int numResampledFrames = resampler.getMaxOutLen(0);
383+
DISTRHO_SAFE_ASSERT_RETURN(numResampledFrames > 0,);
384+
385+
// left channel, always present
386+
float* const irBufResampledL = new float[numResampledFrames];
387+
resampler.oneshot(irBufL, numFrames, irBufResampledL, numResampledFrames);
388+
delete[] irBufL;
389+
irBufL = irBufResampledL;
390+
391+
// right channel, optional
392+
if (irBufL != irBufR)
393+
{
394+
float* const irBufResampledR = new float[numResampledFrames];
395+
resampler.oneshot(irBufR, numFrames, irBufResampledR, numResampledFrames);
396+
delete[] irBufR;
397+
irBufR = irBufResampledR;
398+
}
399+
400+
numFrames = numResampledFrames;
401+
}
367402

368403
newConvolverL = new TwoStageThreadedConvolver();
369404
newConvolverL->init(headBlockSize, tailBlockSize, irBufL, numFrames);

0 commit comments

Comments
 (0)