| 1 | /* MultiSampledSpectrogram.cpp |
| 2 | * |
| 3 | * Copyright (C) 2021-2022 David Weenink |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or (at |
| 8 | * your option) any later version. |
| 9 | * |
| 10 | * This code is distributed in the hope that it will be useful, but |
| 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | * General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this work. If not, see <http://www.gnu.org/licenses/>. |
| 17 | */ |
| 18 | |
| 19 | #include "Collection.h"cxx . . $ `<file>/sys/Collection.h`/ |
| 20 | #include "Formula.h"cxx . . $ `<file>/sys/Formula.h`/ |
| 21 | #include "MultiSampledSpectrogram.h"cxx . . $ `<file>/dwtools/MultiSampledSpectrogram.h`/ |
| 22 | |
| 23 | #include "oo_DESTROY.h"cxx . . $ `<file>/sys/oo_DESTROY.h`/ |
| 24 | #include "MultiSampledSpectrogram_def.h"cxx . . $ `<file>/dwtools/MultiSampledSpectrogram_def.h`/ |
| 25 | #include "oo_COPY.h"cxx . . $ `<file>/sys/oo_COPY.h`/ |
| 26 | #include "MultiSampledSpectrogram_def.h"cxx . . $ `<file>/dwtools/MultiSampledSpectrogram_def.h`/ |
| 27 | #include "oo_EQUAL.h"cxx . . $ `<file>/sys/oo_EQUAL.h`/ |
| 28 | #include "MultiSampledSpectrogram_def.h"cxx . . $ `<file>/dwtools/MultiSampledSpectrogram_def.h`/ |
| 29 | #include "oo_CAN_WRITE_AS_ENCODING.h"cxx . . $ `<file>/sys/oo_CAN_WRITE_AS_ENCODING.h`/ |
| 30 | #include "MultiSampledSpectrogram_def.h"cxx . . $ `<file>/dwtools/MultiSampledSpectrogram_def.h`/ |
| 31 | #include "oo_WRITE_TEXT.h"cxx . . $ `<file>/sys/oo_WRITE_TEXT.h`/ |
| 32 | #include "MultiSampledSpectrogram_def.h"cxx . . $ `<file>/dwtools/MultiSampledSpectrogram_def.h`/ |
| 33 | #include "oo_READ_TEXT.h"cxx . . $ `<file>/sys/oo_READ_TEXT.h`/ |
| 34 | #include "MultiSampledSpectrogram_def.h"cxx . . $ `<file>/dwtools/MultiSampledSpectrogram_def.h`/ |
| 35 | #include "oo_WRITE_BINARY.h"cxx . . $ `<file>/sys/oo_WRITE_BINARY.h`/ |
| 36 | #include "MultiSampledSpectrogram_def.h"cxx . . $ `<file>/dwtools/MultiSampledSpectrogram_def.h`/ |
| 37 | #include "oo_READ_BINARY.h"cxx . . $ `<file>/sys/oo_READ_BINARY.h`/ |
| 38 | #include "MultiSampledSpectrogram_def.h"cxx . . $ `<file>/dwtools/MultiSampledSpectrogram_def.h`/ |
| 39 | #include "oo_DESCRIPTION.h"cxx . . $ `<file>/sys/oo_DESCRIPTION.h`/ |
| 40 | #include "MultiSampledSpectrogram_def.h"cxx . . $ `<file>/dwtools/MultiSampledSpectrogram_def.h`/ |
| 41 | |
| 42 | Thing_implementcxx . . $ `sys/Thing.h:65:9`! (FrequencyBin, Matrix, 2); |
| 43 | |
| 44 | double structFrequencyBincxx . . $ structFrequencyBin# :: v_getValueAtSamplecxx . . $ structFrequencyBin#v_getValueAtSample(8bbfc6ce471470c9). (integercxx . . $ integer# iframe, integercxx . . $ integer# which, int unit) const { |
| 45 | if (unit == 0) |
| 46 | return ( which == 1 ? zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).iframe] : which == 2 ? zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).2] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).iframe] : undefinedcxx . . $ undefined. ); |
| 47 | const double power = sqrcxx . . $ sqr(ada6a8422704cf8a). (zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).iframe]) + sqrcxx . . $ sqr(ada6a8422704cf8a). (zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).2] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).iframe]); |
| 48 | return ( unit == 1 ? power : unit == 2 ? 10.0 * log10cxx . . $ log10(fee4f1d22bc8e617). ((power + 1e-30) / 4e-10) : undefinedcxx . . $ undefined. ); |
| 49 | } |
| 50 | |
| 51 | Thing_implement_pureVirtualcxx . . $ `sys/Thing.h:70:9`! (MultiSampledSpectrogram, Sampled, 0); |
| 52 | |
| 53 | void structMultiSampledSpectrogram :: v1_info () { |
| 54 | structDaatacxx . . $ structDaata# :: v1_infocxx . . $ structThing#v1_info(49f6e7a06ebc5aa8). (); |
| 55 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"Minimum frequency (Hz): ", v_myFrequencyUnitToHertz (xmincxx . . $ structFunction#xmin.), U" Hz"); |
| 56 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"Maximum frequency (Hz): ", v_myFrequencyUnitToHertz (xmaxcxx . . $ structFunction#xmax.), U" Hz"); |
| 57 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"First frequency (Hz): ", v_myFrequencyUnitToHertz (x1cxx . . $ structSampled#x1.), U" Hz"); |
| 58 | const integercxx . . $ integer# numberOfFrequencies = frequencyBins.sizecxx . . $ CollectionOf#size.; |
| 59 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"Number of frequencies: ", numberOfFrequencies); |
| 60 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"Number of frames in frequency bin 1: ", frequencyBins.atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).1] -> nxcxx . . $ structSampled#nx.); |
| 61 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"Number of frames in frequency bin ", numberOfFrequencies, U": ", frequencyBins.atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).numberOfFrequencies] -> nxcxx . . $ structSampled#nx.); |
| 62 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"Number of frames in all bins: ", MultiSampledSpectrogram_getNumberOfFramescxx . . $ MultiSampledSpectrogram_getNumberOfFrames(ab0ddc12ad1ee977). (this)); |
| 63 | } |
| 64 | |
| 65 | double structMultiSampledSpectrogram :: v_getValueAtSample (integercxx . . $ integer# ifreq, integercxx . . $ integer# iframe , int unit) const { |
| 66 | FrequencyBincxx . . $ FrequencyBin# bin = frequencyBins.atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).ifreq]; |
| 67 | const double value = bin -> v_getValueAtSamplecxx . . $ structFrequencyBin#v_getValueAtSample(8bbfc6ce471470c9). (iframe, 1, unit); |
| 68 | return ( isdefinedcxx . . $ isdefined(f8197d536af80c96). (value) ? ourcxx . . $ `melder/melder.h:42:9`! v_convertStandardToSpecialUnitcxx . . $ structFunction#v_convertStandardToSpecialUnit(d783654ce2b2ffd0). (value, iframe, unit) : undefinedcxx . . $ undefined. ); |
| 69 | } |
| 70 | |
| 71 | double structMultiSampledSpectrogram :: v_myFrequencyUnitToHertz (double f) const { |
| 72 | return f; |
| 73 | } |
| 74 | |
| 75 | double structMultiSampledSpectrogram :: v_hertzToMyFrequencyUnit (double f) const { |
| 76 | return f; |
| 77 | } |
| 78 | |
| 79 | autoFrequencyBincxx . . $ autoFrequencyBin# FrequencyBin_createcxx . . $ FrequencyBin_create(292198bd5fbe916d). (double tmin, double tmax, integercxx . . $ integer# nx, double dx, double x1) { |
| 80 | try { |
| 81 | autoFrequencyBincxx . . $ autoFrequencyBin# me = Thing_newcxx . . $ `sys/Thing.h:514:9`! (FrequencyBin); |
| 82 | Matrix_initcxx . . $ Matrix_init(9dd6c49f9830a091). (me.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), tmin, tmax, nx, dx, x1, 0.5, 2.5, 2, 1.0, 1.0); |
| 83 | return mecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 84 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 85 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"FrequencyBin not created."); |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | void FrequencyBin_formulacxx . . $ FrequencyBin_formula(390b6f79502d3438). (FrequencyBincxx . . $ FrequencyBin# me, conststring32cxx . . $ conststring32# formula, Interpretercxx . . $ Interpreter# interpreter) { |
| 90 | try { |
| 91 | Formula_compilecxx . . $ Formula_compile(3f9bc12732facfd). (interpreter, me, formula, kFormula_EXPRESSION_TYPE_NUMERICcxx . . $ `sys/Formula.h:24:9`!, true); |
| 92 | Formula_Resultcxx . . $ Formula_Result# resultcxx . . $ Formula_Result#Formula_Result(49f6e7a06ebc5aa8).; |
| 93 | for (integercxx . . $ integer# irow = 1; irow <= mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny.; irow ++) |
| 94 | for (integercxx . . $ integer# ibin = 1; ibin <= mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.; ibin ++) { |
| 95 | Formula_runcxx . . $ Formula_run(4cd939002183d562). (irow, ibin, & result); |
| 96 | mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).irow] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).ibin] = result. numericResultcxx . . $ Formula_Result#numericResult.; |
| 97 | } |
| 98 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 99 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": formula not completed."); |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | |
| 104 | // TODO:multiple rows! |
| 105 | double FrequencyBin_getValueAtXcxx . . $ FrequencyBin_getValueAtX(beabf3ea78b0ebe). (FrequencyBincxx . . $ FrequencyBin# me, double x, kVector_valueInterpolationcxx . . $ kVector_valueInterpolation# valueInterpolationType) { |
| 106 | const double leftEdge = mycxx . . $ `melder/melder.h:44:9`! x1cxx . . $ structSampled#x1. - 0.5 * mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx., rightEdge = leftEdge + mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx. * mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx.; |
| 107 | if (x < leftEdge || x > rightEdge) |
| 108 | return undefinedcxx . . $ undefined.; |
| 109 | const integercxx . . $ integer# interpolationDepth = kVector_valueInterpolation_to_interpolationDepthcxx . . $ kVector_valueInterpolation_to_interpolationDepth(42b64d17316aa70a). (valueInterpolationType); |
| 110 | const double index_real = (x - mycxx . . $ `melder/melder.h:44:9`! x1cxx . . $ structSampled#x1.) / mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx. + 1.0; |
| 111 | return NUM_interpolate_sinccxx . . $ NUM_interpolate_sinc(3bff97c7d2c43d6f). (mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z..rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (1), index_real, interpolationDepth); |
| 112 | } |
| 113 | |
| 114 | autoSoundcxx . . $ autoSound# FrequencyBin_to_Soundcxx . . $ FrequencyBin_to_Sound(88f382112297eb18). (FrequencyBincxx . . $ FrequencyBin# me) { |
| 115 | try { |
| 116 | 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.); |
| 117 | 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). (1); |
| 118 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 119 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 120 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": cannot convert to Sound."); |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | autoAnalyticSoundcxx . . $ autoAnalyticSound# FrequencyBin_to_AnalyticSoundcxx . . $ FrequencyBin_to_AnalyticSound(df39bac52a860c55). (FrequencyBincxx . . $ FrequencyBin# me) { |
| 125 | try { |
| 126 | autoAnalyticSoundcxx . . $ autoAnalyticSound# thee = AnalyticSound_createcxx . . $ AnalyticSound_create(3663e8d9e13c92b4). (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.); |
| 127 | thycxx . . $ `melder/melder.h:45:9`! zcxx . . $ structMatrix#z..getcxx . . $ automatrix#get(b2b81450b5bdda66).() <<=cxx . . $ `operator<<=`(a7d93ba40fe22fe0). mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z..getcxx . . $ automatrix#get(b2b81450b5bdda66).(); |
| 128 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 129 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 130 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": cannot convert to AnalyticSound."); |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | void MultiSampledSpectrogram_initcxx . . $ MultiSampledSpectrogram_init(3992d859142ced2). (MultiSampledSpectrogram me, double tmin, double tmax, double fmin, double fmax, |
| 135 | integercxx . . $ integer# numberOfFrequencies, double df, double f1, double frequencyResolutionInBins) |
| 136 | { |
| 137 | mycxx . . $ `melder/melder.h:44:9`! tmin = tmin; |
| 138 | mycxx . . $ `melder/melder.h:44:9`! tmax = tmax; |
| 139 | mycxx . . $ `melder/melder.h:44:9`! frequencyResolutionInBins = frequencyResolutionInBins; |
| 140 | Sampled_initcxx . . $ Sampled_init(5b6f70c633f31208). (me, fmin, fmax, numberOfFrequencies, df, f1); |
| 141 | } |
| 142 | |
| 143 | void MultiSampledSpectrogram_getFrequencyBandcxx . . $ MultiSampledSpectrogram_getFrequencyBand(334fcc698c6bfe6c). (MultiSampledSpectrogram me, integercxx . . $ integer# index, double *out_flow, double *out_fhigh) { |
| 144 | const double centreFrequency = Sampled_indexToXcxx . . $ Sampled_indexToX(65bcd2c9acbb3dd5). (me, index); |
| 145 | if (out_flow) { |
| 146 | double flow = mycxx . . $ `melder/melder.h:44:9`! v_myFrequencyUnitToHertz (centreFrequency - mycxx . . $ `melder/melder.h:44:9`! frequencyResolutionInBins * mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx.); |
| 147 | Melder_clipLeftcxx . . $ Melder_clipLeft(6245cd023a7d1552). (0.0, & flow); |
| 148 | *out_flow = flow; |
| 149 | } |
| 150 | if (out_fhigh) { |
| 151 | const double maximumFrequency = mycxx . . $ `melder/melder.h:44:9`! v_myFrequencyUnitToHertz (mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax.); |
| 152 | double fhigh = mycxx . . $ `melder/melder.h:44:9`! v_myFrequencyUnitToHertz (centreFrequency + mycxx . . $ `melder/melder.h:44:9`! frequencyResolutionInBins * mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx.); |
| 153 | Melder_clipRightcxx . . $ Melder_clipRight(5b63ce711df1ade7). (& fhigh, maximumFrequency); |
| 154 | *out_fhigh = fhigh; |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | void MultiSampledSpectrogram_formulacxx . . $ MultiSampledSpectrogram_formula(9d01cb27578888e0). (MultiSampledSpectrogram me, conststring32cxx . . $ conststring32# formula, Interpretercxx . . $ Interpreter# interpreter) { |
| 159 | try { |
| 160 | for (integercxx . . $ integer# ifreq = 1; ifreq <= mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.; ifreq ++) { |
| 161 | FrequencyBincxx . . $ FrequencyBin# frequencyBin = mycxx . . $ `melder/melder.h:44:9`! frequencyBins.atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).ifreq]; |
| 162 | FrequencyBin_formulacxx . . $ FrequencyBin_formula(390b6f79502d3438). (frequencyBin, formula, interpreter); |
| 163 | } |
| 164 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 165 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": formula not completed."); |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | void MultiSampledSpectrogram_formula_partcxx . . $ MultiSampledSpectrogram_formula_part(f0c580ff93e15909). (MultiSampledSpectrogram me, double fromTime, double toTime, double fromFrequency, double toFrequency, conststring32cxx . . $ conststring32# formula, Interpretercxx . . $ Interpreter# interpreter) { |
| 170 | try { |
| 171 | const double fx1 = mycxx . . $ `melder/melder.h:44:9`! v_myFrequencyUnitToHertz (mycxx . . $ `melder/melder.h:44:9`! x1cxx . . $ structSampled#x1.); |
| 172 | const double fnyquist = mycxx . . $ `melder/melder.h:44:9`! v_myFrequencyUnitToHertz (mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax.); |
| 173 | if (fromFrequency == toFrequency && fromFrequency == 0.0) { |
| 174 | fromFrequency = fx1; |
| 175 | toFrequency = fnyquist; |
| 176 | } |
| 177 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (toFrequency >= fx1 && fromFrequency <= toFrequency && fromFrequency < fnyquist, |
| 178 | U"At least one of the frequencies needs to be in the interval from ", fx1, U" to ", fnyquist, U" Hz."); |
| 179 | Melder_clipcxx . . $ Melder_clip(971c667ea412f82c). (fx1, & fromFrequency, fnyquist); |
| 180 | Melder_clipcxx . . $ Melder_clip(971c667ea412f82c). (fx1, & toFrequency, fnyquist); |
| 181 | const double flow = mycxx . . $ `melder/melder.h:44:9`! v_hertzToMyFrequencyUnit (fromFrequency); |
| 182 | const double fhigh = mycxx . . $ `melder/melder.h:44:9`! v_hertzToMyFrequencyUnit (toFrequency); |
| 183 | integercxx . . $ integer# iflow, ifhigh; |
| 184 | if (Sampled_getWindowSamplescxx . . $ Sampled_getWindowSamples(fe99094ed5bb3f6a). (me, flow, fhigh, & iflow, & ifhigh) > 0) |
| 185 | for (integercxx . . $ integer# ifreq = iflow; ifreq <= ifhigh; ifreq ++) { |
| 186 | FrequencyBincxx . . $ FrequencyBin# frequencyBin = mycxx . . $ `melder/melder.h:44:9`! frequencyBins.atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).ifreq]; |
| 187 | Matrix_formula_partcxx . . $ Matrix_formula_part(bf805b81a4f35360). (frequencyBin, fromTime, toTime, 0.5, 2.5, formula, interpreter, nullptr); |
| 188 | } |
| 189 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 190 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": formula not completed on part."); |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | integercxx . . $ integer# MultiSampledSpectrogram_getNumberOfFramescxx . . $ MultiSampledSpectrogram_getNumberOfFrames(ab0ddc12ad1ee977). (MultiSampledSpectrogram me) { |
| 195 | double numberOfFrames = 0; |
| 196 | for (integercxx . . $ integer# ifreq = 1; ifreq <= mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.; ifreq ++) { |
| 197 | FrequencyBincxx . . $ FrequencyBin# frequencyBin = mycxx . . $ `melder/melder.h:44:9`! frequencyBins.atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).ifreq]; |
| 198 | numberOfFrames += frequencyBin -> nxcxx . . $ structSampled#nx.; |
| 199 | } |
| 200 | return numberOfFrames; |
| 201 | } |
| 202 | |
| 203 | void MultiSampledSpectrogram_paintInsidecxx . . $ MultiSampledSpectrogram_paintInside(52b1324802957f7). (MultiSampledSpectrogram me, Graphicscxx . . $ Graphics# g, double tmin, double tmax, double fmin, double fmax, double dBRange) { |
| 204 | integercxx . . $ integer# itmin, itmax, ifmin, ifmax; |
| 205 | if (tmax <= tmin) { |
| 206 | tmin = mycxx . . $ `melder/melder.h:44:9`! tmin; |
| 207 | tmax = mycxx . . $ `melder/melder.h:44:9`! tmax; |
| 208 | } |
| 209 | if (fmax <= fmin) { |
| 210 | fmax = mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax.; |
| 211 | fmin = mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin.; |
| 212 | } |
| 213 | if (Sampled_getWindowSamplescxx . . $ Sampled_getWindowSamples(fe99094ed5bb3f6a). (me, fmin, fmax, & ifmin, & ifmax) == 0) |
| 214 | return; |
| 215 | const integercxx . . $ integer# maximumNumberOfTimeFrames = Sampled_getWindowSamplescxx . . $ Sampled_getWindowSamples(fe99094ed5bb3f6a). (mycxx . . $ `melder/melder.h:44:9`! frequencyBins.atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).ifmax], tmin, tmax, & itmin, & itmax); |
| 216 | if (maximumNumberOfTimeFrames == 0) |
| 217 | return; |
| 218 | Graphics_setWindowcxx . . $ Graphics_setWindow(72bdb7937dbb13da). (g, tmin, tmax, fmin, fmax); |
| 219 | autoMATcxx . . $ autoMAT# p = raw_MATcxx . . $ raw_MAT(3d09731056d2b97d). (1, maximumNumberOfTimeFrames); |
| 220 | /* |
| 221 | Find maximum power. No need for logarithm in the test |
| 222 | */ |
| 223 | MelderExtremaWithInitcxx . . $ MelderExtremaWithInit# powerExtrema; |
| 224 | for (integercxx . . $ integer# ifreq = ifmin; ifreq <= ifmax; ifreq ++) { |
| 225 | FrequencyBincxx . . $ FrequencyBin# frequencyBin = mycxx . . $ `melder/melder.h:44:9`! frequencyBins.atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).ifreq]; |
| 226 | if (Sampled_getWindowSamplescxx . . $ Sampled_getWindowSamples(fe99094ed5bb3f6a). (frequencyBin, tmin, tmax, & itmin, & itmax) == 0) |
| 227 | continue; |
| 228 | for (integercxx . . $ integer# iframe = itmin; iframe <= itmax; iframe ++) { |
| 229 | double powerdB = frequencyBin -> v_getValueAtSamplecxx . . $ structFrequencyBin#v_getValueAtSample(8bbfc6ce471470c9). (iframe, 0, 2); // 10*log10 (power/..) |
| 230 | powerExtrema.updatecxx . . $ MelderExtremaWithInit#update(ba8836b59fb42830). (powerdB); |
| 231 | } |
| 232 | } |
| 233 | if (powerExtrema.maxcxx . . $ MelderExtremaWithInit#max. == 0.0) |
| 234 | return; // empty |
| 235 | const double maximum = powerExtrema.maxcxx . . $ MelderExtremaWithInit#max.; |
| 236 | const double minimum = stdcxx . . $ std/::maxcxx . . $ std/max(2a338fce5842aa6a). (maximum - dBRange, powerExtrema.mincxx . . $ MelderExtremaWithInit#min.); |
| 237 | double tmin_previousBin = undefinedcxx . . $ undefined., tmax_previousBin = undefinedcxx . . $ undefined.; |
| 238 | for (integercxx . . $ integer# ifreq = ifmin; ifreq <= ifmax; ifreq ++) { |
| 239 | FrequencyBincxx . . $ FrequencyBin# frequencyBin = mycxx . . $ `melder/melder.h:44:9`! frequencyBins.atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).ifreq]; |
| 240 | const double dx = frequencyBin -> dxcxx . . $ structSampled#dx.; |
| 241 | const integercxx . . $ integer# numberOfFrames = Sampled_getWindowSamplescxx . . $ Sampled_getWindowSamples(fe99094ed5bb3f6a). ( |
| 242 | frequencyBin, tmin - 0.4999 * dx, tmax + 0.4999 * dx, & itmin, & itmax); |
| 243 | if (numberOfFrames == 0) |
| 244 | continue; |
| 245 | p.resizecxx . . $ automatrix#resize(a64d57580b9dfd76). (1, numberOfFrames); |
| 246 | integercxx . . $ integer# index = 0; |
| 247 | for (integercxx . . $ integer# iframe = itmin; iframe <= itmax; iframe ++) |
| 248 | p [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1). ++ index] = frequencyBin -> v_getValueAtSamplecxx . . $ structFrequencyBin#v_getValueAtSample(8bbfc6ce471470c9). (iframe, 0, 2); |
| 249 | double tmin_bin = Sampled_indexToXcxx . . $ Sampled_indexToX(65bcd2c9acbb3dd5). (frequencyBin, itmin) - 0.5 * dx; |
| 250 | double tmax_bin = Sampled_indexToXcxx . . $ Sampled_indexToX(65bcd2c9acbb3dd5). (frequencyBin, itmax) + 0.5 * dx; |
| 251 | Melder_clipRightcxx . . $ Melder_clipRight(5b63ce711df1ade7). (& tmin_bin, tmin_previousBin); // clip against previous |
| 252 | Melder_clipLeftcxx . . $ Melder_clipLeft(6245cd023a7d1552). (tmax_previousBin, & tmax_bin); |
| 253 | tmin_previousBin = tmin_bin; |
| 254 | tmax_previousBin = tmax_bin; |
| 255 | const double freq = Sampled_indexToXcxx . . $ Sampled_indexToX(65bcd2c9acbb3dd5). (me, ifreq); |
| 256 | const double ymin = freq - 0.5 * mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx., ymax = freq + 0.5 * mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx.; |
| 257 | Graphics_imagecxx . . $ Graphics_image(a5d48eb8683d0521). (g, pcxx . . $ constmatrixview#constmatrixview(eed9513d24570b3d)..getcxx . . $ automatrix#get(b2b81450b5bdda66).(), tmin_bin, tmax_bin, ymin, ymax, minimum, maximum); |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | /* End of file MultiSampledSpectrogram.cpp */ |