| 1 | /* Sound_to_PointProcess.cpp |
| 2 | * |
| 3 | * Copyright (C) 1992-2008,2011,2014-2018,2020 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_to_PointProcess.h"cxx . . $ `<file>/fon/Sound_to_PointProcess.h`/ |
| 20 | #include "Sound_to_Pitch.h"cxx . . $ `<file>/fon/Sound_to_Pitch.h`/ |
| 21 | #include "Pitch_to_PointProcess.h"cxx . . $ `<file>/fon/Pitch_to_PointProcess.h`/ |
| 22 | |
| 23 | autoPointProcesscxx . . $ autoPointProcess# Sound_to_PointProcess_extremacxx . . $ Sound_to_PointProcess_extrema(d43a2772443e4bbf). (Soundcxx . . $ Sound# me, integercxx . . $ integer# channelNumber, kVector_peakInterpolationcxx . . $ kVector_peakInterpolation# peakInterpolationType, bool includeMaxima, bool includeMinima) { |
| 24 | try { |
| 25 | /* |
| 26 | * Pass 1: count the extrema. There may be a maximum and minimum in the same interval! |
| 27 | */ |
| 28 | integercxx . . $ integer# numberOfMaxima = 0; |
| 29 | integercxx . . $ integer# numberOfMinima = 0; |
| 30 | constVECcxx . . $ constVEC# y = mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z..rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (channelNumber); |
| 31 | for (integercxx . . $ integer# i = 2; i <= mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx. - 1; i ++) { |
| 32 | if (includeMaxima && y [cxx . . $ constvector#`operator[]`(e616e229aa94bfcf).i] > y [cxx . . $ constvector#`operator[]`(e616e229aa94bfcf).i - 1] && y [cxx . . $ constvector#`operator[]`(e616e229aa94bfcf).i] >= y [cxx . . $ constvector#`operator[]`(e616e229aa94bfcf).i + 1]) |
| 33 | numberOfMaxima ++; |
| 34 | if (includeMinima && y [cxx . . $ constvector#`operator[]`(e616e229aa94bfcf).i] <= y [cxx . . $ constvector#`operator[]`(e616e229aa94bfcf).i - 1] && y [cxx . . $ constvector#`operator[]`(e616e229aa94bfcf).i] < y [cxx . . $ constvector#`operator[]`(e616e229aa94bfcf).i + 1]) |
| 35 | numberOfMinima ++; |
| 36 | } |
| 37 | /* |
| 38 | * Create the empty result. |
| 39 | */ |
| 40 | autoPointProcesscxx . . $ autoPointProcess# thee = PointProcess_createcxx . . $ PointProcess_create(7a858f446a8dd7cc). (mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin., mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax., numberOfMaxima + numberOfMinima); |
| 41 | /* |
| 42 | * Pass 2: compute and register the extrema. |
| 43 | */ |
| 44 | const integercxx . . $ integer# interpolationDepth = kVector_peakInterpolation_to_interpolationDepthcxx . . $ kVector_peakInterpolation_to_interpolationDepth(5f6fa5b1fce060b0). (peakInterpolationType); |
| 45 | for (integercxx . . $ integer# i = 2; i <= mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx. - 1; i ++) { |
| 46 | double time, i_real; |
| 47 | if (includeMaxima && y [cxx . . $ constvector#`operator[]`(e616e229aa94bfcf).i] > y [cxx . . $ constvector#`operator[]`(e616e229aa94bfcf).i - 1] && y [cxx . . $ constvector#`operator[]`(e616e229aa94bfcf).i] >= y [cxx . . $ constvector#`operator[]`(e616e229aa94bfcf).i + 1]) { |
| 48 | (void) NUMimproveMaximumcxx . . $ NUMimproveMaximum(c86a71e1ecac36cd). (y, i, interpolationDepth, & i_real); |
| 49 | time = mycxx . . $ `melder/melder.h:44:9`! x1cxx . . $ structSampled#x1. + (i_real - 1.0) * mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx.; |
| 50 | PointProcess_addPointcxx . . $ PointProcess_addPoint(29f3b64796387061). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), time); |
| 51 | } |
| 52 | if (includeMinima && y [cxx . . $ constvector#`operator[]`(e616e229aa94bfcf).i] <= y [cxx . . $ constvector#`operator[]`(e616e229aa94bfcf).i - 1] && y [cxx . . $ constvector#`operator[]`(e616e229aa94bfcf).i] < y [cxx . . $ constvector#`operator[]`(e616e229aa94bfcf).i + 1]) { |
| 53 | (void) NUMimproveMinimumcxx . . $ NUMimproveMinimum(c86a71e1ecac36cd). (y, i, interpolationDepth, & i_real); |
| 54 | time = mycxx . . $ `melder/melder.h:44:9`! x1cxx . . $ structSampled#x1. + (i_real - 1.0) * mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx.; |
| 55 | PointProcess_addPointcxx . . $ PointProcess_addPoint(29f3b64796387061). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), time); |
| 56 | } |
| 57 | } |
| 58 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 59 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 60 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": extrema not computed."); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | autoPointProcesscxx . . $ autoPointProcess# Sound_to_PointProcess_maximacxx . . $ Sound_to_PointProcess_maxima(b9b262cab941c1ba). (Soundcxx . . $ Sound# me, integercxx . . $ integer# channel, kVector_peakInterpolationcxx . . $ kVector_peakInterpolation# peakInterpolationType) { |
| 65 | return Sound_to_PointProcess_extremacxx . . $ Sound_to_PointProcess_extrema(d43a2772443e4bbf). (me, channel, peakInterpolationType, true, false); |
| 66 | } |
| 67 | autoPointProcesscxx . . $ autoPointProcess# Sound_to_PointProcess_minimacxx . . $ Sound_to_PointProcess_minima(b9b262cab941c1ba). (Soundcxx . . $ Sound# me, integercxx . . $ integer# channel, kVector_peakInterpolationcxx . . $ kVector_peakInterpolation# peakInterpolationType) { |
| 68 | return Sound_to_PointProcess_extremacxx . . $ Sound_to_PointProcess_extrema(d43a2772443e4bbf). (me, channel, peakInterpolationType, false, true); |
| 69 | } |
| 70 | autoPointProcesscxx . . $ autoPointProcess# Sound_to_PointProcess_allExtremacxx . . $ Sound_to_PointProcess_allExtrema(b9b262cab941c1ba). (Soundcxx . . $ Sound# me, integercxx . . $ integer# channel, kVector_peakInterpolationcxx . . $ kVector_peakInterpolation# peakInterpolationType) { |
| 71 | return Sound_to_PointProcess_extremacxx . . $ Sound_to_PointProcess_extrema(d43a2772443e4bbf). (me, channel, peakInterpolationType, true, true); |
| 72 | } |
| 73 | |
| 74 | autoPointProcesscxx . . $ autoPointProcess# Sound_to_PointProcess_zeroescxx . . $ Sound_to_PointProcess_zeroes(6c6d24490c26fe8b). (Soundcxx . . $ Sound# me, integercxx . . $ integer# channel, bool includeRaisers, bool includeFallers) { |
| 75 | try { |
| 76 | /* |
| 77 | * Pass 1: count the zeroes. |
| 78 | */ |
| 79 | integercxx . . $ integer# numberOfRaisers = 0; |
| 80 | integercxx . . $ integer# numberOfFallers = 0; |
| 81 | double *y = & mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).channel] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).0]; |
| 82 | for (integercxx . . $ integer# i = 2; i <= mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.; i ++) { |
| 83 | if (includeRaisers && y [i - 1] < 0.0 && y [i] >= 0.0) numberOfRaisers ++; |
| 84 | if (includeFallers && y [i - 1] >= 0.0 && y [i] < 0.0) numberOfFallers ++; |
| 85 | } |
| 86 | /* |
| 87 | * Create the empty result. |
| 88 | */ |
| 89 | autoPointProcesscxx . . $ autoPointProcess# thee = PointProcess_createcxx . . $ PointProcess_create(7a858f446a8dd7cc). (mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin., mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax., numberOfRaisers + numberOfFallers); |
| 90 | /* |
| 91 | * Pass 2: compute and register the zeroes. |
| 92 | */ |
| 93 | for (integercxx . . $ integer# i = 2; i <= mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.; i ++) { |
| 94 | if ((includeRaisers && y [i - 1] < 0.0 && y [i] >= 0.0) || |
| 95 | (includeFallers && y [i - 1] >= 0.0 && y [i] < 0.0)) |
| 96 | { |
| 97 | double time = Sampled_indexToXcxx . . $ Sampled_indexToX(65bcd2c9acbb3dd5). (me, i - 1) + mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx. * y [i - 1] / (y [i - 1] - y [i]); // linear |
| 98 | PointProcess_addPointcxx . . $ PointProcess_addPoint(29f3b64796387061). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), time); |
| 99 | } |
| 100 | } |
| 101 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 102 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 103 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": zeroes not computed."); |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | autoPointProcesscxx . . $ autoPointProcess# Sound_to_PointProcess_periodic_cccxx . . $ Sound_to_PointProcess_periodic_cc(ba11ba6b6def1c3b). (Soundcxx . . $ Sound# me, double fmin, double fmax) { |
| 108 | try { |
| 109 | autoPitchcxx . . $ autoPitch# pitch = Sound_to_Pitchcxx . . $ Sound_to_Pitch(c773ddec40eb7e2b). (me, 0.0, fmin, fmax); |
| 110 | autoPointProcesscxx . . $ autoPointProcess# thee = Sound_Pitch_to_PointProcess_cccxx . . $ Sound_Pitch_to_PointProcess_cc(f94f2d65883a605d). (me, pitch.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).()); |
| 111 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 112 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 113 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": periodic pulses (cc) not computed."); |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | autoPointProcesscxx . . $ autoPointProcess# Sound_to_PointProcess_periodic_peakscxx . . $ Sound_to_PointProcess_periodic_peaks(980d566298bb5008). (Soundcxx . . $ Sound# me, double fmin, double fmax, bool includeMaxima, bool includeMinima) { |
| 118 | try { |
| 119 | autoPitchcxx . . $ autoPitch# pitch = Sound_to_Pitchcxx . . $ Sound_to_Pitch(c773ddec40eb7e2b). (me, 0.0, fmin, fmax); |
| 120 | autoPointProcesscxx . . $ autoPointProcess# thee = Sound_Pitch_to_PointProcess_peakscxx . . $ Sound_Pitch_to_PointProcess_peaks(37075ccf8fa5b996). (me, pitch.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), includeMaxima, includeMinima); |
| 121 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 122 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 123 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": periodic pulses (peaks) not computed."); |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | /* End of file Sound_to_PointProcess.cpp */ |