git-svn-id: http://moon:8086/svn/matlab/trunk@127 801c6759-fa7c-4059-a304-17956f83a07c
71 lines
1.5 KiB
C
71 lines
1.5 KiB
C
#include <mex.h>
|
|
#include <math.h>
|
|
void mexFunction (int nlhs, mxArray *plhs[],
|
|
int nrhs, const mxArray *prhs[])
|
|
{
|
|
const char *funcName = mexFunctionName ();
|
|
mexPrintf ("You called function: %s\n", funcName);
|
|
mexPrintf ("I have %d inputs and %d outputs\n", nrhs, nlhs);
|
|
|
|
if (nrhs < 3)
|
|
mexErrMsgTxt ("Too few arguments");
|
|
|
|
const mxArray *array_x = prhs[0];
|
|
const mxArray *scalar_alpha_attack = prhs[1];
|
|
const mxArray *scalar_alpha_release = prhs[2];
|
|
|
|
|
|
plhs[0] = mxCreateNumericArray (mxGetNumberOfDimensions (array_x),
|
|
mxGetDimensions (array_x),
|
|
mxGetClassID (array_x),
|
|
mxIsComplex (array_x));
|
|
|
|
mwIndex channelsDim = 1;
|
|
double alpha_a = *mxGetPr(scalar_alpha_attack);
|
|
double alpha_r = *mxGetPr(scalar_alpha_release);
|
|
|
|
double *vri = mxGetPr (array_x);
|
|
double *vro = mxGetPr (plhs[0]);
|
|
|
|
mwSize M = mxGetM (array_x);
|
|
mwSize N = mxGetN (array_x);
|
|
if (channelsDim == 1)
|
|
{
|
|
M = mxGetN (array_x);
|
|
N = mxGetM (array_x);
|
|
}
|
|
|
|
mexPrintf ("Number of channels = %u\n", M);
|
|
mexPrintf ("Number of samples per channel = %u\n", N);
|
|
mexPrintf ("alpha_a = %f\n", alpha_a);
|
|
mexPrintf ("alpha_r = %f\n", alpha_r);
|
|
|
|
double level[M];
|
|
for (mwIndex m=0; m < M; m++)
|
|
{
|
|
level[m] = 0;
|
|
}
|
|
|
|
for (mwIndex n=0; n < N; n++)
|
|
{
|
|
for (mwIndex m=0; m < M; m++)
|
|
{
|
|
double x = vri[n*M + m];
|
|
double xmag = fabs(x);
|
|
|
|
if (xmag > level[m])
|
|
{
|
|
level[m] = (1.0-alpha_a)*level[m] + alpha_a*xmag;
|
|
}
|
|
else
|
|
{
|
|
level[m] = (1.0-alpha_r)*level[m];
|
|
}
|
|
vro[n*M + m] = level[m];
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|