Skip to content

Fix build with -fsingle-precision-constant#98

Open
falkTX wants to merge 1 commit intoValleyAudio:mainfrom
CardinalModules:fix-single-precision-build
Open

Fix build with -fsingle-precision-constant#98
falkTX wants to merge 1 commit intoValleyAudio:mainfrom
CardinalModules:fix-single-precision-build

Conversation

@falkTX
Copy link
Contributor

@falkTX falkTX commented Mar 1, 2024

The -fsingle-precision-constant compiler flag is used to get some performance benefits for systems where 32bit float math is faster than 64bit, it automatically converts all staticly typed doubles into floats which reduces the chance of "double promotion".

This can generate some conflicts at times with templated functions, and is the case for ValleyAudio modules, with the error being:

ValleyAudio/src/Plateau/Dattorro.cpp: In member function 'void Dattorro1997Tank::setDiffusion(double)':
ValleyAudio/src/Plateau/Dattorro.cpp:162:71: error: no matching function for call to 'scale(const double&, float, float, float, const double&)'
     double diffusion1 = scale(diffusion, 0.0, 10.0, 0.0, maxDiffusion1);
                                                                       ^
In file included from ValleyAudio/src/Plateau/../dsp/delays/InterpDelay.hpp:12:0,
                 from ValleyAudio/src/Plateau/../dsp/delays/AllpassFilter.hpp:8,
                 from ValleyAudio/src/Plateau/Dattorro.hpp:6,
                 from ValleyAudio/src/Plateau/Dattorro.cpp:1:
ValleyAudio/src/Plateau/../dsp/delays/../../utilities/Utilities.hpp:17:3: note: candidate: template<class T> T scale(T, T, T, T, T)
 T scale(T a, T inMin, T inMax, T outMin, T outMax) {
   ^~~~~
ValleyAudio/src/Plateau/../dsp/delays/../../utilities/Utilities.hpp:17:3: note:   template argument deduction/substitution failed:
ValleyAudio/src/Plateau/Dattorro.cpp:162:71: note:   deduced conflicting types for parameter 'T' ('double' and 'float')
     double diffusion1 = scale(diffusion, 0.0, 10.0, 0.0, maxDiffusion1);

The fix is straight forward, we can just specify the function template type, which is more verbose but doesn't hurt anything.

Signed-off-by: falkTX <falktx@falktx.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant