From a8079b277fefa22da7ba611920cb175f3eb440ed Mon Sep 17 00:00:00 2001 From: xenakios Date: Thu, 22 Feb 2018 20:01:29 +0200 Subject: [PATCH] Attempt to do fade outs and fade ins when seeking source sound, but not working yet. Readme changes. --- Source/PS_Source/Input/AInputS.h | 65 ++++++++++++++++++++++++++---- Source/PS_Source/StretchSource.cpp | 1 + readme.txt | 2 +- 3 files changed, 60 insertions(+), 8 deletions(-) diff --git a/Source/PS_Source/Input/AInputS.h b/Source/PS_Source/Input/AInputS.h index 11a0619..151789d 100644 --- a/Source/PS_Source/Input/AInputS.h +++ b/Source/PS_Source/Input/AInputS.h @@ -167,6 +167,37 @@ public: if (inchans == 1 && numchans > 0) { float sig = getCrossFadedSampleLambda(m_currentsample, 0, subsect_t0, subsect_t1, xfadelen); + if (m_seekfade.state == 1) + { + //Logger::writeToLog("Seek requested to pos " + String(m_seekfade.requestedpos)); + m_seekfade.state = 2; + } + if (m_seekfade.state == 2) + { + float seekfadegain = 1.0-(1.0 / m_seekfade.length*m_seekfade.counter); + sig *= seekfadegain; + ++m_seekfade.counter; + if (m_seekfade.counter >= m_seekfade.length) + { + //Logger::writeToLog("Doing seek " + String(m_seekfade.requestedpos)); + m_seekfade.counter = 0; + m_seekfade.state = 3; + seekImpl(m_seekfade.requestedpos); + } + } + if (m_seekfade.state == 3) + { + float seekfadegain = 1.0 / m_seekfade.length*m_seekfade.counter; + sig *= seekfadegain; + ++m_seekfade.counter; + if (m_seekfade.counter >= m_seekfade.length) + { + //Logger::writeToLog("Seek cycle finished"); + m_seekfade.counter = 0; + m_seekfade.state = 0; + m_seekfade.requestedpos = 0.0; + } + } for (int j = 0; j < numchans; ++j) { smps[j][i] = sig; @@ -204,11 +235,11 @@ public: return nsmps; } - void seek(double pos) override //0=start,1.0=end - { + void seekImpl(double pos) + { if (m_using_memory_buffer == true) { - jassert(m_readbuf.getNumSamples() > 0 && m_afreader==nullptr); + jassert(m_readbuf.getNumSamples() > 0 && m_afreader == nullptr); m_loopcount = 0; m_silenceoutputted = 0; m_cache_misses = 0; @@ -217,9 +248,9 @@ public: m_cached_file_range = { 0,m_readbuf.getNumSamples() }; return; } - //jassert(m_afreader!=nullptr); - if (m_afreader==nullptr) - return; + //jassert(m_afreader!=nullptr); + if (m_afreader == nullptr) + return; m_loopcount = 0; m_silenceoutputted = 0; m_cache_misses = 0; @@ -229,7 +260,20 @@ public: //if (m_cached_file_range.contains(info.currentsample)==false) m_cached_file_range = Range(); updateXFadeCache(); - //m_cached_crossfade_range = Range(); + //m_cached_crossfade_range = Range(); + } + void seek(double pos) override //0=start,1.0=end + { + std::lock_guard locker(m_mutex); + if (m_seekfade.state == 0) + { + m_seekfade.state = 1; + m_seekfade.counter = 0; + } + m_seekfade.length = 16384; + m_seekfade.requestedpos = pos; + + } std::pair,Range> getCachedRangesNormalized() { @@ -312,4 +356,11 @@ private: bool m_using_memory_buffer = true; AudioFormatManager* m_manager = nullptr; std::mutex m_mutex; + struct + { + int state = 0; // 0 inactive, 1 seek requested, 2 fade out, 3 fade in + int counter = 0; + int length = 44100; + double requestedpos = 0.0; + } m_seekfade; }; diff --git a/Source/PS_Source/StretchSource.cpp b/Source/PS_Source/StretchSource.cpp index e421717..d2d83c1 100644 --- a/Source/PS_Source/StretchSource.cpp +++ b/Source/PS_Source/StretchSource.cpp @@ -605,6 +605,7 @@ void StretchAudioSource::seekPercent(double pos) { ScopedLock locker(m_cs); m_seekpos = pos; + //m_resampler->Reset(); m_inputfile->seek(pos); ++m_param_change_count; } diff --git a/readme.txt b/readme.txt index 3ec14ff..a1b4beb 100644 --- a/readme.txt +++ b/readme.txt @@ -12,7 +12,7 @@ History : -Show approximate stretched output duration in info label (only valid if the stretch amount is not automated in the host) -Added stretch processing bypass parameter (to play the original sound looped like it is passed into the stretcher) -Waveform selection can be moved by dragging with shift pressed - -Waveform should no longer disappear when not intended + -Fixes for the waveform graphics disappearing unexpectedly (this probably still isn't entirely fixed, though) 02-16-2018 1.0.1 -Increased maximum number of input channels to 8 -Added zoom/scroll bar for waveform