Debian Codegraph @

fon/Pitch_to_Sound.cpp

raw symbols SCIP
1 /* Pitch_to_Sound.cpp
2 *
3 * Copyright (C) 1992-2011,2015,2016,2017,2022 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 "Pitch_to_PointProcess.h"
20 #include "PointProcess_and_Sound.h"
21 #include "Pitch_to_Sound.h"
22 #include "PitchTier_to_Sound.h"
23 #include "Pitch_to_PitchTier.h"
24
25 autoSound Pitch_to_Sound (Pitch me, double tmin, double tmax, bool hum) {
26 static double formant [1 + 6] { 0.0, 600.0, 1400.0, 2400.0, 3400.0, 4500.0, 5500.0 };
27 static double bandwidth [1 + 6] { 0.0, 50.0, 100.0, 200.0, 300.0, 400.0, 500.0 };
28 try {
29 autoPointProcess point = Pitch_to_PointProcess (me);
30 autoSound sound = PointProcess_to_Sound_pulseTrain (point.get(), 44100.0, 0.7, 0.05, 30);
31 if (hum)
32 Sound_filterWithFormants (sound.get(), tmin, tmax, 6, formant, bandwidth);
33 return sound;
34 } catch (MelderError) {
35 Melder_throw (me, U": not converted to Sound.");
36 }
37 }
38
39 void Pitch_play (Pitch me, double tmin, double tmax) { // BUG: why no callback?
40 try {
41 Function_unidirectionalAutowindow (me, & tmin, & tmax);
42 autoSound sound = Pitch_to_Sound (me, tmin, tmax, false);
43 Sound_playPart (sound.get(), tmin, tmax, nullptr, nullptr);
44 } catch (MelderError) {
45 Melder_throw (me, U": not played.");
46 }
47 }
48
49 void Pitch_hum (Pitch me, double tmin, double tmax, Sound_PlayCallback playCallback, Thing playBoss) {
50 try {
51 Function_unidirectionalAutowindow (me, & tmin, & tmax);
52 autoSound sound = Pitch_to_Sound (me, tmin, tmax, true);
53 Sound_playPart (sound.get(), tmin, tmax, playCallback, playBoss);
54 } catch (MelderError) {
55 Melder_throw (me, U": not played.");
56 }
57 }
58
59 autoSound Pitch_to_Sound_sine (Pitch me, double tmin, double tmax, double samplingFrequency, bool roundToNearestZeroCrossings) {
60 try {
61 autoPitchTier tier = Pitch_to_PitchTier (me);
62 autoSound sound = PitchTier_to_Sound_sine (tier.get(), tmin, tmax, samplingFrequency);
63 integer iframe = 1;
64 double unvoicedMin = my xmin;
65 double unvoicedMax = my x1 + (iframe - 1.5) * my dx;
66 for (;;) {
67 while (! Pitch_isVoiced_i (me, iframe)) {
68 unvoicedMax = my x1 + (iframe - 0.5) * my dx;
69 if (++ iframe > my nx) break;
70 }
71 if (unvoicedMax > unvoicedMin) {
72 Sound_setZero (sound.get(), unvoicedMin, unvoicedMax, roundToNearestZeroCrossings);
73 }
74 if (iframe > my nx) break;
75 while (Pitch_isVoiced_i (me, iframe)) {
76 unvoicedMin = my x1 + (iframe - 0.5) * my dx;
77 if (++ iframe > my nx) break;
78 }
79 if (iframe > my nx) break;
80 }
81 unvoicedMax = my xmax;
82 if (unvoicedMax > unvoicedMin) {
83 Sound_setZero (sound.get(), unvoicedMin, unvoicedMax, roundToNearestZeroCrossings);
84 }
85 return sound;
86 } catch (MelderError) {
87 Melder_throw (me, U": not converted to Sound (sine).");
88 }
89 }
90
91 /* End of file Pitch_to_Sound.cpp */