Clean up. Removed the MultiStretchAudioSource, hopefully it doesn't need to be restored later...
This commit is contained in:
parent
f414f19e01
commit
42061670a8
@ -636,296 +636,3 @@ bool StretchAudioSource::hasReachedEnd()
|
||||
//return m_output_counter>=m_process_fftsize*2;
|
||||
return m_output_silence_counter>=65536;
|
||||
}
|
||||
|
||||
std::pair<Range<double>, Range<double>> MultiStretchAudioSource::getFileCachedRangesNormalized()
|
||||
{
|
||||
return getActiveStretchSource()->getFileCachedRangesNormalized();
|
||||
}
|
||||
|
||||
void MultiStretchAudioSource::setAudioBufferAsInputSource(AudioBuffer<float>* buf, int sr, int len)
|
||||
{
|
||||
m_stretchsources[0]->setAudioBufferAsInputSource(buf, sr, len);
|
||||
m_stretchsources[1]->setAudioBufferAsInputSource(buf, sr, len);
|
||||
}
|
||||
|
||||
StretchAudioSource * MultiStretchAudioSource::getActiveStretchSource() const
|
||||
{
|
||||
return m_stretchsources[0].get();
|
||||
}
|
||||
|
||||
void MultiStretchAudioSource::switchActiveSource()
|
||||
{
|
||||
std::swap(m_stretchsources[0], m_stretchsources[1]);
|
||||
m_is_in_switch = true;
|
||||
m_xfadegain.reset(m_samplerate, 2.0);
|
||||
m_xfadegain.setValue(1.0);
|
||||
}
|
||||
|
||||
MultiStretchAudioSource::MultiStretchAudioSource(int initialnumoutchans, AudioFormatManager* afm)
|
||||
: m_afm(afm)
|
||||
{
|
||||
m_stretchsources.resize(2);
|
||||
m_stretchsources[0] = std::make_shared<StretchAudioSource>(initialnumoutchans,m_afm);
|
||||
m_stretchsources[1] = std::make_shared<StretchAudioSource>(initialnumoutchans,m_afm);
|
||||
m_numoutchans = initialnumoutchans;
|
||||
m_processbuffers[0].setSize(m_numoutchans, 4096);
|
||||
m_processbuffers[1].setSize(m_numoutchans, 4096);
|
||||
}
|
||||
|
||||
MultiStretchAudioSource::~MultiStretchAudioSource()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void MultiStretchAudioSource::prepareToPlay(int samplesPerBlockExpected, double sampleRate)
|
||||
{
|
||||
m_is_in_switch = false;
|
||||
m_is_playing = true;
|
||||
m_blocksize = samplesPerBlockExpected;
|
||||
m_samplerate = sampleRate;
|
||||
if (m_processbuffers[0].getNumSamples() < samplesPerBlockExpected)
|
||||
{
|
||||
m_processbuffers[0].setSize(m_numoutchans, samplesPerBlockExpected);
|
||||
m_processbuffers[1].setSize(m_numoutchans, samplesPerBlockExpected);
|
||||
}
|
||||
getActiveStretchSource()->prepareToPlay(samplesPerBlockExpected, sampleRate);
|
||||
|
||||
}
|
||||
|
||||
void MultiStretchAudioSource::releaseResources()
|
||||
{
|
||||
m_is_playing = false;
|
||||
getActiveStretchSource()->releaseResources();
|
||||
}
|
||||
|
||||
void MultiStretchAudioSource::getNextAudioBlock(const AudioSourceChannelInfo & bufferToFill)
|
||||
{
|
||||
std::lock_guard<std::mutex> locker(m_mutex);
|
||||
m_blocksize = bufferToFill.numSamples;
|
||||
if (m_is_in_switch == false)
|
||||
{
|
||||
getActiveStretchSource()->setMainVolume(val_MainVolume.getValue());
|
||||
getActiveStretchSource()->setLoopXFadeLength(val_XFadeLen.getValue());
|
||||
getActiveStretchSource()->setFreezing(m_freezing);
|
||||
getActiveStretchSource()->getNextAudioBlock(bufferToFill);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
//if (bufferToFill.numSamples > m_processbuffers[0].getNumSamples())
|
||||
{
|
||||
m_processbuffers[0].setSize(m_numoutchans, bufferToFill.numSamples);
|
||||
m_processbuffers[1].setSize(m_numoutchans, bufferToFill.numSamples);
|
||||
}
|
||||
AudioSourceChannelInfo ascinfo1(m_processbuffers[0]);
|
||||
AudioSourceChannelInfo ascinfo2(m_processbuffers[1]);
|
||||
m_stretchsources[0]->setMainVolume(val_MainVolume.getValue());
|
||||
m_stretchsources[1]->setMainVolume(val_MainVolume.getValue());
|
||||
m_stretchsources[0]->setLoopXFadeLength(val_XFadeLen.getValue());
|
||||
m_stretchsources[1]->setLoopXFadeLength(val_XFadeLen.getValue());
|
||||
m_stretchsources[0]->setFreezing(m_freezing);
|
||||
m_stretchsources[1]->setFreezing(m_freezing);
|
||||
m_stretchsources[1]->setFFTWindowingType(m_stretchsources[0]->getFFTWindowingType());
|
||||
m_stretchsources[0]->getNextAudioBlock(ascinfo1);
|
||||
m_stretchsources[1]->getNextAudioBlock(ascinfo2);
|
||||
int offset = bufferToFill.startSample;
|
||||
float** outbufpts = bufferToFill.buffer->getArrayOfWritePointers();
|
||||
for (int i = 0; i < bufferToFill.numSamples; ++i)
|
||||
{
|
||||
double fadegain = m_xfadegain.getNextValue();
|
||||
for (int j = 0; j < m_numoutchans; ++j)
|
||||
{
|
||||
double procsample0 = (1.0-fadegain)*m_processbuffers[0].getSample(j, i);
|
||||
double procsample1 = (fadegain)*m_processbuffers[1].getSample(j, i);
|
||||
outbufpts[j][i + offset] = procsample0 + procsample1;
|
||||
}
|
||||
}
|
||||
if (m_xfadegain.isSmoothing() == false)
|
||||
{
|
||||
std::swap(m_stretchsources[0], m_stretchsources[1]);
|
||||
m_xfadegain.setValue(0.0);
|
||||
m_xfadegain.reset(m_samplerate, m_switchxfadelen);
|
||||
m_is_in_switch = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MultiStretchAudioSource::setNextReadPosition(int64 newPosition)
|
||||
{
|
||||
getActiveStretchSource()->setNextReadPosition(newPosition);
|
||||
}
|
||||
|
||||
int64 MultiStretchAudioSource::getNextReadPosition() const
|
||||
{
|
||||
return getActiveStretchSource()->getNextReadPosition();
|
||||
}
|
||||
|
||||
int64 MultiStretchAudioSource::getTotalLength() const
|
||||
{
|
||||
return getActiveStretchSource()->getTotalLength();
|
||||
}
|
||||
|
||||
bool MultiStretchAudioSource::isLooping() const
|
||||
{
|
||||
return getActiveStretchSource()->isLooping();
|
||||
}
|
||||
|
||||
String MultiStretchAudioSource::setAudioFile(File file)
|
||||
{
|
||||
if (m_is_playing == false)
|
||||
{
|
||||
return m_stretchsources[0]->setAudioFile(file);
|
||||
}
|
||||
else
|
||||
{
|
||||
String result = m_stretchsources[1]->setAudioFile(file);
|
||||
m_stretchsources[1]->setFFTSize(m_stretchsources[0]->getFFTSize());
|
||||
m_stretchsources[1]->setNumOutChannels(m_stretchsources[0]->getNumOutChannels());
|
||||
m_stretchsources[1]->setRate(m_stretchsources[0]->getRate());
|
||||
m_stretchsources[1]->setPlayRange({ 0.0,1.0 }, m_stretchsources[0]->isLoopEnabled());
|
||||
auto pars = m_stretchsources[0]->getProcessParameters();
|
||||
m_stretchsources[1]->setProcessParameters(&pars);
|
||||
m_stretchsources[1]->setSpectrumProcessOrder(m_stretchsources[0]->getSpectrumProcessOrder());
|
||||
m_stretchsources[1]->prepareToPlay(m_blocksize, m_samplerate);
|
||||
|
||||
m_mutex.lock();
|
||||
m_xfadegain.reset(m_samplerate, m_switchxfadelen);
|
||||
m_xfadegain.setValue(1.0);
|
||||
m_is_in_switch = true;
|
||||
m_mutex.unlock();
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
File MultiStretchAudioSource::getAudioFile()
|
||||
{
|
||||
return getActiveStretchSource()->getAudioFile();
|
||||
}
|
||||
|
||||
void MultiStretchAudioSource::setNumOutChannels(int chans)
|
||||
{
|
||||
m_numoutchans = chans;
|
||||
getActiveStretchSource()->setNumOutChannels(chans);
|
||||
}
|
||||
|
||||
double MultiStretchAudioSource::getInfilePositionPercent()
|
||||
{
|
||||
return getActiveStretchSource()->getInfilePositionPercent();
|
||||
}
|
||||
|
||||
void MultiStretchAudioSource::setRate(double rate)
|
||||
{
|
||||
getActiveStretchSource()->setRate(rate);
|
||||
}
|
||||
|
||||
double MultiStretchAudioSource::getRate()
|
||||
{
|
||||
return getActiveStretchSource()->getRate();
|
||||
}
|
||||
|
||||
void MultiStretchAudioSource::setProcessParameters(ProcessParameters * pars)
|
||||
{
|
||||
getActiveStretchSource()->setProcessParameters(pars);
|
||||
}
|
||||
|
||||
void MultiStretchAudioSource::setFFTWindowingType(int windowtype)
|
||||
{
|
||||
getActiveStretchSource()->setFFTWindowingType(windowtype);
|
||||
}
|
||||
|
||||
void MultiStretchAudioSource::setFFTSize(int size)
|
||||
{
|
||||
if (size == getActiveStretchSource()->getFFTSize())
|
||||
return;
|
||||
if (m_is_playing == false)
|
||||
{
|
||||
getActiveStretchSource()->setFFTSize(size);
|
||||
}
|
||||
else
|
||||
{
|
||||
double curpos = m_stretchsources[0]->getInfilePositionPercent();
|
||||
m_stretchsources[1]->setFFTSize(size);
|
||||
m_stretchsources[1]->setNumOutChannels(m_stretchsources[0]->getNumOutChannels());
|
||||
if (m_stretchsources[0]->getAudioFile()!=File())
|
||||
m_stretchsources[1]->setAudioFile(m_stretchsources[0]->getAudioFile());
|
||||
m_stretchsources[1]->setRate(m_stretchsources[0]->getRate());
|
||||
m_stretchsources[1]->setPlayRange(m_stretchsources[0]->getPlayRange(), m_stretchsources[0]->isLoopEnabled());
|
||||
m_stretchsources[1]->seekPercent(curpos);
|
||||
auto pars = m_stretchsources[0]->getProcessParameters();
|
||||
m_stretchsources[1]->setProcessParameters(&pars);
|
||||
m_stretchsources[1]->setSpectrumProcessOrder(m_stretchsources[0]->getSpectrumProcessOrder());
|
||||
m_stretchsources[1]->prepareToPlay(m_blocksize, m_samplerate);
|
||||
m_mutex.lock();
|
||||
m_xfadegain.reset(m_samplerate, m_switchxfadelen);
|
||||
m_xfadegain.setValue(1.0);
|
||||
m_is_in_switch = true;
|
||||
m_mutex.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
int MultiStretchAudioSource::getFFTSize()
|
||||
{
|
||||
return getActiveStretchSource()->getFFTSize();
|
||||
}
|
||||
|
||||
|
||||
void MultiStretchAudioSource::seekPercent(double pos)
|
||||
{
|
||||
getActiveStretchSource()->seekPercent(pos);
|
||||
}
|
||||
|
||||
double MultiStretchAudioSource::getInfilePositionSeconds()
|
||||
{
|
||||
return getActiveStretchSource()->getInfilePositionSeconds();
|
||||
}
|
||||
|
||||
double MultiStretchAudioSource::getInfileLengthSeconds()
|
||||
{
|
||||
return getActiveStretchSource()->getInfileLengthSeconds();
|
||||
}
|
||||
|
||||
double MultiStretchAudioSource::getOutputDurationSecondsForRange(Range<double> range, int fftsize)
|
||||
{
|
||||
return getActiveStretchSource()->getOutputDurationSecondsForRange(range, fftsize);
|
||||
}
|
||||
|
||||
void MultiStretchAudioSource::setOnsetDetection(double x)
|
||||
{
|
||||
getActiveStretchSource()->setOnsetDetection(x);
|
||||
}
|
||||
|
||||
void MultiStretchAudioSource::setPlayRange(Range<double> playrange, bool isloop)
|
||||
{
|
||||
getActiveStretchSource()->setPlayRange(playrange, isloop);
|
||||
}
|
||||
|
||||
bool MultiStretchAudioSource::isLoopingEnabled()
|
||||
{
|
||||
return getActiveStretchSource()->isLoopingEnabled();
|
||||
}
|
||||
|
||||
void MultiStretchAudioSource::setLoopingEnabled(bool b)
|
||||
{
|
||||
getActiveStretchSource()->setLoopingEnabled(b);
|
||||
}
|
||||
|
||||
bool MultiStretchAudioSource::hasReachedEnd()
|
||||
{
|
||||
return getActiveStretchSource()->hasReachedEnd();
|
||||
}
|
||||
|
||||
bool MultiStretchAudioSource::isResampling()
|
||||
{
|
||||
return getActiveStretchSource()->isResampling();
|
||||
}
|
||||
|
||||
std::vector<SpectrumProcess> MultiStretchAudioSource::getSpectrumProcessOrder()
|
||||
{
|
||||
return getActiveStretchSource()->getSpectrumProcessOrder();
|
||||
}
|
||||
|
||||
void MultiStretchAudioSource::setSpectrumProcessOrder(std::vector<SpectrumProcess> order)
|
||||
{
|
||||
getActiveStretchSource()->setSpectrumProcessOrder(order);
|
||||
}
|
||||
|
@ -154,76 +154,3 @@ private:
|
||||
} m_xfadetask;
|
||||
int m_pause_fade_counter = 0;
|
||||
};
|
||||
|
||||
class MultiStretchAudioSource final : public PositionableAudioSource
|
||||
{
|
||||
public:
|
||||
MultiStretchAudioSource() {}
|
||||
MultiStretchAudioSource(int initialnumoutchans, AudioFormatManager* afm);
|
||||
~MultiStretchAudioSource();
|
||||
|
||||
void prepareToPlay(int samplesPerBlockExpected, double sampleRate) override;
|
||||
|
||||
void releaseResources() override;
|
||||
|
||||
void getNextAudioBlock(const AudioSourceChannelInfo & bufferToFill) override;
|
||||
|
||||
void setNextReadPosition(int64 newPosition) override;
|
||||
|
||||
int64 getNextReadPosition() const override;
|
||||
|
||||
int64 getTotalLength() const override;
|
||||
|
||||
bool isLooping() const override;
|
||||
|
||||
String setAudioFile(File file);
|
||||
File getAudioFile();
|
||||
|
||||
void setNumOutChannels(int chans);
|
||||
double getInfilePositionPercent();
|
||||
void setRate(double rate);
|
||||
double getRate();
|
||||
void setProcessParameters(ProcessParameters* pars);
|
||||
void setFFTSize(int size);
|
||||
int getFFTSize();
|
||||
|
||||
void seekPercent(double pos);
|
||||
double getInfilePositionSeconds();
|
||||
double getInfileLengthSeconds();
|
||||
|
||||
double getOutputDurationSecondsForRange(Range<double> range, int fftsize);
|
||||
|
||||
void setOnsetDetection(double x);
|
||||
void setPlayRange(Range<double> playrange, bool isloop);
|
||||
bool isLoopingEnabled();
|
||||
void setLoopingEnabled(bool b);
|
||||
bool hasReachedEnd();
|
||||
bool isResampling();
|
||||
std::vector<SpectrumProcess> getSpectrumProcessOrder();
|
||||
void setSpectrumProcessOrder(std::vector<SpectrumProcess> order);
|
||||
void setFFTWindowingType(int windowtype);
|
||||
std::pair<Range<double>, Range<double>> getFileCachedRangesNormalized();
|
||||
void setFreezing(bool b) { m_freezing = b; }
|
||||
bool isFreezing() { return m_freezing; }
|
||||
|
||||
Value val_MainVolume;
|
||||
Value val_XFadeLen;
|
||||
//ValueTree getStateTree();
|
||||
//void setStateTree(ValueTree state);
|
||||
void setAudioBufferAsInputSource(AudioBuffer<float>* buf, int sr, int len);
|
||||
private:
|
||||
std::vector<std::shared_ptr<StretchAudioSource>> m_stretchsources;
|
||||
bool m_is_in_switch{ false };
|
||||
bool m_is_playing = false;
|
||||
bool m_freezing = false;
|
||||
LinearSmoothedValue<double> m_xfadegain;
|
||||
StretchAudioSource* getActiveStretchSource() const;
|
||||
void switchActiveSource();
|
||||
int m_blocksize = 0;
|
||||
double m_samplerate = 44100.0;
|
||||
int m_numoutchans = 2;
|
||||
AudioBuffer<float> m_processbuffers[2];
|
||||
std::mutex m_mutex;
|
||||
double m_switchxfadelen = 1.0;
|
||||
AudioFormatManager* m_afm = nullptr;
|
||||
};
|
||||
|
@ -115,19 +115,6 @@ PaulstretchpluginAudioProcessor::PaulstretchpluginAudioProcessor()
|
||||
addParameter(new AudioParameterFloat("spread0", "Frequency spread", 0.0f, 1.0f, 0.0f)); // 8
|
||||
addParameter(new AudioParameterFloat("compress0", "Compress", 0.0f, 1.0f, 0.0f)); // 9
|
||||
addParameter(new AudioParameterFloat("loopxfadelen0", "Loop xfade length", 0.0f, 1.0f, 0.01f)); // 10
|
||||
auto numhar_convertFrom0To1Func = [](float rangemin, float rangemax, float value)
|
||||
{
|
||||
return jmap<float>(value, 0.0f, 1.0f, 101.0f, 1.0f);
|
||||
};
|
||||
auto numhar_convertTo0To1Func = [](float rangemin, float rangemax, float value)
|
||||
{
|
||||
return jmap<float>(value, 101.0f, 1.0f, 0.0f, 1.0f);
|
||||
};
|
||||
/*
|
||||
addParameter(new AudioParameterFloat("numharmonics0", "Num harmonics",
|
||||
NormalisableRange<float>(1.0f, 101.0f,
|
||||
numhar_convertFrom0To1Func, numhar_convertTo0To1Func), 101.0f)); // 11
|
||||
*/
|
||||
addParameter(new AudioParameterInt("numharmonics0", "Num harmonics", 1, 100, 10)); // 11
|
||||
addParameter(new AudioParameterFloat("harmonicsfreq0", "Harmonics base freq",
|
||||
NormalisableRange<float>(1.0f, 5000.0f, 1.00f, 0.5), 128.0f)); // 12
|
||||
|
Loading…
Reference in New Issue
Block a user