Skip to content

Commit

Permalink
use size_t for latency and tail size expressed as samples
Browse files Browse the repository at this point in the history
  • Loading branch information
sophiapoirier committed Oct 22, 2022
1 parent 928e674 commit 1169f45
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 39 deletions.
4 changes: 2 additions & 2 deletions dfx-library/dfxplugin-vst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ void DfxPlugin::resume()

// do these after calling do_reset,
// because the value for latency could change there
setInitialDelay(getlatency_samples());
setInitialDelay(dfx::math::ToSigned(getlatency_samples()));

// it sure seems like we need to call ioChanged since we just
// called setInitialDelay(). -tom7
Expand All @@ -114,7 +114,7 @@ void DfxPlugin::setSampleRate(float newRate)
// even if the audio input has ended
VstInt32 DfxPlugin::getGetTailSize()
{
return gettailsize_samples();
return dfx::math::ToSigned(gettailsize_samples());
}


Expand Down
36 changes: 18 additions & 18 deletions dfx-library/dfxplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1198,11 +1198,11 @@ void DfxPlugin::setsamplerate(double inSampleRate)
if (mAUElementsHaveBeenCreated)
{
// assume that sample-specified properties change in absolute duration when sample rate changes
if (auto const latencySamples = std::get_if<long>(&mLatency); latencySamples && (*latencySamples != 0))
if (auto const latencySamples = std::get_if<size_t>(&mLatency); latencySamples && (*latencySamples != 0))
{
postupdate_latency();
}
if (auto const tailSizeSamples = std::get_if<long>(&mTailSize); tailSizeSamples && (*tailSizeSamples != 0))
if (auto const tailSizeSamples = std::get_if<size_t>(&mTailSize); tailSizeSamples && (*tailSizeSamples != 0))
{
postupdate_tailsize();
}
Expand Down Expand Up @@ -1526,19 +1526,19 @@ bool DfxPlugin::ischannelcountsupported(size_t inNumInputs, size_t inNumOutputs)
}

//-----------------------------------------------------------------------------
void DfxPlugin::setlatency_samples(long inSamples)
void DfxPlugin::setlatency_samples(size_t inSampleFrames)
{
bool changed = false;
if (std::holds_alternative<double>(mLatency))
{
changed = true;
}
else if (*std::get_if<long>(&mLatency) != inSamples)
else if (*std::get_if<size_t>(&mLatency) != inSampleFrames)
{
changed = true;
}

mLatency = inSamples;
mLatency = inSampleFrames;

if (changed)
{
Expand All @@ -1558,7 +1558,7 @@ void DfxPlugin::setlatency_samples(long inSamples)
void DfxPlugin::setlatency_seconds(double inSeconds)
{
bool changed = false;
if (std::holds_alternative<long>(mLatency))
if (std::holds_alternative<size_t>(mLatency))
{
changed = true;
}
Expand All @@ -1584,15 +1584,15 @@ void DfxPlugin::setlatency_seconds(double inSeconds)
}

//-----------------------------------------------------------------------------
long DfxPlugin::getlatency_samples() const
size_t DfxPlugin::getlatency_samples() const
{
if (auto const latencySamples = std::get_if<long>(&mLatency))
if (auto const latencySamples = std::get_if<size_t>(&mLatency))
{
return *latencySamples;
}
else
{
return std::lround(*std::get_if<double>(&mLatency) * getsamplerate());
return dfx::math::ToUnsigned(std::lround(*std::get_if<double>(&mLatency) * getsamplerate()));
}
}

Expand All @@ -1605,7 +1605,7 @@ double DfxPlugin::getlatency_seconds() const
}
else
{
return static_cast<double>(*std::get_if<long>(&mLatency)) / getsamplerate();
return static_cast<double>(*std::get_if<size_t>(&mLatency)) / getsamplerate();
}
}

Expand All @@ -1622,19 +1622,19 @@ void DfxPlugin::postupdate_latency()
}

//-----------------------------------------------------------------------------
void DfxPlugin::settailsize_samples(long inSamples)
void DfxPlugin::settailsize_samples(size_t inSampleFrames)
{
bool changed = false;
if (std::holds_alternative<double>(mTailSize))
{
changed = true;
}
else if (*std::get_if<long>(&mTailSize) != inSamples)
else if (*std::get_if<size_t>(&mTailSize) != inSampleFrames)
{
changed = true;
}

mTailSize = inSamples;
mTailSize = inSampleFrames;

if (changed)
{
Expand All @@ -1654,7 +1654,7 @@ void DfxPlugin::settailsize_samples(long inSamples)
void DfxPlugin::settailsize_seconds(double inSeconds)
{
bool changed = false;
if (std::holds_alternative<long>(mTailSize))
if (std::holds_alternative<size_t>(mTailSize))
{
changed = true;
}
Expand All @@ -1680,15 +1680,15 @@ void DfxPlugin::settailsize_seconds(double inSeconds)
}

//-----------------------------------------------------------------------------
long DfxPlugin::gettailsize_samples() const
size_t DfxPlugin::gettailsize_samples() const
{
if (auto const tailSizeSamples = std::get_if<long>(&mTailSize))
if (auto const tailSizeSamples = std::get_if<size_t>(&mTailSize))
{
return *tailSizeSamples;
}
else
{
return std::lround(*std::get_if<double>(&mTailSize) * getsamplerate());
return dfx::math::ToUnsigned(std::lround(*std::get_if<double>(&mTailSize) * getsamplerate()));
}
}

Expand All @@ -1701,7 +1701,7 @@ double DfxPlugin::gettailsize_seconds() const
}
else
{
return static_cast<double>(*std::get_if<long>(&mTailSize)) / getsamplerate();
return static_cast<double>(*std::get_if<size_t>(&mTailSize)) / getsamplerate();
}
}

Expand Down
12 changes: 6 additions & 6 deletions dfx-library/dfxplugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -533,15 +533,15 @@ class DfxPlugin : public TARGET_API_BASE_CLASS
return mTimeInfo;
}

void setlatency_samples(long inSamples);
void setlatency_samples(size_t inSampleFrames);
void setlatency_seconds(double inSeconds);
long getlatency_samples() const;
size_t getlatency_samples() const;
double getlatency_seconds() const;
void postupdate_latency();

void settailsize_samples(long inSamples);
void settailsize_samples(size_t inSampleFrames);
void settailsize_seconds(double inSeconds);
long gettailsize_samples() const;
size_t gettailsize_samples() const;
double gettailsize_seconds() const;
void postupdate_tailsize();

Expand Down Expand Up @@ -845,9 +845,9 @@ class DfxPlugin : public TARGET_API_BASE_CLASS
// try to get musical tempo/time/location information from the host
void processtimeinfo();

std::variant<long, double> mLatency {0l};
std::variant<size_t, double> mLatency {size_t(0)}; // TODO C++23: integer literal suffix UZ
std::atomic_flag mLatencyChangeHasPosted;
std::variant<long, double> mTailSize {0l};
std::variant<size_t, double> mTailSize {size_t(0)}; // TODO C++23: integer literal suffix UZ
std::atomic_flag mTailSizeChangeHasPosted;
bool mInPlaceAudioProcessingAllowed = true;
bool mAudioIsRendering = false;
Expand Down
8 changes: 5 additions & 3 deletions exemplar/exemplar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ DFX Exemplar, featuring the Super Destroy FX Windowing System!
#include <cstdio>
#include <fstream>

#include "dfxmath.h"


#define NORMALIZE 1

Expand Down Expand Up @@ -78,7 +80,7 @@ PLUGIN::PLUGIN(TARGET_API_BASE_INSTANCE_TYPE inInstance)
for (int i=NUM_WINDOWSHAPES; i < MAX_WINDOWSHAPES; i++)
setparametervaluestring(P_SHAPE, i, "???");

long delay_samples = buffersizes[getparameter_i(P_BUFSIZE)];
auto const delay_samples = dfx::math::ToUnsigned(buffersizes[getparameter_i(P_BUFSIZE)]);
setlatency_samples(delay_samples);
settailsize_samples(delay_samples);

Expand Down Expand Up @@ -180,9 +182,9 @@ void PLUGINCORE::reset() {
plan.reset(rfftw_create_plan(framesize, FFTW_FORWARD, FFTW_ESTIMATE));
// rplan.reset(rfftw_create_plan(framesize, FFTW_BACKWARD, FFTW_ESTIMATE));

dfxplugin->setlatency_samples(framesize);
dfxplugin->setlatency_samples(dfx::math::ToUnsigned(framesize));
/* tail is the same as delay, of course */
dfxplugin->settailsize_samples(framesize);
dfxplugin->settailsize_samples(dfx::math::ToUnsigned(framesize));
}

void PLUGINCORE::processparameters() {
Expand Down
6 changes: 3 additions & 3 deletions geometer/geometer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ PLUGINCORE::PLUGINCORE(DfxPlugin* inDfxPlugin)
windowenvelope.assign(maxframe, 0.0f);

if (iswaveformsource()) { // does not matter which DSP core, but this just should happen only once
auto const delay_samples = PLUGIN::buffersizes.at(getparameter_i(P_BUFSIZE));
auto const delay_samples = dfx::math::ToUnsigned(PLUGIN::buffersizes.at(getparameter_i(P_BUFSIZE)));
getplugin()->setlatency_samples(delay_samples);
getplugin()->settailsize_samples(delay_samples);
}
Expand Down Expand Up @@ -1259,9 +1259,9 @@ void PLUGINCORE::updatewindowsize()
outstart = 0;
outsize = framesize;

getplugin()->setlatency_samples(framesize);
getplugin()->setlatency_samples(dfx::math::ToUnsigned(framesize));
/* tail is the same as delay, of course */
getplugin()->settailsize_samples(framesize);
getplugin()->settailsize_samples(dfx::math::ToUnsigned(framesize));
}


Expand Down
8 changes: 5 additions & 3 deletions slowft/slowft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ Slowft, featuring the Super Destroy FX Windowing System!
#include <array>
#include <cstdio>

#include "dfxmath.h"

/* this macro does boring entry point stuff for us */
DFX_ENTRY(Slowft);
DFX_CORE_ENTRY(SlowftDSP);
Expand Down Expand Up @@ -55,7 +57,7 @@ PLUGIN::PLUGIN(TARGET_API_BASE_INSTANCE_TYPE inInstance)
for (int i = NUM_WINDOWSHAPES; i < MAX_WINDOWSHAPES; i++)
setparametervaluestring(P_SHAPE, i, "???");

long delay_samples = buffersizes[getparameter_i(P_BUFSIZE)];
auto const delay_samples = dfx::math::ToUnsigned(buffersizes[getparameter_i(P_BUFSIZE)]);
setlatency_samples(delay_samples);
settailsize_samples(delay_samples);

Expand Down Expand Up @@ -102,9 +104,9 @@ void PLUGINCORE::reset() {
outstart = 0;
outsize = framesize;

dfxplugin->setlatency_samples(framesize);
dfxplugin->setlatency_samples(dfx::math::ToUnsigned(framesize));
/* tail is the same as delay, of course */
dfxplugin->settailsize_samples(framesize);
dfxplugin->settailsize_samples(dfx::math::ToUnsigned(framesize));
}

void PLUGINCORE::processparameters() {
Expand Down
3 changes: 2 additions & 1 deletion thrush/thrush.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ To contact the author, use the contact form at http:https://destroyfx.org
#include <cmath>
#include <numeric>

#include "dfxmath.h"
#include "dfxmisc.h"


Expand Down Expand Up @@ -103,7 +104,7 @@ Thrush::Thrush(TARGET_API_BASE_INSTANCE_TYPE inInstance)
addchannelconfig(2, 2); // stereo in / stereo out
//addchannelconfig(1, 2); // it's okay to feed both inputs with the same signal

settailsize_samples(kDelayBufferSize);
settailsize_samples(dfx::math::ToUnsigned(kDelayBufferSize));

mCurrentTempoBPS = getparameter_f(kTempo) / 60.;

Expand Down
8 changes: 5 additions & 3 deletions windowingstub/windowingstub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ Windowingstub, featuring the Super Destroy FX Windowing System!
#include <cmath>
#include <cstdio>

#include "dfxmath.h"

/* this macro does boring entry point stuff for us */
DFX_ENTRY(Windowingstub);
DFX_CORE_ENTRY(WindowingstubDSP);
Expand Down Expand Up @@ -58,7 +60,7 @@ PLUGIN::PLUGIN(TARGET_API_BASE_INSTANCE_TYPE inInstance)
for (int i = NUM_WINDOWSHAPES; i < MAX_WINDOWSHAPES; i++)
setparametervaluestring(P_SHAPE, i, "???");

long delay_samples = buffersizes[getparameter_i(P_BUFSIZE)];
auto const delay_samples = dfx::math::ToUnsigned(buffersizes[getparameter_i(P_BUFSIZE)]);
setlatency_samples(delay_samples);
settailsize_samples(delay_samples);

Expand Down Expand Up @@ -105,9 +107,9 @@ void PLUGINCORE::reset() {
outstart = 0;
outsize = framesize;

getplugin()->setlatency_samples(framesize);
getplugin()->setlatency_samples(dfx::math::ToUnsigned(framesize));
/* tail is the same as delay, of course */
getplugin()->settailsize_samples(framesize);
getplugin()->settailsize_samples(dfx::math::ToUnsigned(framesize));
}

void PLUGINCORE::processparameters() {
Expand Down

0 comments on commit 1169f45

Please sign in to comment.