-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathanmod3m.c
More file actions
132 lines (103 loc) · 3.24 KB
/
Copy pathanmod3m.c
File metadata and controls
132 lines (103 loc) · 3.24 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
122
123
124
125
126
127
128
129
130
131
132
/* anmod3m.c */
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "mex.h"
#include "anmod3m.h"
int an3()
{
int error;
int n;
/* locations of poles */
double ta; /*Pa in Fig. 3 of the paper */
double tb; /*Pb in Fig. 3 of the paper */
double rgain; /* location of the pole closest to imaginary axis */
double nlgain; /* gain for the control signal */
double zero_r; /* Location of zeros */
int delayn; /* forced delay for AN model */
error = 0;
/* overheader, ... will be removed before finish */
for (n=1; n<=sound_length; n=n+1)
{
soundout[n]=2.0*soundin[n];
}
/* end of overheader */
/*=======================================*/
/* parameter setup */
/*=======================================*/
setparameter(cf, &fp1, &ta, &tb, &rgain, &nlgain, &zero_r, &delayn);
middleear();
controlpath(nlgain);
signalpath(ta, tb, rgain, zero_r);
ihczxd2001();
printf("nlgain = %f\n", nlgain); /* This gain, due to the nonlinear control path, varies with CF */
return error;
}
void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )
{
double *mxsoundin;
double *mxsoundout;
double *para;
int mrows;
int ncols;
int mnewvec; /*these two are used to create a new vector */
int nnewvec;
int error;
int length;
int n;
/* Check for proper number of arguments. */
if(nrhs!=2)
mexErrMsgTxt("Required format: sout = an3m(cf,input);");
if(nlhs!=1)
mexErrMsgTxt("You need one output argument");
/* Get the input parameters. */
if((mxGetM(prhs[0])*mxGetN(prhs[0]))!=1)
mexErrMsgTxt("The first input must be cf only");
para = mxGetPr(prhs[0]);
cf = para[0];
/* Get the input */
mxsoundin = mxGetPr(prhs[1]);
/* Get the dimensions of the matrix input in. */
mrows = mxGetM(prhs[1]);
ncols = mxGetN(prhs[1]);
/* Check if it is a vector */
if (mrows!=1 && ncols!=1)
mexErrMsgTxt("The input sound has to be a vector");
/* Create a new vector with index starting from 1 */
if (mrows==1)
{
mnewvec=mrows;
nnewvec=ncols+1;
}
if (ncols==1)
{
mnewvec=mrows+1;
nnewvec=ncols;
}
soundin = mxGetPr(mxCreateDoubleMatrix(mnewvec, nnewvec, mxREAL));
soundout = mxGetPr(mxCreateDoubleMatrix(mnewvec, nnewvec, mxREAL));
meout = mxGetPr(mxCreateDoubleMatrix(mnewvec, nnewvec, mxREAL));
control_signal = mxGetPr(mxCreateDoubleMatrix(mnewvec, nnewvec, mxREAL));
ihc_out = mxGetPr(mxCreateDoubleMatrix(mnewvec, nnewvec, mxREAL));
sout = mxGetPr(mxCreateDoubleMatrix(mnewvec, nnewvec, mxREAL));
/* Set the output pointer to the output matrix. */
plhs[0] = mxCreateDoubleMatrix(mrows,ncols, mxREAL);
mxsoundout = mxGetPr(plhs[0]);
length = mrows*ncols;
/* Get the input */
for (n=1; n<=length; n=n+1)
{
soundin[n]=mxsoundin[n-1];
}
printf("cf=%f, input[1]=%f, length=%d\n",
cf, mxsoundin[1], length);
/* Call the C subroutine. */
sound_length = length;
error = an3();
/* Get the output */
for (n=1; n<=length; n=n+1)
{
mxsoundout[n-1]=sout[n];
}
if(error) mexErrMsgTxt("Error in calling the function.");
}