Debian Codegraph @

melder/NUMear.cpp

raw symbols SCIP
1 /* NUMear.cpp
2 *
3 * Copyright (C) 1992-2011,2016-2018,2023 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 "melder.h"
20
21 double NUMhertzToBark (double hertz) {
22 const double r = hertz / 650.0;
23 return hertz < 0.0 ? undefined : 7.0 * log (r + sqrt (1.0 + r * r));
24 }
25 double NUMbarkToHertz (double bark) {
26 return bark < 0.0 ? undefined : 650.0 * sinh (bark / 7.0);
27 }
28
29 double NUMphonToDifferenceLimens (double phon) {
30 return phon < 0.0 ? undefined : 30.0 * (pow (61.0 / 60.0, phon) - 1.0);
31 }
32 double NUMdifferenceLimensToPhon (double ndli) {
33 return ndli < 0.0 ? undefined : log (1.0 + ndli / 30.0) / log (61.0 / 60.0);
34 }
35
36 double NUMsoundPressureToPhon (double soundPressure, double bark) {
37 if (soundPressure <= 0.0 || bark < 0.0)
38 return undefined;
39
40 /* dB = 20 * log10 (soundPressure / threshold) */
41 double result = 20.0 * log10 (soundPressure / 2.0e-5); // first approximation: phon = dB
42
43 /* Phones from dB */
44 if (result < 90.0 && bark < 8.0)
45 result -= sqr ((90.0 - result) * (8.0 - bark)) / 2500.0;
46
47 result += 5.0 * exp (- sqr (bark / 3.6 - 5.0));
48 if (bark > 20.0)
49 result -= 0.5 * sqr (bark - 20.0);
50 Melder_clipLeft (0.0, & result);
51 return result;
52 }
53
54 double NUMhertzToMel (double hertz) {
55 return hertz < 0.0 ? undefined : 550.0 * log (1.0 + hertz / 550.0);
56 }
57 double NUMmelToHertz (double mel) {
58 return mel < 0.0 ? undefined : 550.0 * (exp (mel / 550.0) - 1.0);
59 }
60
61 double NUMhertzToSemitones (double hertz) {
62 return hertz <= 0.0 ? undefined : 12.0 * log (hertz / 100.0) / NUMln2;
63 }
64 double NUMsemitonesToHertz (double semitones) {
65 return isundef (semitones) ? undefined : 100.0 * exp (semitones * (NUMln2 / 12.0));
66 }
67
68 /* Moore & Glasberg 1983 JASA 74: 750 */
69
70 double NUMerb (double f) {
71 return 6.23e-6 * f * f + 0.09339 * f + 28.52;
72 }
73 double NUMhertzToErb (double hertz) {
74 return hertz < 0.0 ? undefined : 11.17 * log ((hertz + 312.0) / (hertz + 14680.0)) + 43.0;
75 }
76 double NUMerbToHertz (double erb) {
77 double dum = exp ((erb - 43.0) / 11.17);
78 return erb < 0.0 ? undefined : (14680.0 * dum - 312.0) / (1.0 - dum);
79 }
80
81 /* End of file NUMear.cpp */