Use CriticalSection in audio source. Add bool argument for seek to get immediate seeks. etc
This commit is contained in:
parent
1f8f57666d
commit
b8e408a73e
@ -36,8 +36,6 @@ inline double ramp(int64_t pos, int64_t totallen, int64_t rampinlen, int64_t ram
|
|||||||
return 1.0;
|
return 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
using LockGuard = std::lock_guard<std::recursive_mutex>;
|
|
||||||
|
|
||||||
class AInputS final : public InputS
|
class AInputS final : public InputS
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -53,7 +51,7 @@ public:
|
|||||||
|
|
||||||
void setAudioBuffer(AudioBuffer<float>* buf, int samplerate, int len)
|
void setAudioBuffer(AudioBuffer<float>* buf, int samplerate, int len)
|
||||||
{
|
{
|
||||||
LockGuard locker(m_mutex);
|
ScopedLock locker(m_mutex);
|
||||||
m_afreader = nullptr;
|
m_afreader = nullptr;
|
||||||
m_using_memory_buffer = true;
|
m_using_memory_buffer = true;
|
||||||
m_readbuf = *buf;
|
m_readbuf = *buf;
|
||||||
@ -64,7 +62,7 @@ public:
|
|||||||
m_loop_enabled = true;
|
m_loop_enabled = true;
|
||||||
m_crossfadebuf.setSize(info.nchannels, m_crossfadebuf.getNumSamples());
|
m_crossfadebuf.setSize(info.nchannels, m_crossfadebuf.getNumSamples());
|
||||||
m_cached_file_range = { 0,len };
|
m_cached_file_range = { 0,len };
|
||||||
seek(m_activerange.getStart());
|
seek(m_activerange.getStart(), true);
|
||||||
updateXFadeCache();
|
updateXFadeCache();
|
||||||
}
|
}
|
||||||
virtual AudioBuffer<float>* getAudioBuffer() override
|
virtual AudioBuffer<float>* getAudioBuffer() override
|
||||||
@ -79,7 +77,7 @@ public:
|
|||||||
AudioFormatReader* reader = m_manager->createReaderFor(file);
|
AudioFormatReader* reader = m_manager->createReaderFor(file);
|
||||||
if (reader)
|
if (reader)
|
||||||
{
|
{
|
||||||
LockGuard locker(m_mutex);
|
ScopedLock locker(m_mutex);
|
||||||
m_using_memory_buffer = false;
|
m_using_memory_buffer = false;
|
||||||
m_afreader = std::unique_ptr<AudioFormatReader>(reader);
|
m_afreader = std::unique_ptr<AudioFormatReader>(reader);
|
||||||
if (m_activerange.isEmpty())
|
if (m_activerange.isEmpty())
|
||||||
@ -109,7 +107,7 @@ public:
|
|||||||
}
|
}
|
||||||
int readNextBlock(AudioBuffer<float>& abuf, int nsmps, int numchans) override
|
int readNextBlock(AudioBuffer<float>& abuf, int nsmps, int numchans) override
|
||||||
{
|
{
|
||||||
LockGuard locker(m_mutex);
|
ScopedLock locker(m_mutex);
|
||||||
if (m_afreader == nullptr && m_using_memory_buffer == false)
|
if (m_afreader == nullptr && m_using_memory_buffer == false)
|
||||||
{
|
{
|
||||||
jassert(false);
|
jassert(false);
|
||||||
@ -281,11 +279,14 @@ public:
|
|||||||
updateXFadeCache();
|
updateXFadeCache();
|
||||||
//m_cached_crossfade_range = Range<int64_t>();
|
//m_cached_crossfade_range = Range<int64_t>();
|
||||||
}
|
}
|
||||||
void seek(double pos) override //0=start,1.0=end
|
void seek(double pos, bool immediate) override //0=start,1.0=end
|
||||||
{
|
{
|
||||||
//seekImpl(pos);
|
ScopedLock locker(m_mutex);
|
||||||
|
if (immediate == true)
|
||||||
LockGuard locker(m_mutex);
|
{
|
||||||
|
seekImpl(pos);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (m_seekfade.state == 0)
|
if (m_seekfade.state == 0)
|
||||||
{
|
{
|
||||||
m_seekfade.state = 1;
|
m_seekfade.state = 1;
|
||||||
@ -332,7 +333,7 @@ public:
|
|||||||
}
|
}
|
||||||
void setActiveRange(Range<double> rng) override
|
void setActiveRange(Range<double> rng) override
|
||||||
{
|
{
|
||||||
LockGuard locker(m_mutex);
|
ScopedLock locker(m_mutex);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
if (rng.contains(getCurrentPositionPercent()))
|
if (rng.contains(getCurrentPositionPercent()))
|
||||||
@ -395,7 +396,7 @@ private:
|
|||||||
int64_t m_loopcount = 0;
|
int64_t m_loopcount = 0;
|
||||||
bool m_using_memory_buffer = true;
|
bool m_using_memory_buffer = true;
|
||||||
AudioFormatManager* m_manager = nullptr;
|
AudioFormatManager* m_manager = nullptr;
|
||||||
std::recursive_mutex m_mutex;
|
CriticalSection m_mutex;
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
int state = 0; // 0 inactive, 1 seek requested, 2 fade out, 3 fade in
|
int state = 0; // 0 inactive, 1 seek requested, 2 fade out, 3 fade in
|
||||||
|
@ -50,7 +50,7 @@ public:
|
|||||||
nsmps-=readsize;
|
nsmps-=readsize;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
virtual void seek(double pos)=0;//0=start,1.0=end
|
virtual void seek(double pos, bool immediate)=0;//0=start,1.0=end
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
int64_t nsamples=0;
|
int64_t nsamples=0;
|
||||||
|
@ -505,7 +505,7 @@ void StretchAudioSource::initObjects()
|
|||||||
ScopedLock locker(m_cs);
|
ScopedLock locker(m_cs);
|
||||||
m_inputfile->setActiveRange(m_playrange);
|
m_inputfile->setActiveRange(m_playrange);
|
||||||
if (m_inputfile->getActiveRange().contains(m_inputfile->getCurrentPositionPercent())==false)
|
if (m_inputfile->getActiveRange().contains(m_inputfile->getCurrentPositionPercent())==false)
|
||||||
m_inputfile->seek(m_playrange.getStart());
|
m_inputfile->seek(m_playrange.getStart(), true);
|
||||||
|
|
||||||
m_firstbuffer = true;
|
m_firstbuffer = true;
|
||||||
if (m_stretchoutringbuf.getSize() < m_num_outchans*m_process_fftsize)
|
if (m_stretchoutringbuf.getSize() < m_num_outchans*m_process_fftsize)
|
||||||
@ -695,7 +695,7 @@ void StretchAudioSource::seekPercent(double pos)
|
|||||||
m_seekpos = pos;
|
m_seekpos = pos;
|
||||||
//m_firstbuffer = true;
|
//m_firstbuffer = true;
|
||||||
//m_resampler->Reset();
|
//m_resampler->Reset();
|
||||||
m_inputfile->seek(pos);
|
m_inputfile->seek(pos, true);
|
||||||
++m_param_change_count;
|
++m_param_change_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -542,6 +542,7 @@ void PaulstretchpluginAudioProcessor::prepareToPlay(double sampleRate, int sampl
|
|||||||
m_curmaxblocksize = samplesPerBlock;
|
m_curmaxblocksize = samplesPerBlock;
|
||||||
m_input_buffer.setSize(getMainBusNumInputChannels(), samplesPerBlock);
|
m_input_buffer.setSize(getMainBusNumInputChannels(), samplesPerBlock);
|
||||||
*getBoolParameter(cpi_rewind) = false;
|
*getBoolParameter(cpi_rewind) = false;
|
||||||
|
m_lastrewind = false;
|
||||||
int numoutchans = *m_outchansparam;
|
int numoutchans = *m_outchansparam;
|
||||||
if (numoutchans != m_cur_num_out_chans)
|
if (numoutchans != m_cur_num_out_chans)
|
||||||
m_prebuffering_inited = false;
|
m_prebuffering_inited = false;
|
||||||
@ -693,7 +694,7 @@ void PaulstretchpluginAudioProcessor::processBlock (AudioSampleBuffer& buffer, M
|
|||||||
if (m_stretch_source->isLoopEnabled() != *getBoolParameter(cpi_looping_enabled))
|
if (m_stretch_source->isLoopEnabled() != *getBoolParameter(cpi_looping_enabled))
|
||||||
m_stretch_source->setLoopingEnabled(*getBoolParameter(cpi_looping_enabled));
|
m_stretch_source->setLoopingEnabled(*getBoolParameter(cpi_looping_enabled));
|
||||||
bool rew = *getBoolParameter(cpi_rewind);
|
bool rew = *getBoolParameter(cpi_rewind);
|
||||||
if (rew !=m_lastrewind)
|
if (rew != m_lastrewind)
|
||||||
{
|
{
|
||||||
if (rew == true)
|
if (rew == true)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user