diff --git a/Source/PS_Source/StretchSource.cpp b/Source/PS_Source/StretchSource.cpp index 5209aa2..9297f40 100644 --- a/Source/PS_Source/StretchSource.cpp +++ b/Source/PS_Source/StretchSource.cpp @@ -23,7 +23,7 @@ StretchAudioSource::~StretchAudioSource() } -void StretchAudioSource::prepareToPlay(int /*samplesPerBlockExpected*/, double sampleRate) +void StretchAudioSource::prepareToPlay(int samplesPerBlockExpected, double sampleRate) { m_outsr = sampleRate; m_vol_smoother.reset(sampleRate, 0.5); @@ -34,7 +34,7 @@ void StretchAudioSource::prepareToPlay(int /*samplesPerBlockExpected*/, double s m_stream_end_reached = false; m_firstbuffer = true; m_output_has_begun = false; - + m_drypreviewbuf.setSize(m_num_outchans, 65536); initObjects(); } @@ -161,9 +161,36 @@ void StretchAudioSource::setLoopXFadeLength(double lenseconds) } } +void StretchAudioSource::setPreviewDry(bool b) +{ + if (b == m_preview_dry) + return; + if (m_cs.tryEnter()) + { + m_preview_dry = b; + ++m_param_change_count; + m_cs.exit(); + } +} + +bool StretchAudioSource::isPreviewingDry() const +{ + return m_preview_dry; +} + void StretchAudioSource::getNextAudioBlock(const AudioSourceChannelInfo & bufferToFill) { ScopedLock locker(m_cs); + double maingain = Decibels::decibelsToGain(m_main_volume); + if (m_preview_dry == true && m_inputfile!=nullptr && m_inputfile->info.nsamples>0) + { + m_inputfile->setXFadeLenSeconds(m_loopxfadelen); + m_inputfile->readNextBlock(m_drypreviewbuf, bufferToFill.numSamples, m_num_outchans); + for (int i = 0; i < m_num_outchans; ++i) + bufferToFill.buffer->copyFrom(i, bufferToFill.startSample, m_drypreviewbuf, i, 0, bufferToFill.numSamples); + bufferToFill.buffer->applyGain(bufferToFill.startSample, bufferToFill.numSamples, maingain); + return; + } if (m_pause_state == 2) { bufferToFill.buffer->clear(bufferToFill.startSample,bufferToFill.numSamples); @@ -181,7 +208,7 @@ void StretchAudioSource::getNextAudioBlock(const AudioSourceChannelInfo & buffer e->set_freezing(m_freezing); } - double maingain = Decibels::decibelsToGain(m_main_volume); + if (m_vol_smoother.getTargetValue() != maingain) m_vol_smoother.setValue(maingain); FloatVectorOperations::disableDenormalisedNumberSupport(); diff --git a/Source/PS_Source/StretchSource.h b/Source/PS_Source/StretchSource.h index 7859ec2..8922cf1 100644 --- a/Source/PS_Source/StretchSource.h +++ b/Source/PS_Source/StretchSource.h @@ -99,6 +99,8 @@ public: double getMainVolume() const { return m_main_volume; } void setLoopXFadeLength(double lenseconds); double getLoopXFadeLengtj() const { return m_loopxfadelen; } + void setPreviewDry(bool b); + bool isPreviewingDry() const; int m_param_change_count = 0; private: CircularBuffer m_stretchoutringbuf{ 1024 * 1024 }; @@ -153,4 +155,6 @@ private: File requested_file; } m_xfadetask; int m_pause_fade_counter = 0; + bool m_preview_dry = false; + AudioBuffer m_drypreviewbuf; }; diff --git a/Source/PluginProcessor.cpp b/Source/PluginProcessor.cpp index ec896d1..67f24fe 100644 --- a/Source/PluginProcessor.cpp +++ b/Source/PluginProcessor.cpp @@ -151,6 +151,7 @@ PaulstretchpluginAudioProcessor::PaulstretchpluginAudioProcessor() setPreBufferAmount(2); startTimer(1, 50); m_show_technical_info = m_propsfile->m_props_file->getBoolValue("showtechnicalinfo", false); + m_stretch_source->setPreviewDry(true); } PaulstretchpluginAudioProcessor::~PaulstretchpluginAudioProcessor()