31 soundtouch.reset(
new soundtouch::SoundTouch());
35 logger.dualPrint(Logger::Level::Error,
"Failed to create SoundTouch handle");
45 void TimeStretch::
updateParams(
const juce::AudioProcessorValueTreeState& params,
46 const juce::String& blockId)
48 float _irLengthS = getParam(params, blockId);
50 if (_irLengthS != irLengthS)
52 irLengthS = _irLengthS;
74 logger.dualPrint(Logger::Level::Error,
"No SoundTouch instance exists, cannot apply time stretch to IR");
78 soundtouch->setChannels(1);
79 soundtouch->setSampleRate((
unsigned)sampleRate);
83 double sampleRateRatio = (
double)irOrig.getNumSamples() / (
double)newNumSamples;
87 soundtouch->setTempo(sampleRateRatio);
89 soundtouch->putSamples(irOrig.getReadPointer(0), irOrig.getNumSamples());
92 unsigned curSample = 0;
93 unsigned nbSamplesReceived = 0;
97 curSample += nbSamplesReceived;
100 auto curWritePtr = &ir.getChannelPointer(0)[curSample];
102 nbSamplesReceived = soundtouch->receiveSamples(curWritePtr,
103 (
unsigned)ir.getNumSamples() - curSample);
105 while (nbSamplesReceived != 0);
111 auto curWritePtr = &ir.getChannelPointer(0)[curSample];
113 nbSamplesReceived = soundtouch->receiveSamples(curWritePtr,
114 (
unsigned)ir.getNumSamples() - curSample);
116 curSample += nbSamplesReceived;
118 while (nbSamplesReceived != 0);
120 jassert(curSample == ir.getNumSamples());
134 void TimeStretch::
prepareIR(juce::AudioSampleBuffer& ir)
136 irOrig.makeCopyOf(ir);
137 ir.setSize(ir.getNumChannels(), getOutputNumSamples());
147 return (
int)std::ceil(irLengthS * sampleRate);
float getParam(const juce::AudioProcessorValueTreeState ¶ms, const juce::String &blockId) const
Internal method used to get (and check) a parameter's value.
void prepareIR(juce::AudioSampleBuffer &ir)
Copies given IR to internal representation and resizes it before processing.
TimeStretch(juce::AudioProcessor *processor)
Constructs a TimeStretch object associated with an AudioProcessor.
int getOutputNumSamples()
Returns expected number of samples after processing.
virtual AudioBlock exec(AudioBlock ir) override
Apply time stretching algorithm to input IR buffer to change sample rate.
virtual void updateParams(const juce::AudioProcessorValueTreeState ¶ms, const juce::String &blockID) override
Updates parameters from processor parameter tree.