compute_yin
compute_pitch(sig_torch, sr, w_len=1024, w_step=256, f0_min=50, f0_max=1000, harmo_thresh=0.25)
Compute the pitch of an audio signal using the Yin algorithm.
The Yin algorithm is a widely used method for pitch detection in speech and music signals. This function uses the Yin algorithm to compute the pitch of the input audio signal, and then normalizes and interpolates the pitch values. Returns the normalized and interpolated pitch values.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sig_torch |
Tensor
|
The audio signal as a 1D numpy array of floats. |
required |
sr |
int
|
The sampling rate of the signal. |
required |
w_len |
int
|
The size of the analysis window in samples. |
1024
|
w_step |
int
|
The size of the lag between two consecutive windows in samples. |
256
|
f0_min |
int
|
The minimum fundamental frequency that can be detected in Hz. |
50
|
f0_max |
int
|
The maximum fundamental frequency that can be detected in Hz. |
1000
|
harmo_thresh |
float
|
The threshold of detection. The algorithm returns the first minimum of the CMND function below this threshold. |
0.25
|
Returns:
Type | Description |
---|---|
np.ndarray: The normalized and interpolated pitch values of the audio signal. |
Source code in training/preprocess/compute_yin.py
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
|
compute_yin(sig_torch, sr, w_len=512, w_step=256, f0_min=100, f0_max=500, harmo_thresh=0.1)
Compute the Yin Algorithm for pitch detection on an audio signal.
The Yin Algorithm is a widely used method for pitch detection in speech and music signals. It works by computing the Cumulative Mean Normalized Difference function (CMND) of the difference function of the signal, and finding the first minimum of the CMND below a given threshold. The fundamental period of the signal is then estimated as the inverse of the lag corresponding to this minimum.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sig_torch |
Tensor
|
The audio signal as a 1D numpy array of floats. |
required |
sr |
int
|
The sampling rate of the signal. |
required |
w_len |
int
|
The size of the analysis window in samples. Defaults to 512. |
512
|
w_step |
int
|
The size of the lag between two consecutive windows in samples. Defaults to 256. |
256
|
f0_min |
int
|
The minimum fundamental frequency that can be detected in Hz. Defaults to 100. |
100
|
f0_max |
int
|
The maximum fundamental frequency that can be detected in Hz. Defaults to 500. |
500
|
harmo_thresh |
float
|
The threshold of detection. The algorithm returns the first minimum of the CMND function below this threshold. Defaults to 0.1. |
0.1
|
Returns:
Type | Description |
---|---|
Tuple[ndarray, List[float], List[float], List[float]]
|
Tuple[np.ndarray, List[float], List[float], List[float]]: A tuple containing the following elements: * pitches (np.ndarray): A 1D numpy array of fundamental frequencies estimated for each analysis window. * harmonic_rates (List[float]): A list of harmonic rate values for each fundamental frequency value, which can be interpreted as a confidence value. * argmins (List[float]): A list of the minimums of the Cumulative Mean Normalized Difference Function for each analysis window. * times (List[float]): A list of the time of each estimation, in seconds. |
References
[1] A. K. Jain, Fundamentals of Digital Image Processing, Prentice Hall, 1989. [2] A. de Cheveigné and H. Kawahara, "YIN, a fundamental frequency estimator for speech and music," The Journal of the Acoustical Society of America, vol. 111, no. 4, pp. 1917-1930, 2002.
Source code in training/preprocess/compute_yin.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
|
cumulativeMeanNormalizedDifferenceFunction(df, N)
Compute the cumulative mean normalized difference function (CMND) of a difference function.
The CMND is defined as the element-wise product of the difference function with a range of values from 1 to N-1, divided by the cumulative sum of the difference function up to that point, plus a small epsilon value to avoid division by zero. The first element of the CMND is set to 1.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df |
ndarray
|
The difference function. |
required |
N |
int
|
The length of the data. |
required |
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: The cumulative mean normalized difference function. |
References
[1] K. K. Paliwal and R. P. Sharma, "A robust algorithm for pitch detection in noisy speech signals," Speech Communication, vol. 12, no. 3, pp. 249-263, 1993.
Source code in training/preprocess/compute_yin.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
|
differenceFunction(x, N, tau_max)
Compute the difference function of an audio signal.
This function computes the difference function of an audio signal x
using the algorithm described in equation (6) of [1]. The difference function is a measure of the similarity between the signal and a time-shifted version of itself, and is commonly used in pitch detection algorithms.
This implementation uses the NumPy FFT functions to compute the difference function efficiently.
Parameters x (np.ndarray): The audio signal to compute the difference function for. N (int): The length of the audio signal. tau_max (int): The maximum integration window size to use.
Returns np.ndarray: The difference function of the audio signal.
References [1] A. de Cheveigné and H. Kawahara, "YIN, a fundamental frequency estimator for speech and music," The Journal of the Acoustical Society of America, vol. 111, no. 4, pp. 1917-1930, 2002.
Source code in training/preprocess/compute_yin.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
|
getPitch(cmdf, tau_min, tau_max, harmo_th=0.1)
Compute the fundamental period of a frame based on the Cumulative Mean Normalized Difference function (CMND).
The CMND is a measure of the periodicity of a signal, and is computed as the cumulative mean normalized difference
function of the difference function of the signal. The fundamental period is the first value of the index tau
between tau_min
and tau_max
where the CMND is below the harmo_th
threshold. If there are no such values, the
function returns 0 to indicate that the signal is unvoiced.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cmdf |
ndarray
|
The Cumulative Mean Normalized Difference function of the signal. |
required |
tau_min |
int
|
The minimum period for speech. |
required |
tau_max |
int
|
The maximum period for speech. |
required |
harmo_th |
float
|
The harmonicity threshold to determine if it is necessary to compute pitch frequency. Defaults to 0.1. |
0.1
|
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
The fundamental period of the signal, or 0 if the signal is unvoiced. |
References
[1] K. K. Paliwal and R. P. Sharma, "A robust algorithm for pitch detection in noisy speech signals," Speech Communication, vol. 12, no. 3, pp. 249-263, 1993.
Source code in training/preprocess/compute_yin.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
|
norm_interp_f0(f0)
Normalize and interpolate the fundamental frequency (f0) values.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
f0 |
ndarray
|
The input f0 values. |
required |
Returns:
Type | Description |
---|---|
Tuple[ndarray, ndarray]
|
Tuple[np.ndarray, np.ndarray]: A tuple containing the normalized f0 values and a boolean array indicating which values were interpolated. |
Examples:
>>> f0 = np.array([0, 100, 0, 200, 0])
>>> norm_interp_f0(f0)
(
np.array([100, 100, 150, 200, 200]),
np.array([True, False, True, False, True]),
)
Source code in training/preprocess/compute_yin.py
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
|