Add method to get sanitized samplerate as getSampleRate might return 0.0 when called from outside audio processing method. Comment out Spectral visualizer instance in editor.

This commit is contained in:
xenakios 2017-12-17 18:16:39 +02:00
parent 9e7b37afba
commit 7ea18cc805
4 changed files with 25 additions and 11 deletions

View File

@ -117,7 +117,7 @@ void PaulstretchpluginAudioProcessorEditor::timerCallback(int id)
auto bufptr = processor.getStretchSource()->getSourceAudioBuffer();
if (bufptr!=nullptr)
m_wavecomponent.setAudioBuffer(bufptr,
processor.getSampleRate(), bufptr->getNumSamples());
processor.getSampleRateChecked(), bufptr->getNumSamples());
}
m_wavecomponent.setTimeSelection(processor.getTimeSelection());

View File

@ -324,7 +324,7 @@ public:
private:
PaulstretchpluginAudioProcessor& processor;
std::vector<std::shared_ptr<ParameterComponent>> m_parcomps;
SpectralVisualizer m_specvis;
//SpectralVisualizer m_specvis;
TextButton m_import_button;
Label m_info_label;

View File

@ -189,7 +189,8 @@ bool PaulstretchpluginAudioProcessor::isMidiEffect() const
double PaulstretchpluginAudioProcessor::getTailLengthSeconds() const
{
return (double)m_bufamounts[m_prebuffer_amount]/getSampleRate();
return 0.0;
//return (double)m_bufamounts[m_prebuffer_amount]/getSampleRate();
}
int PaulstretchpluginAudioProcessor::getNumPrograms()
@ -248,12 +249,19 @@ void PaulstretchpluginAudioProcessor::startplay(Range<double> playrange, int num
m_stretch_source->setProcessParameters(&m_ppar);
m_last_outpos_pos = 0.0;
m_last_in_pos = playrange.getStart()*m_stretch_source->getInfileLengthSeconds();
m_buffering_source->prepareToPlay(maxBlockSize, getSampleRate());
};
m_buffering_source->prepareToPlay(maxBlockSize, getSampleRateChecked());
}
double PaulstretchpluginAudioProcessor::getSampleRateChecked()
{
if (m_cur_sr < 1.0)
return 44100.0;
return m_cur_sr;
}
void PaulstretchpluginAudioProcessor::prepareToPlay(double sampleRate, int samplesPerBlock)
{
ScopedLock locker(m_cs);
m_cur_sr = sampleRate;
m_curmaxblocksize = samplesPerBlock;
int numoutchans = *m_outchansparam;
if (numoutchans != m_cur_num_out_chans)
@ -262,9 +270,9 @@ void PaulstretchpluginAudioProcessor::prepareToPlay(double sampleRate, int sampl
{
int len = jlimit(100,m_recbuffer.getNumSamples(), m_rec_pos);
m_stretch_source->setAudioBufferAsInputSource(&m_recbuffer,
getSampleRate(),
getSampleRateChecked(),
len);
callGUI(this,[this,len](auto ed) { ed->setAudioBuffer(&m_recbuffer, getSampleRate(), len); },false);
callGUI(this,[this,len](auto ed) { ed->setAudioBuffer(&m_recbuffer, getSampleRateChecked(), len); },false);
}
if (m_ready_to_play == false)
{
@ -332,6 +340,9 @@ void PaulstretchpluginAudioProcessor::processBlock (AudioSampleBuffer& buffer, M
{
ScopedLock locker(m_cs);
ScopedNoDenormals noDenormals;
double srtemp = getSampleRate();
if (srtemp != m_cur_sr)
m_cur_sr = srtemp;
const int totalNumInputChannels = getTotalNumInputChannels();
const int totalNumOutputChannels = getTotalNumOutputChannels();
@ -476,17 +487,17 @@ void PaulstretchpluginAudioProcessor::setStateInformation (const void* data, int
void PaulstretchpluginAudioProcessor::setRecordingEnabled(bool b)
{
ScopedLock locker(m_cs);
int lenbufframes = getSampleRate()*m_max_reclen;
int lenbufframes = getSampleRateChecked()*m_max_reclen;
if (b == true)
{
m_using_memory_buffer = true;
m_current_file = File();
m_recbuffer.setSize(2, m_max_reclen*getSampleRate()+4096,false,false,true);
m_recbuffer.setSize(2, m_max_reclen*getSampleRateChecked()+4096,false,false,true);
m_recbuffer.clear();
m_rec_pos = 0;
callGUI(this,[this,lenbufframes](PaulstretchpluginAudioProcessorEditor* ed)
{
ed->beginAddingAudioBlocks(2, getSampleRate(), lenbufframes);
ed->beginAddingAudioBlocks(2, getSampleRateChecked(), lenbufframes);
},false);
m_is_recording = true;
}
@ -583,7 +594,7 @@ void PaulstretchpluginAudioProcessor::timerCallback(int id)
void PaulstretchpluginAudioProcessor::finishRecording(int lenrecording)
{
m_is_recording = false;
m_stretch_source->setAudioBufferAsInputSource(&m_recbuffer, getSampleRate(), lenrecording);
m_stretch_source->setAudioBufferAsInputSource(&m_recbuffer, getSampleRateChecked(), lenrecording);
m_stretch_source->setPlayRange({ *getFloatParameter(cpi_soundstart),*getFloatParameter(cpi_soundend) }, true);
auto ed = dynamic_cast<PaulstretchpluginAudioProcessorEditor*>(getActiveEditor());
if (ed)

View File

@ -98,6 +98,7 @@ public:
StretchAudioSource* getStretchSource() { return m_stretch_source.get(); }
double getPreBufferingPercent();
void timerCallback(int id) override;
double getSampleRateChecked();
private:
@ -130,6 +131,8 @@ private:
SharedResourcePointer<MyThumbCache> m_thumbcache;
AudioParameterInt* m_outchansparam = nullptr;
int m_curmaxblocksize = 0;
double m_cur_sr = 0.0;
//==============================================================================
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PaulstretchpluginAudioProcessor)
};