Skip to content

Commit

Permalink
Intital Tempo Sync Delay Implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
RachelMaryamLocke committed Oct 24, 2023
1 parent 26f3b4c commit 021416a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 8 deletions.
40 changes: 32 additions & 8 deletions src/processors/other/Delay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,30 +234,45 @@ void DelayModule::processPingPongDelay (AudioBuffer<float>& buffer, DelayType& d
void DelayModule::processAudio (AudioBuffer<float>& buffer)
{
feedbackSmoothBuffer.process (std::pow (feedbackParam->getCurrentValue() * 0.67f, 0.9f), buffer.getNumSamples());

if (!tempoSyncOnOffParam)
auto tempoSync = (int)*tempoSyncOnOffParam;
if (!tempoSync)
{
std::cout << "Delay Time In Ms..." << std::endl;
delaySmooth.setTargetValue (fs * *delayTimeMsParam * 0.001f); //delay time in samples (if tempo-sync change the calculation here?)
}
else
{
float delayInSamples = fs * 200 * 0.001f ;
std::cout << "Delay Time In Notes..." << std::endl;
//calculate delay time based on delayTimeTempoSyncParam
auto positionInfo = audioPlayHead.getPosition();
// auto hardcodedBpm = 120;
auto bpm = positionInfo->getBpm();
auto noteDivision = (int)*delayTimeTempoSyncParam;
if (noteDivision == 0)
std::cout<< "1/2 note delay" << std::endl;
{
delayInSamples = calculateTempoSyncDelayTime(2.0f, *bpm);
std::cout << "1/2 Note Delay..." << std::endl;
}
else if (noteDivision == 1)
std::cout<< "1/4 note delay" << std::endl;
{
delayInSamples = calculateTempoSyncDelayTime(1.0f, *bpm);
std::cout << "1/4 Note Delay..." << std::endl;
}
else if (noteDivision == 2)
std::cout<< "1/8 note delay" << std::endl;
{
delayInSamples = calculateTempoSyncDelayTime (0.5f, *bpm);
std::cout << "1/8 Note Delay..." << std::endl;
}
else if (noteDivision == 3)
std::cout<< "1/8 note dottod delay" << std::endl;
{
delayInSamples = calculateTempoSyncDelayTime (0.75f, *bpm);
std::cout << "1/8 Note Dotted Delay..." << std::endl;
}
delaySmooth.setTargetValue (delayInSamples);
}
freqSmooth.setTargetValue (*freqParam);

const auto delayTypeIndex = (int) *delayTypeParam;
const auto tempoSyncAmountIndex = (int) *delayTimeTempoSyncParam;
if (delayTypeIndex != prevDelayTypeIndex)
{
cleanDelayLine.reset();
Expand Down Expand Up @@ -298,6 +313,15 @@ void DelayModule::processAudioBypassed (AudioBuffer<float>& buffer)
outputBuffers.getReference (0) = &buffer;
}

float DelayModule::calculateTempoSyncDelayTime(const float noteDuration, const double bpm) const
{
//calculate tempo sync delay in samples
auto beatsPerSecond = static_cast<float> (bpm / 60);
auto secondsPerBeat = 1/beatsPerSecond;

return floor(noteDuration * secondsPerBeat * fs);
}

bool DelayModule::getCustomComponents (OwnedArray<Component>& customComps, chowdsp::HostContextProvider& hcp)
{
using namespace chowdsp::ParamUtils;
Expand Down
10 changes: 10 additions & 0 deletions src/processors/other/Delay.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,23 @@ class DelayModule : public BaseProcessor
void releaseMemory() override;
void processAudio (AudioBuffer<float>& buffer) override;
void processAudioBypassed (AudioBuffer<float>& buffer) override;
float calculateTempoSyncDelayTime(const float noteDuration, const double bpm) const;

private:
template <typename DelayType>
void processMonoStereoDelay (AudioBuffer<float>& buffer, DelayType& delayLine);
template <typename DelayType>
void processPingPongDelay (AudioBuffer<float>& buffer, DelayType& delayLine);

struct SimpleAudioPlayHead : juce::AudioPlayHead {
juce::Optional<AudioPlayHead::PositionInfo> getPosition() const override {
PositionInfo info;
return info;
}
};

SimpleAudioPlayHead audioPlayHead;

chowdsp::FloatParameter* freqParam = nullptr;
chowdsp::FloatParameter* feedbackParam = nullptr;
chowdsp::FloatParameter* mixParam = nullptr;
Expand Down

0 comments on commit 021416a

Please sign in to comment.