Added pause playback feature with fades for smoothing
This commit is contained in:
parent
6ad663da47
commit
dc86913533
@ -164,6 +164,11 @@ void StretchAudioSource::setLoopXFadeLength(double lenseconds)
|
||||
void StretchAudioSource::getNextAudioBlock(const AudioSourceChannelInfo & bufferToFill)
|
||||
{
|
||||
ScopedLock locker(m_cs);
|
||||
if (m_pause_state == 2)
|
||||
{
|
||||
bufferToFill.buffer->clear(bufferToFill.startSample,bufferToFill.numSamples);
|
||||
return;
|
||||
}
|
||||
if (m_stretchoutringbuf.available() > 0)
|
||||
m_output_has_begun = true;
|
||||
bool freezing = m_freezing;
|
||||
@ -341,8 +346,17 @@ void StretchAudioSource::getNextAudioBlock(const AudioSourceChannelInfo & buffer
|
||||
}
|
||||
|
||||
}
|
||||
//if (m_inputfile->hasEnded())
|
||||
m_output_counter += bufferToFill.numSamples;
|
||||
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;
|
||||
}
|
||||
|
||||
void StretchAudioSource::setNextReadPosition(int64 /*newPosition*/)
|
||||
@ -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)
|
||||
{
|
||||
ScopedLock locker(m_cs);
|
||||
|
@ -69,6 +69,9 @@ public:
|
||||
void setFreezing(bool b) { m_freezing = b; }
|
||||
bool isFreezing() { return m_freezing; }
|
||||
|
||||
void setPaused(bool b);
|
||||
bool isPaused() const;
|
||||
|
||||
void seekPercent(double pos);
|
||||
|
||||
double getOutputDurationSecondsForRange(Range<double> range, int fftsize);
|
||||
@ -122,6 +125,8 @@ private:
|
||||
double m_seekpos = 0.0;
|
||||
|
||||
bool m_freezing = false;
|
||||
|
||||
int m_pause_state = 0;
|
||||
Range<double> m_playrange{ 0.0,1.0 };
|
||||
|
||||
bool m_stream_end_reached = false;
|
||||
@ -148,6 +153,7 @@ private:
|
||||
int requested_fft_size = 0;
|
||||
File requested_file;
|
||||
} m_xfadetask;
|
||||
int m_pause_fade_counter = 0;
|
||||
};
|
||||
|
||||
class MultiStretchAudioSource final : public PositionableAudioSource
|
||||
|
@ -116,8 +116,9 @@ PaulstretchpluginAudioProcessor::PaulstretchpluginAudioProcessor()
|
||||
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 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(new AudioParameterBool("pause_enabled0", "Pause", false)); // 28
|
||||
startTimer(1, 50);
|
||||
}
|
||||
|
||||
@ -253,7 +254,7 @@ void PaulstretchpluginAudioProcessor::prepareToPlay(double sampleRate, int sampl
|
||||
{
|
||||
setFFTSize(*getFloatParameter(cpi_fftsize));
|
||||
m_stretch_source->setProcessParameters(&m_ppar);
|
||||
|
||||
m_stretch_source->setFFTWindowingType(1);
|
||||
String err;
|
||||
startplay({ *getFloatParameter(cpi_soundstart),*getFloatParameter(cpi_soundend) },
|
||||
numoutchans, samplesPerBlock, err);
|
||||
@ -372,6 +373,7 @@ void PaulstretchpluginAudioProcessor::processBlock (AudioSampleBuffer& buffer, M
|
||||
t1 = t0 + 0.001;
|
||||
m_stretch_source->setPlayRange({ t0,t1 }, true);
|
||||
m_stretch_source->setFreezing(getParameter(cpi_freeze));
|
||||
m_stretch_source->setPaused(getParameter(cpi_pause_enabled));
|
||||
m_stretch_source->setProcessParameters(&m_ppar);
|
||||
|
||||
AudioSourceChannelInfo aif(buffer);
|
||||
|
@ -43,6 +43,7 @@ const int cpi_filter_high = 24;
|
||||
const int cpi_onsetdetection = 25;
|
||||
const int cpi_capture_enabled = 26;
|
||||
const int cpi_num_outchans = 27;
|
||||
const int cpi_pause_enabled = 28;
|
||||
|
||||
class PaulstretchpluginAudioProcessor : public AudioProcessor, public MultiTimer
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user