| 1 | /* Sound.cpp |
| 2 | * |
| 3 | * Copyright (C) 1992-2025 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 3 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 | /* |
| 20 | * a selection of changes: |
| 21 | * pb 2006/12/31 stereo |
| 22 | * pb 2010/03/26 Sounds_convolve, Sounds_crossCorrelate, Sound_autocorrelate |
| 23 | */ |
| 24 | |
| 25 | #include "Sound.h"cxx . . $ `<file>/fon/Sound.h`/ |
| 26 | #include "Sound_extensions.h"cxx . . $ `<file>/dwtools/Sound_extensions.h`/ |
| 27 | #include "NUM2.h"cxx . . $ `<file>/dwsys/NUM2.h`/ |
| 28 | |
| 29 | #include "enums_getText.h"cxx . . $ `<file>/melder/enums_getText.h`/ |
| 30 | #include "Sound_enums.h"cxx . . $ `<file>/fon/Sound_enums.h`/ |
| 31 | #include "enums_getValue.h"cxx . . $ `<file>/melder/enums_getValue.h`/ |
| 32 | #include "Sound_enums.h"cxx . . $ `<file>/fon/Sound_enums.h`/ |
| 33 | |
| 34 | Thing_implementcxx . . $ `sys/Thing.h:65:9`! (Sound, Vector, 2); |
| 35 | |
| 36 | void structSoundcxx . . $ structSound# :: v1_infocxx . . $ structSound#v1_info(49f6e7a06ebc5aa8). () { |
| 37 | structDaatacxx . . $ structDaata# :: v1_infocxx . . $ structThing#v1_info(49f6e7a06ebc5aa8). (); |
| 38 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"Number of channels: ", ourcxx . . $ `melder/melder.h:42:9`! nycxx . . $ structSampledXY#ny., ourcxx . . $ `melder/melder.h:42:9`! nycxx . . $ structSampledXY#ny. == 1 ? U" (mono)" : ourcxx . . $ `melder/melder.h:42:9`! nycxx . . $ structSampledXY#ny. == 2 ? U" (stereo)" : U""); |
| 39 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"Time domain:"); |
| 40 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U" Start time: ", ourcxx . . $ `melder/melder.h:42:9`! xmincxx . . $ structFunction#xmin., U" seconds"); |
| 41 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U" End time: ", ourcxx . . $ `melder/melder.h:42:9`! xmaxcxx . . $ structFunction#xmax., U" seconds"); |
| 42 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U" Total duration: ", ourcxx . . $ `melder/melder.h:42:9`! xmaxcxx . . $ structFunction#xmax. - ourcxx . . $ `melder/melder.h:42:9`! xmincxx . . $ structFunction#xmin., U" seconds"); |
| 43 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"Time sampling:"); |
| 44 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U" Number of samples: ", ourcxx . . $ `melder/melder.h:42:9`! nxcxx . . $ structSampled#nx.); |
| 45 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U" Sampling period: ", ourcxx . . $ `melder/melder.h:42:9`! dxcxx . . $ structSampled#dx., U" seconds"); |
| 46 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U" Sampling frequency: ", Melder_singlecxx . . $ Melder_single(f05d861d9dbec9b2). (1.0 / ourcxx . . $ `melder/melder.h:42:9`! dxcxx . . $ structSampled#dx.), U" Hz"); |
| 47 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U" First sample centred at: ", ourcxx . . $ `melder/melder.h:42:9`! x1cxx . . $ structSampled#x1., U" seconds"); |
| 48 | integercxx . . $ integer# numberOfCells = ourcxx . . $ `melder/melder.h:42:9`! nxcxx . . $ structSampled#nx. * ourcxx . . $ `melder/melder.h:42:9`! nycxx . . $ structSampledXY#ny.; |
| 49 | bool thereAreEnoughObservationsToComputeFirstOrderOverallStatistics = ( numberOfCells >= 1 ); |
| 50 | if (thereAreEnoughObservationsToComputeFirstOrderOverallStatistics) { |
| 51 | double minimum_Pa = ourcxx . . $ `melder/melder.h:42:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).1], maximum_Pa = minimum_Pa; |
| 52 | longdoublecxx . . $ longdouble# sum_Pa = 0.0, sumOfSquares_Pa2 = 0.0; |
| 53 | for (integercxx . . $ integer# channel = 1; channel <= ourcxx . . $ `melder/melder.h:42:9`! nycxx . . $ structSampledXY#ny.; channel ++) { |
| 54 | constVECcxx . . $ constVEC# const& waveform_Pa = ourcxx . . $ `melder/melder.h:42:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).channel]; |
| 55 | for (integercxx . . $ integer# i = 1; i <= ourcxx . . $ `melder/melder.h:42:9`! nxcxx . . $ structSampled#nx.; i ++) { |
| 56 | const double value_Pa = waveform_Pa [cxx . . $ constvector#`operator[]`(e616e229aa94bfcf).i]; |
| 57 | sum_Pa += value_Pa; |
| 58 | sumOfSquares_Pa2 += value_Pa * value_Pa; |
| 59 | if (value_Pa < minimum_Pa) |
| 60 | minimum_Pa = value_Pa; |
| 61 | if (value_Pa > maximum_Pa) |
| 62 | maximum_Pa = value_Pa; |
| 63 | } |
| 64 | } |
| 65 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"Amplitude:"); |
| 66 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U" Minimum: ", Melder_singlecxx . . $ Melder_single(f05d861d9dbec9b2). (minimum_Pa), U" Pascal"); |
| 67 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U" Maximum: ", Melder_singlecxx . . $ Melder_single(f05d861d9dbec9b2). (maximum_Pa), U" Pascal"); |
| 68 | const double mean_Pa = (double) sum_Pa / numberOfCells; |
| 69 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U" Mean: ", Melder_singlecxx . . $ Melder_single(f05d861d9dbec9b2). (mean_Pa), U" Pascal"); |
| 70 | const double meanSquare_Pa2 = (double) sumOfSquares_Pa2 / numberOfCells; |
| 71 | const double rootMeanSquare_Pa = sqrtcxx . . $ sqrt(fee4f1d22bc8e617). (meanSquare_Pa2); |
| 72 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U" Root-mean-square: ", Melder_singlecxx . . $ Melder_single(f05d861d9dbec9b2). (rootMeanSquare_Pa), U" Pascal"); |
| 73 | const double energy_Pa2s = (double) sumOfSquares_Pa2 * ourcxx . . $ `melder/melder.h:42:9`! dxcxx . . $ structSampled#dx. / ourcxx . . $ `melder/melder.h:42:9`! nycxx . . $ structSampledXY#ny.; // Pa2 s = kg2 m-2 s-3 |
| 74 | MelderInfo_writecxx . . $ MelderInfo_write(3eb398314feba58b). (U"Total energy: ", Melder_singlecxx . . $ Melder_single(f05d861d9dbec9b2). (energy_Pa2s), U" Pascal\u00B2 sec"); |
| 75 | const double rho_c = 400.0; // rho = 1.14 kg m-3; c = 353 m s-1; [rho c] = kg m-2 s-1 |
| 76 | const double energy_J_m2 = energy_Pa2s / rho_c; // kg s-2 = Joule m-2 |
| 77 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U" (energy in air: ", Melder_singlecxx . . $ Melder_single(f05d861d9dbec9b2). (energy_J_m2), U" Joule/m\u00B2)"); |
| 78 | const double physicalDuration_s = ourcxx . . $ `melder/melder.h:42:9`! dxcxx . . $ structSampled#dx. * ourcxx . . $ `melder/melder.h:42:9`! nxcxx . . $ structSampled#nx.; |
| 79 | const double power_W_m2 = energy_J_m2 / physicalDuration_s; // kg s-3 = Watt/m2 |
| 80 | MelderInfo_writecxx . . $ MelderInfo_write(3eb398314feba58b). (U"Mean power (intensity) in air: ", Melder_singlecxx . . $ Melder_single(f05d861d9dbec9b2). (power_W_m2), U" Watt/m\u00B2"); |
| 81 | if (power_W_m2 != 0.0) { |
| 82 | const double referencePower_W_m2 = 1.0e-12; // this equals the square of 2.0e-5 Pa, divided by rho c |
| 83 | const double power_dB = 10.0 * log10cxx . . $ log10(fee4f1d22bc8e617). (power_W_m2 / referencePower_W_m2); |
| 84 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U" = ", Melder_halfcxx . . $ Melder_half(f05d861d9dbec9b2). (power_dB), U" dB"); |
| 85 | } else { |
| 86 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U""); |
| 87 | } |
| 88 | } |
| 89 | const bool thereAreEnoughObservationsToComputeSecondOrderChannelStatistics = ( ourcxx . . $ `melder/melder.h:42:9`! nxcxx . . $ structSampled#nx. >= 2 ); |
| 90 | if (thereAreEnoughObservationsToComputeSecondOrderChannelStatistics) { |
| 91 | for (integercxx . . $ integer# channel = 1; channel <= ourcxx . . $ `melder/melder.h:42:9`! nycxx . . $ structSampledXY#ny.; channel ++) { |
| 92 | const double stdev = NUMstdevcxx . . $ NUMstdev(4bb9c3e3a8dd5442). (ourcxx . . $ `melder/melder.h:42:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).channel]); |
| 93 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"Standard deviation in channel ", channel, U": ", Melder_singlecxx . . $ Melder_single(f05d861d9dbec9b2). (stdev), U" Pascal"); |
| 94 | } |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | double structSoundcxx . . $ structSound# :: v_getMatrixcxx . . $ structSound#v_getMatrix(f7a1f362ba849873). (const integercxx . . $ integer# irow, const integercxx . . $ integer# icol) const { |
| 99 | if (irow < 1 || irow > ourcxx . . $ `melder/melder.h:42:9`! nycxx . . $ structSampledXY#ny.) { |
| 100 | if (irow == 0) { |
| 101 | if (icol < 1 || icol > nxcxx . . $ structSampled#nx.) |
| 102 | return 0.0; |
| 103 | if (ourcxx . . $ `melder/melder.h:42:9`! nycxx . . $ structSampledXY#ny. == 1) |
| 104 | return ourcxx . . $ `melder/melder.h:42:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).icol]; // optimization |
| 105 | if (ourcxx . . $ `melder/melder.h:42:9`! nycxx . . $ structSampledXY#ny. == 2) |
| 106 | return 0.5 * (ourcxx . . $ `melder/melder.h:42:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).icol] + ourcxx . . $ `melder/melder.h:42:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).2] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).icol]); // optimization |
| 107 | longdoublecxx . . $ longdouble# sum = 0.0; |
| 108 | for (integercxx . . $ integer# channel = 1; channel <= nycxx . . $ structSampledXY#ny.; channel ++) |
| 109 | sum += ourcxx . . $ `melder/melder.h:42:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).channel] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).icol]; |
| 110 | return (double) sum / ourcxx . . $ `melder/melder.h:42:9`! nycxx . . $ structSampledXY#ny.; |
| 111 | } |
| 112 | return 0.0; |
| 113 | } |
| 114 | if (icol < 1 || icol > nxcxx . . $ structSampled#nx.) |
| 115 | return 0.0; |
| 116 | return ourcxx . . $ `melder/melder.h:42:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).irow] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).icol]; |
| 117 | } |
| 118 | |
| 119 | double structSoundcxx . . $ structSound# :: v_getFunction2cxx . . $ structSound#v_getFunction2(726307d3d9a4aee5). (const double x, const double y) const { |
| 120 | const integercxx . . $ integer# channel = Melder_ifloorcxx . . $ `melder/melder_ftoi.h:33:9`! (y); |
| 121 | if (channel < 0 || channel > ourcxx . . $ `melder/melder.h:42:9`! nycxx . . $ structSampledXY#ny. || y != (double) channel) |
| 122 | return 0.0; |
| 123 | return v_getFunction1cxx . . $ structVector#v_getFunction1(6525b878db7c2448). (channel, x); |
| 124 | } |
| 125 | |
| 126 | autoSoundcxx . . $ autoSound# Sound_createcxx . . $ Sound_create(39ab106d6b9a0135). (integercxx . . $ integer# numberOfChannels, double xmin, double xmax, integercxx . . $ integer# nx, double dx, double x1) { |
| 127 | try { |
| 128 | autoSoundcxx . . $ autoSound# me = Thing_newcxx . . $ `sys/Thing.h:514:9`! (Sound); |
| 129 | Matrix_initcxx . . $ Matrix_init(9dd6c49f9830a091). (me.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), xmin, xmax, nx, dx, x1, 1, numberOfChannels, numberOfChannels, 1, 1); |
| 130 | return mecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 131 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 132 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Sound not created."); |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | autoSoundcxx . . $ autoSound# Sound_createSimplecxx . . $ Sound_createSimple(fcb03a673f737ce). (integercxx . . $ integer# numberOfChannels, double duration, double samplingFrequency) { |
| 137 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (duration >= 0.0); |
| 138 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (samplingFrequency > 0.0); |
| 139 | const double numberOfSamples_real = roundcxx . . $ round(fee4f1d22bc8e617). (duration * samplingFrequency); |
| 140 | if (numberOfSamples_real > double (INT32_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:112:10`!)) |
| 141 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Cannot create sounds with more than ", Melder_bigInteger (INT32_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:112:10`!), U" samples, because they cannot be saved to disk."); |
| 142 | return Sound_createcxx . . $ Sound_create(39ab106d6b9a0135). (numberOfChannels, 0.0, duration, (integercxx . . $ integer#) (int32cxx . . $ int32#) numberOfSamples_real, |
| 143 | 1.0 / samplingFrequency, 0.5 / samplingFrequency); |
| 144 | } |
| 145 | |
| 146 | autoSoundcxx . . $ autoSound# Sound_convertToMonocxx . . $ Sound_convertToMono(4e9053a6db58af83). (constSoundcxx . . $ constSound# me) { |
| 147 | if (mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny. == 1) |
| 148 | return Data_copycxx . . $ Data_copy(97a542a26794c80e). (me); // optimization |
| 149 | try { |
| 150 | autoSoundcxx . . $ autoSound# thee = Sound_createcxx . . $ Sound_create(39ab106d6b9a0135). (1, mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin., mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax., mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx., mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx., mycxx . . $ `melder/melder.h:44:9`! x1cxx . . $ structSampled#x1.); |
| 151 | if (mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny. == 2) { // optimization |
| 152 | for (integercxx . . $ integer# i = 1; i <= mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.; i ++) |
| 153 | thycxx . . $ `melder/melder.h:45:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i] = 0.5 * (mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i] + mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).2] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i]); |
| 154 | } else { |
| 155 | for (integercxx . . $ integer# i = 1; i <= mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.; i ++) { |
| 156 | longdoublecxx . . $ longdouble# sum = mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i] + mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).2] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i] + mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).3] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i]; |
| 157 | for (integercxx . . $ integer# channel = 4; channel <= mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny.; channel ++) |
| 158 | sum += mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).channel] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i]; |
| 159 | thycxx . . $ `melder/melder.h:45:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i] = double (sum / mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny.); |
| 160 | } |
| 161 | } |
| 162 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 163 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 164 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": not converted to mono."); |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | autoSoundcxx . . $ autoSound# Sound_convertToStereocxx . . $ Sound_convertToStereo(4e9053a6db58af83). (constSoundcxx . . $ constSound# me) { |
| 169 | if (mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny. == 2) |
| 170 | return Data_copycxx . . $ Data_copy(97a542a26794c80e). (me); |
| 171 | try { |
| 172 | if (mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny. > 2) |
| 173 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"The Sound has ", mycxx . . $ `melder/melder.h:44:9`! ny, U" channels; don't know which to choose."); |
| 174 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (mycxx . . $ `melder/melder.h:44:9`! ny == 1); |
| 175 | autoSoundcxx . . $ autoSound# thee = Sound_createcxx . . $ Sound_create(39ab106d6b9a0135). (2, mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin., mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax., mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx., mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx., mycxx . . $ `melder/melder.h:44:9`! x1cxx . . $ structSampled#x1.); |
| 176 | for (integercxx . . $ integer# i = 1; i <= mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.; i ++) |
| 177 | thycxx . . $ `melder/melder.h:45:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i] = thycxx . . $ `melder/melder.h:45:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).2] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i] = mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i]; |
| 178 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 179 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 180 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": not converted to stereo."); |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | autoSoundcxx . . $ autoSound# Sounds_combineToStereocxx . . $ Sounds_combineToStereo(1972390e3e72148d). (OrderedOfcxx . . $ OrderedOf#<structSoundcxx . . $ structSound#>* me) { |
| 185 | try { |
| 186 | integercxx . . $ integer# totalNumberOfChannels = 0; |
| 187 | double sharedSamplingPeriod = 0.0; |
| 188 | for (integercxx . . $ integer# isound = 1; isound <= mycxx . . $ `melder/melder.h:44:9`! sizecxx . . $ CollectionOf#size.; isound ++) { |
| 189 | Soundcxx . . $ Sound# sound = mycxx . . $ `melder/melder.h:44:9`! atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).isound]; |
| 190 | totalNumberOfChannels += sound -> nycxx . . $ structSampledXY#ny.; |
| 191 | if (sharedSamplingPeriod == 0.0) { |
| 192 | sharedSamplingPeriod = sound -> dxcxx . . $ structSampled#dx.; |
| 193 | } else if (sound -> dxcxx . . $ structSampled#dx. != sharedSamplingPeriod) { |
| 194 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"To combine sounds, their sampling frequencies should be equal.\n" |
| 195 | U"You could resample one or more of the sounds before combining."); |
| 196 | } |
| 197 | } |
| 198 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (mycxx . . $ `melder/melder.h:44:9`! size > 0); |
| 199 | double sharedMinimumTime = mycxx . . $ `melder/melder.h:44:9`! atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).1] -> xmincxx . . $ structFunction#xmin.; |
| 200 | double sharedMaximumTime = mycxx . . $ `melder/melder.h:44:9`! atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).1] -> xmaxcxx . . $ structFunction#xmax.; |
| 201 | for (integercxx . . $ integer# isound = 2; isound <= mycxx . . $ `melder/melder.h:44:9`! sizecxx . . $ CollectionOf#size.; isound ++) { |
| 202 | Soundcxx . . $ Sound# sound = mycxx . . $ `melder/melder.h:44:9`! atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).isound]; |
| 203 | if (sound -> xmincxx . . $ structFunction#xmin. < sharedMinimumTime) |
| 204 | sharedMinimumTime = sound -> xmincxx . . $ structFunction#xmin.; |
| 205 | if (sound -> xmaxcxx . . $ structFunction#xmax. > sharedMaximumTime) |
| 206 | sharedMaximumTime = sound -> xmaxcxx . . $ structFunction#xmax.; |
| 207 | } |
| 208 | autoINTVECcxx . . $ autoINTVEC# numberOfInitialZeroes = zero_INTVECcxx . . $ zero_INTVEC(dab5d3ef28d6a25). (mycxx . . $ `melder/melder.h:44:9`! sizecxx . . $ CollectionOf#size.); |
| 209 | integercxx . . $ integer# sharedNumberOfSamples = 0; |
| 210 | double sumOfFirstTimes = 0.0; |
| 211 | for (integercxx . . $ integer# isound = 1; isound <= mycxx . . $ `melder/melder.h:44:9`! sizecxx . . $ CollectionOf#size.; isound ++) { |
| 212 | Soundcxx . . $ Sound# sound = mycxx . . $ `melder/melder.h:44:9`! atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).isound]; |
| 213 | numberOfInitialZeroes [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).isound] = Melder_ifloorcxx . . $ `melder/melder_ftoi.h:33:9`! ((sound -> xmincxx . . $ structFunction#xmin. - sharedMinimumTime) / sharedSamplingPeriod); |
| 214 | const double newFirstTime = sound -> x1cxx . . $ structSampled#x1. - sound -> dxcxx . . $ structSampled#dx. * numberOfInitialZeroes [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).isound]; |
| 215 | sumOfFirstTimes += newFirstTime; |
| 216 | const integercxx . . $ integer# newNumberOfSamplesThroughLastNonzero = sound -> nxcxx . . $ structSampled#nx. + numberOfInitialZeroes [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).isound]; |
| 217 | if (newNumberOfSamplesThroughLastNonzero > sharedNumberOfSamples) |
| 218 | sharedNumberOfSamples = newNumberOfSamplesThroughLastNonzero; |
| 219 | } |
| 220 | const double sharedTimeOfFirstSample = sumOfFirstTimes / mycxx . . $ `melder/melder.h:44:9`! sizecxx . . $ CollectionOf#size.; // this is an approximation |
| 221 | autoSoundcxx . . $ autoSound# thee = Sound_createcxx . . $ Sound_create(39ab106d6b9a0135). (totalNumberOfChannels, sharedMinimumTime, sharedMaximumTime, |
| 222 | sharedNumberOfSamples, sharedSamplingPeriod, sharedTimeOfFirstSample); |
| 223 | integercxx . . $ integer# channelNumber = 0; |
| 224 | for (integercxx . . $ integer# isound = 1; isound <= mycxx . . $ `melder/melder.h:44:9`! sizecxx . . $ CollectionOf#size.; isound ++) { |
| 225 | Soundcxx . . $ Sound# sound = mycxx . . $ `melder/melder.h:44:9`! atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).isound]; |
| 226 | const integercxx . . $ integer# offset = numberOfInitialZeroes [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).isound]; |
| 227 | for (integercxx . . $ integer# ichan = 1; ichan <= sound -> nycxx . . $ structSampledXY#ny.; ichan ++) { |
| 228 | channelNumber ++; |
| 229 | for (integercxx . . $ integer# isamp = 1; isamp <= sound -> nxcxx . . $ structSampled#nx.; isamp ++) |
| 230 | thycxx . . $ `melder/melder.h:45:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).channelNumber] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).isamp + offset] = sound -> zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).ichan] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).isamp]; |
| 231 | } |
| 232 | } |
| 233 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 234 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 235 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Sounds not combined to stereo."); |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | static void Sound_checkChannelNumberWithinRangecxx . . $ Sound_checkChannelNumberWithinRange(67215716496261da). (constSoundcxx . . $ constSound# me, integercxx . . $ integer# channel) { |
| 240 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (channel > 0, |
| 241 | U"Your channel number is ", channel, U", but it should be positive."); |
| 242 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (channel <= mycxx . . $ `melder/melder.h:44:9`! ny, |
| 243 | U"Your channel number is ", channel, |
| 244 | U", but it should not be greater than my number of channels, which is ", |
| 245 | mycxx . . $ `melder/melder.h:44:9`! ny, U"." |
| 246 | ); |
| 247 | } |
| 248 | |
| 249 | autoSoundcxx . . $ autoSound# Sound_extractChannelcxx . . $ Sound_extractChannel(fdb1ba3dfee1bd33). (constSoundcxx . . $ constSound# me, integercxx . . $ integer# channel) { |
| 250 | try { |
| 251 | Sound_checkChannelNumberWithinRangecxx . . $ Sound_checkChannelNumberWithinRange(67215716496261da). (me, channel); |
| 252 | autoSoundcxx . . $ autoSound# you = Sound_createcxx . . $ Sound_create(39ab106d6b9a0135). (1, mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin., mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax., mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx., mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx., mycxx . . $ `melder/melder.h:44:9`! x1cxx . . $ structSampled#x1.); |
| 253 | yourcxx . . $ `melder/melder.h:46:9`! zcxx . . $ structMatrix#z..rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (1) <<=cxx . . $ `operator<<=`(adea042513329390). mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z..rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (channel); |
| 254 | return youcxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 255 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 256 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": channel ", channel, U" not extracted."); |
| 257 | } |
| 258 | } |
| 259 | |
| 260 | autoSoundcxx . . $ autoSound# Sound_extractChannelscxx . . $ Sound_extractChannels(854b47aef71dd5a5). (constSoundcxx . . $ constSound# me, constINTVECVUcxx . . $ constINTVECVU# const& channels) { |
| 261 | try { |
| 262 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (channels.size > 0, |
| 263 | U"The number of channels should be greater than 0."); |
| 264 | autoSoundcxx . . $ autoSound# you = Sound_createcxx . . $ Sound_create(39ab106d6b9a0135). (channels.sizecxx . . $ constvectorview#size., mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin., mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax., mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx., mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx., mycxx . . $ `melder/melder.h:44:9`! x1cxx . . $ structSampled#x1.); |
| 265 | for (integercxx . . $ integer# ichan = 1; ichan <= channels.sizecxx . . $ constvectorview#size.; ichan ++) { |
| 266 | Sound_checkChannelNumberWithinRangecxx . . $ Sound_checkChannelNumberWithinRange(67215716496261da). (me, channels [cxx . . $ constvectorview#`operator[]`(e616e229aa94bfcf).ichan]); |
| 267 | yourcxx . . $ `melder/melder.h:46:9`! zcxx . . $ structMatrix#z..rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (ichan) <<=cxx . . $ `operator<<=`(adea042513329390). mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z..rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (channels [cxx . . $ constvectorview#`operator[]`(e616e229aa94bfcf).ichan]); |
| 268 | } |
| 269 | return youcxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 270 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 271 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": channels not extracted."); |
| 272 | } |
| 273 | } |
| 274 | |
| 275 | void Sound_shiftTimesToBetweenZeroAndPhysicalDurationcxx . . $ Sound_shiftTimesToBetweenZeroAndPhysicalDuration(88106389304369e6). (mutableSoundcxx . . $ mutableSound# me) { |
| 276 | mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin. = 0.0; |
| 277 | mycxx . . $ `melder/melder.h:44:9`! x1cxx . . $ structSampled#x1. = 0.5 * mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx.; |
| 278 | mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax. = mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx. * mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx.; |
| 279 | } |
| 280 | |
| 281 | double Sound_getRootMeanSquarecxx . . $ Sound_getRootMeanSquare(511c4e44d03f8807). (constSoundcxx . . $ constSound# me, double tmin, double tmax) { |
| 282 | /* mutable accumulate */ double meanOfSquared = 0.0; |
| 283 | for (integercxx . . $ integer# ichan = 1; ichan <= mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny.; ichan ++) |
| 284 | meanOfSquared += Sampled_getMeanOfSquaredcxx . . $ Sampled_getMeanOfSquared(2a8b0d40a92e6734). (me, tmin, tmax, ichan, 0, false); |
| 285 | return isdefinedcxx . . $ isdefined(f8197d536af80c96). (meanOfSquared) ? sqrtcxx . . $ sqrt(fee4f1d22bc8e617). (meanOfSquared / mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny.) : undefinedcxx . . $ undefined.; |
| 286 | } |
| 287 | |
| 288 | double Sound_getEnergycxx . . $ Sound_getEnergy(511c4e44d03f8807). (constSoundcxx . . $ constSound# me, double tmin, double tmax) { |
| 289 | /* mutable accumulate */ double integralOfSquared = 0.0; |
| 290 | for (integercxx . . $ integer# ichan = 1; ichan <= mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny.; ichan ++) |
| 291 | integralOfSquared += Sampled_getIntegralOfSquaredcxx . . $ Sampled_getIntegralOfSquared(2a8b0d40a92e6734). (me, tmin, tmax, ichan, 0, false); |
| 292 | return isdefinedcxx . . $ isdefined(f8197d536af80c96). (integralOfSquared) ? integralOfSquared / mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny. : undefinedcxx . . $ undefined.; |
| 293 | } |
| 294 | |
| 295 | double Sound_getPowercxx . . $ Sound_getPower(511c4e44d03f8807). (constSoundcxx . . $ constSound# me, double tmin, double tmax) { |
| 296 | /* mutable accumulate */ double meanOfSquared = 0.0; |
| 297 | for (integercxx . . $ integer# ichan = 1; ichan <= mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny.; ichan ++) |
| 298 | meanOfSquared += Sampled_getMeanOfSquaredcxx . . $ Sampled_getMeanOfSquared(2a8b0d40a92e6734). (me, tmin, tmax, ichan, 0, false); |
| 299 | return isdefinedcxx . . $ isdefined(f8197d536af80c96). (meanOfSquared) ? meanOfSquared / mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny. : undefinedcxx . . $ undefined.; |
| 300 | } |
| 301 | |
| 302 | double Sound_getEnergyInAircxx . . $ Sound_getEnergyInAir(9577c4e030d3505d). (constSoundcxx . . $ constSound# me) { |
| 303 | /* mutable accumulate */ double integralOfSquared = 0.0; |
| 304 | for (integercxx . . $ integer# ichan = 1; ichan <= mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny.; ichan ++) |
| 305 | integralOfSquared += Sampled_getIntegralOfSquaredcxx . . $ Sampled_getIntegralOfSquared(2a8b0d40a92e6734). (me, 0.0, 0.0, ichan, 0, false); |
| 306 | return isdefinedcxx . . $ isdefined(f8197d536af80c96). (integralOfSquared) ? integralOfSquared / (400.0 * mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny.) : undefinedcxx . . $ undefined.; |
| 307 | } |
| 308 | |
| 309 | double Sound_getIntensity_dBcxx . . $ Sound_getIntensity_dB(9577c4e030d3505d). (constSoundcxx . . $ constSound# me) { |
| 310 | /* mutable accumulate */ double meanOfSquared = 0.0; |
| 311 | for (integercxx . . $ integer# ichan = 1; ichan <= mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny.; ichan ++) |
| 312 | meanOfSquared += Sampled_getMeanOfSquaredcxx . . $ Sampled_getMeanOfSquared(2a8b0d40a92e6734). (me, 0.0, 0.0, ichan, 0, false); |
| 313 | return isdefinedcxx . . $ isdefined(f8197d536af80c96). (meanOfSquared) && meanOfSquared != 0.0 ? 10.0 * log10cxx . . $ log10(fee4f1d22bc8e617). (meanOfSquared / (4.0e-10 * mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny.)) : undefinedcxx . . $ undefined.; |
| 314 | } |
| 315 | |
| 316 | double Sound_getPowerInAircxx . . $ Sound_getPowerInAir(9577c4e030d3505d). (constSoundcxx . . $ constSound# me) { |
| 317 | /* mutable accumulate */ double meanOfSquared = 0.0; |
| 318 | for (integercxx . . $ integer# ichan = 1; ichan <= mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny.; ichan ++) |
| 319 | meanOfSquared += Sampled_getMeanOfSquaredcxx . . $ Sampled_getMeanOfSquared(2a8b0d40a92e6734). (me, 0.0, 0.0, ichan, 0, false); |
| 320 | return ( isdefinedcxx . . $ isdefined(f8197d536af80c96). (meanOfSquared) ? meanOfSquared / (400.0 * mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny.) : undefinedcxx . . $ undefined. ); |
| 321 | } |
| 322 | |
| 323 | autoSoundcxx . . $ autoSound# Matrix_to_Sound_monocxx . . $ Matrix_to_Sound_mono(5f0ff142d6a3cd23). (constMatrixcxx . . $ constMatrix# me, integercxx . . $ integer# rowNumber) { |
| 324 | try { |
| 325 | autoSoundcxx . . $ autoSound# thee = Sound_createcxx . . $ Sound_create(39ab106d6b9a0135). (1, mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin., mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax., mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx., mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx., mycxx . . $ `melder/melder.h:44:9`! x1cxx . . $ structSampled#x1.); |
| 326 | if (rowNumber < 0) |
| 327 | rowNumber = mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny. + 1 + rowNumber; |
| 328 | Melder_clipcxx . . $ Melder_clip(971c667ea412f82c). (1_integercxx . . $ `operator""_integer`(85240eb457c3721a)., & rowNumber, mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny.); |
| 329 | thycxx . . $ `melder/melder.h:45:9`! zcxx . . $ structMatrix#z..rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (1) <<=cxx . . $ `operator<<=`(adea042513329390). mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z..rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (rowNumber); |
| 330 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 331 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 332 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": not converted to Sound."); |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | autoSoundcxx . . $ autoSound# Matrix_to_Soundcxx . . $ Matrix_to_Sound(abc428493b3c02a4). (constMatrixcxx . . $ constMatrix# me) { |
| 337 | try { |
| 338 | autoSoundcxx . . $ autoSound# thee = Thing_newcxx . . $ `sys/Thing.h:514:9`! (Sound); |
| 339 | mycxx . . $ `melder/melder.h:44:9`! structMatrixcxx . . $ structMatrix# :: v1_copycxx . . $ structMatrix#v1_copy(42659c2335f2eda7). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).()); |
| 340 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 341 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 342 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": not converted to Sound."); |
| 343 | } |
| 344 | } |
| 345 | |
| 346 | autoMatrixcxx . . $ autoMatrix# Sound_to_Matrixcxx . . $ Sound_to_Matrix(593cc862e33913cb). (constSoundcxx . . $ constSound# me) { |
| 347 | try { |
| 348 | autoMatrixcxx . . $ autoMatrix# thee = Thing_newcxx . . $ `sys/Thing.h:514:9`! (Matrix); |
| 349 | mycxx . . $ `melder/melder.h:44:9`! structMatrixcxx . . $ structMatrix# :: v1_copycxx . . $ structMatrix#v1_copy(42659c2335f2eda7). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).()); |
| 350 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 351 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 352 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": not converted to Matrix."); |
| 353 | } |
| 354 | } |
| 355 | |
| 356 | autoSoundcxx . . $ autoSound# Sound_upsamplecxx . . $ Sound_upsample(4e9053a6db58af83). (constSoundcxx . . $ constSound# me) { |
| 357 | try { |
| 358 | constexpr integercxx . . $ integer# antiTurnAround = 1000; |
| 359 | constexpr integercxx . . $ integer# sampleRateFactor = 2; |
| 360 | constexpr integercxx . . $ integer# numberOfPaddingSides = 2; // namely beginning and end |
| 361 | const integercxx . . $ integer# nfft = Melder_iroundUpToPowerOfTwocxx . . $ Melder_iroundUpToPowerOfTwo(8ce0d1b217db7fd1). (mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx. + antiTurnAround * numberOfPaddingSides); |
| 362 | const double newDx = mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx. / sampleRateFactor; |
| 363 | /* |
| 364 | The computation of the new x1 relies on the idea that the left edge |
| 365 | of the old first sample should coincide with the left edge of the new first sample |
| 366 | (typically, e.g. if the old first sample starts at zero, which is usual, |
| 367 | then the new first sample should also start at zero): |
| 368 | old x1 - 0.5 * old dx == new x1 - 0.5 * new dx |
| 369 | ==> |
| 370 | new x1 == old x1 - 0.5 * (old dx - new dx) |
| 371 | */ |
| 372 | autoSoundcxx . . $ autoSound# thee = Sound_createcxx . . $ Sound_create(39ab106d6b9a0135). (mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny., mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin., mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax., mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx. * sampleRateFactor, |
| 373 | newDx, mycxx . . $ `melder/melder.h:44:9`! x1cxx . . $ structSampled#x1. - 0.5 * (mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx. - newDx)); |
| 374 | for (integercxx . . $ integer# ichan = 1; ichan <= mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny.; ichan ++) { |
| 375 | autoVECcxx . . $ autoVEC# data = zero_VECcxx . . $ zero_VEC(e4395f764b859b1e). (sampleRateFactor * nfft); // zeroing is important... |
| 376 | datacxx . . $ vectorview#vectorview(eac9d6ec4c4bfecd)..partcxx . . $ autovector#part(2d8d48654ca64e70). (antiTurnAround + 1, antiTurnAround + mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.) <<=cxx . . $ `operator<<=`(adea042513329390). mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z..rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (ichan); // ...because this fills only part of the sound |
| 377 | NUMrealftcxx . . $ NUMrealft(6864105cb93afedb). (data.partcxx . . $ autovector#part(2d8d48654ca64e70). (1, nfft), 1); |
| 378 | const integercxx . . $ integer# imin = (integercxx . . $ integer#) (nfft * 0.95); |
| 379 | for (integercxx . . $ integer# i = imin + 1; i <= nfft; i ++) |
| 380 | data [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] *= ((double) (nfft - i)) / (nfft - imin); |
| 381 | data [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).2] = 0.0; |
| 382 | NUMrealftcxx . . $ NUMrealft(6864105cb93afedb). (data.getcxx . . $ autovector#get(e8d1da7fe68a6585).(), -1); |
| 383 | const double factor = 1.0 / nfft; |
| 384 | for (integercxx . . $ integer# i = 1; i <= thycxx . . $ `melder/melder.h:45:9`! nxcxx . . $ structSampled#nx.; i ++) |
| 385 | thycxx . . $ `melder/melder.h:45:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).ichan] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i] = data [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i + sampleRateFactor * antiTurnAround] * factor; |
| 386 | } |
| 387 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 388 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 389 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": not upsampled."); |
| 390 | } |
| 391 | } |
| 392 | |
| 393 | autoSoundcxx . . $ autoSound# Sound_resamplecxx . . $ Sound_resample(872961da5f5e69e5). (constSoundcxx . . $ constSound# me, double samplingFrequency, integercxx . . $ integer# precision) { |
| 394 | const double upfactor = samplingFrequency * mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx.; |
| 395 | if (fabscxx . . $ fabs(fee4f1d22bc8e617). (upfactor - 2.0) < 1e-6) |
| 396 | return Sound_upsamplecxx . . $ Sound_upsample(4e9053a6db58af83). (me); |
| 397 | if (fabscxx . . $ fabs(fee4f1d22bc8e617). (upfactor - 1.0) < 1e-6) |
| 398 | return Data_copycxx . . $ Data_copy(97a542a26794c80e). (me); |
| 399 | try { |
| 400 | const integercxx . . $ integer# numberOfSamples = Melder_iroundcxx . . $ `melder/melder_ftoi.h:78:9`! ((mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax. - mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin.) * samplingFrequency); |
| 401 | if (numberOfSamples < 1) |
| 402 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"The resampled Sound would have no samples."); |
| 403 | autoSoundcxx . . $ autoSound# filteredcxx . . $ autoSomeThing#autoSomeThing(49f6e7a06ebc5aa8).; |
| 404 | const bool weNeedAnAntiAliasingFilter = ( upfactor < 1.0 ); |
| 405 | if (weNeedAnAntiAliasingFilter) { |
| 406 | constexpr integercxx . . $ integer# antiTurnAround = 1000; |
| 407 | constexpr integercxx . . $ integer# numberOfPaddingSides = 2; // namely beginning and end |
| 408 | const integercxx . . $ integer# nfft = Melder_iroundUpToPowerOfTwocxx . . $ Melder_iroundUpToPowerOfTwo(8ce0d1b217db7fd1). (mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx. + antiTurnAround * numberOfPaddingSides); |
| 409 | autoVECcxx . . $ autoVEC# data = raw_VECcxx . . $ raw_VEC(e4395f764b859b1e). (nfft); // will be zeroed in every turn of the loop |
| 410 | filtered =cxx . . $ autoSomeThing#`operator=`(80cc59814f7161e8). Sound_createcxx . . $ Sound_create(39ab106d6b9a0135). (mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny., mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin., mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax., mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx., mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx., mycxx . . $ `melder/melder.h:44:9`! x1cxx . . $ structSampled#x1.); |
| 411 | for (integercxx . . $ integer# ichan = 1; ichan <= mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny.; ichan ++) { |
| 412 | for (integercxx . . $ integer# i = 1; i <= nfft; i ++) |
| 413 | data [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] = 0.0; |
| 414 | datacxx . . $ vectorview#vectorview(eac9d6ec4c4bfecd)..partcxx . . $ autovector#part(2d8d48654ca64e70). (antiTurnAround + 1, antiTurnAround + mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.) <<=cxx . . $ `operator<<=`(adea042513329390). mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z..rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (ichan); |
| 415 | NUMrealftcxx . . $ NUMrealft(6864105cb93afedb). (data.getcxx . . $ autovector#get(e8d1da7fe68a6585).(), 1); // go to the frequency domain |
| 416 | for (integercxx . . $ integer# i = Melder_ifloorcxx . . $ `melder/melder_ftoi.h:33:9`! (upfactor * nfft); i <= nfft; i ++) |
| 417 | data [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] = 0.0; // filter away high frequencies |
| 418 | data [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).2] = 0.0; |
| 419 | NUMrealftcxx . . $ NUMrealft(6864105cb93afedb). (data.getcxx . . $ autovector#get(e8d1da7fe68a6585).(), -1); // return to the time domain |
| 420 | const double factor = 1.0 / nfft; |
| 421 | const VECcxx . . $ VEC# to = filtered ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). zcxx . . $ structMatrix#z..rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (ichan); |
| 422 | for (integercxx . . $ integer# i = 1; i <= mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.; i ++) |
| 423 | to [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i] = data [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i + antiTurnAround] * factor; |
| 424 | } |
| 425 | me = filtered.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(); // reference copy; remove at end |
| 426 | } |
| 427 | autoSoundcxx . . $ autoSound# thee = Sound_createcxx . . $ Sound_create(39ab106d6b9a0135). (mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny., mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin., mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax., numberOfSamples, 1.0 / samplingFrequency, |
| 428 | 0.5 * (mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin. + mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax. - (numberOfSamples - 1) / samplingFrequency)); |
| 429 | for (integercxx . . $ integer# ichan = 1; ichan <= mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny.; ichan ++) { |
| 430 | if (precision <= 1) { |
| 431 | for (integercxx . . $ integer# i = 1; i <= numberOfSamples; i ++) { |
| 432 | const double x = Sampled_indexToXcxx . . $ Sampled_indexToX(65bcd2c9acbb3dd5). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), i); |
| 433 | const double index = Sampled_xToIndexcxx . . $ Sampled_xToIndex(b395a896ba2eff9a). (me, x); |
| 434 | const integercxx . . $ integer# leftSample = Melder_ifloorcxx . . $ `melder/melder_ftoi.h:33:9`! (index); |
| 435 | const double fraction = index - leftSample; |
| 436 | thycxx . . $ `melder/melder.h:45:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).ichan] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i] = ( leftSample < 1 || leftSample >= mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx. ? 0.0 : |
| 437 | (1 - fraction) * mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).ichan] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).leftSample] + fraction * mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).ichan] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).leftSample + 1] ); |
| 438 | } |
| 439 | } else { |
| 440 | for (integercxx . . $ integer# i = 1; i <= numberOfSamples; i ++) { |
| 441 | const double x = Sampled_indexToXcxx . . $ Sampled_indexToX(65bcd2c9acbb3dd5). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), i); |
| 442 | const double index = Sampled_xToIndexcxx . . $ Sampled_xToIndex(b395a896ba2eff9a). (me, x); |
| 443 | thycxx . . $ `melder/melder.h:45:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).ichan] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i] = NUM_interpolate_sinccxx . . $ NUM_interpolate_sinc(3bff97c7d2c43d6f). (mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z..rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (ichan), index, precision); |
| 444 | } |
| 445 | } |
| 446 | } |
| 447 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 448 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 449 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": not resampled."); |
| 450 | } |
| 451 | } |
| 452 | |
| 453 | autoSoundcxx . . $ autoSound# Sounds_appendcxx . . $ Sounds_append(87708204a3e78041). (constSoundcxx . . $ constSound# me, double silenceDuration, constSoundcxx . . $ constSound# thee) { |
| 454 | try { |
| 455 | const integercxx . . $ integer# nx_silence = Melder_iroundcxx . . $ `melder/melder_ftoi.h:78:9`! (silenceDuration / mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx.), nx = mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx. + nx_silence + thycxx . . $ `melder/melder.h:45:9`! nxcxx . . $ structSampled#nx.; |
| 456 | if (mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny. != thycxx . . $ `melder/melder.h:45:9`! nycxx . . $ structSampledXY#ny.) |
| 457 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"The numbers of channels are not equal (e.g. one is mono, the other stereo)."); |
| 458 | if (mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx. != thycxx . . $ `melder/melder.h:45:9`! dxcxx . . $ structSampled#dx.) |
| 459 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"The sampling frequencies are not equal."); |
| 460 | autoSoundcxx . . $ autoSound# him = Sound_createcxx . . $ Sound_create(39ab106d6b9a0135). (mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny., 0.0, nx * mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx., nx, mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx., 0.5 * mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx.); |
| 461 | hiscxx . . $ `melder/melder.h:47:9`! zcxx . . $ structMatrix#z..verticalBandcxx . . $ automatrix#verticalBand(244fa7aab97a21b1). (1, mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.) <<=cxx . . $ `operator<<=`(a7d93ba40fe22fe0). mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z..allcxx . . $ automatrix#all(2114117ba8ed4224).(); |
| 462 | hiscxx . . $ `melder/melder.h:47:9`! zcxx . . $ structMatrix#z..verticalBandcxx . . $ automatrix#verticalBand(244fa7aab97a21b1). (mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx. + nx_silence + 1, nx) <<=cxx . . $ `operator<<=`(a7d93ba40fe22fe0). thycxx . . $ `melder/melder.h:45:9`! zcxx . . $ structMatrix#z..allcxx . . $ automatrix#all(2114117ba8ed4224).(); |
| 463 | return himcxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 464 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 465 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U" & ", thee, U": not appended."); |
| 466 | } |
| 467 | } |
| 468 | |
| 469 | autoSoundcxx . . $ autoSound# Sounds_concatenatecxx . . $ Sounds_concatenate(83bbb24deeaff801). (SoundListcxx . . $ SoundList# list, double overlapTime) { |
| 470 | try { |
| 471 | integercxx . . $ integer# sharedNumberOfChannels = 0, totalNumberOfSamples = 0; |
| 472 | double sharedTimeStep = 0.0; |
| 473 | for (integercxx . . $ integer# i = 1; i <= list->sizecxx . . $ CollectionOf#size.; i ++) { |
| 474 | const Soundcxx . . $ Sound# sound = list->atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).i]; |
| 475 | if (sharedNumberOfChannels == 0) { |
| 476 | sharedNumberOfChannels = sound -> nycxx . . $ structSampledXY#ny.; |
| 477 | } else if (sound -> nycxx . . $ structSampledXY#ny. != sharedNumberOfChannels) { |
| 478 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"To concatenate sounds, their numbers of channels (mono, stereo) should be equal."); |
| 479 | } |
| 480 | if (sharedTimeStep == 0.0) { |
| 481 | sharedTimeStep = sound -> dxcxx . . $ structSampled#dx.; |
| 482 | } else if (sound -> dxcxx . . $ structSampled#dx. != sharedTimeStep) { |
| 483 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"To concatenate sounds, their sampling frequencies should be equal.\n" |
| 484 | U"You could resample one or more of the sounds before concatenating."); |
| 485 | } |
| 486 | totalNumberOfSamples += sound -> nxcxx . . $ structSampled#nx.; |
| 487 | } |
| 488 | const integercxx . . $ integer# numberOfSmoothingSamples = Melder_iroundcxx . . $ `melder/melder_ftoi.h:78:9`! (overlapTime / sharedTimeStep); |
| 489 | totalNumberOfSamples -= numberOfSmoothingSamples * (list->sizecxx . . $ CollectionOf#size. - 1); |
| 490 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (totalNumberOfSamples > 0, |
| 491 | U"The joint overlap should not exceed the total duration of the sounds.\nChoose a shorter overlap time."); |
| 492 | autoSoundcxx . . $ autoSound# thee = Sound_createcxx . . $ Sound_create(39ab106d6b9a0135). (sharedNumberOfChannels, 0.0, totalNumberOfSamples * sharedTimeStep, |
| 493 | totalNumberOfSamples, sharedTimeStep, 0.5 * sharedTimeStep); |
| 494 | autoVECcxx . . $ autoVEC# smoothercxx . . $ autovector#autovector(49f6e7a06ebc5aa8).; |
| 495 | if (numberOfSmoothingSamples > 0) { |
| 496 | smoother =cxx . . $ autovector#`operator=`(f4f0443dbfdd1e40). raw_VECcxx . . $ raw_VEC(e4395f764b859b1e). (numberOfSmoothingSamples); |
| 497 | const double factor = NUMpicxx . . $ NUMpi. / numberOfSmoothingSamples; |
| 498 | for (integercxx . . $ integer# i = 1; i <= numberOfSmoothingSamples; i ++) |
| 499 | smoother [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] = 0.5 - 0.5 * coscxx . . $ cos(fee4f1d22bc8e617). (factor * (i - 0.5)); |
| 500 | } |
| 501 | integercxx . . $ integer# sampleOffset = 0; |
| 502 | for (integercxx . . $ integer# i = 1; i <= list->sizecxx . . $ CollectionOf#size.; i ++) { |
| 503 | const Soundcxx . . $ Sound# sound = list->atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).i]; |
| 504 | if (numberOfSmoothingSamples > 2 * sound -> nxcxx . . $ structSampled#nx.) |
| 505 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"At least one of the sounds is shorter than twice the overlap time.\nChoose a shorter overlap time."); |
| 506 | const bool thisIsTheFirstSound = ( i == 1 ); |
| 507 | const bool thisIsTheLastSound = ( i == list->sizecxx . . $ CollectionOf#size. ); |
| 508 | const bool weNeedSmoothingAtTheStartOfThisSound = ! thisIsTheFirstSound; |
| 509 | const bool weNeedSmoothingAtTheEndOfThisSound = ! thisIsTheLastSound; |
| 510 | const integercxx . . $ integer# numberOfSmoothingSamplesAtTheStartOfThisSound = ( weNeedSmoothingAtTheStartOfThisSound ? numberOfSmoothingSamples : 0 ); |
| 511 | const integercxx . . $ integer# numberOfSmoothingSamplesAtTheEndOfThisSound = ( weNeedSmoothingAtTheEndOfThisSound ? numberOfSmoothingSamples : 0 ); |
| 512 | for (integercxx . . $ integer# channel = 1; channel <= sharedNumberOfChannels; channel ++) { |
| 513 | for (integercxx . . $ integer# j = 1, mySample = 1, thySample = mySample + sampleOffset; |
| 514 | j <= numberOfSmoothingSamplesAtTheStartOfThisSound; |
| 515 | j ++, mySample ++, thySample ++) |
| 516 | { |
| 517 | thycxx . . $ `melder/melder.h:45:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).channel] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).thySample] += sound -> zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).channel] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).mySample] * smoother [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).j]; // add |
| 518 | } |
| 519 | thycxx . . $ `melder/melder.h:45:9`! zcxx . . $ structMatrix#z..rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (channel).partcxx . . $ vector#part(ae267db9e2c04be7). (sampleOffset + 1 + numberOfSmoothingSamplesAtTheStartOfThisSound, |
| 520 | sampleOffset + sound -> nxcxx . . $ structSampled#nx. - numberOfSmoothingSamplesAtTheEndOfThisSound) <<=cxx . . $ `operator<<=`(adea042513329390). |
| 521 | soundcxx . . $ constvectorview#constvectorview(eac9d6ec4c4bfecd). -> zcxx . . $ structMatrix#z..rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (channel).partcxx . . $ vector#part(ae267db9e2c04be7). (1 + numberOfSmoothingSamplesAtTheStartOfThisSound, |
| 522 | sound -> nxcxx . . $ structSampled#nx. - numberOfSmoothingSamplesAtTheEndOfThisSound); |
| 523 | for (integercxx . . $ integer# j = 1, mySample = sound -> nxcxx . . $ structSampled#nx. - numberOfSmoothingSamplesAtTheEndOfThisSound + 1, thySample = mySample + sampleOffset; |
| 524 | j <= numberOfSmoothingSamplesAtTheEndOfThisSound; |
| 525 | j ++, mySample ++, thySample ++) |
| 526 | { |
| 527 | thycxx . . $ `melder/melder.h:45:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).channel] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).thySample] = sound -> zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).channel] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).mySample] * smoother [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).numberOfSmoothingSamplesAtTheEndOfThisSound + 1 - j]; // replace (or add, which is the same since it's all zeroes to start with) |
| 528 | } |
| 529 | } |
| 530 | sampleOffset += sound -> nxcxx . . $ structSampled#nx. - numberOfSmoothingSamplesAtTheEndOfThisSound; |
| 531 | } |
| 532 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (sampleOffset == totalNumberOfSamples); |
| 533 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 534 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 535 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Sounds not concatenated."); |
| 536 | } |
| 537 | } |
| 538 | |
| 539 | autoSoundcxx . . $ autoSound# Sounds_convolvecxx . . $ Sounds_convolve(b7360aaa447e63e). (constSoundcxx . . $ constSound# me, constSoundcxx . . $ constSound# thee, kSounds_convolve_scaling scaling, kSounds_convolve_signalOutsideTimeDomain signalOutsideTimeDomain) { |
| 540 | try { |
| 541 | if (mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny. > 1 && thycxx . . $ `melder/melder.h:45:9`! nycxx . . $ structSampledXY#ny. > 1 && mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny. != thycxx . . $ `melder/melder.h:45:9`! nycxx . . $ structSampledXY#ny.) |
| 542 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"The numbers of channels of the two sounds have to be equal or 1."); |
| 543 | if (mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx. != thycxx . . $ `melder/melder.h:45:9`! dxcxx . . $ structSampled#dx.) |
| 544 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"The sampling frequencies of the two sounds have to be equal."); |
| 545 | const integercxx . . $ integer# n1 = mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx., n2 = thycxx . . $ `melder/melder.h:45:9`! nxcxx . . $ structSampled#nx.; |
| 546 | const integercxx . . $ integer# n3 = n1 + n2 - 1; |
| 547 | const integercxx . . $ integer# nfft = Melder_iroundUpToPowerOfTwocxx . . $ Melder_iroundUpToPowerOfTwo(8ce0d1b217db7fd1). (n3); |
| 548 | autoVECcxx . . $ autoVEC# data1 = raw_VECcxx . . $ raw_VEC(e4395f764b859b1e). (nfft); |
| 549 | autoVECcxx . . $ autoVEC# data2 = raw_VECcxx . . $ raw_VEC(e4395f764b859b1e). (nfft); |
| 550 | integercxx . . $ integer# numberOfChannels = stdcxx . . $ std/::maxcxx . . $ std/max(2a338fce5842aa6a). (mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny., thycxx . . $ `melder/melder.h:45:9`! nycxx . . $ structSampledXY#ny.); |
| 551 | autoSoundcxx . . $ autoSound# him = Sound_createcxx . . $ Sound_create(39ab106d6b9a0135). (numberOfChannels, mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin. + thycxx . . $ `melder/melder.h:45:9`! xmincxx . . $ structFunction#xmin., mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax. + thycxx . . $ `melder/melder.h:45:9`! xmaxcxx . . $ structFunction#xmax., n3, mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx., mycxx . . $ `melder/melder.h:44:9`! x1cxx . . $ structSampled#x1. + thycxx . . $ `melder/melder.h:45:9`! x1cxx . . $ structSampled#x1.); |
| 552 | for (integercxx . . $ integer# channel = 1; channel <= numberOfChannels; channel ++) { |
| 553 | VECcxx . . $ VEC# a = mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z..rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny. == 1 ? 1 : channel); |
| 554 | for (integercxx . . $ integer# i = n1; i > 0; i --) |
| 555 | data1 [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] = a [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i]; |
| 556 | for (integercxx . . $ integer# i = n1 + 1; i <= nfft; i ++) |
| 557 | data1 [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] = 0.0; |
| 558 | a =cxx . . $ vector#`operator=`(b5ebf627ac2fae1e). thycxx . . $ `melder/melder.h:45:9`! zcxx . . $ structMatrix#z..rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (thycxx . . $ `melder/melder.h:45:9`! nycxx . . $ structSampledXY#ny. == 1 ? 1 : channel); |
| 559 | for (integercxx . . $ integer# i = n2; i > 0; i --) |
| 560 | data2 [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] = a [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i]; |
| 561 | for (integercxx . . $ integer# i = n2 + 1; i <= nfft; i ++) |
| 562 | data2 [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] = 0.0; |
| 563 | NUMrealftcxx . . $ NUMrealft(6864105cb93afedb). (data1.getcxx . . $ autovector#get(e8d1da7fe68a6585).(), 1); |
| 564 | NUMrealftcxx . . $ NUMrealft(6864105cb93afedb). (data2.getcxx . . $ autovector#get(e8d1da7fe68a6585).(), 1); |
| 565 | data2 [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).1] *= data1 [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).1]; |
| 566 | data2 [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).2] *= data1 [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).2]; |
| 567 | for (integercxx . . $ integer# i = 3; i <= nfft; i += 2) { |
| 568 | const double temp = data1 [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] * data2 [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] - data1 [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i + 1] * data2 [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i + 1]; |
| 569 | data2 [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i + 1] = data1 [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] * data2 [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i + 1] + data1 [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i + 1] * data2 [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i]; |
| 570 | data2 [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] = temp; |
| 571 | } |
| 572 | NUMrealftcxx . . $ NUMrealft(6864105cb93afedb). (data2.getcxx . . $ autovector#get(e8d1da7fe68a6585).(), -1); |
| 573 | a =cxx . . $ vector#`operator=`(b5ebf627ac2fae1e). hiscxx . . $ `melder/melder.h:47:9`! zcxx . . $ structMatrix#z..rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (channel); |
| 574 | for (integercxx . . $ integer# i = 1; i <= n3; i ++) |
| 575 | a [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i] = data2 [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i]; |
| 576 | } |
| 577 | switch (signalOutsideTimeDomain) { |
| 578 | case kSounds_convolve_signalOutsideTimeDomain::ZERO: { |
| 579 | // do nothing |
| 580 | } break; |
| 581 | case kSounds_convolve_signalOutsideTimeDomain::SIMILAR: { |
| 582 | for (integercxx . . $ integer# channel = 1; channel <= numberOfChannels; channel ++) { |
| 583 | const VECcxx . . $ VEC# a = hiscxx . . $ `melder/melder.h:47:9`! zcxx . . $ structMatrix#z..rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (channel); |
| 584 | const double edge = stdcxx . . $ std/::mincxx . . $ std/min(2a338fce5842aa6a). (n1, n2); |
| 585 | for (integercxx . . $ integer# i = 1; i < edge; i ++) { |
| 586 | const double factor = edge / i; |
| 587 | a [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i] *= factor; |
| 588 | a [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).n3 + 1 - i] *= factor; |
| 589 | } |
| 590 | } |
| 591 | } break; |
| 592 | //case kSounds_convolve_signalOutsideTimeDomain_PERIODIC: { |
| 593 | // do nothing |
| 594 | //} break; |
| 595 | default: Melder_crashcxx . . $ `melder/melder_error.h:98:9`! (U"Sounds_convolve: unimplemented outside-time-domain strategy ", (int) signalOutsideTimeDomain); |
| 596 | } |
| 597 | switch (scaling) { |
| 598 | case kSounds_convolve_scaling::INTEGRAL: { |
| 599 | Vector_multiplyByScalarcxx . . $ Vector_multiplyByScalar(54f31cdb89d1acde). (him.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx. / nfft); |
| 600 | } break; |
| 601 | case kSounds_convolve_scaling::SUM: { |
| 602 | Vector_multiplyByScalarcxx . . $ Vector_multiplyByScalar(54f31cdb89d1acde). (him.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), 1.0 / nfft); |
| 603 | } break; |
| 604 | case kSounds_convolve_scaling::NORMALIZE: { |
| 605 | double normalizationFactor = Matrix_getNormcxx . . $ Matrix_getNorm(97cb7fd1b392c56c). (me) * Matrix_getNormcxx . . $ Matrix_getNorm(97cb7fd1b392c56c). (thee); |
| 606 | if (normalizationFactor != 0.0) |
| 607 | Vector_multiplyByScalarcxx . . $ Vector_multiplyByScalar(54f31cdb89d1acde). (him.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), 1.0 / nfft / normalizationFactor); |
| 608 | } break; |
| 609 | case kSounds_convolve_scaling::PEAK_099: { |
| 610 | Vector_scalecxx . . $ Vector_scale(54f31cdb89d1acde). (him.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), 0.99); |
| 611 | } break; |
| 612 | default: Melder_crashcxx . . $ `melder/melder_error.h:98:9`! (U"Sounds_convolve: unimplemented scaling ", (int) scaling); |
| 613 | } |
| 614 | return himcxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 615 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 616 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U" & ", thee, U": not convolved."); |
| 617 | } |
| 618 | } |
| 619 | |
| 620 | autoSoundcxx . . $ autoSound# Sounds_crossCorrelatecxx . . $ Sounds_crossCorrelate(b7360aaa447e63e). (constSoundcxx . . $ constSound# me, constSoundcxx . . $ constSound# thee, kSounds_convolve_scaling scaling, kSounds_convolve_signalOutsideTimeDomain signalOutsideTimeDomain) { |
| 621 | try { |
| 622 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (mycxx . . $ `melder/melder.h:44:9`! ny == 1 || thycxx . . $ `melder/melder.h:45:9`! ny == 1 || mycxx . . $ `melder/melder.h:44:9`! ny == thycxx . . $ `melder/melder.h:45:9`! ny, |
| 623 | U"The numbers of channels of the two sounds have to be equal or 1."); |
| 624 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (mycxx . . $ `melder/melder.h:44:9`! dx == thycxx . . $ `melder/melder.h:45:9`! dx, |
| 625 | U"The sampling frequencies of the two sounds have to be equal."); |
| 626 | const integercxx . . $ integer# numberOfChannels = stdcxx . . $ std/::maxcxx . . $ std/max(2a338fce5842aa6a). (mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny., thycxx . . $ `melder/melder.h:45:9`! nycxx . . $ structSampledXY#ny.); |
| 627 | const integercxx . . $ integer# n1 = mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx., n2 = thycxx . . $ `melder/melder.h:45:9`! nxcxx . . $ structSampled#nx., n3 = n1 + n2 - 1; |
| 628 | const integercxx . . $ integer# nfft = Melder_iroundUpToPowerOfTwocxx . . $ Melder_iroundUpToPowerOfTwo(8ce0d1b217db7fd1). (n3); |
| 629 | autoVECcxx . . $ autoVEC# data1 = raw_VECcxx . . $ raw_VEC(e4395f764b859b1e). (nfft); |
| 630 | autoVECcxx . . $ autoVEC# data2 = raw_VECcxx . . $ raw_VEC(e4395f764b859b1e). (nfft); |
| 631 | const double my_xlast = mycxx . . $ `melder/melder.h:44:9`! x1cxx . . $ structSampled#x1. + (n1 - 1) * mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx.; |
| 632 | autoSoundcxx . . $ autoSound# him = Sound_createcxx . . $ Sound_create(39ab106d6b9a0135). (numberOfChannels, thycxx . . $ `melder/melder.h:45:9`! xmincxx . . $ structFunction#xmin. - mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax., thycxx . . $ `melder/melder.h:45:9`! xmaxcxx . . $ structFunction#xmax. - mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin., n3, mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx., thycxx . . $ `melder/melder.h:45:9`! x1cxx . . $ structSampled#x1. - my_xlast); |
| 633 | for (integercxx . . $ integer# channel = 1; channel <= numberOfChannels; channel ++) { |
| 634 | VECcxx . . $ VEC# a = mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z..rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny. == 1 ? 1 : channel); |
| 635 | for (integercxx . . $ integer# i = n1; i > 0; i --) |
| 636 | data1 [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] = a [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i]; |
| 637 | for (integercxx . . $ integer# i = n1 + 1; i <= nfft; i ++) |
| 638 | data1 [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] = 0.0; |
| 639 | a =cxx . . $ vector#`operator=`(b5ebf627ac2fae1e). thycxx . . $ `melder/melder.h:45:9`! zcxx . . $ structMatrix#z..rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (thycxx . . $ `melder/melder.h:45:9`! nycxx . . $ structSampledXY#ny. == 1 ? 1 : channel); |
| 640 | for (integercxx . . $ integer# i = n2; i > 0; i --) |
| 641 | data2 [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] = a [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i]; |
| 642 | for (integercxx . . $ integer# i = n2 + 1; i <= nfft; i ++) |
| 643 | data2 [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] = 0.0; |
| 644 | NUMrealftcxx . . $ NUMrealft(6864105cb93afedb). (data1.getcxx . . $ autovector#get(e8d1da7fe68a6585).(), 1); |
| 645 | NUMrealftcxx . . $ NUMrealft(6864105cb93afedb). (data2.getcxx . . $ autovector#get(e8d1da7fe68a6585).(), 1); |
| 646 | data2 [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).1] *= data1 [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).1]; |
| 647 | data2 [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).2] *= data1 [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).2]; |
| 648 | for (integercxx . . $ integer# i = 3; i <= nfft; i += 2) { |
| 649 | const double temp = data1 [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] * data2 [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] + data1 [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i + 1] * data2 [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i + 1]; // reverse me by taking the conjugate of data1 |
| 650 | data2 [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i + 1] = data1 [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] * data2 [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i + 1] - data1 [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i + 1] * data2 [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i]; // reverse me by taking the conjugate of data1 |
| 651 | data2 [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] = temp; |
| 652 | } |
| 653 | NUMrealftcxx . . $ NUMrealft(6864105cb93afedb). (data2.getcxx . . $ autovector#get(e8d1da7fe68a6585).(), -1); |
| 654 | a =cxx . . $ vector#`operator=`(b5ebf627ac2fae1e). hiscxx . . $ `melder/melder.h:47:9`! zcxx . . $ structMatrix#z..rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (channel); |
| 655 | for (integercxx . . $ integer# i = 1; i < n1; i ++) |
| 656 | a [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i] = data2 [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i + (nfft - (n1 - 1))]; // data for the first part ("negative lags") is at the end of data2 |
| 657 | for (integercxx . . $ integer# i = 1; i <= n2; i ++) |
| 658 | a [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i + (n1 - 1)] = data2 [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i]; // data for the second part ("positive lags") is at the beginning of data2 |
| 659 | } |
| 660 | switch (signalOutsideTimeDomain) { |
| 661 | case kSounds_convolve_signalOutsideTimeDomain::ZERO: { |
| 662 | // do nothing |
| 663 | } break; |
| 664 | case kSounds_convolve_signalOutsideTimeDomain::SIMILAR: { |
| 665 | for (integercxx . . $ integer# channel = 1; channel <= numberOfChannels; channel ++) { |
| 666 | double *const a = & hiscxx . . $ `melder/melder.h:47:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).channel] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).0]; |
| 667 | double const edge = stdcxx . . $ std/::mincxx . . $ std/min(2a338fce5842aa6a). (n1, n2); |
| 668 | for (integercxx . . $ integer# i = 1; i < edge; i ++) { |
| 669 | const double factor = edge / i; |
| 670 | a [i] *= factor; |
| 671 | a [n3 + 1 - i] *= factor; |
| 672 | } |
| 673 | } |
| 674 | } break; |
| 675 | //case kSounds_convolve_signalOutsideTimeDomain_PERIODIC: { |
| 676 | // do nothing |
| 677 | //} break; |
| 678 | default: Melder_crashcxx . . $ `melder/melder_error.h:98:9`! (U"Sounds_crossCorrelate: unimplemented outside-time-domain strategy ", (int) signalOutsideTimeDomain); |
| 679 | } |
| 680 | switch (scaling) { |
| 681 | case kSounds_convolve_scaling::INTEGRAL: { |
| 682 | Vector_multiplyByScalarcxx . . $ Vector_multiplyByScalar(54f31cdb89d1acde). (him.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx. / nfft); |
| 683 | } break; |
| 684 | case kSounds_convolve_scaling::SUM: { |
| 685 | Vector_multiplyByScalarcxx . . $ Vector_multiplyByScalar(54f31cdb89d1acde). (him.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), 1.0 / nfft); |
| 686 | } break; |
| 687 | case kSounds_convolve_scaling::NORMALIZE: { |
| 688 | const double normalizationFactor = Matrix_getNormcxx . . $ Matrix_getNorm(97cb7fd1b392c56c). (me) * Matrix_getNormcxx . . $ Matrix_getNorm(97cb7fd1b392c56c). (thee); |
| 689 | if (normalizationFactor != 0.0) |
| 690 | Vector_multiplyByScalarcxx . . $ Vector_multiplyByScalar(54f31cdb89d1acde). (him.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), 1.0 / nfft / normalizationFactor); |
| 691 | } break; |
| 692 | case kSounds_convolve_scaling::PEAK_099: { |
| 693 | Vector_scalecxx . . $ Vector_scale(54f31cdb89d1acde). (him.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), 0.99); |
| 694 | } break; |
| 695 | default: Melder_crashcxx . . $ `melder/melder_error.h:98:9`! (U"Sounds_crossCorrelate: unimplemented scaling ", (int) scaling); |
| 696 | } |
| 697 | return himcxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 698 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 699 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U" & ", thee, U": not cross-correlated."); |
| 700 | } |
| 701 | } |
| 702 | |
| 703 | autoSoundcxx . . $ autoSound# Sound_autoCorrelatecxx . . $ Sound_autoCorrelate(48c242b038311e1f). (constSoundcxx . . $ constSound# me, kSounds_convolve_scaling scaling, kSounds_convolve_signalOutsideTimeDomain signalOutsideTimeDomain) { |
| 704 | try { |
| 705 | const integercxx . . $ integer# numberOfChannels = mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny., n1 = mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx., n2 = n1 + n1 - 1; |
| 706 | const integercxx . . $ integer# nfft = Melder_iroundUpToPowerOfTwocxx . . $ Melder_iroundUpToPowerOfTwo(8ce0d1b217db7fd1). (n2); |
| 707 | autoVECcxx . . $ autoVEC# data = raw_VECcxx . . $ raw_VEC(e4395f764b859b1e). (nfft); |
| 708 | const double my_xlast = mycxx . . $ `melder/melder.h:44:9`! x1cxx . . $ structSampled#x1. + (n1 - 1) * mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx.; |
| 709 | autoSoundcxx . . $ autoSound# thee = Sound_createcxx . . $ Sound_create(39ab106d6b9a0135). (numberOfChannels, mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin. - mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax., mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax. - mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin., n2, mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx., mycxx . . $ `melder/melder.h:44:9`! x1cxx . . $ structSampled#x1. - my_xlast); |
| 710 | for (integercxx . . $ integer# channel = 1; channel <= numberOfChannels; channel ++) { |
| 711 | VECcxx . . $ VEC# a = mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z..rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (channel); |
| 712 | for (integercxx . . $ integer# i = n1; i > 0; i --) |
| 713 | data [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] = a [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i]; |
| 714 | for (integercxx . . $ integer# i = n1 + 1; i <= nfft; i ++) |
| 715 | data [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] = 0.0; |
| 716 | NUMrealftcxx . . $ NUMrealft(6864105cb93afedb). (data.getcxx . . $ autovector#get(e8d1da7fe68a6585).(), 1); |
| 717 | data [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).1] *= data [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).1]; |
| 718 | data [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).2] *= data [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).2]; |
| 719 | for (integercxx . . $ integer# i = 3; i <= nfft; i += 2) { |
| 720 | data [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] = data [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] * data [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] + data [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i + 1] * data [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i + 1]; |
| 721 | data [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i + 1] = 0.0; // reverse me by taking the conjugate of data1 |
| 722 | } |
| 723 | NUMrealftcxx . . $ NUMrealft(6864105cb93afedb). (data.getcxx . . $ autovector#get(e8d1da7fe68a6585).(), -1); |
| 724 | a =cxx . . $ vector#`operator=`(b5ebf627ac2fae1e). thycxx . . $ `melder/melder.h:45:9`! zcxx . . $ structMatrix#z..rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (channel); |
| 725 | for (integercxx . . $ integer# i = 1; i < n1; i ++) |
| 726 | a [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i] = data [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i + (nfft - (n1 - 1))]; // data for the first part ("negative lags") is at the end of data |
| 727 | for (integercxx . . $ integer# i = 1; i <= n1; i ++) |
| 728 | a [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i + (n1 - 1)] = data [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i]; // data for the second part ("positive lags") is at the beginning of data |
| 729 | } |
| 730 | switch (signalOutsideTimeDomain) { |
| 731 | case kSounds_convolve_signalOutsideTimeDomain::ZERO: { |
| 732 | // do nothing |
| 733 | } break; |
| 734 | case kSounds_convolve_signalOutsideTimeDomain::SIMILAR: { |
| 735 | for (integercxx . . $ integer# channel = 1; channel <= numberOfChannels; channel ++) { |
| 736 | const VECcxx . . $ VEC# a = thycxx . . $ `melder/melder.h:45:9`! zcxx . . $ structMatrix#z..rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (channel); |
| 737 | const double edge = n1; |
| 738 | for (integercxx . . $ integer# i = 1; i < edge; i ++) { |
| 739 | const double factor = edge / i; |
| 740 | a [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i] *= factor; |
| 741 | a [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).n2 + 1 - i] *= factor; |
| 742 | } |
| 743 | } |
| 744 | } break; |
| 745 | //case kSounds_convolve_signalOutsideTimeDomain_PERIODIC: { |
| 746 | // do nothing |
| 747 | //} break; |
| 748 | default: Melder_crashcxx . . $ `melder/melder_error.h:98:9`! (U"Sounds_autoCorrelate: unimplemented outside-time-domain strategy ", (int) signalOutsideTimeDomain); |
| 749 | } |
| 750 | switch (scaling) { |
| 751 | case kSounds_convolve_scaling::INTEGRAL: { |
| 752 | Vector_multiplyByScalarcxx . . $ Vector_multiplyByScalar(54f31cdb89d1acde). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx. / nfft); |
| 753 | } break; |
| 754 | case kSounds_convolve_scaling::SUM: { |
| 755 | Vector_multiplyByScalarcxx . . $ Vector_multiplyByScalar(54f31cdb89d1acde). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), 1.0 / nfft); |
| 756 | } break; |
| 757 | case kSounds_convolve_scaling::NORMALIZE: { |
| 758 | const double normalizationFactor = Matrix_getNormcxx . . $ Matrix_getNorm(97cb7fd1b392c56c). (me) * Matrix_getNormcxx . . $ Matrix_getNorm(97cb7fd1b392c56c). (me); |
| 759 | if (normalizationFactor != 0.0) |
| 760 | Vector_multiplyByScalarcxx . . $ Vector_multiplyByScalar(54f31cdb89d1acde). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), 1.0 / nfft / normalizationFactor); |
| 761 | } break; |
| 762 | case kSounds_convolve_scaling::PEAK_099: { |
| 763 | Vector_scalecxx . . $ Vector_scale(54f31cdb89d1acde). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), 0.99); |
| 764 | } break; |
| 765 | default: Melder_crashcxx . . $ `melder/melder_error.h:98:9`! (U"Sounds_autoCorrelate: unimplemented scaling ", (int) scaling); |
| 766 | } |
| 767 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 768 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 769 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": autocorrelation not computed."); |
| 770 | } |
| 771 | } |
| 772 | |
| 773 | void Sound_drawcxx . . $ Sound_draw(9ce2a9dfe752ed09). (constSoundcxx . . $ constSound# me, Graphicscxx . . $ Graphics# g, |
| 774 | double tmin, double tmax, double minimum, double maximum, bool garnish, conststring32cxx . . $ conststring32# method) |
| 775 | { |
| 776 | const bool timesAreReversed = ( tmin > tmax ); |
| 777 | if (timesAreReversed) |
| 778 | stdcxx . . $ std/::swapcxx . . $ std/swap(c75b8fd57d7c2e06). (tmin, tmax); |
| 779 | Function_bidirectionalAutowindowcxx . . $ Function_bidirectionalAutowindow(88b7840c59a57eaf). (me, & tmin, & tmax); |
| 780 | /* |
| 781 | Domain expressed in sample numbers. |
| 782 | */ |
| 783 | integercxx . . $ integer# ixmin, ixmax; |
| 784 | const integercxx . . $ integer# n = Matrix_getWindowSamplesXcxx . . $ Matrix_getWindowSamplesX(c738979be11bd51a). (me, tmin, tmax, & ixmin, & ixmax); |
| 785 | if (n < 1) |
| 786 | return; |
| 787 | /* |
| 788 | Automatic vertical range. |
| 789 | */ |
| 790 | if (minimum == maximum) { |
| 791 | Matrix_getWindowExtremacxx . . $ Matrix_getWindowExtrema(d50591dd897af896). (me, ixmin, ixmax, 1, mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny., & minimum, & maximum); |
| 792 | if (minimum == maximum) { |
| 793 | minimum -= 1.0; |
| 794 | maximum += 1.0; |
| 795 | } |
| 796 | } |
| 797 | /* |
| 798 | Set coordinates for drawing. |
| 799 | */ |
| 800 | Graphics_setInnercxx . . $ Graphics_setInner(2d838ed765120c5d). (g); |
| 801 | for (integercxx . . $ integer# channel = 1; channel <= mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny.; channel ++) { |
| 802 | Graphics_setWindowcxx . . $ Graphics_setWindow(72bdb7937dbb13da). (g, timesAreReversed ? tmax : tmin, timesAreReversed ? tmin : tmax, |
| 803 | minimum - (mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny. - channel) * (maximum - minimum), |
| 804 | maximum + (channel - 1) * (maximum - minimum) |
| 805 | ); |
| 806 | if (str32strcxx . . $ str32str(2de17cd8f7c584a6). (method, U"bars") || str32strcxx . . $ str32str(2de17cd8f7c584a6). (method, U"Bars")) { |
| 807 | for (integercxx . . $ integer# ix = ixmin; ix <= ixmax; ix ++) { |
| 808 | const double x = Sampled_indexToXcxx . . $ Sampled_indexToX(65bcd2c9acbb3dd5). (me, ix); |
| 809 | const double y = stdcxx . . $ std/::mincxx . . $ std/min(2a338fce5842aa6a). (mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).channel] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).ix], maximum); |
| 810 | const double left = stdcxx . . $ std/::maxcxx . . $ std/max(2a338fce5842aa6a). (x - 0.5 * mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx., tmin); |
| 811 | const double right = stdcxx . . $ std/::mincxx . . $ std/min(2a338fce5842aa6a). (x + 0.5 * mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx., tmax); |
| 812 | Graphics_linecxx . . $ Graphics_line(72bdb7937dbb13da). (g, left, y, right, y); |
| 813 | Graphics_linecxx . . $ Graphics_line(72bdb7937dbb13da). (g, left, y, left, minimum); |
| 814 | Graphics_linecxx . . $ Graphics_line(72bdb7937dbb13da). (g, right, y, right, minimum); |
| 815 | } |
| 816 | } else if (str32strcxx . . $ str32str(2de17cd8f7c584a6). (method, U"poles") || str32strcxx . . $ str32str(2de17cd8f7c584a6). (method, U"Poles")) { |
| 817 | for (integercxx . . $ integer# ix = ixmin; ix <= ixmax; ix ++) { |
| 818 | const double x = Sampled_indexToXcxx . . $ Sampled_indexToX(65bcd2c9acbb3dd5). (me, ix); |
| 819 | Graphics_linecxx . . $ Graphics_line(72bdb7937dbb13da). (g, x, 0, x, mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).channel] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).ix]); |
| 820 | } |
| 821 | } else if (str32strcxx . . $ str32str(2de17cd8f7c584a6). (method, U"speckles") || str32strcxx . . $ str32str(2de17cd8f7c584a6). (method, U"Speckles")) { |
| 822 | for (integercxx . . $ integer# ix = ixmin; ix <= ixmax; ix ++) { |
| 823 | const double x = Sampled_indexToXcxx . . $ Sampled_indexToX(65bcd2c9acbb3dd5). (me, ix); |
| 824 | Graphics_specklecxx . . $ Graphics_speckle(c84ba9158791aef6). (g, x, mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).channel] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).ix]); |
| 825 | } |
| 826 | } else { |
| 827 | /* |
| 828 | The default: draw as a curve. |
| 829 | */ |
| 830 | Graphics_functioncxx . . $ Graphics_function(1c6279e2c8b8beb1). (g, & mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).channel] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).0], ixmin, ixmax, |
| 831 | Matrix_columnToXcxx . . $ Matrix_columnToX(89d6d8659270b8b7). (me, ixmin), Matrix_columnToXcxx . . $ Matrix_columnToX(89d6d8659270b8b7). (me, ixmax)); |
| 832 | } |
| 833 | } |
| 834 | Graphics_setWindowcxx . . $ Graphics_setWindow(72bdb7937dbb13da). (g, timesAreReversed ? tmax : tmin, timesAreReversed ? tmin : tmax, minimum, maximum); |
| 835 | if (garnish && mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny. == 2) |
| 836 | Graphics_linecxx . . $ Graphics_line(72bdb7937dbb13da). (g, tmin, 0.5 * (minimum + maximum), tmax, 0.5 * (minimum + maximum)); |
| 837 | Graphics_unsetInnercxx . . $ Graphics_unsetInner(2d838ed765120c5d). (g); |
| 838 | if (garnish) { |
| 839 | Graphics_drawInnerBoxcxx . . $ Graphics_drawInnerBox(2d838ed765120c5d). (g); |
| 840 | Graphics_textBottomcxx . . $ Graphics_textBottom(48cf1f690ec61203). (g, true, U"Time (s)"); |
| 841 | Graphics_marksBottomcxx . . $ Graphics_marksBottom(c3a11a8a55b243ff). (g, 2, true, true, false); |
| 842 | Graphics_setWindowcxx . . $ Graphics_setWindow(72bdb7937dbb13da). (g, tmin, tmax, minimum - (mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny. - 1) * (maximum - minimum), maximum); |
| 843 | Graphics_markLeftcxx . . $ Graphics_markLeft(e82cc8dc402e8bd7). (g, minimum, true, true, false, nullptr); |
| 844 | Graphics_markLeftcxx . . $ Graphics_markLeft(e82cc8dc402e8bd7). (g, maximum, true, true, false, nullptr); |
| 845 | if (minimum != 0.0 && maximum != 0.0 && (minimum > 0.0) != (maximum > 0.0)) |
| 846 | Graphics_markLeftcxx . . $ Graphics_markLeft(e82cc8dc402e8bd7). (g, 0.0, true, true, true, nullptr); |
| 847 | if (mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny. == 2) { |
| 848 | Graphics_setWindowcxx . . $ Graphics_setWindow(72bdb7937dbb13da). (g, timesAreReversed ? tmax : tmin, timesAreReversed ? tmin : tmax, |
| 849 | minimum, maximum + (mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny. - 1) * (maximum - minimum)); |
| 850 | Graphics_markRightcxx . . $ Graphics_markRight(e82cc8dc402e8bd7). (g, minimum, true, true, false, nullptr); |
| 851 | Graphics_markRightcxx . . $ Graphics_markRight(e82cc8dc402e8bd7). (g, maximum, true, true, false, nullptr); |
| 852 | if (minimum != 0.0 && maximum != 0.0 && (minimum > 0.0) != (maximum > 0.0)) |
| 853 | Graphics_markRightcxx . . $ Graphics_markRight(e82cc8dc402e8bd7). (g, 0.0, true, true, true, nullptr); |
| 854 | } |
| 855 | } |
| 856 | } |
| 857 | |
| 858 | static double interpolatecxx . . $ interpolate(ab6b449d3469cc22). (constSoundcxx . . $ constSound# me, integercxx . . $ integer# i1, integercxx . . $ integer# channel) |
| 859 | /* Precondition: my z [1] [i1] != my z [1] [i1 + 1]; */ |
| 860 | { |
| 861 | const integercxx . . $ integer# i2 = i1 + 1; |
| 862 | const double x1 = Sampled_indexToXcxx . . $ Sampled_indexToX(65bcd2c9acbb3dd5). (me, i1), x2 = Sampled_indexToXcxx . . $ Sampled_indexToX(65bcd2c9acbb3dd5). (me, i2); |
| 863 | const double y1 = mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).channel] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i1], y2 = mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).channel] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i2]; |
| 864 | return x1 + (x2 - x1) * y1 / (y1 - y2); // linear |
| 865 | } |
| 866 | double Sound_getNearestZeroCrossingcxx . . $ Sound_getNearestZeroCrossing(f92830f351830df8). (constSoundcxx . . $ constSound# me, double position, integercxx . . $ integer# channel) { |
| 867 | VECcxx . . $ VEC# amplitude = mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z..rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (channel); |
| 868 | const integercxx . . $ integer# leftSample = Sampled_xToLowIndexcxx . . $ Sampled_xToLowIndex(405c2491bc3636e9). (me, position); |
| 869 | const integercxx . . $ integer# rightSample = leftSample + 1; |
| 870 | /* Are we already at a zero crossing? */ |
| 871 | if (leftSample >= 1 && rightSample <= mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx. && |
| 872 | (amplitude [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).leftSample] >= 0.0) != |
| 873 | (amplitude [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).rightSample] >= 0.0)) |
| 874 | { |
| 875 | return interpolatecxx . . $ interpolate(ab6b449d3469cc22). (me, leftSample, channel); |
| 876 | } |
| 877 | integercxx . . $ integer# ileft, iright; |
| 878 | double leftZero, rightZero; |
| 879 | |
| 880 | /* |
| 881 | Search to the left. |
| 882 | */ |
| 883 | if (leftSample > mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.) |
| 884 | return undefinedcxx . . $ undefined.; |
| 885 | for (ileft = leftSample - 1; ileft >= 1; ileft --) |
| 886 | if ((amplitude [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).ileft] >= 0.0) != (amplitude [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).ileft + 1] >= 0.0)) { |
| 887 | leftZero = interpolatecxx . . $ interpolate(ab6b449d3469cc22). (me, ileft, channel); |
| 888 | break; |
| 889 | } |
| 890 | |
| 891 | /* |
| 892 | Search to the right. |
| 893 | */ |
| 894 | if (rightSample < 1) |
| 895 | return undefinedcxx . . $ undefined.; |
| 896 | for (iright = rightSample + 1; iright <= mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.; iright ++) |
| 897 | if ((amplitude [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).iright] >= 0.0) != (amplitude [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).iright - 1] >= 0.0)) { |
| 898 | rightZero = interpolatecxx . . $ interpolate(ab6b449d3469cc22). (me, iright - 1, channel); |
| 899 | break; |
| 900 | } |
| 901 | |
| 902 | if (ileft < 1 && iright > mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.) |
| 903 | return undefinedcxx . . $ undefined.; |
| 904 | return ileft < 1 ? rightZero : iright > mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx. ? leftZero : |
| 905 | position - leftZero < rightZero - position ? leftZero : rightZero; |
| 906 | } |
| 907 | |
| 908 | void Sound_setZerocxx . . $ Sound_setZero(31bbd7258342aec7). (mutableSoundcxx . . $ mutableSound# me, double tmin_in, double tmax_in, bool roundTimesToNearestZeroCrossing) { |
| 909 | Function_unidirectionalAutowindowcxx . . $ Function_unidirectionalAutowindow(88b7840c59a57eaf). (me, & tmin_in, & tmax_in); |
| 910 | Function_intersectRangeWithDomaincxx . . $ Function_intersectRangeWithDomain(b58540e0674cd12). (me, & tmin_in, & tmax_in); |
| 911 | for (integercxx . . $ integer# channel = 1; channel <= mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny.; channel ++) { |
| 912 | /* mutable */ double tmin = tmin_in, tmax = tmax_in; |
| 913 | if (roundTimesToNearestZeroCrossing) { |
| 914 | if (tmin > mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin.) |
| 915 | tmin = Sound_getNearestZeroCrossingcxx . . $ Sound_getNearestZeroCrossing(f92830f351830df8). (me, tmin_in, channel); |
| 916 | if (tmax < mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax.) |
| 917 | tmax = Sound_getNearestZeroCrossingcxx . . $ Sound_getNearestZeroCrossing(f92830f351830df8). (me, tmax_in, channel); |
| 918 | } |
| 919 | if (isundefcxx . . $ isundef(f8197d536af80c96). (tmin)) |
| 920 | tmin = mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin.; |
| 921 | if (isundefcxx . . $ isundef(f8197d536af80c96). (tmax)) |
| 922 | tmax = mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax.; |
| 923 | /* mutable */ integercxx . . $ integer# imin, imax; |
| 924 | Sampled_getWindowSamplescxx . . $ Sampled_getWindowSamples(fe99094ed5bb3f6a). (me, tmin, tmax, & imin, & imax); |
| 925 | for (integercxx . . $ integer# i = imin; i <= imax; i ++) |
| 926 | mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).channel] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i] = 0.0; |
| 927 | } |
| 928 | } |
| 929 | |
| 930 | autoSoundcxx . . $ autoSound# Sound_createAsPureTonecxx . . $ Sound_createAsPureTone(961256c6deadb130). (integercxx . . $ integer# numberOfChannels, double startingTime, double endTime, |
| 931 | double sampleRate, double frequency, double amplitude, double fadeInDuration, double fadeOutDuration) |
| 932 | { |
| 933 | try { |
| 934 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (numberOfChannels >= 1, |
| 935 | U"The number of channels should be at least 1."); |
| 936 | const double numberOfSamples_real = roundcxx . . $ round(fee4f1d22bc8e617). ((endTime - startingTime) * sampleRate); |
| 937 | if (numberOfSamples_real > double (INT32_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:112:10`!)) |
| 938 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Cannot create sounds with more than ", Melder_bigInteger (INT32_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:112:10`!), U" samples, because they cannot be saved to disk."); |
| 939 | autoSoundcxx . . $ autoSound# me = Sound_createcxx . . $ Sound_create(39ab106d6b9a0135). (numberOfChannels, startingTime, endTime, (integercxx . . $ integer#) (int32cxx . . $ int32#) numberOfSamples_real, |
| 940 | 1.0 / sampleRate, startingTime + 0.5 / sampleRate); |
| 941 | for (integercxx . . $ integer# isamp = 1; isamp <= mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.; isamp ++) { |
| 942 | const double time = mycxx . . $ `melder/melder.h:44:9`! x1cxx . . $ structSampled#x1. + (isamp - 1) * mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx.; |
| 943 | /* mutable */ double value = amplitude * sincxx . . $ sin(fee4f1d22bc8e617). (2.0 * NUMpicxx . . $ NUMpi. * frequency * time); |
| 944 | const double timeFromStart = time - startingTime; |
| 945 | if (timeFromStart < fadeInDuration) |
| 946 | value *= 0.5 - 0.5 * coscxx . . $ cos(fee4f1d22bc8e617). (NUMpicxx . . $ NUMpi. * timeFromStart / fadeInDuration); |
| 947 | const double timeFromEnd = endTime - time; |
| 948 | if (timeFromEnd < fadeOutDuration) |
| 949 | value *= 0.5 - 0.5 * coscxx . . $ cos(fee4f1d22bc8e617). (NUMpicxx . . $ NUMpi. * timeFromEnd / fadeOutDuration); |
| 950 | for (integercxx . . $ integer# ichan = 1; ichan <= mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny.; ichan ++) |
| 951 | mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).ichan] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).isamp] = value; |
| 952 | } |
| 953 | return mecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 954 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 955 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Sound not created from tone complex."); |
| 956 | } |
| 957 | } |
| 958 | |
| 959 | autoSoundcxx . . $ autoSound# Sound_createAsToneComplexcxx . . $ Sound_createAsToneComplex(2a3ca0e83d185f95). (double startTime, double endTime, double samplingFrequency, |
| 960 | int phase, double frequencyStep, double firstFrequency, double ceiling, integercxx . . $ integer# numberOfComponents) |
| 961 | { |
| 962 | try { |
| 963 | if (frequencyStep == 0.0) |
| 964 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"The frequency step should not be zero."); |
| 965 | /* |
| 966 | Translate default firstFrequency. |
| 967 | */ |
| 968 | if (firstFrequency <= 0.0) |
| 969 | firstFrequency = frequencyStep; |
| 970 | const double firstOmega = 2.0 * NUMpicxx . . $ NUMpi. * firstFrequency; |
| 971 | /* |
| 972 | Translate default ceiling. |
| 973 | */ |
| 974 | const double omegaStep = 2.0 * NUMpicxx . . $ NUMpi. * frequencyStep; |
| 975 | const double nyquistFrequency = 0.5 * samplingFrequency; |
| 976 | if (ceiling <= 0.0 || ceiling > nyquistFrequency) |
| 977 | ceiling = nyquistFrequency; |
| 978 | /* |
| 979 | Translate number of components. |
| 980 | */ |
| 981 | const integercxx . . $ integer# maximumNumberOfComponents = Melder_ifloorcxx . . $ `melder/melder_ftoi.h:33:9`! ((ceiling - firstFrequency) / frequencyStep) + 1; |
| 982 | if (numberOfComponents <= 0 || numberOfComponents > maximumNumberOfComponents) |
| 983 | numberOfComponents = maximumNumberOfComponents; |
| 984 | if (numberOfComponents < 1) |
| 985 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"There would be zero sine waves."); |
| 986 | /* |
| 987 | Generate the Sound. |
| 988 | */ |
| 989 | const double factor = 0.99 / numberOfComponents; |
| 990 | autoSoundcxx . . $ autoSound# me = Sound_createcxx . . $ Sound_create(39ab106d6b9a0135). (1, startTime, endTime, Melder_iroundcxx . . $ `melder/melder_ftoi.h:78:9`! ((endTime - startTime) * samplingFrequency), |
| 991 | 1.0 / samplingFrequency, startTime + 0.5 / samplingFrequency); |
| 992 | for (integercxx . . $ integer# isamp = 1; isamp <= mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.; isamp ++) { |
| 993 | const double t = Sampled_indexToXcxx . . $ Sampled_indexToX(65bcd2c9acbb3dd5). (me.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), isamp); |
| 994 | const double omegaStepT = omegaStep * t; |
| 995 | const double firstOmegaT = firstOmega * t; |
| 996 | longdoublecxx . . $ longdouble# value = 0.0; |
| 997 | if (phase == Sound_TONE_COMPLEX_SINEcxx . . $ `fon/Sound.h:176:9`!) { |
| 998 | for (integercxx . . $ integer# icomp = 1; icomp <= numberOfComponents; icomp ++) |
| 999 | value += sincxx . . $ sin(fee4f1d22bc8e617). (firstOmegaT + (icomp - 1) * omegaStepT); |
| 1000 | } else { |
| 1001 | for (integercxx . . $ integer# icomp = 1; icomp <= numberOfComponents; icomp ++) |
| 1002 | value += coscxx . . $ cos(fee4f1d22bc8e617). (firstOmegaT + (icomp - 1) * omegaStepT); |
| 1003 | } |
| 1004 | mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).isamp] = double (value) * factor; |
| 1005 | } |
| 1006 | return mecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 1007 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 1008 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Sound not created as tone complex."); |
| 1009 | } |
| 1010 | } |
| 1011 | |
| 1012 | void Sound_multiplyByWindowcxx . . $ Sound_multiplyByWindow(bbea490a38595013). (mutableSoundcxx . . $ mutableSound# me, kSound_windowShape windowShape) { |
| 1013 | for (integercxx . . $ integer# ichan = 1; ichan <= mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny.; ichan ++) { |
| 1014 | const integercxx . . $ integer# n = mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.; |
| 1015 | VECcxx . . $ VEC# channel = mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z..rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (ichan); |
| 1016 | switch (windowShape) { |
| 1017 | case kSound_windowShape::RECTANGULAR: { |
| 1018 | ; |
| 1019 | } break; case kSound_windowShape::TRIANGULAR: { // "Bartlett" |
| 1020 | for (integercxx . . $ integer# i = 1; i <= n; i ++) { |
| 1021 | const double phase = double (i - 0.5) / n; // 0..1 |
| 1022 | channel [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i] *= 1.0 - fabscxx . . $ fabs(fee4f1d22bc8e617). ((2.0 * phase - 1.0)); |
| 1023 | } |
| 1024 | } break; case kSound_windowShape::PARABOLIC: { // "Welch" |
| 1025 | for (integercxx . . $ integer# i = 1; i <= n; i ++) { |
| 1026 | const double phase = double (i - 0.5) / n; |
| 1027 | channel [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i] *= 1.0 - (2.0 * phase - 1.0) * (2.0 * phase - 1.0); |
| 1028 | } |
| 1029 | } break; case kSound_windowShape::HANNING: { |
| 1030 | for (integercxx . . $ integer# i = 1; i <= n; i ++) { |
| 1031 | const double phase = double (i - 0.5) / n; |
| 1032 | channel [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i] *= 0.5 * (1.0 - coscxx . . $ cos(fee4f1d22bc8e617). (2.0 * NUMpicxx . . $ NUMpi. * phase)); |
| 1033 | } |
| 1034 | } break; case kSound_windowShape::HAMMING: { |
| 1035 | for (integercxx . . $ integer# i = 1; i <= n; i ++) { |
| 1036 | const double phase = double (i - 0.5) / n; |
| 1037 | channel [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i] *= 0.54 - 0.46 * coscxx . . $ cos(fee4f1d22bc8e617). (2.0 * NUMpicxx . . $ NUMpi. * phase); |
| 1038 | } |
| 1039 | } break; case kSound_windowShape::GAUSSIAN_1: { |
| 1040 | const double imid = 0.5 * double (n + 1), edge = expcxx . . $ exp(fee4f1d22bc8e617). (-3.0), onebyedge1 = 1.0 / (1.0 - edge); |
| 1041 | for (integercxx . . $ integer# i = 1; i <= n; i ++) { |
| 1042 | const double phase = ((double) i - imid) / n; // -0.5..+0.5 |
| 1043 | channel [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i] *= (expcxx . . $ exp(fee4f1d22bc8e617). (-12.0 * phase * phase) - edge) * onebyedge1; |
| 1044 | } |
| 1045 | } break; case kSound_windowShape::GAUSSIAN_2: { |
| 1046 | const double imid = 0.5 * double (n + 1), edge = expcxx . . $ exp(fee4f1d22bc8e617). (-12.0), onebyedge1 = 1.0 / (1.0 - edge); |
| 1047 | for (integercxx . . $ integer# i = 1; i <= n; i ++) { |
| 1048 | const double phase = ((double) i - imid) / n; |
| 1049 | channel [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i] *= (expcxx . . $ exp(fee4f1d22bc8e617). (-48.0 * phase * phase) - edge) * onebyedge1; |
| 1050 | } |
| 1051 | } break; case kSound_windowShape::GAUSSIAN_3: { |
| 1052 | const double imid = 0.5 * double (n + 1), edge = expcxx . . $ exp(fee4f1d22bc8e617). (-27.0), onebyedge1 = 1.0 / (1.0 - edge); |
| 1053 | for (integercxx . . $ integer# i = 1; i <= n; i ++) { |
| 1054 | const double phase = ((double) i - imid) / n; |
| 1055 | channel [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i] *= (expcxx . . $ exp(fee4f1d22bc8e617). (-108.0 * phase * phase) - edge) * onebyedge1; |
| 1056 | } |
| 1057 | } break; case kSound_windowShape::GAUSSIAN_4: { |
| 1058 | const double imid = 0.5 * double (n + 1), edge = expcxx . . $ exp(fee4f1d22bc8e617). (-48.0), onebyedge1 = 1.0 / (1.0 - edge); |
| 1059 | for (integercxx . . $ integer# i = 1; i <= n; i ++) { |
| 1060 | const double phase = ((double) i - imid) / n; |
| 1061 | channel [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i] *= (expcxx . . $ exp(fee4f1d22bc8e617). (-192.0 * phase * phase) - edge) * onebyedge1; |
| 1062 | } |
| 1063 | } break; case kSound_windowShape::GAUSSIAN_5: { |
| 1064 | const double imid = 0.5 * double (n + 1), edge = expcxx . . $ exp(fee4f1d22bc8e617). (-75.0), onebyedge1 = 1.0 / (1.0 - edge); |
| 1065 | for (integercxx . . $ integer# i = 1; i <= n; i ++) { |
| 1066 | const double phase = ((double) i - imid) / n; |
| 1067 | channel [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i] *= (expcxx . . $ exp(fee4f1d22bc8e617). (-300.0 * phase * phase) - edge) * onebyedge1; |
| 1068 | } |
| 1069 | } break; case kSound_windowShape::KAISER_1: { |
| 1070 | const double imid = 0.5 * double (n + 1); |
| 1071 | const double factor = 1.0 / NUMbessel_i0_fcxx . . $ NUMbessel_i0_f(447c67c6676f75c3). (2 * NUMpicxx . . $ NUMpi.); |
| 1072 | for (integercxx . . $ integer# i = 1; i <= n; i ++) { |
| 1073 | const double phase = 2.0 * ((double) i - imid) / n; // -1..+1 |
| 1074 | const double root = 1.0 - phase * phase; |
| 1075 | channel [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i] *= root <= 0.0 ? 0.0 : factor * NUMbessel_i0_fcxx . . $ NUMbessel_i0_f(447c67c6676f75c3). (2.0 * NUMpicxx . . $ NUMpi. * sqrtcxx . . $ sqrt(fee4f1d22bc8e617). (root)); |
| 1076 | } |
| 1077 | } break; case kSound_windowShape::KAISER_2: { |
| 1078 | const double imid = 0.5 * double (n + 1); |
| 1079 | const double factor = 1.0 / NUMbessel_i0_fcxx . . $ NUMbessel_i0_f(447c67c6676f75c3). (2 * NUMpicxx . . $ NUMpi. * NUMpicxx . . $ NUMpi. + 0.5); |
| 1080 | for (integercxx . . $ integer# i = 1; i <= n; i ++) { |
| 1081 | const double phase = 2.0 * ((double) i - imid) / n; // -1..+1 |
| 1082 | const double root = 1.0 - phase * phase; |
| 1083 | channel [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i] *= root <= 0.0 ? 0.0 : factor * NUMbessel_i0_fcxx . . $ NUMbessel_i0_f(447c67c6676f75c3). ((2.0 * NUMpicxx . . $ NUMpi. * NUMpicxx . . $ NUMpi. + 0.5) * sqrtcxx . . $ sqrt(fee4f1d22bc8e617). (root)); |
| 1084 | } |
| 1085 | } break; default: { |
| 1086 | } |
| 1087 | } |
| 1088 | } |
| 1089 | } |
| 1090 | |
| 1091 | void Sound_scaleIntensitycxx . . $ Sound_scaleIntensity(e59d264236af2337). (mutableSoundcxx . . $ mutableSound# me, double newAverageIntensity) { |
| 1092 | const double currentIntensity = Sound_getIntensity_dBcxx . . $ Sound_getIntensity_dB(9577c4e030d3505d). (me); |
| 1093 | if (isundefcxx . . $ isundef(f8197d536af80c96). (currentIntensity)) |
| 1094 | return; |
| 1095 | const double factor = powcxx . . $ pow(b71928d39fde4295). (10.0, (newAverageIntensity - currentIntensity) / 20.0); |
| 1096 | mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z..allcxx . . $ automatrix#all(2114117ba8ed4224).() *=cxx . . $ `operator*=`(50b469ae42a42f64). factor; |
| 1097 | } |
| 1098 | |
| 1099 | void Sound_overrideSamplingFrequencycxx . . $ Sound_overrideSamplingFrequency(e59d264236af2337). (mutableSoundcxx . . $ mutableSound# me, double newSamplingFrequency) { |
| 1100 | mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx. = 1.0 / newSamplingFrequency; |
| 1101 | mycxx . . $ `melder/melder.h:44:9`! x1cxx . . $ structSampled#x1. = mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin. + 0.5 * mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx.; |
| 1102 | mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax. = mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin. + mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx. * mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx.; |
| 1103 | } |
| 1104 | |
| 1105 | autoSoundcxx . . $ autoSound# Sound_extractPartcxx . . $ Sound_extractPart(e1651eb055dd2f09). (constSoundcxx . . $ constSound# me, double tmin, double tmax, kSound_windowShape windowShape, double relativeWidth, bool preserveTimes) { |
| 1106 | try { |
| 1107 | /* |
| 1108 | We do not clip to the Sound's time domain. |
| 1109 | Any samples outside it are taken to be zero. |
| 1110 | */ |
| 1111 | |
| 1112 | Function_unidirectionalAutowindowcxx . . $ Function_unidirectionalAutowindow(88b7840c59a57eaf). (me, & tmin, & tmax); |
| 1113 | /* |
| 1114 | Allow window tails outside specified domain. |
| 1115 | */ |
| 1116 | if (relativeWidth != 1.0) { |
| 1117 | const double margin = 0.5 * (relativeWidth - 1) * (tmax - tmin); |
| 1118 | tmin -= margin; |
| 1119 | tmax += margin; |
| 1120 | } |
| 1121 | /* |
| 1122 | Determine index range. We use all the real or virtual samples that fit within [t1..t2]. |
| 1123 | */ |
| 1124 | const integercxx . . $ integer# itmin = 1 + Melder_iceilingcxx . . $ `melder/melder_ftoi.h:45:9`! ((tmin - mycxx . . $ `melder/melder.h:44:9`! x1cxx . . $ structSampled#x1.) / mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx.); |
| 1125 | const integercxx . . $ integer# itmax = 1 + Melder_ifloorcxx . . $ `melder/melder_ftoi.h:33:9`! ((tmax - mycxx . . $ `melder/melder.h:44:9`! x1cxx . . $ structSampled#x1.) / mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx.); |
| 1126 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (itmax >= itmin, |
| 1127 | U"Extracted Sound would contain no samples."); |
| 1128 | /* |
| 1129 | Create sound, optionally shifted to [0..t2-t1]. |
| 1130 | */ |
| 1131 | autoSoundcxx . . $ autoSound# thee = Sound_createcxx . . $ Sound_create(39ab106d6b9a0135). (mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny., tmin, tmax, itmax - itmin + 1, mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx., mycxx . . $ `melder/melder.h:44:9`! x1cxx . . $ structSampled#x1. + (itmin - 1) * mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx.); |
| 1132 | if (! preserveTimes) { |
| 1133 | thycxx . . $ `melder/melder.h:45:9`! xmincxx . . $ structFunction#xmin. = 0.0; |
| 1134 | thycxx . . $ `melder/melder.h:45:9`! xmaxcxx . . $ structFunction#xmax. -= tmin; |
| 1135 | thycxx . . $ `melder/melder.h:45:9`! x1cxx . . $ structSampled#x1. -= tmin; |
| 1136 | } |
| 1137 | /* |
| 1138 | Copy only *real* samples into the new sound. |
| 1139 | The *virtual* samples will remain at zero. |
| 1140 | */ |
| 1141 | for (integercxx . . $ integer# ichan = 1; ichan <= mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny.; ichan ++) { |
| 1142 | const integercxx . . $ integer# itmin_clipped = Melder_clippedLeftcxx . . $ Melder_clippedLeft(f80f7d6260b3ee3a). (1_integercxx . . $ `operator""_integer`(85240eb457c3721a)., itmin); |
| 1143 | const integercxx . . $ integer# itmax_clipped = Melder_clippedRightcxx . . $ Melder_clippedRight(f80f7d6260b3ee3a). (itmax, mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.); |
| 1144 | thycxx . . $ `melder/melder.h:45:9`! zcxx . . $ structMatrix#z..rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (ichan).partcxx . . $ vector#part(ae267db9e2c04be7). (1 - itmin + itmin_clipped, 1 - itmin + itmax_clipped) |
| 1145 | <<=cxx . . $ `operator<<=`(adea042513329390). mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z..rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (ichan).partcxx . . $ vector#part(ae267db9e2c04be7). (itmin_clipped, itmax_clipped); |
| 1146 | } |
| 1147 | /* |
| 1148 | Multiply by a window that extends throughout the target domain. |
| 1149 | */ |
| 1150 | Sound_multiplyByWindowcxx . . $ Sound_multiplyByWindow(bbea490a38595013). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), windowShape); |
| 1151 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 1152 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 1153 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": part not extracted."); |
| 1154 | } |
| 1155 | } |
| 1156 | |
| 1157 | autoSoundcxx . . $ autoSound# Sound_extractPartForOverlapcxx . . $ Sound_extractPartForOverlap(a9298ecf594d39cf). (constSoundcxx . . $ constSound# me, double tmin, double tmax, double overlap) { |
| 1158 | try { |
| 1159 | Function_unidirectionalAutowindowcxx . . $ Function_unidirectionalAutowindow(88b7840c59a57eaf). (me, & tmin, & tmax); |
| 1160 | if (overlap > 0.0) { |
| 1161 | const double margin = 0.5 * overlap; |
| 1162 | tmin -= margin; |
| 1163 | tmax += margin; |
| 1164 | } |
| 1165 | Melder_clipLeftcxx . . $ Melder_clipLeft(6245cd023a7d1552). (mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin., & tmin); |
| 1166 | Melder_clipRightcxx . . $ Melder_clipRight(5b63ce711df1ade7). (& tmax, mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax.); |
| 1167 | /* |
| 1168 | Determine index range. We use all the real or virtual samples that fit within [t1..t2]. |
| 1169 | */ |
| 1170 | const integercxx . . $ integer# itmin = 1 + Melder_iceilingcxx . . $ `melder/melder_ftoi.h:45:9`! ((tmin - mycxx . . $ `melder/melder.h:44:9`! x1cxx . . $ structSampled#x1.) / mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx.); |
| 1171 | const integercxx . . $ integer# itmax = 1 + Melder_ifloorcxx . . $ `melder/melder_ftoi.h:33:9`! ((tmax - mycxx . . $ `melder/melder.h:44:9`! x1cxx . . $ structSampled#x1.) / mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx.); |
| 1172 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (itmax >= itmin, |
| 1173 | U"Extracted Sound would contain no samples."); |
| 1174 | /* |
| 1175 | Create sound. |
| 1176 | */ |
| 1177 | autoSoundcxx . . $ autoSound# thee = Sound_createcxx . . $ Sound_create(39ab106d6b9a0135). (mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny., tmin, tmax, itmax - itmin + 1, mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx., mycxx . . $ `melder/melder.h:44:9`! x1cxx . . $ structSampled#x1. + (itmin - 1) * mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx.); |
| 1178 | thycxx . . $ `melder/melder.h:45:9`! xmincxx . . $ structFunction#xmin. = 0.0; |
| 1179 | thycxx . . $ `melder/melder.h:45:9`! xmaxcxx . . $ structFunction#xmax. -= tmin; |
| 1180 | thycxx . . $ `melder/melder.h:45:9`! x1cxx . . $ structSampled#x1. -= tmin; |
| 1181 | /* |
| 1182 | Copy only *real* samples into the new sound. |
| 1183 | The *virtual* samples will remain at zero. |
| 1184 | */ |
| 1185 | for (integercxx . . $ integer# ichan = 1; ichan <= mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny.; ichan ++) { |
| 1186 | const integercxx . . $ integer# itmin_clipped = Melder_clippedLeftcxx . . $ Melder_clippedLeft(f80f7d6260b3ee3a). (1_integercxx . . $ `operator""_integer`(85240eb457c3721a)., itmin); |
| 1187 | const integercxx . . $ integer# itmax_clipped = Melder_clippedRightcxx . . $ Melder_clippedRight(f80f7d6260b3ee3a). (itmax, mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.); |
| 1188 | thycxx . . $ `melder/melder.h:45:9`! zcxx . . $ structMatrix#z..rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (ichan).partcxx . . $ vector#part(ae267db9e2c04be7). (1 - itmin + itmin_clipped, 1 - itmin + itmax_clipped) |
| 1189 | <<=cxx . . $ `operator<<=`(adea042513329390). mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z..rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (ichan).partcxx . . $ vector#part(ae267db9e2c04be7). (itmin_clipped, itmax_clipped); |
| 1190 | } |
| 1191 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 1192 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 1193 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": part not extracted."); |
| 1194 | } |
| 1195 | } |
| 1196 | |
| 1197 | void Sound_filterWithFormantscxx . . $ Sound_filterWithFormants(2aef0a9fc25232a8). (mutableSoundcxx . . $ mutableSound# me, double tmin, double tmax, |
| 1198 | int numberOfFormants, double formant [], double bandwidth []) |
| 1199 | { |
| 1200 | try { |
| 1201 | Function_unidirectionalAutowindowcxx . . $ Function_unidirectionalAutowindow(88b7840c59a57eaf). (me, & tmin, & tmax); |
| 1202 | integercxx . . $ integer# itmin, itmax; |
| 1203 | integercxx . . $ integer# n = Sampled_getWindowSamplescxx . . $ Sampled_getWindowSamples(fe99094ed5bb3f6a). (me, tmin, tmax, & itmin, & itmax); |
| 1204 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (n >= 3, |
| 1205 | U"Sound too short."); |
| 1206 | for (integercxx . . $ integer# ichan = 1; ichan <= mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny.; ichan ++) { |
| 1207 | VECVUcxx . . $ VECVU# const& channel = mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z..rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (ichan); |
| 1208 | VECVUcxx . . $ VECVU# const& window = channel.partcxx . . $ vectorview#part(fd45ed87dd839590). (itmin, itmax); |
| 1209 | VECdeemphasize_f_inplacecxx . . $ VECdeemphasize_f_inplace(963991e5268b1933). (window, mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx., 50.0); |
| 1210 | for (int iformant = 1; iformant <= numberOfFormants; iformant ++) |
| 1211 | VECfilterSecondOrderSection_fb_inplacecxx . . $ VECfilterSecondOrderSection_fb_inplace(1af0a15671a05e99). (window, mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx., formant [iformant], bandwidth [iformant]); |
| 1212 | } |
| 1213 | Matrix_scaleAbsoluteExtremumcxx . . $ Matrix_scaleAbsoluteExtremum(fed8a1cea6a7ff47). (me, 0.99); |
| 1214 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 1215 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": not filtered."); |
| 1216 | } |
| 1217 | } |
| 1218 | |
| 1219 | autoSoundcxx . . $ autoSound# Sound_filter_oneFormantcxx . . $ Sound_filter_oneFormant(d3fc085af13920bc). (constSoundcxx . . $ constSound# me, double frequency, double bandwidth) { |
| 1220 | try { |
| 1221 | autoSoundcxx . . $ autoSound# thee = Data_copycxx . . $ Data_copy(97a542a26794c80e). (me); |
| 1222 | Sound_filterWithOneFormantInplacecxx . . $ Sound_filterWithOneFormantInplace(77a4df2843109656). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), frequency, bandwidth); |
| 1223 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 1224 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 1225 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": not filtered (one formant)."); |
| 1226 | } |
| 1227 | } |
| 1228 | |
| 1229 | void Sound_filterWithOneFormantInplacecxx . . $ Sound_filterWithOneFormantInplace(77a4df2843109656). (mutableSoundcxx . . $ mutableSound# me, double frequency, double bandwidth) { |
| 1230 | for (integercxx . . $ integer# ichan = 1; ichan <= mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny.; ichan ++) { |
| 1231 | const VECcxx . . $ VEC# channel = mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z..rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (ichan); |
| 1232 | VECfilterSecondOrderSection_fb_inplacecxx . . $ VECfilterSecondOrderSection_fb_inplace(1af0a15671a05e99). (channelcxx . . $ vectorview#vectorview(eac9d6ec4c4bfecd)., mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx., frequency, bandwidth); |
| 1233 | } |
| 1234 | Matrix_scaleAbsoluteExtremumcxx . . $ Matrix_scaleAbsoluteExtremum(fed8a1cea6a7ff47). (me, 0.99); |
| 1235 | } |
| 1236 | |
| 1237 | double Sound_computeEmphasisFactorcxx . . $ Sound_computeEmphasisFactor(922ce31e9502a5ee). (constSoundcxx . . $ constSound# me, double cutoffFrequency) { |
| 1238 | return expcxx . . $ exp(fee4f1d22bc8e617). (- NUM2picxx . . $ NUM2pi. * cutoffFrequency * mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx.); |
| 1239 | } |
| 1240 | |
| 1241 | void Sound_preEmphasize_inplacecxx . . $ Sound_preEmphasize_inplace(e59d264236af2337). (mutableSoundcxx . . $ mutableSound# me, double cutoffFrequency) { |
| 1242 | const double emphasisFactor = Sound_computeEmphasisFactorcxx . . $ Sound_computeEmphasisFactor(922ce31e9502a5ee). (me, cutoffFrequency); |
| 1243 | if (emphasisFactor != 0.0) // OPTIMIZE; will happen for cut-off frequencies above 119 times the sampling frequency |
| 1244 | for (integercxx . . $ integer# channel = 1; channel <= mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny.; channel ++) { |
| 1245 | const VECcxx . . $ VEC# s = mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z..rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (channel); |
| 1246 | for (integercxx . . $ integer# i = mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.; i >= 2; i --) |
| 1247 | s [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i] -= emphasisFactor * s [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i - 1]; |
| 1248 | } |
| 1249 | } |
| 1250 | |
| 1251 | void Sound_deEmphasize_inplacecxx . . $ Sound_deEmphasize_inplace(e59d264236af2337). (Soundcxx . . $ Sound# me, double cutoffFrequency) { |
| 1252 | const double emphasisFactor = Sound_computeEmphasisFactorcxx . . $ Sound_computeEmphasisFactor(922ce31e9502a5ee). (me, cutoffFrequency); |
| 1253 | if (emphasisFactor != 0.0) // OPTIMIZE; will happen for cut-off frequencies above 119 times the sampling frequency |
| 1254 | for (integercxx . . $ integer# channel = 1; channel <= mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny.; channel ++) { |
| 1255 | const VECcxx . . $ VEC# s = mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z..rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (channel); |
| 1256 | for (integercxx . . $ integer# i = 2; i <= mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.; i ++) |
| 1257 | s [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i] += emphasisFactor * s [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i - 1]; |
| 1258 | } |
| 1259 | } |
| 1260 | |
| 1261 | autoSoundcxx . . $ autoSound# Sound_filter_preemphasiscxx . . $ Sound_filter_preemphasis(5bde49e4335e9a5a). (constSoundcxx . . $ constSound# me, double frequency) { |
| 1262 | try { |
| 1263 | autoSoundcxx . . $ autoSound# thee = Data_copycxx . . $ Data_copy(97a542a26794c80e). (me); |
| 1264 | Sound_preEmphasize_inplacecxx . . $ Sound_preEmphasize_inplace(e59d264236af2337). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), frequency); |
| 1265 | Matrix_scaleAbsoluteExtremumcxx . . $ Matrix_scaleAbsoluteExtremum(fed8a1cea6a7ff47). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), 0.99); |
| 1266 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 1267 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 1268 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": not filtered (pre-emphasis)."); |
| 1269 | } |
| 1270 | } |
| 1271 | |
| 1272 | autoSoundcxx . . $ autoSound# Sound_filter_deemphasiscxx . . $ Sound_filter_deemphasis(5bde49e4335e9a5a). (constSoundcxx . . $ constSound# me, double frequency) { |
| 1273 | try { |
| 1274 | autoSoundcxx . . $ autoSound# thee = Data_copycxx . . $ Data_copy(97a542a26794c80e). (me); |
| 1275 | Sound_deEmphasize_inplacecxx . . $ Sound_deEmphasize_inplace(e59d264236af2337). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), frequency); |
| 1276 | Matrix_scaleAbsoluteExtremumcxx . . $ Matrix_scaleAbsoluteExtremum(fed8a1cea6a7ff47). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), 0.99); |
| 1277 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 1278 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 1279 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": not filtered (de-emphasis)."); |
| 1280 | } |
| 1281 | } |
| 1282 | |
| 1283 | void Sound_reversecxx . . $ Sound_reverse(77a4df2843109656). (mutableSoundcxx . . $ mutableSound# me, double tmin, double tmax) { |
| 1284 | Function_unidirectionalAutowindowcxx . . $ Function_unidirectionalAutowindow(88b7840c59a57eaf). (me, & tmin, & tmax); |
| 1285 | integercxx . . $ integer# itmin, itmax; |
| 1286 | const integercxx . . $ integer# n = Sampled_getWindowSamplescxx . . $ Sampled_getWindowSamples(fe99094ed5bb3f6a). (me, tmin, tmax, & itmin, & itmax) / 2; |
| 1287 | for (integercxx . . $ integer# channel = 1; channel <= mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny.; channel ++) { |
| 1288 | double * const amp = & mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).channel] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).0]; |
| 1289 | for (integercxx . . $ integer# i = 0; i < n; i ++) |
| 1290 | stdcxx . . $ std/::swapcxx . . $ std/swap(c75b8fd57d7c2e06). (amp [itmin + i], amp [itmax - i]); |
| 1291 | } |
| 1292 | } |
| 1293 | |
| 1294 | autoSoundcxx . . $ autoSound# Sounds_crossCorrelate_shortcxx . . $ Sounds_crossCorrelate_short(619b4afbd70d9931). (constSoundcxx . . $ constSound# me, constSoundcxx . . $ constSound# thee, double tmin, double tmax, bool normalize) { |
| 1295 | try { |
| 1296 | if (mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx. != thycxx . . $ `melder/melder.h:45:9`! dxcxx . . $ structSampled#dx.) |
| 1297 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Sampling frequencies are not equal."); |
| 1298 | if (mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny. != thycxx . . $ `melder/melder.h:45:9`! nycxx . . $ structSampledXY#ny.) |
| 1299 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Numbers of channels are not equal."); |
| 1300 | const double dt = mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx.; |
| 1301 | double dphase = (thycxx . . $ `melder/melder.h:45:9`! x1cxx . . $ structSampled#x1. - mycxx . . $ `melder/melder.h:44:9`! x1cxx . . $ structSampled#x1.) / dt; |
| 1302 | dphase -= Melder_roundDowncxx . . $ Melder_roundDown(447c67c6676f75c3). (dphase); // a number between 0 and 1 |
| 1303 | const integercxx . . $ integer# i1 = Melder_iceilingcxx . . $ `melder/melder_ftoi.h:45:9`! (tmin / dt - dphase); // index of first sample if sample at dphase has index 0 |
| 1304 | const integercxx . . $ integer# i2 = Melder_ifloorcxx . . $ `melder/melder_ftoi.h:33:9`! (tmax / dt - dphase); // index of last sample if sample at dphase has index 0 |
| 1305 | const integercxx . . $ integer# nt = i2 - i1 + 1; |
| 1306 | if (nt < 1) |
| 1307 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Window too small."); |
| 1308 | const double t1 = (dphase + i1) * dt; |
| 1309 | autoSoundcxx . . $ autoSound# him = Sound_createcxx . . $ Sound_create(39ab106d6b9a0135). (1, tmin, tmax, nt, dt, t1); |
| 1310 | for (integercxx . . $ integer# i = 1; i <= nt; i ++) { |
| 1311 | const integercxx . . $ integer# di = i - 1 + i1; |
| 1312 | for (integercxx . . $ integer# ime = 1; ime <= mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.; ime ++) { |
| 1313 | if (ime + di < 1) |
| 1314 | continue; |
| 1315 | if (ime + di > thycxx . . $ `melder/melder.h:45:9`! nxcxx . . $ structSampled#nx.) |
| 1316 | break; |
| 1317 | for (integercxx . . $ integer# channel = 1; channel <= mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny.; channel ++) |
| 1318 | hiscxx . . $ `melder/melder.h:47:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i] += mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).channel] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).ime] * thycxx . . $ `melder/melder.h:45:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).channel] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).ime + di]; |
| 1319 | } |
| 1320 | } |
| 1321 | if (normalize) { |
| 1322 | longdoublecxx . . $ longdouble# mypower = 0.0, thypower = 0.0; |
| 1323 | for (integercxx . . $ integer# channel = 1; channel <= mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny.; channel ++) { |
| 1324 | for (integercxx . . $ integer# i = 1; i <= mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.; i ++) { |
| 1325 | const double value = mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).channel] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i]; |
| 1326 | mypower += value * value; |
| 1327 | } |
| 1328 | for (integercxx . . $ integer# i = 1; i <= thycxx . . $ `melder/melder.h:45:9`! nxcxx . . $ structSampled#nx.; i ++) { |
| 1329 | const double value = thycxx . . $ `melder/melder.h:45:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).channel] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i]; |
| 1330 | thypower += value * value; |
| 1331 | } |
| 1332 | } |
| 1333 | if (mypower != 0.0 && thypower != 0.0) { |
| 1334 | const double factor = 1.0 / (sqrtcxx . . $ sqrt(fee4f1d22bc8e617). (double (mypower)) * sqrtcxx . . $ sqrt(fee4f1d22bc8e617). (double (thypower))); |
| 1335 | for (integercxx . . $ integer# i = 1; i <= nt; i ++) { |
| 1336 | hiscxx . . $ `melder/melder.h:47:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i] *= factor; |
| 1337 | } |
| 1338 | } |
| 1339 | } else { |
| 1340 | const double factor = dt / mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny.; |
| 1341 | for (integercxx . . $ integer# i = 1; i <= nt; i ++) { |
| 1342 | hiscxx . . $ `melder/melder.h:47:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i] *= factor; |
| 1343 | } |
| 1344 | } |
| 1345 | return himcxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 1346 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 1347 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": not cross-correlated."); |
| 1348 | } |
| 1349 | } |
| 1350 | |
| 1351 | Thing_implementcxx . . $ `sys/Thing.h:65:9`! (SoundList, Ordered, 0); |
| 1352 | |
| 1353 | /* End of file Sound.cpp */ |