CiCueTea v0.0.1
Loading...
Searching...
No Matches
FFT_MKL.h
Go to the documentation of this file.
1//
2// FFT_MKL.h
3// CQTDSP
4//
5// Created by Juan Sierra on 6/11/25.
6//
7
15
16#pragma once
17
18#include <Eigen/Core>
19#include <mkl.h>
20
21using namespace Eigen;
22
23namespace jsa::cicuetea {
24class DFTImpl
25{
26 public:
27 DFTImpl(size_t fftSize) :
28 fftSize(fftSize)
29 {
30 DftiCreateDescriptor(&realSetup, DFTI_DOUBLE, DFTI_REAL, 1, this->fftSize);
31 status += DftiSetValue(realSetup, DFTI_PLACEMENT, DFTI_NOT_INPLACE);
32 status += DftiSetValue(realSetup, DFTI_CONJUGATE_EVEN_STORAGE, DFTI_COMPLEX_COMPLEX);
33 status += DftiSetValue(realSetup, DFTI_FORWARD_SCALE, 1.0);
34 status += DftiSetValue(realSetup, DFTI_BACKWARD_SCALE, 1.0 / fftSize);
35 status += DftiCommitDescriptor(realSetup);
36
37 DftiCreateDescriptor(&cplxSetup, DFTI_DOUBLE, DFTI_COMPLEX, 1, this->fftSize);
38 status += DftiSetValue(realSetup, DFTI_PLACEMENT, DFTI_NOT_INPLACE);
39 status += DftiSetValue(realSetup, DFTI_CONJUGATE_EVEN_STORAGE, DFTI_COMPLEX_COMPLEX);
40 status += DftiSetValue(realSetup, DFTI_FORWARD_SCALE, 1.0);
41 status += DftiSetValue(realSetup, DFTI_BACKWARD_SCALE, 1.0 / fftSize);
42 status += DftiCommitDescriptor(cplxSetup);
43 assert(status == DFTI_NO_ERROR);
44 }
45
46 ~DFTImpl()
47 {
48 if (realSetup) DftiFreeDescriptor(&realSetup);
49 if (cplxSetup) DftiFreeDescriptor(&cplxSetup);
50 }
51
52 void dft(const dcomplex* inPtr, dcomplex* outPtr)
53 {
54 MKL_Complex16* inPtr_ = reinterpret_cast<MKL_Complex16*>(const_cast<dcomplex*>(inPtr));
55 MKL_Complex16* outPtr_ = reinterpret_cast<MKL_Complex16*>(outPtr);
56 DftiComputeForward(cplxSetup, inPtr_, outPtr_);
57 }
58
59 void idft(const dcomplex* inPtr, dcomplex* outPtr)
60 {
61 MKL_Complex16* inPtr_ = reinterpret_cast<MKL_Complex16*>(const_cast<dcomplex*>(inPtr));
62 MKL_Complex16* outPtr_ = reinterpret_cast<MKL_Complex16*>(outPtr);
63 DftiComputeBackward(cplxSetup, inPtr_, outPtr_);
64 }
65
66 void rdft(const double* inPtr, dcomplex* outPtr)
67 {
68 double* inPtr_ = const_cast<double*>(inPtr);
69 MKL_Complex16* outPtr_ = reinterpret_cast<MKL_Complex16*>(outPtr);
70 DftiComputeForward(realSetup, inPtr_, outPtr_);
71 }
72
73 void irdft(const dcomplex* inPtr, double* outPtr)
74 {
75 MKL_Complex16* inPtr_ = reinterpret_cast<MKL_Complex16*>(const_cast<dcomplex*>(inPtr));
76 DftiComputeBackward(cplxSetup, inPtr_, outPtr);
77 }
78
79 static const std::string getName()
80 {
81 return "FFT_MKL";
82 }
83
84 private:
85 const size_t fftSize;
86 DFTI_DESCRIPTOR_HANDLE realSetup;
87 DFTI_DESCRIPTOR_HANDLE cplxSetup;
88 long status = DFTI_NO_ERROR;
89};
90} // namespace jsa::cicuetea
Definition FFT_FFTW.h:25