Debian Codegraph @

dwtools/Sound_and_MultiSampledSpectrogram.cpp

raw symbols SCIP
1 /* Sound_and_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 "Sound_and_MultiSampledSpectrogram.h"cxx . . $ `<file>/dwtools/Sound_and_MultiSampledSpectrogram.h`/
20 #include "Sound_and_Spectrum.h"cxx . . $ `<file>/fon/Sound_and_Spectrum.h`/
21 #include "Spectrum_extensions.h"cxx . . $ `<file>/dwtools/Spectrum_extensions.h`/
22 #include "Spectrum_and_MultiSampledSpectrogram.h"cxx . . $ `<file>/dwtools/Spectrum_and_MultiSampledSpectrogram.h`/
23 #include "NUM2.h"cxx . . $ `<file>/dwsys/NUM2.h`/
24
25
26 autoSoundcxx . . $ autoSound# MultiSampledSpectrogram_to_Soundcxx . . $ MultiSampledSpectrogram_to_Sound(a21fff60469ac77a). (MultiSampledSpectrogramcxx . . $ MultiSampledSpectrogram# me) {
27 try {
28 autoSpectrumcxx . . $ autoSpectrum# spectrum = MultiSampledSpectrogram_to_Spectrumcxx . . $ MultiSampledSpectrogram_to_Spectrum(f80e55b4ddb107af). (me);
29 autoSoundcxx . . $ autoSound# thee = Spectrum_to_Soundcxx . . $ Spectrum_to_Sound(b9577246d0f6b8d7). (spectrum.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).());
30 const double synthesizedDuration = thycxx . . $ `melder/melder.h:45:9`! xmaxcxx . . $ structFunction#xmax. - thycxx . . $ `melder/melder.h:45:9`! xmincxx . . $ structFunction#xmin.;
31 const double wantedDuration = mycxx . . $ `melder/melder.h:44:9`! tmaxcxx . . $ structMultiSampledSpectrogram#tmax. - mycxx . . $ `melder/melder.h:44:9`! tmincxx . . $ structMultiSampledSpectrogram#tmin.;
32 if (synthesizedDuration > wantedDuration) {
33 /*
34 The number of samples in the original was not a power of 2 and to apply the FFT the number of samples had to be extended.
35 */
36 autoSoundcxx . . $ autoSound# part = Sound_extractPartcxx . . $ Sound_extractPart(e1651eb055dd2f09). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), 0.0, wantedDuration, kSound_windowShapecxx . . $ kSound_windowShape#::RECTANGULARcxx . . $ kSound_windowShape#RECTANGULAR., 1.0, false);
37 part ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). xmincxx . . $ structFunction#xmin. = mycxx . . $ `melder/melder.h:44:9`! tmincxx . . $ structMultiSampledSpectrogram#tmin.;
38 part ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). xmaxcxx . . $ structFunction#xmax. = mycxx . . $ `melder/melder.h:44:9`! tmaxcxx . . $ structMultiSampledSpectrogram#tmax.;
39 thee =cxx . . $ autoSomeThing#`operator=`(80cc59814f7161e8). part.movecxx . . $ autoSomeThing#move(25acc3554b7d1642).();
40 } else if (synthesizedDuration == wantedDuration) {
41 thycxx . . $ `melder/melder.h:45:9`! xmincxx . . $ structFunction#xmin. = mycxx . . $ `melder/melder.h:44:9`! tmincxx . . $ structMultiSampledSpectrogram#tmin.;
42 thycxx . . $ `melder/melder.h:45:9`! xmaxcxx . . $ structFunction#xmax. = mycxx . . $ `melder/melder.h:44:9`! tmaxcxx . . $ structMultiSampledSpectrogram#tmax.;
43 } else {
44 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"The synthesized number of samples is too low!");
45 }
46 return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).;
47
48 } catch (MelderErrorcxx . . $ MelderError#) {
49 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": could not create Sound.");
50 }
51 }
52
53 autoConstantQLog2FSpectrogramcxx . . $ autoConstantQLog2FSpectrogram# Sound_to_ConstantQLog2FSpectrogramcxx . . $ Sound_to_ConstantQLog2FSpectrogram(b479bf2c3e27b2ee). (Soundcxx . . $ Sound# me, double lowestFrequency, double fmax,
54 integercxx . . $ integer# numberOfBinsPerOctave, double frequencyResolutionInBins, double timeOversamplingFactor,
55 kSound_windowShapecxx . . $ kSound_windowShape# filterShape) {
56 try {
57 const double nyquistFrequency = 0.5 / mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx.;
58 if (fmax <= 0.0 || fmax > nyquistFrequency)
59 fmax = nyquistFrequency;
60 Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (lowestFrequency < fmax,
61 U"The lowest frequency should be smaller than the maximum frequency (", fmax, U" Hz).");
62 Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (frequencyResolutionInBins > 0.0,
63 U"The frequency resolution should be larger than zero.");
64 Melder_clipLeftcxx . . $ Melder_clipLeft(6245cd023a7d1552). (1.0, & timeOversamplingFactor);
65 autoConstantQLog2FSpectrogramcxx . . $ autoConstantQLog2FSpectrogram# thee = ConstantQLog2FSpectrogram_createcxx . . $ ConstantQLog2FSpectrogram_create(ec02a1924e4f27e8). (mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin., mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax.,
66 lowestFrequency, fmax, numberOfBinsPerOctave, frequencyResolutionInBins);
67 autoSpectrumcxx . . $ autoSpectrum# him = Sound_and_MultiSampledSpectrogram_to_Spectrumcxx . . $ Sound_and_MultiSampledSpectrogram_to_Spectrum(c1a18e113ea441a6). (me, thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).());
68 Spectrum_into_MultiSampledSpectrogramcxx . . $ Spectrum_into_MultiSampledSpectrogram(49c964880100cdf6). (him.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), timeOversamplingFactor, filterShape);
69 return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).;
70 } catch (MelderErrorcxx . . $ MelderError#) {
71 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": cannot create ConstantQLog2FSpectrogram.");
72 }
73 }
74
75 autoGaborSpectrogramcxx . . $ autoGaborSpectrogram# Sound_to_GaborSpectrogramcxx . . $ Sound_to_GaborSpectrogram(56c564cbf60aeff2). (Soundcxx . . $ Sound# me, double fmax, double filterBandwidth,
76 double frequencyStep, double timeOversamplingFactor, kSound_windowShapecxx . . $ kSound_windowShape# filterShape)
77 {
78 try {
79 const double nyquistFrequency = 0.5 / mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx.;
80 bool resample = true;
81 if (fmax <= 0.0 || fmax >= nyquistFrequency) {
82 fmax = nyquistFrequency;
83 resample = false;
84 }
85 autoGaborSpectrogramcxx . . $ autoGaborSpectrogram# thee = GaborSpectrogram_createcxx . . $ GaborSpectrogram_create(25d0239ed9e3fa48). (mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin., mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax., fmax, filterBandwidth, frequencyStep);
86 autoSoundcxx . . $ autoSound# resampledcxx . . $ autoSomeThing#autoSomeThing(49f6e7a06ebc5aa8).;
87 if (resample)
88 resampled =cxx . . $ autoSomeThing#`operator=`(80cc59814f7161e8). Sound_resamplecxx . . $ Sound_resample(872961da5f5e69e5). (me, 2.0 * fmax, 50);
89 autoSpectrumcxx . . $ autoSpectrum# him = Sound_to_Spectrumcxx . . $ Sound_to_Spectrum(e96f4d575d8eeb8c). ((resample ? resampled.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).() : me), true);
90 Spectrum_into_MultiSampledSpectrogramcxx . . $ Spectrum_into_MultiSampledSpectrogram(49c964880100cdf6). (him.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), timeOversamplingFactor, filterShape);
91 return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).;
92 } catch (MelderErrorcxx . . $ MelderError#) {
93 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": cannot create GaborSpectrogram.");
94 }
95 }
96 /* End of file Sound_and_MultiSampledSpectrogram.cpp */