From 0eadb853f7c261198a546c1f3d1eab3e4c332855 Mon Sep 17 00:00:00 2001 From: xenakios Date: Thu, 8 Nov 2018 18:43:00 +0200 Subject: [PATCH] Use constexpr if in FFTWBuffer memory helper functions --- Source/PS_Source/Stretch.h | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/Source/PS_Source/Stretch.h b/Source/PS_Source/Stretch.h index 269fd42..117c294 100644 --- a/Source/PS_Source/Stretch.h +++ b/Source/PS_Source/Stretch.h @@ -27,6 +27,7 @@ #include "../JuceLibraryCode/JuceHeader.h" #include +#include template class FFTWBuffer @@ -91,28 +92,22 @@ public: private: T* m_buf = nullptr; int m_size = 0; - void mallocimpl(float*& buf,int size) + void mallocimpl(T*& buf,int size) { - buf = (float*)fftwf_malloc(size*sizeof(float)); + if constexpr (std::is_same::value) + buf = (float*)fftwf_malloc(size*sizeof(float)); + else + buf = (double*)fftw_malloc(size * sizeof(double)); } - void mallocimpl(double*& buf,int size) - { - buf = (double*)fftw_malloc(size*sizeof(double)); - } - void freeimpl(float*& buf) + void freeimpl(T*& buf) { if (buf!=nullptr) { - fftwf_free(buf); - buf = nullptr; - } - } - void freeimpl(double*& buf) - { - if (buf!=nullptr) - { - fftw_free(buf); - buf = nullptr; + if constexpr (std::is_same::value) + fftwf_free(buf); + else + fftw_free(buf); + buf = nullptr; } } };