44#include "sphinxbase/fixpoint.h"
69cmn_diff(int16
const *signal, int32 *out_diff,
int ndiff)
79 for (tscale = 0; tscale < 32; ++tscale)
80 if (ndiff & (1<<(31-tscale)))
88 for (t = 1; t < ndiff; ++t) {
89 uint32 dd, dshift, norm;
94 for (j = 0; j < ndiff; ++j) {
95 int diff = signal[j] - signal[t + j];
97 if (dd > (1UL<<tscale)) {
101 dd += (diff * diff) >> dshift;
105 if (dshift > cshift) {
106 cum += dd << (dshift-cshift);
109 cum += dd >> (cshift-dshift);
113 while (cum > (1UL<<tscale)) {
118 if (cum == 0) cum = 1;
120 norm = (t << tscale) / cum;
122 out_diff[t] = (int32)(((
long long)dd * norm)
123 >> (tscale - 15 + cshift - dshift));
131 float search_range,
int smooth_window)
136 pe->frame_size = frame_size;
139 pe->
wsize = smooth_window * 2 + 1;
171thresholded_search(int32 *diff_window, fixed32 threshold,
int start,
int end)
177 for (i = start; i < end; ++i) {
178 int diff = diff_window[i];
180 if (diff < threshold) {
207 difflen = pe->frame_size / 2;
223 int wstart, wlen, half_wsize, i;
224 int best, best_diff, search_width, low_period, high_period;
226 half_wsize = (pe->
wsize-1)/2;
229 if (half_wsize == 0) {
239 if (pe->
endut == 0 && pe->
nfr < half_wsize + 1) {
253 wlen = pe->
wstart - wstart;
254 if (wlen < 0) wlen += pe->
wsize;
273 for (i = 0; i < wlen; ++i) {
281 if (diff < best_diff) {
294 *out_bestdiff = best_diff;
301 if (search_width == 0) search_width = 1;
302 low_period = best - search_width;
303 high_period = best + search_width;
304 if (low_period < 0) low_period = 0;
305 if (high_period > pe->frame_size / 2) high_period = pe->frame_size / 2;
309 low_period, high_period);
313 *out_period = (best > 65535) ? 65535 : best;
315 *out_bestdiff = (best_diff > 65535) ? 65535 : best_diff;
Sphinx's memory allocation/deallocation routines.
SPHINXBASE_EXPORT void ckd_free(void *ptr)
Test and free a 1-D array.
SPHINXBASE_EXPORT void ckd_free_2d(void *ptr)
Free a 2-D array (ptr) previously allocated by ckd_calloc_2d.
#define ckd_calloc_2d(d1, d2, sz)
Macro for ckd_calloc_2d
#define ckd_calloc(n, sz)
Macros to simplify the use of above functions.
Basic type definitions used in Sphinx.
unsigned char wsize
Size of smoothing window.
unsigned char wstart
First frame in window.
uint16 * period_window
Window of best period estimates.
uint16 search_range
Range around best local estimate to search, in Q15.
unsigned char endut
Hoch Hech! Are we at the utterance end?
uint16 search_threshold
Size of analysis frame.
fixed32 ** diff_window
Window of difference function outputs.
unsigned char wcur
Current frame of analysis.
uint16 nfr
Number of frames read so far.
int yin_read(yin_t *pe, uint16 *out_period, uint16 *out_bestdiff)
Read a raw estimated pitch value from the pitch estimator.
void yin_free(yin_t *pe)
Free a moving-window pitch estimator.
void yin_end(yin_t *pe)
Mark the end of an utterance.
yin_t * yin_init(int frame_size, float search_threshold, float search_range, int smooth_window)
Initialize moving-window pitch estimation.
void yin_write(yin_t *pe, int16 const *frame)
Feed a frame of data to the pitch estimator.
void yin_start(yin_t *pe)
Start processing an utterance.
Implementation of pitch estimation.