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;
uint16 * period_window
Window of best period estimates.
#define ckd_calloc_2d(d1, d2, sz)
Macro for ckd_calloc_2d
unsigned char wstart
First frame in window.
#define ckd_calloc(n, sz)
Macros to simplify the use of above functions.
int yin_read(yin_t *pe, uint16 *out_period, uint16 *out_bestdiff)
Read a raw estimated pitch value from the pitch estimator.
Sphinx's memory allocation/deallocation routines.
void yin_start(yin_t *pe)
Start processing an utterance.
unsigned char endut
Hoch Hech! Are we at the utterance end?
uint16 nfr
Number of frames read so far.
Basic type definitions used in Sphinx.
unsigned char wsize
Size of smoothing window.
SPHINXBASE_EXPORT void ckd_free(void *ptr)
Test and free a 1-D array.
unsigned char wcur
Current frame of analysis.
yin_t * yin_init(int frame_size, float search_threshold, float search_range, int smooth_window)
Initialize moving-window pitch estimation.
uint16 search_range
Range around best local estimate to search, in Q15.
fixed32 ** diff_window
Window of difference function outputs.
Implementation of pitch estimation.
void yin_free(yin_t *pe)
Free a moving-window pitch estimator.
void yin_end(yin_t *pe)
Mark the end of an utterance.
SPHINXBASE_EXPORT void ckd_free_2d(void *ptr)
Free a 2-D array (ptr) previously allocated by ckd_calloc_2d.
uint16 search_threshold
Size of analysis frame.
void yin_write(yin_t *pe, int16 const *frame)
Feed a frame of data to the pitch estimator.