From d97975f27a35e32de80c4f6437f8c93ba10f30e2 Mon Sep 17 00:00:00 2001 From: xenakios Date: Mon, 13 Nov 2017 18:15:07 +0200 Subject: [PATCH] OK, it plays some crappy audio but crashes on quit and all that kind of great stuff --- Source/PS_Source/PaulStretchControl.cpp | 19 +++++++--- Source/PS_Source/PaulStretchControl.h | 3 +- Source/PS_Source/Stretch.cpp | 4 +-- Source/PS_Source/StretchSource.cpp | 30 +++------------- Source/PluginProcessor.cpp | 48 +++++++++++++++++-------- Source/PluginProcessor.h | 1 + paulstretchplugin.jucer | 8 ++--- 7 files changed, 60 insertions(+), 53 deletions(-) diff --git a/Source/PS_Source/PaulStretchControl.cpp b/Source/PS_Source/PaulStretchControl.cpp index 3150b63..a581ae3 100644 --- a/Source/PS_Source/PaulStretchControl.cpp +++ b/Source/PS_Source/PaulStretchControl.cpp @@ -61,8 +61,17 @@ Control::Control(AudioFormatManager* afm) : m_afm(afm), m_bufferingthread("stret Control::~Control() { - -}; + m_bufferingthread.stopThread(1000); +} +void Control::processAudio(AudioBuffer& buf) +{ + if (m_buffering_source != nullptr) + { + AudioSourceChannelInfo aif(buf); + m_buffering_source->getNextAudioBlock(aif); + } +} + void Control::setStretchAmount(double rate) @@ -274,7 +283,9 @@ void Control::startplay(bool /*bypass*/, bool /*realtime*/, Range playra m_bufferingthread, false, bufamt, numoutchans, false); m_recreate_buffering_source = false; } - + if (m_bufferingthread.isThreadRunning() == false) + m_bufferingthread.startThread(); + m_buffering_source->prepareToPlay(1024, 44100.0); m_stretch_source->setNumOutChannels(numoutchans); m_stretch_source->setFFTSize(m_fft_size_to_use); update_process_parameters(); @@ -289,7 +300,7 @@ void Control::startplay(bool /*bypass*/, bool /*realtime*/, Range playra void Control::stopplay() { //m_adm->removeAudioCallback(&m_test_callback); - + m_bufferingthread.stopThread(1000); }; void Control::set_seek_pos(REALTYPE x) diff --git a/Source/PS_Source/PaulStretchControl.h b/Source/PS_Source/PaulStretchControl.h index ca8c40a..f2f6570 100644 --- a/Source/PS_Source/PaulStretchControl.h +++ b/Source/PS_Source/PaulStretchControl.h @@ -90,7 +90,8 @@ class Control public: Control(AudioFormatManager* afm); ~Control(); - void startplay(bool bypass, bool realtime, Range playrange, int numoutchans, String& err); + void processAudio(AudioBuffer& buf); + void startplay(bool bypass, bool realtime, Range playrange, int numoutchans, String& err); void stopplay(); void set_seek_pos(REALTYPE x); REALTYPE get_seek_pos(); diff --git a/Source/PS_Source/Stretch.cpp b/Source/PS_Source/Stretch.cpp index 1a2072a..6d929a2 100644 --- a/Source/PS_Source/Stretch.cpp +++ b/Source/PS_Source/Stretch.cpp @@ -20,8 +20,6 @@ #include #include -extern std::unique_ptr g_propsfile; - FFT::FFT(int nsamples_) { nsamples=nsamples_; @@ -39,7 +37,7 @@ FFT::FFT(int nsamples_) data.resize(nsamples,true); - bool allow_long_planning = g_propsfile->getBoolValue("fftw_allow_long_planning",false); + bool allow_long_planning = false; // g_propsfile->getBoolValue("fftw_allow_long_planning", false); //double t0 = Time::getMillisecondCounterHiRes(); if (allow_long_planning) { diff --git a/Source/PS_Source/StretchSource.cpp b/Source/PS_Source/StretchSource.cpp index a4dd446..2111dec 100644 --- a/Source/PS_Source/StretchSource.cpp +++ b/Source/PS_Source/StretchSource.cpp @@ -7,38 +7,18 @@ #undef max #endif -extern std::unique_ptr g_propsfile; - StretchAudioSource::StretchAudioSource(int initialnumoutchans, AudioFormatManager* afm) : m_afm(afm) { m_resampler = std::make_unique(); m_resampler_outbuf.resize(1024*1024); m_inputfile = std::make_unique(m_afm); m_specproc_order = { 0,1,2,3,4,5,6,7 }; - String order = g_propsfile->getValue("spectral_order", "01234567"); - if (order.isNotEmpty()) - { - std::vector temp; - for (int i = 0; i= 0 && index<8) - { - temp.push_back(index); - //Logger::writeToLog(temp.back().m_name); - } - } - m_specproc_order = temp; - } setNumOutChannels(initialnumoutchans); } StretchAudioSource::~StretchAudioSource() { - String temp; - for (auto& e : m_specproc_order) - temp.append(String(e),1); - g_propsfile->setValue("spectral_order", temp); + } void StretchAudioSource::prepareToPlay(int /*samplesPerBlockExpected*/, double sampleRate) @@ -59,6 +39,7 @@ void StretchAudioSource::prepareToPlay(int /*samplesPerBlockExpected*/, double s void StretchAudioSource::releaseResources() { + } bool StretchAudioSource::isResampling() @@ -149,7 +130,7 @@ void StretchAudioSource::getNextAudioBlock(const AudioSourceChannelInfo & buffer for (auto& e : m_stretchers) e->set_freezing(m_freezing); } - double maingain = Decibels::decibelsToGain((double)val_MainVolume.getValue()); + double maingain = 0.5; // Decibels::decibelsToGain((double)val_MainVolume.getValue()); if (m_vol_smoother.getTargetValue() != maingain) m_vol_smoother.setValue(maingain); FloatVectorOperations::disableDenormalisedNumberSupport(); @@ -532,10 +513,7 @@ MultiStretchAudioSource::MultiStretchAudioSource(int initialnumoutchans, AudioFo MultiStretchAudioSource::~MultiStretchAudioSource() { - String temp; - for (auto& e : getActiveStretchSource()->getSpectrumProcessOrder()) - temp.append(String(e), 1); - g_propsfile->setValue("spectral_order", temp); + } void MultiStretchAudioSource::prepareToPlay(int samplesPerBlockExpected, double sampleRate) diff --git a/Source/PluginProcessor.cpp b/Source/PluginProcessor.cpp index 4b4f133..50cd872 100644 --- a/Source/PluginProcessor.cpp +++ b/Source/PluginProcessor.cpp @@ -28,6 +28,11 @@ PaulstretchpluginAudioProcessor::PaulstretchpluginAudioProcessor() m_afm = std::make_unique(); m_afm->registerBasicFormats(); m_control = std::make_unique(m_afm.get()); + m_control->getStretchAudioSource()->setLoopingEnabled(true); + addParameter(new AudioParameterFloat("mainvolume0", "Main volume", -24.0f, 12.0f, -3.0f)); + addParameter(new AudioParameterFloat("stretchamount0", "Stretch amount", 0.1f, 128.0f, 1.0f)); + addParameter(new AudioParameterFloat("pitchshift0", "Pitch shift", -24.0f, 24.0f, 0.0f)); + } PaulstretchpluginAudioProcessor::~PaulstretchpluginAudioProcessor() @@ -97,16 +102,27 @@ void PaulstretchpluginAudioProcessor::changeProgramName (int index, const String } //============================================================================== -void PaulstretchpluginAudioProcessor::prepareToPlay (double sampleRate, int samplesPerBlock) +void PaulstretchpluginAudioProcessor::prepareToPlay(double sampleRate, int samplesPerBlock) { - // Use this method as the place to do any pre-playback - // initialisation that you need.. + m_ready_to_play = false; + m_control->set_input_file(File("C:/MusicAudio/sourcesamples/sheila.wav"), [this](String cberr) + { + if (cberr.isEmpty()) + { + m_ready_to_play = true; + String err; + m_control->update_player_stretch(); + m_control->update_process_parameters(); + m_control->startplay(false, true, { 0.0,1.0 }, 2, err); + } + else m_ready_to_play = false; + }); + } void PaulstretchpluginAudioProcessor::releaseResources() { - // When playback stops, you can use this as an opportunity to free up any - // spare memory, etc. + m_control->stopplay(); } #ifndef JucePlugin_PreferredChannelConfigurations @@ -147,15 +163,16 @@ void PaulstretchpluginAudioProcessor::processBlock (AudioSampleBuffer& buffer, M // this code if your algorithm always overwrites all the output channels. for (int i = totalNumInputChannels; i < totalNumOutputChannels; ++i) buffer.clear (i, 0, buffer.getNumSamples()); - - // This is the place where you'd normally do the guts of your plugin's - // audio processing... - for (int channel = 0; channel < totalNumInputChannels; ++channel) - { - float* channelData = buffer.getWritePointer (channel); - - // ..do something to the data... - } + if (m_ready_to_play == false) + return; + auto& params = getParameters(); + AudioParameterFloat* par = (AudioParameterFloat*)params[1]; + m_control->getStretchAudioSource()->setRate(*par); + par = (AudioParameterFloat*)params[2]; + m_control->ppar.pitch_shift.enabled = true; + m_control->ppar.pitch_shift.cents = *par * 100.0; + m_control->update_process_parameters(); + m_control->processAudio(buffer); } //============================================================================== @@ -166,7 +183,8 @@ bool PaulstretchpluginAudioProcessor::hasEditor() const AudioProcessorEditor* PaulstretchpluginAudioProcessor::createEditor() { - return new PaulstretchpluginAudioProcessorEditor (*this); + return new GenericAudioProcessorEditor(this); + //return new PaulstretchpluginAudioProcessorEditor (*this); } //============================================================================== diff --git a/Source/PluginProcessor.h b/Source/PluginProcessor.h index ee36563..7485128 100644 --- a/Source/PluginProcessor.h +++ b/Source/PluginProcessor.h @@ -59,6 +59,7 @@ public: private: std::unique_ptr m_control; std::unique_ptr m_afm; + bool m_ready_to_play = false; //============================================================================== JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PaulstretchpluginAudioProcessor) }; diff --git a/paulstretchplugin.jucer b/paulstretchplugin.jucer index a219b3f..58bece0 100644 --- a/paulstretchplugin.jucer +++ b/paulstretchplugin.jucer @@ -79,13 +79,13 @@ + headerPath="Source/PS_Source Source/WDL " vstBinaryLocation="C:\Program Files\VSTPlugins"/> + headerPath="Source/PS_Source Source/WDL " vstBinaryLocation="C:\Program Files\VSTPlugins"/>