From 88d5cc09a467ef90057237f20ca96eaa181c078e Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Wed, 21 Mar 2018 00:52:08 -0400 Subject: [PATCH] Fix Delay, add libsamplerate to Fundamental build system --- .gitmodules | 3 +++ Makefile | 11 +++++++++++ dep/libsamplerate | 1 + src/Delay.cpp | 35 ++++++++++++++++++++--------------- src/VCMixer.cpp | 2 +- 5 files changed, 36 insertions(+), 16 deletions(-) create mode 100644 .gitmodules create mode 160000 dep/libsamplerate diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..e2038b0 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "dep/libsamplerate"] + path = dep/libsamplerate + url = https://github.com/erikd/libsamplerate.git diff --git a/Makefile b/Makefile index 7600c9f..04b95cd 100644 --- a/Makefile +++ b/Makefile @@ -5,5 +5,16 @@ SOURCES += $(wildcard src/*.cpp) DISTRIBUTABLES += $(wildcard LICENSE*) res +FLAGS += -Idep/libsamplerate/src +LDFLAGS += -Ldep/libsamplerate/src/.libs -l:libsamplerate.a + +libsamplerate = dep/libsamplerate/src/.libs/libsamplerate.a +$(libsamplerate): + cd dep/libsamplerate && ./autogen.sh + cd dep/libsamplerate && CFLAGS=-fPIC ./configure + cd dep/libsamplerate && $(MAKE) + +RESOURCES += $(libsamplerate) + RACK_DIR ?= ../.. include $(RACK_DIR)/plugin.mk diff --git a/dep/libsamplerate b/dep/libsamplerate new file mode 160000 index 0000000..56c3897 --- /dev/null +++ b/dep/libsamplerate @@ -0,0 +1 @@ +Subproject commit 56c3897f605dbfbd3db55f46866275823c9ba4bd diff --git a/src/Delay.cpp b/src/Delay.cpp index 0d97e32..1ce1602 100644 --- a/src/Delay.cpp +++ b/src/Delay.cpp @@ -2,6 +2,7 @@ #include "dsp/samplerate.hpp" #include "dsp/ringbuffer.hpp" #include "dsp/filter.hpp" +#include "samplerate.h" #define HISTORY_SIZE (1<<21) @@ -29,12 +30,19 @@ struct Delay : Module { DoubleRingBuffer historyBuffer; DoubleRingBuffer outBuffer; - SampleRateConverter<1> src; + SRC_STATE *src; float lastWet = 0.0f; RCFilter lowpassFilter; RCFilter highpassFilter; - Delay() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS) {} + Delay() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS) { + src = src_new(SRC_SINC_FASTEST, 1, NULL); + assert(src); + } + + ~Delay() { + src_delete(src); + } void step() override; }; @@ -60,9 +68,6 @@ void Delay::step() { // How many samples do we need consume to catch up? float consume = index - historyBuffer.size(); - // printf("%f\t%d\t%f\n", index, historyBuffer.size(), consume); - - // printf("wanted: %f\tactual: %d\tdiff: %d\tratio: %f\n", index, historyBuffer.size(), consume, index / historyBuffer.size()); if (outBuffer.empty()) { double ratio = 1.0f; if (consume <= -16) @@ -70,16 +75,16 @@ void Delay::step() { else if (consume >= 16) ratio = 2.0f; - // printf("%f\t%lf\n", consume, ratio); - int inFrames = min(historyBuffer.size(), 16); - int outFrames = outBuffer.capacity(); - // printf(">\t%d\t%d\n", inFrames, outFrames); - src.setRates(ratio * engineGetSampleRate(), engineGetSampleRate()); - src.process((const Frame<1>*)historyBuffer.startData(), &inFrames, (Frame<1>*)outBuffer.endData(), &outFrames); - historyBuffer.startIncr(inFrames); - outBuffer.endIncr(outFrames); - // printf("<\t%d\t%d\n", inFrames, outFrames); - // printf("====================================\n"); + SRC_DATA srcData; + srcData.data_in = (const float*) historyBuffer.startData(); + srcData.data_out = (float*) outBuffer.endData(); + srcData.input_frames = min(historyBuffer.size(), 16); + srcData.output_frames = outBuffer.capacity(); + srcData.end_of_input = false; + srcData.src_ratio = ratio; + src_process(src, &srcData); + historyBuffer.startIncr(srcData.input_frames_used); + outBuffer.endIncr(srcData.output_frames_gen); } float wet = 0.0f; diff --git a/src/VCMixer.cpp b/src/VCMixer.cpp index 05786b6..5af56d4 100644 --- a/src/VCMixer.cpp +++ b/src/VCMixer.cpp @@ -25,7 +25,7 @@ struct VCMixer : Module { float mix = 0.f; for (int i = 0; i < 4; i++) { float ch = inputs[CH_INPUT + i].value; - ch *= powf(params[LVL_PARAM + i].value, 3.f); + ch *= powf(params[LVL_PARAM + i].value, 2.f); ch *= clamp(inputs[CV_INPUT + i].normalize(10.f) / 10.f, 0.f, 1.f); outputs[CH_OUTPUT + i].value = ch; mix += ch;