From ce7571dcc13cfb3156c4c77449d4668b8971d3fe Mon Sep 17 00:00:00 2001 From: Ken Cooke Date: Tue, 18 Jun 2019 10:29:23 -0700 Subject: [PATCH] Replace NEXTPOW2() macros with constexpr (supported since VS2015) --- libraries/audio/src/AudioReverb.cpp | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/libraries/audio/src/AudioReverb.cpp b/libraries/audio/src/AudioReverb.cpp index 4d89172a38..26f5528866 100644 --- a/libraries/audio/src/AudioReverb.cpp +++ b/libraries/audio/src/AudioReverb.cpp @@ -35,16 +35,6 @@ static const double SQRT2 = 1.41421356237309504880; static const double FIXQ31 = 2147483648.0; static const double FIXQ32 = 4294967296.0; -// Round an integer to the next power-of-two, at compile time. -// VS2013 does not support constexpr so macros are used instead. -#define SETBITS0(x) (x) -#define SETBITS1(x) (SETBITS0(x) | (SETBITS0(x) >> 1)) -#define SETBITS2(x) (SETBITS1(x) | (SETBITS1(x) >> 2)) -#define SETBITS3(x) (SETBITS2(x) | (SETBITS2(x) >> 4)) -#define SETBITS4(x) (SETBITS3(x) | (SETBITS3(x) >> 8)) -#define SETBITS5(x) (SETBITS4(x) | (SETBITS4(x) >> 16)) -#define NEXTPOW2(x) (SETBITS5((x) - 1) + 1) - // // Allpass delay modulation // @@ -111,6 +101,18 @@ static const int M_AP19 = 113; static const int M_AP20 = 107; static const int M_AP21 = 127; +// Round an integer to the next power-of-two, at compile time +constexpr uint32_t NEXTPOW2(uint32_t n) { + n -= 1; + n |= (n >> 1); + n |= (n >> 2); + n |= (n >> 4); + n |= (n >> 8); + n |= (n >> 16); + n += 1; + return n; +} + // // Filter design tools using analog-matched response. // All filter types approximate the s-plane response, including cutoff > Nyquist.