Use constexpr if in FFTWBuffer memory helper functions

This commit is contained in:
xenakios 2018-11-08 18:43:00 +02:00
parent 778a360cd6
commit 0eadb853f7

View File

@ -27,6 +27,7 @@
#include "../JuceLibraryCode/JuceHeader.h"
#include <random>
#include <type_traits>
template<typename T>
class FFTWBuffer
@ -91,26 +92,20 @@ public:
private:
T* m_buf = nullptr;
int m_size = 0;
void mallocimpl(float*& buf,int size)
void mallocimpl(T*& buf,int size)
{
if constexpr (std::is_same<T,float>::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)
{
if constexpr (std::is_same<T, float>::value)
fftwf_free(buf);
buf = nullptr;
}
}
void freeimpl(double*& buf)
{
if (buf!=nullptr)
{
else
fftw_free(buf);
buf = nullptr;
}