Calculate smoothed prebuffering available amount in the processor

This commit is contained in:
xenakios 2018-05-01 18:22:21 +03:00
parent d42971e09f
commit 60293c6a84
5 changed files with 19 additions and 12 deletions

View File

@ -359,14 +359,20 @@ public:
} }
void setSlope(double x, double sr) void setSlope(double x, double sr)
{ {
m_slope = x; if (x != m_slope || sr != m_sr)
double srCompensate = srCompensate = sr / 100.0; {
double compensated_a = powf(x, (1.0 / srCompensate)); m_slope = x;
m_a = compensated_a; m_sr = sr;
m_b = 1.0 - m_a; double srCompensate = srCompensate = sr / 100.0;
double compensated_a = powf(x, (1.0 / srCompensate));
m_a = compensated_a;
m_b = 1.0 - m_a;
}
} }
double slope() const { return m_slope; } double getSlope() const { return m_slope; }
double getSamplerate() const { return m_sr; }
private: private:
double m_a, m_b, m_z; double m_a, m_b, m_z;
double m_slope; double m_slope;
double m_sr = 0.0;
}; };

View File

@ -1277,7 +1277,6 @@ PerfMeterComponent::PerfMeterComponent(PaulstretchpluginAudioProcessor * p)
m_gradient.addColour(0.0, Colours::red); m_gradient.addColour(0.0, Colours::red);
m_gradient.addColour(0.25, Colours::yellow); m_gradient.addColour(0.25, Colours::yellow);
m_gradient.addColour(1.0, Colours::green); m_gradient.addColour(1.0, Colours::green);
m_smoother.setSlope(0.9, 10.0);
} }
void PerfMeterComponent::paint(Graphics & g) void PerfMeterComponent::paint(Graphics & g)
@ -1285,7 +1284,7 @@ void PerfMeterComponent::paint(Graphics & g)
m_gradient.point1 = {0.0f,0.0f}; m_gradient.point1 = {0.0f,0.0f};
m_gradient.point2 = {(float)getWidth(),0.0f}; m_gradient.point2 = {(float)getWidth(),0.0f};
g.fillAll(Colours::grey); g.fillAll(Colours::grey);
double amt = m_smoother.process(m_proc->getPreBufferingPercent()); double amt = m_proc->getPreBufferingPercent();
g.setColour(Colours::green); g.setColour(Colours::green);
int w = amt * getWidth(); int w = amt * getWidth();
//g.setGradientFill(m_gradient); //g.setGradientFill(m_gradient);

View File

@ -113,7 +113,6 @@ public:
PaulstretchpluginAudioProcessor* m_proc = nullptr; PaulstretchpluginAudioProcessor* m_proc = nullptr;
private: private:
ColourGradient m_gradient; ColourGradient m_gradient;
SignalSmoother m_smoother;
}; };
class MyThumbCache : public AudioThumbnailCache class MyThumbCache : public AudioThumbnailCache

View File

@ -639,7 +639,9 @@ void PaulstretchpluginAudioProcessor::processBlock (AudioSampleBuffer& buffer, M
double srtemp = getSampleRate(); double srtemp = getSampleRate();
if (srtemp != m_cur_sr) if (srtemp != m_cur_sr)
m_cur_sr = srtemp; m_cur_sr = srtemp;
const int totalNumInputChannels = getTotalNumInputChannels(); m_prebufsmoother.setSlope(0.9, srtemp / buffer.getNumSamples());
m_smoothed_prebuffer_ready = m_prebufsmoother.process(m_buffering_source->getPercentReady());
const int totalNumInputChannels = getTotalNumInputChannels();
const int totalNumOutputChannels = getTotalNumOutputChannels(); const int totalNumOutputChannels = getTotalNumOutputChannels();
for (int i = 0; i < totalNumInputChannels; ++i) for (int i = 0; i < totalNumInputChannels; ++i)
m_input_buffer.copyFrom(i, 0, buffer, i, 0, buffer.getNumSamples()); m_input_buffer.copyFrom(i, 0, buffer, i, 0, buffer.getNumSamples());
@ -822,7 +824,7 @@ double PaulstretchpluginAudioProcessor::getPreBufferingPercent()
{ {
if (m_buffering_source==nullptr) if (m_buffering_source==nullptr)
return 0.0; return 0.0;
return m_buffering_source->getPercentReady(); return m_smoothed_prebuffer_ready;
} }
void PaulstretchpluginAudioProcessor::timerCallback(int id) void PaulstretchpluginAudioProcessor::timerCallback(int id)

View File

@ -235,7 +235,8 @@ private:
std::unique_ptr<MyBufferingAudioSource> m_buffering_source; std::unique_ptr<MyBufferingAudioSource> m_buffering_source;
int m_prebuffer_amount = 1; int m_prebuffer_amount = 1;
bool m_recreate_buffering_source = true; bool m_recreate_buffering_source = true;
double m_smoothed_prebuffer_ready = 0.0;
SignalSmoother m_prebufsmoother;
int m_fft_size_to_use = 1024; int m_fft_size_to_use = 1024;
double m_last_outpos_pos = 0.0; double m_last_outpos_pos = 0.0;
double m_last_in_pos = 0.0; double m_last_in_pos = 0.0;