diff --git a/Source/PS_Source/ProcessedStretch.cpp b/Source/PS_Source/ProcessedStretch.cpp index b1c8e59..da7d79e 100644 --- a/Source/PS_Source/ProcessedStretch.cpp +++ b/Source/PS_Source/ProcessedStretch.cpp @@ -41,18 +41,22 @@ void ProcessedStretch::set_parameters(ProcessParameters *ppar) } void ProcessedStretch::setBufferSize(int sz) { + jassert(sz > 0); Stretch::setBufferSize(sz); - nfreq = bufsize; - infreq = floatvector(nfreq); - sumfreq = floatvector(nfreq); - tmpfreq1 = floatvector(nfreq); - tmpfreq2 = floatvector(nfreq); - //fbfreq=new REALTYPE[nfreq]; - free_filter_freqs = floatvector(nfreq); - for (int i = 0; i(bufsize * 2); } jassert(infft != nullptr && fft != nullptr && outfft != nullptr); + fill_container(outfft->smp, 0.0f); for (int i = 0; iset_onset_detection_sensitivity(onsetsens); m_stretchers[i]->set_parameters(&m_ppar); m_stretchers[i]->set_freezing(m_freezing); + fill_container(m_stretchers[i]->out_buf, 0.0f); m_stretchers[i]->m_spectrum_processes = m_specproc_order; } m_inbufs.resize(m_num_outchans); diff --git a/Source/PS_Source/globals.h b/Source/PS_Source/globals.h index 5d2a21c..32480b2 100644 --- a/Source/PS_Source/globals.h +++ b/Source/PS_Source/globals.h @@ -187,3 +187,9 @@ private: int m_avail = 0; std::vector m_buf; }; + +template +inline void fill_container(Cont& c, const T& x) +{ + std::fill(std::begin(c), std::end(c), x); +} diff --git a/Source/PluginProcessor.cpp b/Source/PluginProcessor.cpp index e93b8b0..e66cd8d 100644 --- a/Source/PluginProcessor.cpp +++ b/Source/PluginProcessor.cpp @@ -192,13 +192,13 @@ void PaulstretchpluginAudioProcessor::setPreBufferAmount(int x) m_prebuffer_amount = temp; m_recreate_buffering_source = true; ScopedLock locker(m_cs); - m_ready_to_play = false; + m_prebuffering_inited = false; m_cur_num_out_chans = *m_outchansparam; //Logger::writeToLog("Switching to use " + String(m_cur_num_out_chans) + " out channels"); String err; startplay({ *getFloatParameter(cpi_soundstart),*getFloatParameter(cpi_soundend) }, m_cur_num_out_chans, m_curmaxblocksize, err); - m_ready_to_play = true; + m_prebuffering_inited = true; } } @@ -321,7 +321,7 @@ void PaulstretchpluginAudioProcessor::prepareToPlay(double sampleRate, int sampl m_input_buffer.setSize(2, samplesPerBlock); int numoutchans = *m_outchansparam; if (numoutchans != m_cur_num_out_chans) - m_ready_to_play = false; + m_prebuffering_inited = false; if (m_using_memory_buffer == true) { int len = jlimit(100,m_recbuffer.getNumSamples(), @@ -331,7 +331,7 @@ void PaulstretchpluginAudioProcessor::prepareToPlay(double sampleRate, int sampl len); callGUI(this,[this,len](auto ed) { ed->setAudioBuffer(&m_recbuffer, getSampleRateChecked(), len); },false); } - if (m_ready_to_play == false) + if (m_prebuffering_inited == false) { setFFTSize(*getFloatParameter(cpi_fftsize)); m_stretch_source->setProcessParameters(&m_ppar); @@ -340,9 +340,12 @@ void PaulstretchpluginAudioProcessor::prepareToPlay(double sampleRate, int sampl startplay({ *getFloatParameter(cpi_soundstart),*getFloatParameter(cpi_soundend) }, numoutchans, samplesPerBlock, err); m_cur_num_out_chans = numoutchans; - m_ready_to_play = true; + m_prebuffering_inited = true; + } + else + { + m_buffering_source->prepareToPlay(samplesPerBlock, getSampleRateChecked()); } - } void PaulstretchpluginAudioProcessor::releaseResources() @@ -412,7 +415,7 @@ void PaulstretchpluginAudioProcessor::processBlock (AudioSampleBuffer& buffer, M m_input_buffer.copyFrom(i, 0, buffer, i, 0, buffer.getNumSamples()); for (int i = totalNumInputChannels; i < totalNumOutputChannels; ++i) buffer.clear (i, 0, buffer.getNumSamples()); - if (m_ready_to_play == false) + if (m_prebuffering_inited == false) return; if (m_is_recording == true) { @@ -698,13 +701,13 @@ void PaulstretchpluginAudioProcessor::timerCallback(int id) { jassert(m_curmaxblocksize > 0); ScopedLock locker(m_cs); - m_ready_to_play = false; + m_prebuffering_inited = false; m_cur_num_out_chans = *m_outchansparam; //Logger::writeToLog("Switching to use " + String(m_cur_num_out_chans) + " out channels"); String err; startplay({ *getFloatParameter(cpi_soundstart),*getFloatParameter(cpi_soundend) }, m_cur_num_out_chans, m_curmaxblocksize, err); - m_ready_to_play = true; + m_prebuffering_inited = true; } } } diff --git a/Source/PluginProcessor.h b/Source/PluginProcessor.h index 08f8c97..f0c396b 100644 --- a/Source/PluginProcessor.h +++ b/Source/PluginProcessor.h @@ -148,7 +148,7 @@ public: private: - bool m_ready_to_play = false; + bool m_prebuffering_inited = false; AudioBuffer m_recbuffer; double m_max_reclen = 10.0; bool m_is_recording = false;