44 #include "sphinxbase/fixpoint.h"
81 cmn_diff(int16
const *signal,
float *out_diff,
int ndiff)
89 for (t = 1; t < ndiff; ++t) {
92 for (j = 0; j < ndiff; ++j) {
93 int diff = signal[j] - signal[t + j];
97 out_diff[t] = (float)(dd * t / cum);
102 cmn_diff(int16
const *signal, int32 *out_diff,
int ndiff)
112 for (tscale = 0; tscale < 32; ++tscale)
113 if (ndiff & (1<<(31-tscale)))
121 for (t = 1; t < ndiff; ++t) {
122 uint32 dd, dshift, norm;
127 for (j = 0; j < ndiff; ++j) {
128 int diff = signal[j] - signal[t + j];
130 if (dd > (1UL<<tscale)) {
134 dd += (diff * diff) >> dshift;
138 if (dshift > cshift) {
139 cum += dd << (dshift-cshift);
142 cum += dd >> (cshift-dshift);
146 while (cum > (1UL<<tscale)) {
151 if (cum == 0) cum = 1;
153 norm = (t << tscale) / cum;
155 out_diff[t] = (int32)(((
long long)dd * norm)
156 >> (tscale - 15 + cshift - dshift));
165 float search_range,
int smooth_window)
170 pe->frame_size = frame_size;
178 pe->
wsize = smooth_window * 2 + 1;
212 thresholded_search(
float *diff_window,
float threshold,
int start,
int end)
214 thresholded_search(int32 *diff_window, fixed32 threshold,
int start,
int end)
224 min = diff_window[start];
226 for (i = start + 1; i < end; ++i) {
228 float diff = diff_window[i];
230 int diff = diff_window[i];
233 if (diff < threshold) {
249 memcpy(pe->
frame, frame, pe->frame_size *
sizeof(*pe->
frame));
266 difflen = pe->frame_size / 2;
288 int wstart, wlen, half_wsize, i;
289 int best, search_width, low_period, high_period;
296 half_wsize = (pe->
wsize-1)/2;
299 if (half_wsize == 0) {
313 if (pe->
endut == 0 && pe->
nfr < half_wsize + 1) {
327 wlen = pe->
wstart - wstart;
328 if (wlen < 0) wlen += pe->
wsize;
347 for (i = 0; i < wlen; ++i) {
359 if (diff < best_diff) {
373 *out_bestdiff = best_diff;
375 *out_bestdiff = best_diff / 32768.0f;
387 if (search_width == 0) search_width = 1;
388 low_period = best - search_width;
389 high_period = best + search_width;
390 if (low_period < 0) low_period = 0;
391 if (high_period > pe->frame_size / 2) high_period = pe->frame_size / 2;
395 low_period, high_period);
399 *out_period = (best > 65535) ? 65535 : best;
402 *out_bestdiff = (best_diff > 1.0f) ? 1.0f : best_diff;
404 *out_bestdiff = (best_diff > 32768) ? 1.0f : best_diff / 32768.0f;
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.
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.
float search_threshold
Size of analysis frame.
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.
float ** diff_window
Window of difference function outputs.
void yin_store(yin_t *pe, int16 const *frame)
Store a frame of data to the pitch estimator.
int yin_read(yin_t *pe, uint16 *out_period, float *out_bestdiff)
Read a raw estimated pitch value from the pitch estimator.
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.
int16 * frame
Storage for frame.
float search_range
Range around best local estimate to search.
void yin_write_stored(yin_t *pe)
Feed stored frame of data to the pitch estimator.
void yin_write(yin_t *pe, int16 const *frame)
Feed a frame of data to the pitch estimator.