Added pause playback feature with fades for smoothing

This commit is contained in:
xenakios 2017-12-14 22:17:45 +02:00
parent 6ad663da47
commit dc86913533
4 changed files with 51 additions and 4 deletions

View File

@ -164,6 +164,11 @@ void StretchAudioSource::setLoopXFadeLength(double lenseconds)
void StretchAudioSource::getNextAudioBlock(const AudioSourceChannelInfo & bufferToFill) void StretchAudioSource::getNextAudioBlock(const AudioSourceChannelInfo & bufferToFill)
{ {
ScopedLock locker(m_cs); ScopedLock locker(m_cs);
if (m_pause_state == 2)
{
bufferToFill.buffer->clear(bufferToFill.startSample,bufferToFill.numSamples);
return;
}
if (m_stretchoutringbuf.available() > 0) if (m_stretchoutringbuf.available() > 0)
m_output_has_begun = true; m_output_has_begun = true;
bool freezing = m_freezing; bool freezing = m_freezing;
@ -341,7 +346,16 @@ void StretchAudioSource::getNextAudioBlock(const AudioSourceChannelInfo & buffer
} }
} }
//if (m_inputfile->hasEnded()) if (m_pause_state == 1)
{
bufferToFill.buffer->applyGainRamp(bufferToFill.startSample, bufferToFill.numSamples, 1.0f, 0.0f);
m_pause_state = 2;
}
if (m_pause_state == 3)
{
bufferToFill.buffer->applyGainRamp(bufferToFill.startSample, bufferToFill.numSamples, 0.0f, 1.0f);
m_pause_state = 0;
}
m_output_counter += bufferToFill.numSamples; m_output_counter += bufferToFill.numSamples;
} }
@ -538,6 +552,30 @@ void StretchAudioSource::setFFTSize(int size)
} }
} }
void StretchAudioSource::setPaused(bool b)
{
if (b == true && m_pause_state>0)
return;
if (b == false && m_pause_state == 0)
return;
ScopedLock locker(m_cs);
if (b == true && m_pause_state == 0)
{
m_pause_state = 1;
return;
}
if (b == false && m_pause_state == 2)
{
m_pause_state = 3;
return;
}
}
bool StretchAudioSource::isPaused() const
{
return m_pause_state > 0;
}
void StretchAudioSource::seekPercent(double pos) void StretchAudioSource::seekPercent(double pos)
{ {
ScopedLock locker(m_cs); ScopedLock locker(m_cs);

View File

@ -69,6 +69,9 @@ public:
void setFreezing(bool b) { m_freezing = b; } void setFreezing(bool b) { m_freezing = b; }
bool isFreezing() { return m_freezing; } bool isFreezing() { return m_freezing; }
void setPaused(bool b);
bool isPaused() const;
void seekPercent(double pos); void seekPercent(double pos);
double getOutputDurationSecondsForRange(Range<double> range, int fftsize); double getOutputDurationSecondsForRange(Range<double> range, int fftsize);
@ -122,6 +125,8 @@ private:
double m_seekpos = 0.0; double m_seekpos = 0.0;
bool m_freezing = false; bool m_freezing = false;
int m_pause_state = 0;
Range<double> m_playrange{ 0.0,1.0 }; Range<double> m_playrange{ 0.0,1.0 };
bool m_stream_end_reached = false; bool m_stream_end_reached = false;
@ -148,6 +153,7 @@ private:
int requested_fft_size = 0; int requested_fft_size = 0;
File requested_file; File requested_file;
} m_xfadetask; } m_xfadetask;
int m_pause_fade_counter = 0;
}; };
class MultiStretchAudioSource final : public PositionableAudioSource class MultiStretchAudioSource final : public PositionableAudioSource

View File

@ -116,8 +116,9 @@ PaulstretchpluginAudioProcessor::PaulstretchpluginAudioProcessor()
addParameter(new AudioParameterFloat("filter_high_0", "Filter high", 20.0f, 20000.0f, 20000.0f)); // 24 addParameter(new AudioParameterFloat("filter_high_0", "Filter high", 20.0f, 20000.0f, 20000.0f)); // 24
addParameter(new AudioParameterFloat("onsetdetect_0", "Onset detection", 0.0f, 1.0f, 0.0f)); // 25 addParameter(new AudioParameterFloat("onsetdetect_0", "Onset detection", 0.0f, 1.0f, 0.0f)); // 25
addParameter(new AudioParameterBool("capture_enabled0", "Capture", false)); // 26 addParameter(new AudioParameterBool("capture_enabled0", "Capture", false)); // 26
m_outchansparam = new AudioParameterInt("numoutchans0", "Num output channels", 2, 8, 2); m_outchansparam = new AudioParameterInt("numoutchans0", "Num output channels", 2, 8, 2); // 27
addParameter(m_outchansparam); // 27 addParameter(m_outchansparam); // 27
addParameter(new AudioParameterBool("pause_enabled0", "Pause", false)); // 28
startTimer(1, 50); startTimer(1, 50);
} }
@ -253,7 +254,7 @@ void PaulstretchpluginAudioProcessor::prepareToPlay(double sampleRate, int sampl
{ {
setFFTSize(*getFloatParameter(cpi_fftsize)); setFFTSize(*getFloatParameter(cpi_fftsize));
m_stretch_source->setProcessParameters(&m_ppar); m_stretch_source->setProcessParameters(&m_ppar);
m_stretch_source->setFFTWindowingType(1);
String err; String err;
startplay({ *getFloatParameter(cpi_soundstart),*getFloatParameter(cpi_soundend) }, startplay({ *getFloatParameter(cpi_soundstart),*getFloatParameter(cpi_soundend) },
numoutchans, samplesPerBlock, err); numoutchans, samplesPerBlock, err);
@ -372,6 +373,7 @@ void PaulstretchpluginAudioProcessor::processBlock (AudioSampleBuffer& buffer, M
t1 = t0 + 0.001; t1 = t0 + 0.001;
m_stretch_source->setPlayRange({ t0,t1 }, true); m_stretch_source->setPlayRange({ t0,t1 }, true);
m_stretch_source->setFreezing(getParameter(cpi_freeze)); m_stretch_source->setFreezing(getParameter(cpi_freeze));
m_stretch_source->setPaused(getParameter(cpi_pause_enabled));
m_stretch_source->setProcessParameters(&m_ppar); m_stretch_source->setProcessParameters(&m_ppar);
AudioSourceChannelInfo aif(buffer); AudioSourceChannelInfo aif(buffer);

View File

@ -43,6 +43,7 @@ const int cpi_filter_high = 24;
const int cpi_onsetdetection = 25; const int cpi_onsetdetection = 25;
const int cpi_capture_enabled = 26; const int cpi_capture_enabled = 26;
const int cpi_num_outchans = 27; const int cpi_num_outchans = 27;
const int cpi_pause_enabled = 28;
class PaulstretchpluginAudioProcessor : public AudioProcessor, public MultiTimer class PaulstretchpluginAudioProcessor : public AudioProcessor, public MultiTimer
{ {