8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation; either
11 version 2.1 of the License, or (at your option) any later version.
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public
19 License along with this library; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28 float inner_prod(float *x
, float *y
, int len
)
39 void find_pitch(float *x
, float *gain
, float *pitch
, int start
, int end
, int len
)
45 for (i
=start
;i
<=end
;i
++)
48 corr
= inner_prod(x
,x
-i
,len
);
49 E
= inner_prod(x
-i
,x
-i
,len
);
50 //E = inner_prod(x,x,len);
52 score
= corr
*fabs(corr
)/(1e4
+E
);
54 if (score
> max_score
|| i
==start
)
61 if (p
== start
|| p
== end
)
65 *pitch
= p
+.5*(sc
[p
+1]-sc
[p
-1])/(2*sc
[p
]-sc
[p
-1]-sc
[p
+1]);
70 void find_spectral_pitch(float *x
, float *y
, int lag
, int len
, int *pitch
, float *curve
)
76 fft
= spx_fft_init(lag
);
93 float n
= 1.f
/(1e1
+sqrt((X
[2*i
-1]*X
[2*i
-1] + X
[2*i
]*X
[2*i
])*(Y
[2*i
-1]*Y
[2*i
-1] + Y
[2*i
]*Y
[2*i
])));
100 float tmp
= X
[2*i
-1];
101 X
[2*i
-1] = (X
[2*i
-1]*Y
[2*i
-1] + X
[2*i
]*Y
[2*i
])*n
;
102 X
[2*i
] = (- X
[2*i
]*Y
[2*i
-1] + tmp
*Y
[2*i
])*n
;
106 spx_ifft(fft
, X
, xx
);
111 for (i
=0;i
<lag
-len
;i
++)
113 //printf ("%f ", xx[i]);
114 if (xx
[i
] > max_corr
)
120 //printf ("%d\n", *pitch);