Skip to content

Commit

Permalink
Use std::nan instead of FP_NAN
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Willis committed Dec 7, 2020
1 parent 91eaade commit 554e1ad
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion common/DragonflyVersion.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@

#define MAJOR_VERSION 3
#define MINOR_VERSION 2
#define PATCH_VERSION 1
#define PATCH_VERSION 2
#define VERSION_SUFFIX ""
14 changes: 7 additions & 7 deletions plugins/dragonfly-early-reflections/DSP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ DragonflyReverbDSP::DragonflyReverbDSP(double sampleRate) {

for (uint32_t param = 0; param < paramCount; param++) {
newParams[param] = DEFAULTS[param];
oldParams[param] = FP_NAN;
oldParams[param] = std::nan("");
}

sampleRateChanged(sampleRate);
Expand All @@ -53,7 +53,7 @@ void DragonflyReverbDSP::setParameterValue(uint32_t index, float value) {

void DragonflyReverbDSP::run(const float** inputs, float** outputs, uint32_t frames) {
for (uint32_t index = 0; index < paramCount; index++) {
if (d_isNotEqual(oldParams[index], newParams[index])) {
if (std::isnan(oldParams[index]) || d_isNotEqual(oldParams[index], newParams[index])) {
oldParams[index] = newParams[index];
float value = newParams[index];

Expand All @@ -67,7 +67,7 @@ void DragonflyReverbDSP::run(const float** inputs, float** outputs, uint32_t fra
}

if (index == paramProgram) {
model.loadPresetReflection(programs[(int)value].number);
model.loadPresetReflection(programs[(int)value].number);
}
}
}
Expand All @@ -90,12 +90,12 @@ void DragonflyReverbDSP::run(const float** inputs, float** outputs, uint32_t fra

for (uint32_t i = 0; i < buffer_frames; i++) {
outputs[0][offset + i] =
dry_level * inputs[0][offset + i] +
wet_level * output_buffer[0][i];
dry_level * inputs[0][offset + i] +
wet_level * output_buffer[0][i];

outputs[1][offset + i] =
dry_level * inputs[1][offset + i] +
wet_level * output_buffer[1][i];
dry_level * inputs[1][offset + i] +
wet_level * output_buffer[1][i];
}

}
Expand Down
4 changes: 2 additions & 2 deletions plugins/dragonfly-early-reflections/DSP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ class DragonflyReverbDSP : public AbstractDSP {

double sampleRate;

float dry_level;
float wet_level;
float dry_level = 0.0;
float wet_level = 0.0;

static const uint32_t BUFFER_SIZE = 256;

Expand Down
4 changes: 2 additions & 2 deletions plugins/dragonfly-hall-reverb/DSP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ DragonflyReverbDSP::DragonflyReverbDSP(double sampleRate) {

for (uint32_t param = 0; param < paramCount; param++) {
newParams[param] = banks[DEFAULT_BANK].presets[DEFAULT_PRESET].params[param];
oldParams[param] = FP_NAN;
oldParams[param] = std::nan("");
}
}

Expand All @@ -59,7 +59,7 @@ void DragonflyReverbDSP::setParameterValue(uint32_t index, float value) {

void DragonflyReverbDSP::run(const float** inputs, float** outputs, uint32_t frames) {
for (uint32_t index = 0; index < paramCount; index++) {
if (d_isNotEqual(oldParams[index], newParams[index])) {
if (std::isnan(oldParams[index]) || d_isNotEqual(oldParams[index], newParams[index])) {
oldParams[index] = newParams[index];
float value = newParams[index];

Expand Down
4 changes: 2 additions & 2 deletions plugins/dragonfly-plate-reverb/DSP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ DragonflyReverbDSP::DragonflyReverbDSP(double sampleRate) {

for (uint32_t param = 0; param < paramCount; param++) {
newParams[param] = presets[DEFAULT_PRESET].params[param];
oldParams[param] = FP_NAN;
oldParams[param] = std::nan("");
}

sampleRateChanged(sampleRate);
Expand All @@ -177,7 +177,7 @@ void DragonflyReverbDSP::setParameterValue(uint32_t index, float value) {

void DragonflyReverbDSP::run(const float** inputs, float** outputs, uint32_t frames) {
for (uint32_t index = 0; index < paramCount; index++) {
if (d_isNotEqual(oldParams[index], newParams[index])) {
if (std::isnan(oldParams[index]) || d_isNotEqual(oldParams[index], newParams[index])) {
oldParams[index] = newParams[index];
float value = newParams[index];

Expand Down
4 changes: 2 additions & 2 deletions plugins/dragonfly-plate-reverb/DSP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ class DragonflyReverbDSP : public AbstractDSP {

double sampleRate;

float dry_level;
float wet_level;
float dry_level = 0.0;
float wet_level = 0.0;

static const uint32_t BUFFER_SIZE = 256;

Expand Down
4 changes: 2 additions & 2 deletions plugins/dragonfly-room-reverb/DSP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ DragonflyReverbDSP::DragonflyReverbDSP(double sampleRate) {

for (uint32_t param = 0; param < paramCount; param++) {
newParams[param] = banks[DEFAULT_BANK].presets[DEFAULT_PRESET].params[param];
oldParams[param] = FP_NAN;
oldParams[param] = std::nan("");
}

sampleRateChanged(sampleRate);
Expand All @@ -69,7 +69,7 @@ void DragonflyReverbDSP::setParameterValue(uint32_t index, float value) {

void DragonflyReverbDSP::run(const float** inputs, float** outputs, uint32_t frames) {
for (uint32_t index = 0; index < paramCount; index++) {
if (d_isNotEqual(oldParams[index], newParams[index])) {
if (std::isnan(oldParams[index]) || d_isNotEqual(oldParams[index], newParams[index])) {
oldParams[index] = newParams[index];
float value = newParams[index];

Expand Down
8 changes: 4 additions & 4 deletions plugins/dragonfly-room-reverb/DSP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ class DragonflyReverbDSP : public AbstractDSP {

double sampleRate;

float dry_level;
float early_level;
float early_send;
float late_level;
float dry_level = 0.0;
float early_level = 0.0;
float early_send = 0.0;
float late_level = 0.0;

fv3::iir_1st_f input_lpf_0, input_lpf_1, input_hpf_0, input_hpf_1;

Expand Down

4 comments on commit 554e1ad

@michaelwillis
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Zadagu @colin-m-fletcher Please take a look at this since you were both involved in the discussion about nan.

@Zadagu
Copy link
Contributor

@Zadagu Zadagu commented on 554e1ad Dec 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is the right direction. But as I posted today already, d_isNotEqual needs also a patch, because it doesn't handle NaN as it should:

printf("d_isNotEqual(nan, 0.0) = %d\n", d_isNotEqual(std::numeric_limits<double>::quiet_NaN(), 0.0));
// d_isNotEqual(nan, 0.0) = 0

@michaelwillis
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Zadagu Right, d_isNotEqual does not handle nan, so I included this in each conditional: std::isnan(oldParams[index])

@colin-m-fletcher
Copy link

@colin-m-fletcher colin-m-fletcher commented on 554e1ad Dec 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks reasonable to me.

As it happens, any comparison of a NaN to anything will always evaluate as false, so not only is nan("") == 0 false, but so are (for example) nan("") != 0, nan("") > 0, nan("") < 0, and nan("") == nan(""). So if (std::isnan(x) || d_isNotEqual(x, y)) could maybe be written more simply as if (!d_isEqual(x, y)), though that might not be as clear.

Please sign in to comment.