From 8d008e5d2e858802a850b2c4b67b76cd5e85a02e Mon Sep 17 00:00:00 2001 From: xenakios Date: Mon, 20 Aug 2018 15:49:51 +0300 Subject: [PATCH] Support resampled playrate changes for non stretched playback --- Source/PS_Source/StretchSource.cpp | 19 ++++++++++++++++++- Source/PS_Source/StretchSource.h | 3 +++ Source/PluginEditor.cpp | 5 ++++- Source/PluginEditor.h | 1 + Source/PluginProcessor.cpp | 3 ++- Source/PluginProcessor.h | 1 + 6 files changed, 29 insertions(+), 3 deletions(-) diff --git a/Source/PS_Source/StretchSource.cpp b/Source/PS_Source/StretchSource.cpp index 56d1b73..bf025ce 100644 --- a/Source/PS_Source/StretchSource.cpp +++ b/Source/PS_Source/StretchSource.cpp @@ -269,6 +269,23 @@ bool StretchAudioSource::isPreviewingDry() const return m_preview_dry; } +void StretchAudioSource::setDryPlayrate(double rate) +{ + if (rate == m_dryplayrate) + return; + if (m_cs.tryEnter()) + { + m_dryplayrate = rate; + ++m_param_change_count; + m_cs.exit(); + } +} + +double StretchAudioSource::getDryPlayrate() const +{ + return m_dryplayrate; +} + void StretchAudioSource::getNextAudioBlock(const AudioSourceChannelInfo & bufferToFill) { ScopedLock locker(m_cs); @@ -568,7 +585,7 @@ void StretchAudioSource::playDrySound(const AudioSourceChannelInfo & bufferToFil double maingain = Decibels::decibelsToGain(m_main_volume); m_inputfile->setXFadeLenSeconds(m_loopxfadelen); double* rsinbuf = nullptr; - m_resampler->SetRates(m_inputfile->info.samplerate, m_outsr); + m_resampler->SetRates(m_inputfile->info.samplerate*m_dryplayrate, m_outsr); int wanted = m_resampler->ResamplePrepare(bufferToFill.numSamples, m_num_outchans, &rsinbuf); m_inputfile->readNextBlock(m_drypreviewbuf, wanted, m_num_outchans); for (int i = 0; i < wanted; ++i) diff --git a/Source/PS_Source/StretchSource.h b/Source/PS_Source/StretchSource.h index 7b0d243..865dde4 100644 --- a/Source/PS_Source/StretchSource.h +++ b/Source/PS_Source/StretchSource.h @@ -104,6 +104,8 @@ public: double getLoopXFadeLengtj() const { return m_loopxfadelen; } void setPreviewDry(bool b); bool isPreviewingDry() const; + void setDryPlayrate(double rate); + double getDryPlayrate() const; int m_param_change_count = 0; double getLastSeekPos() const { return m_seekpos; } CriticalSection* getMutex() { return &m_cs; } @@ -163,6 +165,7 @@ private: } m_xfadetask; int m_pause_fade_counter = 0; bool m_preview_dry = false; + double m_dryplayrate = 1.0; AudioBuffer m_drypreviewbuf; void playDrySound(const AudioSourceChannelInfo & bufferToFill); }; diff --git a/Source/PluginEditor.cpp b/Source/PluginEditor.cpp index db92b2e..4da6926 100644 --- a/Source/PluginEditor.cpp +++ b/Source/PluginEditor.cpp @@ -119,7 +119,7 @@ PaulstretchpluginAudioProcessorEditor::PaulstretchpluginAudioProcessorEditor(Pau m_parcomps.push_back(nullptr); } } - + //m_parcomps[cpi_dryplayrate]->getSlider()->setSkewFactorFromMidPoint(1.0); //addAndMakeVisible(&m_specvis); m_wave_container->addAndMakeVisible(&m_zs); m_zs.RangeChanged = [this](Range r) @@ -375,6 +375,9 @@ void PaulstretchpluginAudioProcessorEditor::resized() xoffs += div; m_parcomps[cpi_soundend]->setBounds(xoffs, yoffs, div - 1, 24); yoffs += 25; + xoffs = 1; + m_parcomps[cpi_dryplayrate]->setBounds(xoffs, yoffs, getWidth() - 2, 24); + yoffs += 25; int remain_h = getHeight() - 1 - yoffs; m_spec_order_ed.setBounds(1, yoffs, getWidth() - 2, remain_h / 9 * 1); m_wavefilter_tab.setBounds(1, m_spec_order_ed.getBottom() + 1, getWidth() - 2, remain_h / 9 * 8); diff --git a/Source/PluginEditor.h b/Source/PluginEditor.h index 8075c4b..20a0b0e 100644 --- a/Source/PluginEditor.h +++ b/Source/PluginEditor.h @@ -90,6 +90,7 @@ public: void updateComponent(); void setHighLighted(bool b); int m_group_id = -1; + Slider* getSlider() { return m_slider.get(); } private: Label m_label; AudioProcessorParameter* m_par = nullptr; diff --git a/Source/PluginProcessor.cpp b/Source/PluginProcessor.cpp index bc792a1..5fa9589 100644 --- a/Source/PluginProcessor.cpp +++ b/Source/PluginProcessor.cpp @@ -169,7 +169,7 @@ PaulstretchpluginAudioProcessor::PaulstretchpluginAudioProcessor() addParameter(new AudioParameterBool("loop_enabled0", "Loop", true)); // 60 addParameter(new AudioParameterBool("rewind0", "Rewind", false)); // 61 - + addParameter(new AudioParameterFloat("dryplayrate0", "Dry playrate", 0.1, 8.0, 1.0)); // 62 auto& pars = getParameters(); for (const auto& p : pars) m_reset_pars.push_back(p->getValue()); @@ -697,6 +697,7 @@ void PaulstretchpluginAudioProcessor::processBlock (AudioSampleBuffer& buffer, M m_stretch_source->setMainVolume(*getFloatParameter(cpi_main_volume)); m_stretch_source->setRate(*getFloatParameter(cpi_stretchamount)); m_stretch_source->setPreviewDry(*getBoolParameter(cpi_bypass_stretch)); + m_stretch_source->setDryPlayrate(*getFloatParameter(cpi_dryplayrate)); setFFTSize(*getFloatParameter(cpi_fftsize)); updateStretchParametersFromPluginParameters(m_ppar); diff --git a/Source/PluginProcessor.h b/Source/PluginProcessor.h index 00c3f88..51f0f18 100644 --- a/Source/PluginProcessor.h +++ b/Source/PluginProcessor.h @@ -86,6 +86,7 @@ const int cpi_octaves_ratio6 = 58; const int cpi_octaves_ratio7 = 59; const int cpi_looping_enabled = 60; const int cpi_rewind = 61; +const int cpi_dryplayrate = 62; class MyPropertiesFile {