Skip to content

Commit

Permalink
TempoSync Delay Times Calculation Changed to use chowdsp_rhythm
Browse files Browse the repository at this point in the history
  • Loading branch information
RachelMaryamLocke committed Nov 2, 2023
1 parent 08fa4bb commit bd09319
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 53 deletions.
1 change: 1 addition & 0 deletions modules/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ target_link_libraries(juce_plugin_modules
chowdsp::chowdsp_plugin_base
chowdsp::chowdsp_plugin_utils
chowdsp::chowdsp_reverb
chowdsp::chowdsp_rhythm
chowdsp::chowdsp_presets
chowdsp::chowdsp_serialization
chowdsp::chowdsp_units
Expand Down
88 changes: 37 additions & 51 deletions src/processors/other/Delay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include "gui/utils/ModulatableSlider.h"
#include "processors/PlayheadHelpers.h"

using namespace chowdsp::RhythmUtils;

namespace
{
const String delayTypeTag = "delay_type";
Expand Down Expand Up @@ -234,55 +236,47 @@ void DelayModule::processPingPongDelay (AudioBuffer<float>& buffer, DelayType& d

void DelayModule::processAudio (AudioBuffer<float>& buffer)
{
std::cout << playheadHelpers->bpm << std::endl;
double tempo = playheadHelpers->bpm.load();
std::cout << "My BPM: " << tempo << std::endl;

feedbackSmoothBuffer.process (std::pow (feedbackParam->getCurrentValue() * 0.67f, 0.9f), buffer.getNumSamples());
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; //fallback delay
std::cout << "Delay Time In Notes..." << std::endl;
auto positionInfo = audioPlayHead.getPosition();

std::cout << playheadHelpers->bpm << std::endl;
double tempo = playheadHelpers->bpm.load();
std::cout << "My BPM: " << tempo << std::endl;
// int myIntVal = intRef.load();
// std::cout << "My Int: " << myIntVal << std::endl;


// bpm = PlayheadHelpersRef.bpm.load();

// std::cout << "Playhead Helper BPM: " << bpm << std::endl;
// else
// {
// float delayInSamples = fs * 200 * 0.001f; //fallback delay
// std::cout << "Delay Time In Notes..." << std::endl;
// auto positionInfo = audioPlayHead.getPosition();
//// auto hardcodedBpm = 120;
// auto bpm = positionInfo->getBpm();
// auto noteDivision = (int)*delayTimeTempoSyncParam;
// if (noteDivision == 0)
// {
// delayInSamples = calculateTempoSyncDelayTime(2.0f, *bpm);
// std::cout << "1/2 Note Delay..." << std::endl;
// }
// else if (noteDivision == 1)
// {
// delayInSamples = calculateTempoSyncDelayTime(1.0f, *bpm);
// std::cout << "1/4 Note Delay..." << std::endl;
// }
// else if (noteDivision == 2)
// {
// delayInSamples = calculateTempoSyncDelayTime (0.5f, *bpm);
// std::cout << "1/8 Note Delay..." << std::endl;
// }
// else if (noteDivision == 3)
// {
// delayInSamples = calculateTempoSyncDelayTime (0.75f, *bpm);
// std::cout << "1/8 Note Dotted Delay..." << std::endl;
// }
// delaySmooth.setTargetValue (delayInSamples);
// }
// freqSmooth.setTargetValue (*freqParam);
auto noteDivision = (int)*delayTimeTempoSyncParam;
if (noteDivision == 0)
{
delayInSamples = calculateTempoSyncDelayTime(HALF.getTimeSeconds(tempo), fs);
std::cout << "1/2 Note Delay..." << std::endl;
}
else if (noteDivision == 1)
{
delayInSamples = calculateTempoSyncDelayTime(QUARTER.getTimeSeconds(tempo), fs);
std::cout << "1/4 Note Delay..." << std::endl;
}
else if (noteDivision == 2)
{
delayInSamples = calculateTempoSyncDelayTime (EIGHTH.getTimeSeconds(tempo), fs);
std::cout << "1/8 Note Delay..." << std::endl;
}
else if (noteDivision == 3)
{
delayInSamples = calculateTempoSyncDelayTime (EIGHTH_DOT.getTimeSeconds(tempo), fs);
std::cout << "1/8 Note Dotted Delay..." << std::endl;
}
delaySmooth.setTargetValue (delayInSamples);
}
freqSmooth.setTargetValue (*freqParam);

const auto delayTypeIndex = (int) *delayTypeParam;
if (delayTypeIndex != prevDelayTypeIndex)
Expand Down Expand Up @@ -325,17 +319,9 @@ void DelayModule::processAudioBypassed (AudioBuffer<float>& buffer)
outputBuffers.getReference (0) = &buffer;
}

//void DelayModule::setPlayheadHelpersReference(PlayheadHelpers& helpers) {
// playheadHelpersReference = &helpers;
//}

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

return floor(noteDuration * secondsPerBeat * fs);
return static_cast<float> (timeInSeconds * sampleRate);
}

bool DelayModule::getCustomComponents (OwnedArray<Component>& customComps, chowdsp::HostContextProvider& hcp)
Expand Down
3 changes: 1 addition & 2 deletions src/processors/other/Delay.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ 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;
// void setPlayheadHelpersReference(PlayheadHelpers& helpers);
float calculateTempoSyncDelayTime(const double timeInSeconds, const double sampleRate) const;

private:
template <typename DelayType>
Expand Down

0 comments on commit bd09319

Please sign in to comment.