[ba1662]: mex / comp_filterbank_fft.c Maximize Restore History

Download this file

comp_filterbank_fft.c    126 lines (104 with data), 3.3 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#ifndef _LTFAT_MEX_FILE
#define _LTFAT_MEX_FILE
#define ISNARGINEQ 3
#define TYPEDEPARGS 0, 1
#define SINGLEARGS
#define COMPLEXARGS
#define EXPORTALIAS comp_filterbank_fft
#endif // _LTFAT_MEX_FILE - INCLUDED ONCE
#define MEX_FILE __BASE_FILE__
#include "ltfat_mex_template_helper.h"
#if defined(LTFAT_SINGLE) || defined(LTFAT_DOUBLE)
#include "ltfat_types.h"
#include "math.h"
#include "config.h"
static LTFAT_FFTW(plan)* LTFAT_NAME(oldPlans) = 0;
static mwSize* LTFAT_NAME(oldLc) = 0;
static mwSize LTFAT_NAME(oldM) = 0;
// Calling convention:
// c = comp_filterbank_fft(F,G,a)
void LTFAT_NAME(fftMexAtExitFnc)()
{
#ifdef _DEBUG
mexPrintf("Exit fnc called: %s\n",__PRETTY_FUNCTION__);
#endif
if(LTFAT_NAME(oldPlans)!=0)
{
for(mwIndex m=0; m<LTFAT_NAME(oldM); m++)
{
if(LTFAT_NAME(oldPlans)[m]!=0)
{
LTFAT_FFTW(destroy_plan)(LTFAT_NAME(oldPlans)[m]);
}
}
ltfat_free(LTFAT_NAME(oldPlans));
LTFAT_NAME(oldPlans) = 0;
}
if(LTFAT_NAME(oldLc)!=0)
{
ltfat_free(LTFAT_NAME(oldLc));
LTFAT_NAME(oldLc) = 0;
}
LTFAT_NAME(oldM) = 0;
}
void LTFAT_NAME(ltfatMexFnc)( int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[] )
{
static int atExitFncRegistered = 0;
if(!atExitFncRegistered)
{
LTFAT_NAME(ltfatMexAtExit)(LTFAT_NAME(fftMexAtExitFnc));
atExitFncRegistered = 1;
}
const mxArray* mxF = prhs[0];
const mxArray* mxG = prhs[1];
double* aDouble = mxGetData(prhs[2]);
// input data length
mwSize L = mxGetM(mxF);
// number of channels
mwSize W = mxGetN(mxF);
// filter number
mwSize M = mxGetNumberOfElements(mxG);
// output lengths
mwSize outLen[M];
// Hop sizes
mwSize a[M];
// Filter pointer array
LTFAT_COMPLEX* GPtrs[M];
// POINTER TO THE INPUT
LTFAT_COMPLEX* FPtr = mxGetData(prhs[0]);
// POINTER TO OUTPUTS
LTFAT_COMPLEX* cPtrs[M]; // C99 feature
plhs[0] = mxCreateCellMatrix(M, 1);
if(M!=LTFAT_NAME(oldM))
{
LTFAT_NAME(fftMexAtExitFnc)();
LTFAT_NAME(oldM) = M;
LTFAT_NAME(oldLc) = ltfat_calloc(M,sizeof(mwSize));
LTFAT_NAME(oldPlans) = ltfat_calloc(M,sizeof(LTFAT_FFTW(plan)));
}
for(mwIndex m=0; m<M; ++m)
{
a[m] = (mwSize) aDouble[m];
outLen[m] = (mwSize) ceil( L/a[m] );
GPtrs[m] = (LTFAT_COMPLEX*) mxGetPr(mxGetCell(mxG, m));
mxSetCell(plhs[0], m,
ltfatCreateMatrix(outLen[m], W, LTFAT_MX_CLASSID,mxCOMPLEX));
cPtrs[m] = (LTFAT_COMPLEX*) mxGetData(mxGetCell(plhs[0],m));
if(LTFAT_NAME(oldLc)[m]!=outLen[m])
{
LTFAT_NAME(oldLc)[m] = outLen[m];
LTFAT_FFTW(plan) ptmp = LTFAT_FFTW(plan_dft_1d)(
outLen[m],cPtrs[m],cPtrs[m],
FFTW_BACKWARD, FFTW_OPTITYPE);
if(LTFAT_NAME(oldPlans)[m]!=0)
{
LTFAT_FFTW(destroy_plan)(LTFAT_NAME(oldPlans)[m]);
}
LTFAT_NAME(oldPlans)[m]=ptmp;
}
}
LTFAT_NAME(filterbank_fft_plans)(FPtr, GPtrs, L, W, a, M,
cPtrs, LTFAT_NAME(oldPlans));
}
#endif