44 #include "sphinxbase/fixpoint.h"
70 cmn_diff(int16
const *signal, int32 *out_diff,
int ndiff)
80 for (tscale = 0; tscale < 32; ++tscale)
81 if (ndiff & (1<<(31-tscale)))
89 for (t = 1; t < ndiff; ++t) {
90 uint32 dd, dshift, norm;
95 for (j = 0; j < ndiff; ++j) {
96 int diff = signal[j] - signal[t + j];
98 if (dd > (1UL<<tscale)) {
102 dd += (diff * diff) >> dshift;
106 if (dshift > cshift) {
107 cum += dd << (dshift-cshift);
110 cum += dd >> (cshift-dshift);
114 while (cum > (1UL<<tscale)) {
119 if (cum == 0) cum = 1;
121 norm = (t << tscale) / cum;
123 out_diff[t] = (int32)(((
long long)dd * norm)
124 >> (tscale - 15 + cshift - dshift));
132 float search_range,
int smooth_window)
137 pe->frame_size = frame_size;
140 pe->
wsize = smooth_window * 2 + 1;
172 thresholded_search(int32 *diff_window, fixed32 threshold,
int start,
int end)
178 for (i = start; i < end; ++i) {
179 int diff = diff_window[i];
181 if (diff < threshold) {
208 difflen = pe->frame_size / 2;
224 int wstart, wlen, half_wsize, i;
225 int best, best_diff, search_width, low_period, high_period;
227 half_wsize = (pe->
wsize-1)/2;
230 if (half_wsize == 0) {
240 if (pe->
endut == 0 && pe->
nfr < half_wsize + 1) {
254 wlen = pe->
wstart - wstart;
255 if (wlen < 0) wlen += pe->
wsize;
274 for (i = 0; i < wlen; ++i) {
282 if (diff < best_diff) {
295 *out_bestdiff = best_diff;
302 if (search_width == 0) search_width = 1;
303 low_period = best - search_width;
304 high_period = best + search_width;
305 if (low_period < 0) low_period = 0;
306 if (high_period > pe->frame_size / 2) high_period = pe->frame_size / 2;
310 low_period, high_period);
314 *out_period = (best > 32768) ? 32768 : best;
316 *out_bestdiff = (best_diff > 32768) ? 32768 : best_diff;