From bd1eabf3bf23f3ee64678dda8a76fb2af00ad2a4 Mon Sep 17 00:00:00 2001 From: xenakios Date: Wed, 13 Dec 2017 18:30:09 +0200 Subject: [PATCH] Add more parameters including input capture enabled. A slightly nasty timer hack had to be implemented for that but can't be helped since the Juce provided bool parameter doesn't do callbacks...Small tweaks and fixes. --- Source/PS_Source/Stretch.cpp | 6 +++++ Source/PS_Source/Stretch.h | 7 ++---- Source/PS_Source/StretchSource.cpp | 31 ++++++++++++++++--------- Source/PluginProcessor.cpp | 36 ++++++++++++++++++++++++++++-- Source/PluginProcessor.h | 5 ++++- 5 files changed, 66 insertions(+), 19 deletions(-) diff --git a/Source/PS_Source/Stretch.cpp b/Source/PS_Source/Stretch.cpp index df2bcef..b3a6af2 100644 --- a/Source/PS_Source/Stretch.cpp +++ b/Source/PS_Source/Stretch.cpp @@ -345,6 +345,12 @@ REALTYPE Stretch::process(REALTYPE *smps,int nsmps) return onset; }; +void Stretch::set_onset_detection_sensitivity(REALTYPE detection_sensitivity) +{ + onset_detection_sensitivity = detection_sensitivity; + if (detection_sensitivity<1e-3) extra_onset_time_credit = 0.0; +} + void Stretch::here_is_onset(REALTYPE onset){ if (freezing) return; if (onset>0.5){ diff --git a/Source/PS_Source/Stretch.h b/Source/PS_Source/Stretch.h index 80e87fe..da8d3df 100644 --- a/Source/PS_Source/Stretch.h +++ b/Source/PS_Source/Stretch.h @@ -129,7 +129,7 @@ class FFT void applywindow(FFTWindow type); std::vector smp;//size of samples/2 std::vector freq;//size of samples - int nsamples; + int nsamples=0; private: fftwf_plan planfftw,planifftw; @@ -179,10 +179,7 @@ class Stretch void set_rap(REALTYPE newrap);//set the current stretch value - void set_onset_detection_sensitivity(REALTYPE detection_sensitivity){ - onset_detection_sensitivity=detection_sensitivity; - if (detection_sensitivity<1e-3) extra_onset_time_credit=0.0; - }; + void set_onset_detection_sensitivity(REALTYPE detection_sensitivity);; void here_is_onset(REALTYPE onset); virtual void setSampleRate(REALTYPE sr) { samplerate = jlimit(1000.0f, 38400.0f, sr); } REALTYPE getSampleRate() { return samplerate; } diff --git a/Source/PS_Source/StretchSource.cpp b/Source/PS_Source/StretchSource.cpp index b74f02b..02109ad 100644 --- a/Source/PS_Source/StretchSource.cpp +++ b/Source/PS_Source/StretchSource.cpp @@ -498,12 +498,16 @@ void StretchAudioSource::setFFTWindowingType(int windowtype) { if (windowtype==m_fft_window_type) return; - ScopedLock locker(m_cs); - m_fft_window_type = windowtype; - for (int i = 0; i < m_stretchers.size(); ++i) - { - m_stretchers[i]->window_type = (FFTWindow)windowtype; - } + if (m_cs.tryEnter()) + { + m_fft_window_type = windowtype; + for (int i = 0; i < m_stretchers.size(); ++i) + { + m_stretchers[i]->window_type = (FFTWindow)windowtype; + } + ++m_param_change_count; + m_cs.exit(); + } } void StretchAudioSource::setFFTSize(int size) @@ -552,13 +556,18 @@ double StretchAudioSource::getOutputDurationSecondsForRange(Range range, void StretchAudioSource::setOnsetDetection(double x) { - ScopedLock locker(m_cs); - m_onsetdetection = x; - for (int i = 0; i < m_stretchers.size(); ++i) + if (x == m_onsetdetection) + return; + if (m_cs.tryEnter()) { - m_stretchers[i]->set_onset_detection_sensitivity((float)x); + m_onsetdetection = x; + for (int i = 0; i < m_stretchers.size(); ++i) + { + m_stretchers[i]->set_onset_detection_sensitivity((float)x); + } + ++m_param_change_count; + m_cs.exit(); } - ++m_param_change_count; } void StretchAudioSource::setPlayRange(Range playrange, bool isloop) diff --git a/Source/PluginProcessor.cpp b/Source/PluginProcessor.cpp index eeeb282..28afb64 100644 --- a/Source/PluginProcessor.cpp +++ b/Source/PluginProcessor.cpp @@ -82,6 +82,7 @@ PaulstretchpluginAudioProcessor::PaulstretchpluginAudioProcessor() setPreBufferAmount(2); m_ppar.pitch_shift.enabled = true; m_ppar.freq_shift.enabled = true; + m_ppar.filter.enabled = true; m_stretch_source->setOnsetDetection(0.0); m_stretch_source->setLoopingEnabled(true); m_stretch_source->setFFTWindowingType(1); @@ -108,7 +109,13 @@ PaulstretchpluginAudioProcessor::PaulstretchpluginAudioProcessor() addParameter(new AudioParameterFloat("octavemix1_0", "1 octave up level", 0.0f, 1.0f, 0.0f)); // 18 addParameter(new AudioParameterFloat("octavemix15_0", "1 octave and fifth up level", 0.0f, 1.0f, 0.0f)); // 19 addParameter(new AudioParameterFloat("octavemix2_0", "2 octaves up level", 0.0f, 1.0f, 0.0f)); // 20 - + addParameter(new AudioParameterFloat("tonalvsnoisebw_0", "Tonal vs Noise BW", 0.74f, 1.0f, 0.74f)); // 21 + addParameter(new AudioParameterFloat("tonalvsnoisepreserve_0", "Tonal vs Noise preserve", -1.0f, 1.0f, 0.5f)); // 22 + addParameter(new AudioParameterFloat("filter_low_0", "Filter low", 20.0f, 10000.0f, 20.0f)); // 23 + addParameter(new AudioParameterFloat("filter_high_0", "Filter high", 20.0f, 20000.0f, 20000.0f)); // 24 + addParameter(new AudioParameterFloat("onsetdetect_0", "Onset detection", 0.0f, 1.0f, 0.0f)); // 25 + addParameter(new AudioParameterBool("capture_enabled0", "Capture", false)); // 26 + startTimer(1, 50); } PaulstretchpluginAudioProcessor::~PaulstretchpluginAudioProcessor() @@ -342,6 +349,12 @@ void PaulstretchpluginAudioProcessor::processBlock (AudioSampleBuffer& buffer, M m_ppar.octave.o15 = *getFloatParameter(cpi_octaves15); m_ppar.octave.o2 = *getFloatParameter(cpi_octaves2); m_ppar.octave.enabled = true; + m_ppar.filter.low = *getFloatParameter(cpi_filter_low); + m_ppar.filter.high = *getFloatParameter(cpi_filter_high); + m_ppar.tonal_vs_noise.enabled = (*getFloatParameter(cpi_tonalvsnoisebw)) > 0.75; + m_ppar.tonal_vs_noise.bandwidth = *getFloatParameter(cpi_tonalvsnoisebw); + m_ppar.tonal_vs_noise.preserve = *getFloatParameter(cpi_tonalvsnoisepreserve); + m_stretch_source->setOnsetDetection(*getFloatParameter(cpi_onsetdetection)); m_stretch_source->setLoopXFadeLength(*getFloatParameter(cpi_loopxfadelen)); double t0 = *getFloatParameter(cpi_soundstart); double t1 = *getFloatParameter(cpi_soundend); @@ -422,7 +435,7 @@ void PaulstretchpluginAudioProcessor::setRecordingEnabled(bool b) { m_using_memory_buffer = true; m_current_file = File(); - m_recbuffer.setSize(2, m_max_reclen*getSampleRate()+4096); + m_recbuffer.setSize(2, m_max_reclen*getSampleRate()+4096,false,false,true); m_recbuffer.clear(); m_rec_pos = 0; callGUI(this,[this,lenbufframes](PaulstretchpluginAudioProcessorEditor* ed) @@ -486,6 +499,25 @@ double PaulstretchpluginAudioProcessor::getPreBufferingPercent() return m_buffering_source->getPercentReady(); } +void PaulstretchpluginAudioProcessor::timerCallback(int id) +{ + if (id == 1) + { + bool capture = getParameter(cpi_capture_enabled); + if (capture == true && m_is_recording == false) + { + setRecordingEnabled(true); + return; + } + if (capture == false && m_is_recording == true) + { + setRecordingEnabled(false); + return; + } + + } +} + void PaulstretchpluginAudioProcessor::finishRecording(int lenrecording) { m_is_recording = false; diff --git a/Source/PluginProcessor.h b/Source/PluginProcessor.h index 8198363..09a00e4 100644 --- a/Source/PluginProcessor.h +++ b/Source/PluginProcessor.h @@ -40,8 +40,10 @@ const int cpi_tonalvsnoisebw = 21; const int cpi_tonalvsnoisepreserve = 22; const int cpi_filter_low = 23; const int cpi_filter_high = 24; +const int cpi_onsetdetection = 25; +const int cpi_capture_enabled = 26; -class PaulstretchpluginAudioProcessor : public AudioProcessor +class PaulstretchpluginAudioProcessor : public AudioProcessor, public MultiTimer { public: //============================================================================== @@ -93,6 +95,7 @@ public: SharedResourcePointer m_afm; StretchAudioSource* getStretchSource() { return m_stretch_source.get(); } double getPreBufferingPercent(); + void timerCallback(int id) override; private: