1 /* -*- c-basic-offset: 4; indent-tabs-mode: nil -*- */ 2 /* 3 * Copyright (c) 2008 Beyond Access, Inc. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in 14 * the documentation and/or other materials provided with the 15 * distribution. 16 * 17 * THIS SOFTWARE IS PROVIDED BY BEYOND ACCESS, INC. ``AS IS'' AND ANY 18 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 20 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BEYOND ACCESS, INC. NOR 21 * ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 24 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 25 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 26 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 */ 29 30 /** 31 * @file yin.h 32 * @brief Implementation of pitch estimation 33 * @author David Huggins-Daines <dhuggins@cs.cmu.edu> 34 * 35 * This implements part of the YIN algorithm: 36 * 37 * "YIN, a fundamental frequency estimator for speech and music". 38 * Alain de Cheveigné and Hideki Kawahara. Journal of the Acoustical 39 * Society of America, 111 (4), April 2002. 40 */ 41 42 #ifndef __YIN_H__ 43 #define __YIN_H__ 44 45 #ifdef __cplusplus 46 extern "C" 47 #endif 48 #if 0 49 } /* Fool Emacs. */ 50 #endif 51 52 /* Win32/WinCE DLL gunk */ 53 #include <sphinxbase/sphinxbase_export.h> 54 #include <sphinxbase/prim_type.h> 55 56 /** 57 * Frame-based moving-window pitch estimator. 58 */ 59 typedef struct yin_s yin_t; 60 61 /** 62 * Initialize moving-window pitch estimation. 63 */ 64 SPHINXBASE_EXPORT 65 yin_t *yin_init(int frame_size, float search_threshold, 66 float search_range, int smooth_window); 67 68 /** 69 * Free a moving-window pitch estimator. 70 */ 71 SPHINXBASE_EXPORT 72 void yin_free(yin_t *pe); 73 74 /** 75 * Start processing an utterance. 76 */ 77 SPHINXBASE_EXPORT 78 void yin_start(yin_t *pe); 79 80 /** 81 * Mark the end of an utterance. 82 */ 83 SPHINXBASE_EXPORT 84 void yin_end(yin_t *pe); 85 86 /** 87 * Store a frame of data to the pitch estimator. 88 * 89 * @param pe Pitch estimator. 90 * @param frame Frame of <code>frame_size</code> (see 91 * yin_init()) samples of audio data. 92 */ 93 SPHINXBASE_EXPORT 94 void yin_store(yin_t *pe, int16 const *frame); 95 96 /** 97 * Feed a frame of data to the pitch estimator. 98 * 99 * @param pe Pitch estimator. 100 * @param frame Frame of <code>frame_size</code> (see 101 * yin_init()) samples of audio data. 102 */ 103 SPHINXBASE_EXPORT 104 void yin_write(yin_t *pe, int16 const *frame); 105 106 /** 107 * Feed stored frame of data to the pitch estimator. 108 * (see yin_store()) 109 * 110 * @param pe Pitch estimator. 111 */ 112 SPHINXBASE_EXPORT 113 void yin_write_stored(yin_t *pe); 114 115 /** 116 * Read a raw estimated pitch value from the pitch estimator. 117 * 118 * @param pe Pitch estimator. 119 * @param out_period Output: an estimate of the period (*not* the pitch) 120 * of the signal in samples. 121 * @param out_bestdiff Output: the minimum normalized difference value 122 * associated with <code>*out_pitch</code>, in Q15 123 * format (i.e. scaled by 32768). This can be 124 * interpreted as one minus the probability of voicing. 125 * @return Non-zero if enough data was avaliable to return a pitch 126 * estimate, zero otherwise. 127 */ 128 SPHINXBASE_EXPORT 129 int yin_read(yin_t *pe, uint16 *out_period, float *out_bestdiff); 130 131 #ifdef __cplusplus 132 } 133 #endif 134 135 #endif /* __YIN_H__ */ 136 137