| 1 | /* Spectrum_and_Spectrogram.cpp |
| 2 | * |
| 3 | * Copyright (C) 1992-2011,2014,2015,2017,2021 David Weenink & Paul Boersma |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or (at |
| 8 | * your option) any later version. |
| 9 | * |
| 10 | * This code is distributed in the hope that it will be useful, but |
| 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 13 | * See the GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this work. If not, see <http://www.gnu.org/licenses/>. |
| 17 | */ |
| 18 | |
| 19 | /* |
| 20 | * pb 1998/04/18 |
| 21 | * pb 2002/07/16 GPL |
| 22 | * pb 2011/06/10 C++ |
| 23 | */ |
| 24 | |
| 25 | #include "Spectrum_and_Spectrogram.h"cxx . . $ `<file>/fon/Spectrum_and_Spectrogram.h`/ |
| 26 | |
| 27 | autoSpectrumcxx . . $ autoSpectrum# Spectrogram_to_Spectrumcxx . . $ Spectrogram_to_Spectrum(d0c0706ff5d3b1ac). (Spectrogramcxx . . $ Spectrogram# me, double tim) { |
| 28 | try { |
| 29 | autoSpectrumcxx . . $ autoSpectrum# thee = Spectrum_createcxx . . $ Spectrum_create(a338b9c326abb5ed). (mycxx . . $ `melder/melder.h:44:9`! ymaxcxx . . $ structSampledXY#ymax., mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny.); |
| 30 | /* Override stupid Spectrum values. */ |
| 31 | thycxx . . $ `melder/melder.h:45:9`! xmincxx . . $ structFunction#xmin. = mycxx . . $ `melder/melder.h:44:9`! ymincxx . . $ structSampledXY#ymin.; |
| 32 | thycxx . . $ `melder/melder.h:45:9`! xmaxcxx . . $ structFunction#xmax. = mycxx . . $ `melder/melder.h:44:9`! ymaxcxx . . $ structSampledXY#ymax.; |
| 33 | thycxx . . $ `melder/melder.h:45:9`! x1cxx . . $ structSampled#x1. = mycxx . . $ `melder/melder.h:44:9`! y1cxx . . $ structSampledXY#y1.; // centre of first band, instead of 0 (makes it unFFTable) |
| 34 | thycxx . . $ `melder/melder.h:45:9`! dxcxx . . $ structSampled#dx. = mycxx . . $ `melder/melder.h:44:9`! dycxx . . $ structSampledXY#dy.; // frequency step |
| 35 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (mycxx . . $ `melder/melder.h:44:9`! nx >= 1); // for Melder_clipped |
| 36 | const integercxx . . $ integer# itime = Melder_clippedcxx . . $ Melder_clipped(5eb09607cedc971b). (1_integercxx . . $ `operator""_integer`(85240eb457c3721a)., Sampled_xToNearestIndexcxx . . $ Sampled_xToNearestIndex(405c2491bc3636e9). (me, tim), mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.); |
| 37 | for (integercxx . . $ integer# ifreq = 1; ifreq <= mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny.; ifreq ++) { |
| 38 | const double value = mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).ifreq] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).itime]; |
| 39 | if (value < 0.0) |
| 40 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Negative values in spectrogram."); |
| 41 | thycxx . . $ `melder/melder.h:45:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).ifreq] = sqrtcxx . . $ sqrt(fee4f1d22bc8e617). (value); |
| 42 | thycxx . . $ `melder/melder.h:45:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).2] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).ifreq] = 0.0; |
| 43 | } |
| 44 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 45 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 46 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": spectral slice not extracted."); |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | autoSpectrogramcxx . . $ autoSpectrogram# Spectrum_to_Spectrogramcxx . . $ Spectrum_to_Spectrogram(5977912459a5db57). (Spectrumcxx . . $ Spectrum# me) { |
| 51 | try { |
| 52 | autoSpectrogramcxx . . $ autoSpectrogram# thee = Spectrogram_createcxx . . $ Spectrogram_create(afddb115247e4bb0). (0, 1, 1, 1, 0.5, 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.); |
| 53 | for (integercxx . . $ integer# i = 1; i <= mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.; i ++) |
| 54 | thycxx . . $ `melder/melder.h:45:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).1] = 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).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).2] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i]; |
| 55 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 56 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 57 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": not converted to Spectrogram."); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | /* End of file Spectrum_and_Spectrogram.cpp */ |