| 1 |
/* Sound_to_Pitch.h |
| 2 |
* |
| 3 |
* Copyright (C) 1992-2011,2015,2019,2023,2024 Paul Boersma |
| 4 |
* |
| 5 |
* This code is free software; you can redistribute it and/or modify |
| 6 |
* it under the terms of the GNU General Public License as published by |
| 7 |
* the Free Software Foundation; either version 2 of the License, or (at |
| 8 |
* your option) any later version. |
| 9 |
* |
| 10 |
* This code is distributed in the hope that it will be useful, but |
| 11 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 13 |
* See the GNU General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU General Public License |
| 16 |
* along with this work. If not, see <http://www.gnu.org/licenses/>. |
| 17 |
*/ |
| 18 |
|
| 19 |
#include "Sound.h" |
| 20 |
#include "Pitch.h" |
| 21 |
|
| 22 |
autoPitch Sound_to_Pitch (Sound me, double timeStep, |
| 23 |
double pitchFloor, double pitchCeiling); |
| 24 |
/* Calls Sound_to_Pitch_rawAc with default arguments. */ |
| 25 |
|
| 26 |
autoPitch Sound_to_Pitch_rawAc (Sound me, |
| 27 |
double timeStep, double pitchFloor, double pitchCeiling, |
| 28 |
integer maxnCandidates, bool veryAccurate, |
| 29 |
double silenceThreshold, double voicingThreshold, double octaveCost, |
| 30 |
double octaveJumpCost, double voicedUnvoicedCost); |
| 31 |
/* Calls Sound_to_Pitch_any with AC method. */ |
| 32 |
|
| 33 |
autoPitch Sound_to_Pitch_rawCc (Sound me, |
| 34 |
double timeStep, double pitchFloor, double pitchCeiling, |
| 35 |
integer maxnCandidates, bool veryAccurate, |
| 36 |
double silenceThreshold, double voicingThreshold, double octaveCost, |
| 37 |
double octaveJumpCost, double voicedUnvoicedCost); |
| 38 |
/* Calls Sound_to_Pitch_any with FCC method. */ |
| 39 |
|
| 40 |
autoPitch Sound_to_Pitch_any (Sound me, |
| 41 |
int method, // 0 or 1 = AC, 2 or 3 = FCC, 0 or 2 = fast, 1 or 3 = accurate |
| 42 |
double periodsPerWindow, // ac3 for pitch analysis, 6 or 4.5 for HNR, 1 for FCC |
| 43 |
|
| 44 |
double timeStep, // in seconds; 0.0 = automatic = periodsPerWindow / pitchFloor / 4 |
| 45 |
double pitchFloor, // in Hz |
| 46 |
double pitchCeiling, // in Hz |
| 47 |
integer maxnCandidates, // maximum number of candidates per frame |
| 48 |
|
| 49 |
double silenceThreshold, /* relative to purely periodic; default 0.03 */ |
| 50 |
double voicingThreshold, /* relative to purely periodic; default 0.45 */ |
| 51 |
double octaveCost, /* favours higher pitches; default 0.01 */ |
| 52 |
double octaveJumpCost, /* default 0.35 */ |
| 53 |
double voicedUnvoicedCost); /* default 0.14 */ |
| 54 |
/* |
| 55 |
Function: |
| 56 |
acoustic periodicity analysis. |
| 57 |
Preconditions: |
| 58 |
pitchFloor > 0.0; |
| 59 |
maxnCandidates >= 2; |
| 60 |
Return value: |
| 61 |
the resulting pitch contour. |
| 62 |
Failures: |
| 63 |
Out of memory. |
| 64 |
Pitch floor too low. |
| 65 |
Pitch top (or ceiling) should not be greater than the Sound's Nyquist frequency. |
| 66 |
Description for method 0 or 1: |
| 67 |
There is a Hanning window (method == 0) or Gaussian window (method == 1) |
| 68 |
over the analysis window, in order to avoid phase effects. |
| 69 |
Zeroes are appended to the analysis window to avoid edge effects in the FFT. |
| 70 |
An FFT is done on the window, giving a complex spectrum. |
| 71 |
This complex spectrum is squared, thus giving the power spectrum. |
| 72 |
The power spectrum is FFTed back, thus giving the autocorrelation of |
| 73 |
the windowed frame. This autocorrelation is expressed relative to the power, |
| 74 |
which is the autocorrelation for lag 0. The autocorrelation is divided by |
| 75 |
the normalized autocorrelation of the window, in order to bring |
| 76 |
all maxima of the autocorrelation of a periodic signal to the same height. |
| 77 |
General description: |
| 78 |
The maxima are found by sinc interpolation. |
| 79 |
The pitch values (frequencies) of the highest 'maxnCandidates' maxima |
| 80 |
are saved in 'result', together with their strengths (relative correlations). |
| 81 |
A Viterbi algorithm is used to find a smooth path through the candidates, |
| 82 |
using the last six arguments of this function. |
| 83 |
|
| 84 |
The 'pitchCeiling' argument has no influence on the search for candidates. |
| 85 |
It is directly copied into the Pitch object as a hint for considering |
| 86 |
pitches above a certain value "voiceless". |
| 87 |
*/ |
| 88 |
|
| 89 |
autoPitch Sound_to_Pitch_filteredAc (Sound me, |
| 90 |
double timeStep, double pitchFloor, double pitchTop, |
| 91 |
integer maxnCandidates, bool veryAccurate, |
| 92 |
double attenuationAtTop, |
| 93 |
double silenceThreshold, double voicingThreshold, |
| 94 |
double octaveCost, double octaveJumpCost, double voicedUnvoicedCost); |
| 95 |
|
| 96 |
autoPitch Sound_to_Pitch_filteredCc (Sound me, |
| 97 |
double timeStep, double pitchFloor, double pitchTop, |
| 98 |
integer maxnCandidates, bool veryAccurate, |
| 99 |
double attenuationAtTop, |
| 100 |
double silenceThreshold, double voicingThreshold, |
| 101 |
double octaveCost, double octaveJumpCost, double voicedUnvoicedCost); |
| 102 |
|
| 103 |
/* End of file Sound_to_Pitch.h */ |