| 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 <[email protected]> |
| 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 |
* Feed 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_write(yin_t *pe, int16 const *frame); |
| 95 |
|
| 96 |
/** |
| 97 |
* Read a raw estimated pitch value from the pitch estimator. |
| 98 |
* |
| 99 |
* @param pe Pitch estimator. |
| 100 |
* @param out_period Output: an estimate of the period (*not* the pitch) |
| 101 |
* of the signal in samples. |
| 102 |
* @param out_bestdiff Output: the minimum normalized difference value |
| 103 |
* associated with <code>*out_pitch</code>, in Q15 |
| 104 |
* format (i.e. scaled by 32768). This can be |
| 105 |
* interpreted as one minus the probability of voicing. |
| 106 |
* @return Non-zero if enough data was avaliable to return a pitch |
| 107 |
* estimate, zero otherwise. |
| 108 |
*/ |
| 109 |
SPHINXBASE_EXPORT |
| 110 |
int yin_read(yin_t *pe, uint16 *out_period, uint16 *out_bestdiff); |
| 111 |
|
| 112 |
#ifdef __cplusplus |
| 113 |
} |
| 114 |
#endif |
| 115 |
|
| 116 |
#endif /* __YIN_H__ */ |