diff --git a/Source/PS_Source/StretchSource.cpp b/Source/PS_Source/StretchSource.cpp index e6e6c50..c4c71a6 100644 --- a/Source/PS_Source/StretchSource.cpp +++ b/Source/PS_Source/StretchSource.cpp @@ -253,6 +253,11 @@ void StretchAudioSource::getNextAudioBlock(const AudioSourceChannelInfo & buffer { readed = m_inputfile->readNextBlock(m_file_inbuf, readsize, m_num_outchans); } + if (m_rand_count % (int)m_free_filter_envelope->m_transform_y_random_rate == 0) + { + m_free_filter_envelope->updateRandomState(); + } + ++m_rand_count; auto inbufptrs = m_file_inbuf.getArrayOfWritePointers(); REALTYPE onset_max = std::numeric_limits::min(); #ifdef USE_PPL_TO_PROCESS_STRETCHERS diff --git a/Source/PS_Source/StretchSource.h b/Source/PS_Source/StretchSource.h index 946b7b4..1a642f2 100644 --- a/Source/PS_Source/StretchSource.h +++ b/Source/PS_Source/StretchSource.h @@ -131,7 +131,7 @@ private: int m_pause_state = 0; Range m_playrange{ 0.0,1.0 }; - + int64_t m_rand_count = 0; bool m_stream_end_reached = false; int64_t m_output_silence_counter = 0; File m_curfile; diff --git a/Source/PluginEditor.cpp b/Source/PluginEditor.cpp index df37cf4..ff48fb9 100644 --- a/Source/PluginEditor.cpp +++ b/Source/PluginEditor.cpp @@ -284,6 +284,14 @@ void PaulstretchpluginAudioProcessorEditor::resized() m_parcomps[cpi_freefilter_scaley]->setBounds(xoffs, yoffs, div - 1, 24); xoffs += div; m_parcomps[cpi_freefilter_tilty]->setBounds(xoffs, yoffs, div - 1, 24); + xoffs = 1; + yoffs += 25; + div = w / 3; + m_parcomps[cpi_freefilter_randomy_numbands]->setBounds(xoffs, yoffs, div - 1, 24); + xoffs += div; + m_parcomps[cpi_freefilter_randomy_rate]->setBounds(xoffs, yoffs, div - 1, 24); + xoffs += div; + m_parcomps[cpi_freefilter_randomy_amount]->setBounds(xoffs, yoffs, div - 1, 24); yoffs += 25; int remain_h = getHeight() - 1 - yoffs; m_spec_order_ed.setBounds(1, yoffs, getWidth() - 2, remain_h / 5 * 1); diff --git a/Source/PluginProcessor.cpp b/Source/PluginProcessor.cpp index 9784e3c..884cae9 100644 --- a/Source/PluginProcessor.cpp +++ b/Source/PluginProcessor.cpp @@ -154,6 +154,9 @@ PaulstretchpluginAudioProcessor::PaulstretchpluginAudioProcessor() addParameter(new AudioParameterFloat("freefilter_shifty_0", "Free filter shift Y", -1.0f, 1.0f, 0.0f)); // 35 addParameter(new AudioParameterFloat("freefilter_scaley_0", "Free filter scale Y", -1.0f, 1.0f, 1.0f)); // 36 addParameter(new AudioParameterFloat("freefilter_tilty_0", "Free filter tilt Y", -1.0f, 1.0f, 0.0f)); // 37 + addParameter(new AudioParameterInt("freefilter_randomybands0", "Random bands", 2, 128, 16)); // 38 + addParameter(new AudioParameterInt("freefilter_randomyrate0", "Random rate", 1, 32, 2)); // 39 + addParameter(new AudioParameterFloat("freefilter_randomyamount0", "Random amount", 0.0, 1.0, 0.0)); // 40 auto& pars = getParameters(); for (const auto& p : pars) m_reset_pars.push_back(p->getValue()); @@ -634,7 +637,10 @@ void PaulstretchpluginAudioProcessor::processBlock (AudioSampleBuffer& buffer, M m_free_filter_envelope->m_transform_y_shift = *getFloatParameter(cpi_freefilter_shifty); m_free_filter_envelope->m_transform_y_scale = *getFloatParameter(cpi_freefilter_scaley); m_free_filter_envelope->m_transform_y_tilt = *getFloatParameter(cpi_freefilter_tilty); - + m_free_filter_envelope->m_transform_y_random_bands = *getIntParameter(cpi_freefilter_randomy_numbands); + m_free_filter_envelope->m_transform_y_random_rate = *getIntParameter(cpi_freefilter_randomy_rate); + m_free_filter_envelope->m_transform_y_random_amount = *getFloatParameter(cpi_freefilter_randomy_amount); + m_stretch_source->setMainVolume(*getFloatParameter(cpi_main_volume)); m_stretch_source->setRate(*getFloatParameter(cpi_stretchamount)); m_stretch_source->setPreviewDry(*getBoolParameter(cpi_bypass_stretch)); diff --git a/Source/PluginProcessor.h b/Source/PluginProcessor.h index 5fd88cd..62a3a3e 100644 --- a/Source/PluginProcessor.h +++ b/Source/PluginProcessor.h @@ -64,6 +64,9 @@ const int cpi_freefilter_shiftx = 34; const int cpi_freefilter_shifty = 35; const int cpi_freefilter_scaley = 36; const int cpi_freefilter_tilty = 37; +const int cpi_freefilter_randomy_numbands = 38; +const int cpi_freefilter_randomy_rate = 39; +const int cpi_freefilter_randomy_amount = 40; class MyPropertiesFile { diff --git a/Source/jcdp_envelope.h b/Source/jcdp_envelope.h index d34be95..df33aee 100644 --- a/Source/jcdp_envelope.h +++ b/Source/jcdp_envelope.h @@ -20,6 +20,7 @@ along with CDP front-end. If not, see . #include #include +#include #include "../JuceLibraryCode/JuceHeader.h" #include "PS_Source/globals.h" @@ -193,7 +194,10 @@ inline double interpolate_foo(double atime,double t0, double v0, double t1, doub class breakpoint_envelope { public: - breakpoint_envelope() : m_name("Untitled") {} + breakpoint_envelope() : m_name("Untitled") + { + m_randbuf.resize(1024); + } breakpoint_envelope(String name, double minv=0.0, double maxv=1.0) : m_minvalue(minv), m_maxvalue(maxv), m_name(name) { @@ -202,6 +206,7 @@ public: m_defvalue=0.5; m_updateopinprogress=false; m_value_grid={0.0,0.25,0.5,0.75,1.0}; + m_randbuf.resize(1024); } @@ -567,6 +572,9 @@ public: double m_transform_y_sinus = 0.0; double m_transform_y_sinus_freq = 8.0; double m_transform_y_tilt = 0.0; + double m_transform_y_random_amount = 0.2; + double m_transform_y_random_rate = 2.0; + int m_transform_y_random_bands = 32; bool m_transform_wrap_x = false; double m_min_pt_value = 0.0; double m_max_pt_value = 0.0; @@ -589,12 +597,19 @@ public: sin(2*3.141592653*(x-m_transform_x_shift)*m_transform_y_sinus_freq); double tiltline = m_transform_y_tilt-(2.0*m_transform_y_tilt*x); double tilted = shifted+tiltline; - return jlimit(0.0,1.0,tilted); + if (m_transform_y_random_amount > 0.0) + { + + int tableindex = jlimit(0,m_randbuf.size()-1, floor(x * (m_transform_y_random_bands))); + double randamt = jmap(m_randbuf[tableindex], 0.0, 1.0, -m_transform_y_random_amount, m_transform_y_random_amount); + tilted += randamt; + } + return jlimit(0.0,1.0,tilted); } bool isTransformed() const { return m_transform_x_shift != 0.0 || m_transform_y_shift != 0.0 - || m_transform_y_scale!=1.0 || m_transform_y_sinus!=0.0 || m_transform_y_tilt!=0.0; + || m_transform_y_scale!=1.0 || m_transform_y_sinus!=0.0 || m_transform_y_tilt!=0.0 || m_transform_y_random_amount!=0.0; } void updateMinMaxValues() { @@ -608,6 +623,13 @@ public: m_minvalue = minv; m_maxvalue = maxv; } + void updateRandomState() + { + //Logger::writeToLog("updating envelope random state"); + std::uniform_real_distribution dist(0.0,1.0); + for (int i = 0; i < m_transform_y_random_bands+1; ++i) + m_randbuf[i] = dist(m_randgen); + } private: nodes_t m_nodes; double m_playoffset=0.0; @@ -625,6 +647,8 @@ private: nodes_t m_old_nodes; nodes_t m_repeater_nodes; grid_t m_value_grid; + std::mt19937 m_randgen; + std::vector m_randbuf; JUCE_LEAK_DETECTOR(breakpoint_envelope) };