From dc8691353321405529e0df712386c7b6098f0cdf Mon Sep 17 00:00:00 2001 From: xenakios Date: Thu, 14 Dec 2017 22:17:45 +0200 Subject: [PATCH] Added pause playback feature with fades for smoothing --- Source/PS_Source/StretchSource.cpp | 42 ++++++++++++++++++++++++++++-- Source/PS_Source/StretchSource.h | 6 +++++ Source/PluginProcessor.cpp | 6 +++-- Source/PluginProcessor.h | 1 + 4 files changed, 51 insertions(+), 4 deletions(-) diff --git a/Source/PS_Source/StretchSource.cpp b/Source/PS_Source/StretchSource.cpp index 02109ad..9049016 100644 --- a/Source/PS_Source/StretchSource.cpp +++ b/Source/PS_Source/StretchSource.cpp @@ -164,6 +164,11 @@ void StretchAudioSource::setLoopXFadeLength(double lenseconds) void StretchAudioSource::getNextAudioBlock(const AudioSourceChannelInfo & bufferToFill) { ScopedLock locker(m_cs); + if (m_pause_state == 2) + { + bufferToFill.buffer->clear(bufferToFill.startSample,bufferToFill.numSamples); + return; + } if (m_stretchoutringbuf.available() > 0) m_output_has_begun = true; bool freezing = m_freezing; @@ -341,8 +346,17 @@ void StretchAudioSource::getNextAudioBlock(const AudioSourceChannelInfo & buffer } } - //if (m_inputfile->hasEnded()) - m_output_counter += bufferToFill.numSamples; + if (m_pause_state == 1) + { + bufferToFill.buffer->applyGainRamp(bufferToFill.startSample, bufferToFill.numSamples, 1.0f, 0.0f); + m_pause_state = 2; + } + if (m_pause_state == 3) + { + bufferToFill.buffer->applyGainRamp(bufferToFill.startSample, bufferToFill.numSamples, 0.0f, 1.0f); + m_pause_state = 0; + } + m_output_counter += bufferToFill.numSamples; } void StretchAudioSource::setNextReadPosition(int64 /*newPosition*/) @@ -538,6 +552,30 @@ void StretchAudioSource::setFFTSize(int size) } } +void StretchAudioSource::setPaused(bool b) +{ + if (b == true && m_pause_state>0) + return; + if (b == false && m_pause_state == 0) + return; + ScopedLock locker(m_cs); + if (b == true && m_pause_state == 0) + { + m_pause_state = 1; + return; + } + if (b == false && m_pause_state == 2) + { + m_pause_state = 3; + return; + } +} + +bool StretchAudioSource::isPaused() const +{ + return m_pause_state > 0; +} + void StretchAudioSource::seekPercent(double pos) { ScopedLock locker(m_cs); diff --git a/Source/PS_Source/StretchSource.h b/Source/PS_Source/StretchSource.h index 054f5f0..3b687cb 100644 --- a/Source/PS_Source/StretchSource.h +++ b/Source/PS_Source/StretchSource.h @@ -69,6 +69,9 @@ public: void setFreezing(bool b) { m_freezing = b; } bool isFreezing() { return m_freezing; } + void setPaused(bool b); + bool isPaused() const; + void seekPercent(double pos); double getOutputDurationSecondsForRange(Range range, int fftsize); @@ -122,6 +125,8 @@ private: double m_seekpos = 0.0; bool m_freezing = false; + + int m_pause_state = 0; Range m_playrange{ 0.0,1.0 }; bool m_stream_end_reached = false; @@ -148,6 +153,7 @@ private: int requested_fft_size = 0; File requested_file; } m_xfadetask; + int m_pause_fade_counter = 0; }; class MultiStretchAudioSource final : public PositionableAudioSource diff --git a/Source/PluginProcessor.cpp b/Source/PluginProcessor.cpp index 4ce7cec..8ded68f 100644 --- a/Source/PluginProcessor.cpp +++ b/Source/PluginProcessor.cpp @@ -116,8 +116,9 @@ PaulstretchpluginAudioProcessor::PaulstretchpluginAudioProcessor() 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 - m_outchansparam = new AudioParameterInt("numoutchans0", "Num output channels", 2, 8, 2); + m_outchansparam = new AudioParameterInt("numoutchans0", "Num output channels", 2, 8, 2); // 27 addParameter(m_outchansparam); // 27 + addParameter(new AudioParameterBool("pause_enabled0", "Pause", false)); // 28 startTimer(1, 50); } @@ -253,7 +254,7 @@ void PaulstretchpluginAudioProcessor::prepareToPlay(double sampleRate, int sampl { setFFTSize(*getFloatParameter(cpi_fftsize)); m_stretch_source->setProcessParameters(&m_ppar); - + m_stretch_source->setFFTWindowingType(1); String err; startplay({ *getFloatParameter(cpi_soundstart),*getFloatParameter(cpi_soundend) }, numoutchans, samplesPerBlock, err); @@ -372,6 +373,7 @@ void PaulstretchpluginAudioProcessor::processBlock (AudioSampleBuffer& buffer, M t1 = t0 + 0.001; m_stretch_source->setPlayRange({ t0,t1 }, true); m_stretch_source->setFreezing(getParameter(cpi_freeze)); + m_stretch_source->setPaused(getParameter(cpi_pause_enabled)); m_stretch_source->setProcessParameters(&m_ppar); AudioSourceChannelInfo aif(buffer); diff --git a/Source/PluginProcessor.h b/Source/PluginProcessor.h index 4a78b9c..42ab56f 100644 --- a/Source/PluginProcessor.h +++ b/Source/PluginProcessor.h @@ -43,6 +43,7 @@ const int cpi_filter_high = 24; const int cpi_onsetdetection = 25; const int cpi_capture_enabled = 26; const int cpi_num_outchans = 27; +const int cpi_pause_enabled = 28; class PaulstretchpluginAudioProcessor : public AudioProcessor, public MultiTimer {