Added sound play range parameters. Initial work on audio input capture.

This commit is contained in:
xenakios 2017-11-13 21:21:30 +02:00
parent d9e9107ed4
commit c32e64a570
5 changed files with 57 additions and 5 deletions

View File

@ -451,6 +451,8 @@ void StretchAudioSource::setOnsetDetection(double x)
void StretchAudioSource::setPlayRange(Range<double> playrange, bool isloop) void StretchAudioSource::setPlayRange(Range<double> playrange, bool isloop)
{ {
std::lock_guard<std::mutex> locker(m_mutex); std::lock_guard<std::mutex> locker(m_mutex);
if (m_playrange.isEmpty()==false && playrange == m_playrange)
return;
if (playrange.isEmpty()) if (playrange.isEmpty())
m_playrange = { 0.0,1.0 }; m_playrange = { 0.0,1.0 };
else else

View File

@ -23,7 +23,10 @@ PaulstretchpluginAudioProcessorEditor::PaulstretchpluginAudioProcessorEditor (Pa
m_parcomps.back()->setBounds(1, i * 25, 598, 24); m_parcomps.back()->setBounds(1, i * 25, 598, 24);
addAndMakeVisible(m_parcomps.back().get()); addAndMakeVisible(m_parcomps.back().get());
} }
setSize (600, pars.size()*25); addAndMakeVisible(&m_rec_enable);
m_rec_enable.setButtonText("Capture");
m_rec_enable.addListener(this);
setSize (600, pars.size()*25+30);
startTimer(1, 100); startTimer(1, 100);
} }
@ -31,6 +34,14 @@ PaulstretchpluginAudioProcessorEditor::~PaulstretchpluginAudioProcessorEditor()
{ {
} }
void PaulstretchpluginAudioProcessorEditor::buttonClicked(Button * but)
{
if (but == &m_rec_enable)
{
processor.setRecordingEnabled(but->getToggleState());
}
}
//============================================================================== //==============================================================================
void PaulstretchpluginAudioProcessorEditor::paint (Graphics& g) void PaulstretchpluginAudioProcessorEditor::paint (Graphics& g)
{ {
@ -39,8 +50,8 @@ void PaulstretchpluginAudioProcessorEditor::paint (Graphics& g)
void PaulstretchpluginAudioProcessorEditor::resized() void PaulstretchpluginAudioProcessorEditor::resized()
{ {
// This is generally where you'll want to lay out the positions of any m_rec_enable.setBounds(1, getHeight() - 25, 10, 24);
// subcomponents in your editor.. m_rec_enable.changeWidthToFitText();
} }
void PaulstretchpluginAudioProcessorEditor::timerCallback(int id) void PaulstretchpluginAudioProcessorEditor::timerCallback(int id)

View File

@ -71,12 +71,12 @@ private:
}; };
class PaulstretchpluginAudioProcessorEditor : public AudioProcessorEditor, class PaulstretchpluginAudioProcessorEditor : public AudioProcessorEditor,
public MultiTimer public MultiTimer, public Button::Listener
{ {
public: public:
PaulstretchpluginAudioProcessorEditor (PaulstretchpluginAudioProcessor&); PaulstretchpluginAudioProcessorEditor (PaulstretchpluginAudioProcessor&);
~PaulstretchpluginAudioProcessorEditor(); ~PaulstretchpluginAudioProcessorEditor();
void buttonClicked(Button* but) override;
//============================================================================== //==============================================================================
void paint (Graphics&) override; void paint (Graphics&) override;
void resized() override; void resized() override;
@ -84,5 +84,6 @@ public:
private: private:
PaulstretchpluginAudioProcessor& processor; PaulstretchpluginAudioProcessor& processor;
std::vector<std::shared_ptr<ParameterComponent>> m_parcomps; std::vector<std::shared_ptr<ParameterComponent>> m_parcomps;
ToggleButton m_rec_enable;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PaulstretchpluginAudioProcessorEditor) JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PaulstretchpluginAudioProcessorEditor)
}; };

View File

@ -36,6 +36,8 @@ PaulstretchpluginAudioProcessor::PaulstretchpluginAudioProcessor()
addParameter(new AudioParameterFloat("fftsize0", "FFT size", 0.0f, 1.0f, 0.6f)); addParameter(new AudioParameterFloat("fftsize0", "FFT size", 0.0f, 1.0f, 0.6f));
addParameter(new AudioParameterFloat("pitchshift0", "Pitch shift", -24.0f, 24.0f, 0.0f)); addParameter(new AudioParameterFloat("pitchshift0", "Pitch shift", -24.0f, 24.0f, 0.0f));
addParameter(new AudioParameterFloat("freqshift0", "Frequency shift", -1000.0f, 1000.0f, 0.0f)); addParameter(new AudioParameterFloat("freqshift0", "Frequency shift", -1000.0f, 1000.0f, 0.0f));
addParameter(new AudioParameterFloat("playrange_start0", "Sound start", 0.0f, 1.0f, 0.0f));
addParameter(new AudioParameterFloat("playrange_end0", "Sound end", 0.0f, 1.0f, 1.0f));
} }
PaulstretchpluginAudioProcessor::~PaulstretchpluginAudioProcessor() PaulstretchpluginAudioProcessor::~PaulstretchpluginAudioProcessor()
@ -163,10 +165,27 @@ void PaulstretchpluginAudioProcessor::processBlock (AudioSampleBuffer& buffer, M
buffer.clear (i, 0, buffer.getNumSamples()); buffer.clear (i, 0, buffer.getNumSamples());
if (m_ready_to_play == false) if (m_ready_to_play == false)
return; return;
if (m_is_recording == true)
{
m_rec_pos += buffer.getNumSamples();
if (m_rec_pos >= m_max_reclen * getSampleRate())
{
m_is_recording = false;
// Set record buffer as strech source...
}
return;
}
m_control->getStretchAudioSource()->setRate(*getFloatParameter(1)); m_control->getStretchAudioSource()->setRate(*getFloatParameter(1));
//m_control->setFFTSize(*getFloatParameter(2)); //m_control->setFFTSize(*getFloatParameter(2));
m_control->ppar.pitch_shift.cents = *getFloatParameter(3) * 100.0; m_control->ppar.pitch_shift.cents = *getFloatParameter(3) * 100.0;
m_control->ppar.freq_shift.Hz = *getFloatParameter(4); m_control->ppar.freq_shift.Hz = *getFloatParameter(4);
double t0 = *getFloatParameter(5);
double t1 = *getFloatParameter(6);
if (t0 > t1)
std::swap(t0, t1);
if (t1 - t0 < 0.001)
t1 = t0 + 0.001;
m_control->getStretchAudioSource()->setPlayRange({ t0,t1 }, true);
m_control->update_process_parameters(); m_control->update_process_parameters();
m_control->processAudio(buffer); m_control->processAudio(buffer);
} }
@ -196,6 +215,20 @@ void PaulstretchpluginAudioProcessor::setStateInformation (const void* data, int
// whose contents will have been created by the getStateInformation() call. // whose contents will have been created by the getStateInformation() call.
} }
void PaulstretchpluginAudioProcessor::setRecordingEnabled(bool b)
{
if (b == true)
{
m_is_recording = true;
m_recbuffer.setSize(2, m_max_reclen*getSampleRate());
m_rec_pos = 0;
}
else
{
m_is_recording = false;
}
}
//============================================================================== //==============================================================================
// This creates new instances of the plugin.. // This creates new instances of the plugin..
AudioProcessor* JUCE_CALLTYPE createPluginFilter() AudioProcessor* JUCE_CALLTYPE createPluginFilter()

View File

@ -59,10 +59,15 @@ public:
{ {
return dynamic_cast<AudioParameterFloat*>(getParameters()[index]); return dynamic_cast<AudioParameterFloat*>(getParameters()[index]);
} }
void setRecordingEnabled(bool b);
private: private:
std::unique_ptr<Control> m_control; std::unique_ptr<Control> m_control;
std::unique_ptr<AudioFormatManager> m_afm; std::unique_ptr<AudioFormatManager> m_afm;
bool m_ready_to_play = false; bool m_ready_to_play = false;
AudioBuffer<float> m_recbuffer;
double m_max_reclen = 10.0;
bool m_is_recording = true;
int m_rec_pos = 0;
//============================================================================== //==============================================================================
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PaulstretchpluginAudioProcessor) JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PaulstretchpluginAudioProcessor)
}; };