1
2
3
4
5
6
7
8
9
10
11
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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
98
99
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
use crate::;
/**
* Compute the principal argument
*
* This function maps the input phase to its corresponding value wrapped in the range -π ..= π.
*
* - `phase` Unwrapped phase to map to the unit circle
*
* Returns equivalent phase wrapped to the unit circle
*/
/**
* Convert frequency bin to midi value
*/
/**
* Convert midi value to frequency bin
*/
/**
* Convert frequency bin to frequency (Hz)
*
* - `bin` Frequency bin to convert
* - `sample_rate` Sampling rate of the original signal the bin was from
* - `fft_size` Size of the FFT window used to obtain the frequency bin
*/
pub use bin_to_freq as bin_to_hz;
/**
* Convert frequency (Hz) to frequency bin
*
* - `freq` Frequency in Hz to convert
* - `sample_rate` Sampling rate of the original signal the bin was from
* - `fft_size` Size of the FFT window used to obtain the frequency bin
*/
pub use freq_to_bin as hz_to_bin;
/**
* Convert frequency (Hz) to mel
*
* - `freq` Input frequency in Hz to convert
*
* Converts a scalar from the frequency domain to the mel scale using Slaney
* Auditory Toolbox's implementation:
*
* If f < 1000, m = 3 f / 200.
* If f >= 1000, m = 1000 + 27 * (ln(f) - ln(1000)) / (ln(6400) - ln(1000))
*
* See also `mel_to_hz()`, `hz_to_mel_htk()`.
*/
/**
* Convert mel to frequency (Hz)
*
* - `mel` Input mel to convert
*
* Converts a scalar from the mel scale to the frequency domain using Slaney
* Auditory Toolbox's implementation:
*
* If f < 1000, f = 200 m/3.
* If f >= 1000, f = 1000 + (6400 / 1000) ^ ((m - 1000) / 27)
*
* See also `hz_to_mel()`, `mel_to_hz_htk()`.
*
* See:
* - Malcolm Slaney, *Auditory Toolbox Version 2, Technical Report #1998-010*
* https://engineering.purdue.edu/~malcolm/interval/1998-010/
*/
/**
* Convert frequency (Hz) to mel
*
* - `freq` Input frequency to convert, in Hz
*
* Converts a scalar from the frequency domain to the mel scale, using the
* equation defined by O'Shaughnessy, as implemented in the HTK speech
* recognition toolkit:
*
* m = 1127 + ln(1 + f / 700)
*
* See also `mel_to_hz_htk()`, `hz_to_mel()`.
*
* See:
* - Douglas O'Shaughnessy (1987). *Speech communication: human and machine*.
* Addison-Wesley. p. 150. ISBN 978-0-201-16520-3.
* - HTK Speech Recognition Toolkit: http://htk.eng.cam.ac.uk/
*/
/**
* Convert mel to frequency (Hz)
*
* - `mel` Input mel to convert
*
* Converts a scalar from the mel scale to the frequency domain, using the
* equation defined by O'Shaughnessy, as implemented in the HTK speech
* recognition toolkit:
*
* f = 700 * e ^ (f / 1127 - 1)
*
* See also `hz_to_mel_htk()`, `mel_to_hz()`.
*/
/**
* Convert frequency (Hz) to midi value in range 0..128
*
* - `freq` Frequency in Hz to convert
*/
/**
* Convert midi value in range 0..128 to frequency (Hz)
*
* - `midi` Midi note value to convert (0..128)
*/
/**
* Zero-crossing rate (ZCR)
*
* The zero-crossing rate is the number of times a signal changes sign,
* divided by the length of this signal.
*
* - `input` Vector to compute ZCR from
*/
/**
* Compute sound level on a linear scale.
*
* This gives the average of the square amplitudes.
*
* - `input` Vector to compute level from
*/
/**
* Compute sound pressure level (SPL) in dB.
*
* This quantity is often wrongly called "loudness".
* This gives ten times the log10 of the average of the square amplitudes.
*
* - `input` Vector to compute dB SPL from.
*/
/**
* Check if buffer level in dB SPL is under a given threshold.
*
* Returns `true` if the level is under the threshold, `false` otherwise.
*
* Note: this is currently the opposite of the official doc, which seems to
* have a typo in it.
*
* - `input` Vector to get level from
* - `threshold` Threshold in dB SPL
*/
/**
* Get buffer level if level >= threshold, 1.0 otherwise
*
* - `input` Vector to get level from
* - `threshold` Threshold in dB SPL
*/