Implemented free filter processing. Note that the envelope manipulation from the GUI is not handled thread safely yet

This commit is contained in:
xenakios 2018-02-27 15:02:34 +02:00
parent e8d134ce48
commit 195a630060
8 changed files with 62 additions and 7 deletions

View File

@ -39,6 +39,12 @@ void ProcessedStretch::set_parameters(ProcessParameters *ppar)
pars=*ppar; pars=*ppar;
//update_free_filter(); //update_free_filter();
} }
void ProcessedStretch::setFreeFilterEnvelope(shared_envelope env)
{
m_free_filter_envelope = env;
}
void ProcessedStretch::setBufferSize(int sz) void ProcessedStretch::setBufferSize(int sz)
{ {
jassert(sz > 0); jassert(sz > 0);
@ -125,6 +131,8 @@ void ProcessedStretch::process_spectrum(REALTYPE *freq)
spectrum_do_filter(pars,nfreq,samplerate,infreq.data(), freq); spectrum_do_filter(pars,nfreq,samplerate,infreq.data(), freq);
if (e.m_index == 7 && e.m_enabled == true) if (e.m_index == 7 && e.m_enabled == true)
spectrum_do_compressor(pars,nfreq, infreq.data(), freq); spectrum_do_compressor(pars,nfreq, infreq.data(), freq);
if (e.m_index == 8 && e.m_enabled == true)
spectrum_do_free_filter(m_free_filter_envelope, nfreq, samplerate, infreq.data(), freq);
} }
#ifdef USE_OLD_SPEC_PROC #ifdef USE_OLD_SPEC_PROC

View File

@ -21,6 +21,7 @@
#include "FreeEdit.h" #include "FreeEdit.h"
#include "Stretch.h" #include "Stretch.h"
#include "../jcdp_envelope.h"
struct ProcessParameters struct ProcessParameters
{ {
@ -413,6 +414,25 @@ inline void spectrum_do_filter(const ProcessParameters& pars, int nfreq, double
}; };
}; };
inline void spectrum_do_free_filter(shared_envelope& env, int nfreq, double samplerate,
REALTYPE *freq1, REALTYPE *freq2)
{
jassert(env != nullptr);
for (int i = 0; i<nfreq; i++)
{
double binhz = (samplerate / 2.0) / nfreq * i;
if (binhz >= 30.0)
{
double norm = jmap<double>(binhz, 0.0, samplerate / 2.0, 0.0, 1.0);
double db = jmap<double>(env->GetInterpolatedNodeValue(pow(norm, 0.25)), 0.0, 1.0, -36.0, 12.0);
freq2[i] = freq1[i] * Decibels::decibelsToGain(db);
}
else
freq2[i] = freq1[i];
};
};
class SpectrumProcess class SpectrumProcess
{ {
public: public:
@ -430,13 +450,14 @@ public:
ProcessedStretch(REALTYPE rap_,int in_bufsize_,FFTWindow w=W_HAMMING,bool bypass_=false,REALTYPE samplerate_=44100.0f,int stereo_mode=0); ProcessedStretch(REALTYPE rap_,int in_bufsize_,FFTWindow w=W_HAMMING,bool bypass_=false,REALTYPE samplerate_=44100.0f,int stereo_mode=0);
~ProcessedStretch(); ~ProcessedStretch();
void set_parameters(ProcessParameters *ppar); void set_parameters(ProcessParameters *ppar);
void setFreeFilterEnvelope(shared_envelope env);
std::vector<SpectrumProcess> m_spectrum_processes; std::vector<SpectrumProcess> m_spectrum_processes;
void setBufferSize(int sz) override; void setBufferSize(int sz) override;
private: private:
REALTYPE get_stretch_multiplier(REALTYPE pos_percents) override; REALTYPE get_stretch_multiplier(REALTYPE pos_percents) override;
// void process_output(REALTYPE *smps,int nsmps); // void process_output(REALTYPE *smps,int nsmps);
void process_spectrum(REALTYPE *freq) override; void process_spectrum(REALTYPE *freq) override;
shared_envelope m_free_filter_envelope;
//void copy(const realvector& freq1,realvector& freq2); //void copy(const realvector& freq1,realvector& freq2);
void copy(REALTYPE* freq1, REALTYPE* freq2); void copy(REALTYPE* freq1, REALTYPE* freq2);

View File

@ -80,6 +80,16 @@ std::pair<Range<double>, Range<double>> StretchAudioSource::getFileCachedRangesN
return m_inputfile->getCachedRangesNormalized(); return m_inputfile->getCachedRangesNormalized();
} }
void StretchAudioSource::setFreeFilterEnvelope(shared_envelope env)
{
ScopedLock locker(m_cs);
m_free_filter_envelope = env;
for (int i = 0; i < m_stretchers.size(); ++i)
{
m_stretchers[i]->setFreeFilterEnvelope(env);
}
}
ValueTree StretchAudioSource::getStateTree() ValueTree StretchAudioSource::getStateTree()
{ {
ValueTree tree("stretchsourcestate"); ValueTree tree("stretchsourcestate");
@ -456,6 +466,7 @@ void StretchAudioSource::initObjects()
m_stretchers[i]->set_onset_detection_sensitivity(onsetsens); m_stretchers[i]->set_onset_detection_sensitivity(onsetsens);
m_stretchers[i]->set_parameters(&m_ppar); m_stretchers[i]->set_parameters(&m_ppar);
m_stretchers[i]->set_freezing(m_freezing); m_stretchers[i]->set_freezing(m_freezing);
m_stretchers[i]->setFreeFilterEnvelope(m_free_filter_envelope);
fill_container(m_stretchers[i]->out_buf, 0.0f); fill_container(m_stretchers[i]->out_buf, 0.0f);
m_stretchers[i]->m_spectrum_processes = m_specproc_order; m_stretchers[i]->m_spectrum_processes = m_specproc_order;
} }

View File

@ -88,6 +88,8 @@ public:
int getFFTWindowingType() { return m_fft_window_type; } int getFFTWindowingType() { return m_fft_window_type; }
std::pair<Range<double>,Range<double>> getFileCachedRangesNormalized(); std::pair<Range<double>,Range<double>> getFileCachedRangesNormalized();
void setFreeFilterEnvelope(shared_envelope env);
ValueTree getStateTree(); ValueTree getStateTree();
void setStateTree(ValueTree state); void setStateTree(ValueTree state);
void setClippingEnabled(bool b) { m_clip_output = b; } void setClippingEnabled(bool b) { m_clip_output = b; }
@ -144,6 +146,7 @@ private:
int64_t m_output_length = 0; int64_t m_output_length = 0;
bool m_clip_output = true; bool m_clip_output = true;
void initObjects(); void initObjects();
shared_envelope m_free_filter_envelope;
AudioFormatManager* m_afm = nullptr; AudioFormatManager* m_afm = nullptr;
struct struct
{ {

View File

@ -34,7 +34,15 @@ PaulstretchpluginAudioProcessorEditor::PaulstretchpluginAudioProcessorEditor(Pau
{ {
//addAndMakeVisible(&m_free_filter_component); //addAndMakeVisible(&m_free_filter_component);
m_free_filter_component.set_envelope(processor.m_free_filter_envelope); m_free_filter_component.set_envelope(processor.m_free_filter_envelope);
m_wavefilter_tab.setTabBarDepth(17); m_free_filter_component.TimeFromNormalized = [this](double x)
{
return jmap<double>(pow(x, 4.0), 0.0, 1.0, 30.0, processor.getSampleRateChecked()/2.0);
};
m_free_filter_component.ValueFromNormalized = [this](double x)
{
return jmap<double>(x, 0.0, 1.0, -36.0, 12.0);
};
m_wavefilter_tab.setTabBarDepth(20);
addAndMakeVisible(&m_perfmeter); addAndMakeVisible(&m_perfmeter);
@ -822,9 +830,9 @@ void SpectralChainEditor::paint(Graphics & g)
for (int i = 0; i < m_order.size(); ++i) for (int i = 0; i < m_order.size(); ++i)
{ {
//if (i!=m_cur_index) //if (i!=m_cur_index)
drawBox(g, i, i*box_w, 0, box_w - 30, box_h); drawBox(g, i, i*box_w, 0, box_w - 20, box_h);
if (i<m_order.size() - 1) if (i<m_order.size() - 1)
g.drawArrow(juce::Line<float>(i*box_w + (box_w - 30), box_h / 2, i*box_w + box_w, box_h / 2), 2.0f, 15.0f, 15.0f); g.drawArrow(juce::Line<float>(i*box_w + (box_w - 20), box_h / 2, i*box_w + box_w, box_h / 2), 2.0f, 12.0f, 12.0f);
} }
if (m_drag_x>=0 && m_drag_x<getWidth() && m_cur_index>=0) if (m_drag_x>=0 && m_drag_x<getWidth() && m_cur_index>=0)
drawBox(g, m_cur_index, m_drag_x, 0, box_w - 30, box_h); drawBox(g, m_cur_index, m_drag_x, 0, box_w - 30, box_h);

View File

@ -82,6 +82,8 @@ PaulstretchpluginAudioProcessor::PaulstretchpluginAudioProcessor()
m_playposinfo.timeInSeconds = 0.0; m_playposinfo.timeInSeconds = 0.0;
m_free_filter_envelope = std::make_shared<breakpoint_envelope>(); m_free_filter_envelope = std::make_shared<breakpoint_envelope>();
m_free_filter_envelope->AddNode({ 0.0,0.5 });
m_free_filter_envelope->AddNode({ 1.0,0.5 });
m_recbuffer.setSize(2, 44100); m_recbuffer.setSize(2, 44100);
m_recbuffer.clear(); m_recbuffer.clear();
@ -364,7 +366,7 @@ void PaulstretchpluginAudioProcessor::setFFTSize(double size)
void PaulstretchpluginAudioProcessor::startplay(Range<double> playrange, int numoutchans, int maxBlockSize, String& err) void PaulstretchpluginAudioProcessor::startplay(Range<double> playrange, int numoutchans, int maxBlockSize, String& err)
{ {
m_stretch_source->setPlayRange(playrange, true); m_stretch_source->setPlayRange(playrange, true);
m_stretch_source->setFreeFilterEnvelope(m_free_filter_envelope);
int bufamt = m_bufamounts[m_prebuffer_amount]; int bufamt = m_bufamounts[m_prebuffer_amount];
if (m_buffering_source != nullptr && numoutchans != m_buffering_source->getNumberOfChannels()) if (m_buffering_source != nullptr && numoutchans != m_buffering_source->getNumberOfChannels())

View File

@ -170,7 +170,7 @@ public:
bool m_show_technical_info = false; bool m_show_technical_info = false;
Range<double> m_wave_view_range; Range<double> m_wave_view_range;
int m_prepare_count = 0; int m_prepare_count = 0;
std::shared_ptr<breakpoint_envelope> m_free_filter_envelope; shared_envelope m_free_filter_envelope;
private: private:

View File

@ -576,6 +576,7 @@ private:
nodes_t m_old_nodes; nodes_t m_old_nodes;
nodes_t m_repeater_nodes; nodes_t m_repeater_nodes;
grid_t m_value_grid; grid_t m_value_grid;
JUCE_LEAK_DETECTOR(breakpoint_envelope)
}; };
template<typename F, typename... Args> template<typename F, typename... Args>
@ -586,5 +587,6 @@ inline double derivative(const F& f, double x, const Args&... func_args)
return (f(x + epsilon, func_args...) - f(x, func_args...)) / epsilon; return (f(x + epsilon, func_args...) - f(x, func_args...)) / epsilon;
} }
using shared_envelope = std::shared_ptr<breakpoint_envelope>;
#endif // JCDP_ENVELOPE_H #endif // JCDP_ENVELOPE_H