Debian Codegraph @

dwtools/SoundFrames.cpp

raw symbols SCIP
1 /* SoundFrames.cpp
2 *
3 * Copyright (C) 2025 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 "SoundFrames.h"cxx . . $ `<file>/dwtools/SoundFrames.h`/
20
21 Thing_implementcxx . . $ `sys/Thing.h:65:9`! (SoundFrames, Thing, 0);
22
23 void structSoundFramescxx . . $ structSoundFrames# :: initForToSampledcxx . . $ structSoundFrames#initForToSampled(b5ea0db16098c158). (constSoundcxx . . $ constSound# input, double effectiveAnalysisWidth, double timeStep,
24 kSound_windowShapecxx . . $ kSound_windowShape# windowShape, bool subtractChannelMean)
25 {
26 ourcxx . . $ `melder/melder.h:42:9`! inputSoundcxx . . $ structSoundFrames#inputSound. = input;
27 ourcxx . . $ `melder/melder.h:42:9`! physicalAnalysisWidthcxx . . $ structSoundFrames#physicalAnalysisWidth. = getPhysicalAnalysisWidthcxx . . $ getPhysicalAnalysisWidth(746d57f737047cdc). (effectiveAnalysisWidth, windowShape);
28 if (timeStep == 0.0) {
29 // calculate output_dt
30 }
31 outputcxx . . $ structSoundFrames#output. -> dxcxx . . $ structSampled#dx. = timeStep;
32 Sampled_shortTermAnalysiscxx . . $ Sampled_shortTermAnalysis(77f703705034c8a). (inputSoundcxx . . $ structSoundFrames#inputSound., physicalAnalysisWidthcxx . . $ structSoundFrames#physicalAnalysisWidth., outputcxx . . $ structSoundFrames#output. -> dxcxx . . $ structSampled#dx., & outputcxx . . $ structSoundFrames#output. -> nxcxx . . $ structSampled#nx., & outputcxx . . $ structSoundFrames#output. -> x1cxx . . $ structSampled#x1.);
33 initCommoncxx . . $ structSoundFrames#initCommon(e51dc816e62fffe6). (windowShape, subtractChannelMean);
34 }
35
36 void structSoundFramescxx . . $ structSoundFrames# :: initForIntoSampledcxx . . $ structSoundFrames#initForIntoSampled(ecb22456c6d7c3c). (constSoundcxx . . $ constSound# input, mutableSampledcxx . . $ mutableSampled# output, double effectiveAnalysisWidth,
37 kSound_windowShapecxx . . $ kSound_windowShape# windowShape, bool subtractChannelMean)
38 {
39 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (input -> xmin == output -> xmin && input -> xmax == output -> xmax);
40 ourcxx . . $ `melder/melder.h:42:9`! inputSoundcxx . . $ structSoundFrames#inputSound. = input;
41 ourcxx . . $ `melder/melder.h:42:9`! outputcxx . . $ structSoundFrames#output. = output;
42 ourcxx . . $ `melder/melder.h:42:9`! physicalAnalysisWidthcxx . . $ structSoundFrames#physicalAnalysisWidth. = getPhysicalAnalysisWidthcxx . . $ getPhysicalAnalysisWidth(746d57f737047cdc). (effectiveAnalysisWidth, windowShape);
43 initCommoncxx . . $ structSoundFrames#initCommon(e51dc816e62fffe6). (windowShape, subtractChannelMean);
44 }
45
46 void structSoundFramescxx . . $ structSoundFrames# :: initCommoncxx . . $ structSoundFrames#initCommon(e51dc816e62fffe6). (kSound_windowShapecxx . . $ kSound_windowShape# windowShape, bool subtractChannelMean)
47 {
48 ourcxx . . $ `melder/melder.h:42:9`! windowShapecxx . . $ structSoundFrames#windowShape. = windowShape;
49 ourcxx . . $ `melder/melder.h:42:9`! subtractChannelMeancxx . . $ structSoundFrames#subtractChannelMean. = subtractChannelMean;
50 soundFrameSizecxx . . $ structSoundFrames#soundFrameSize. = getSoundFrameSizecxx . . $ getSoundFrameSize(e4170d96af58b73c). (physicalAnalysisWidthcxx . . $ structSoundFrames#physicalAnalysisWidth., inputSoundcxx . . $ structSoundFrames#inputSound. -> dxcxx . . $ structSampled#dx.);
51 windowFunctioncxx . . $ structSoundFrames#windowFunction. =cxx . . $ autovector#`operator=`(f4f0443dbfdd1e40). raw_VECcxx . . $ raw_VEC(e4395f764b859b1e). (soundFrameSizecxx . . $ structSoundFrames#soundFrameSize.); // TODO: move out of thread repetition
52 soundFramecxx . . $ structSoundFrames#soundFrame. =cxx . . $ autovector#`operator=`(f4f0443dbfdd1e40). raw_VECcxx . . $ raw_VEC(e4395f764b859b1e). (soundFrameSizecxx . . $ structSoundFrames#soundFrameSize.);
53 windowShape_into_VECcxx . . $ windowShape_into_VEC(1bbc8fdbd7847e3). (windowShape, windowFunctioncxx . . $ structSoundFrames#windowFunction..getcxx . . $ autovector#get(e8d1da7fe68a6585).());
54 frameAsSoundcxx . . $ structSoundFrames#frameAsSound. =cxx . . $ autoSomeThing#`operator=`(80cc59814f7161e8). Sound_createcxx . . $ Sound_create(39ab106d6b9a0135). (inputSoundcxx . . $ structSoundFrames#inputSound. -> nycxx . . $ structSampledXY#ny., 0.0, soundFrameSizecxx . . $ structSoundFrames#soundFrameSize. * inputSoundcxx . . $ structSoundFrames#inputSound. -> dxcxx . . $ structSampled#dx., soundFrameSizecxx . . $ structSoundFrames#soundFrameSize.,
55 inputSoundcxx . . $ structSoundFrames#inputSound. -> dxcxx . . $ structSampled#dx., 0.5 * inputSoundcxx . . $ structSoundFrames#inputSound. -> dxcxx . . $ structSampled#dx.);
56 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (soundFrame.size == soundFrameSize);
57 }
58
59 Soundcxx . . $ Sound# structSoundFramescxx . . $ structSoundFrames# :: getFramecxx . . $ structSoundFrames#getFrame(4fb1c00207b05668). (integercxx . . $ integer# iframe) {
60 const double midTime = Sampled_indexToXcxx . . $ Sampled_indexToX(65bcd2c9acbb3dd5). (outputcxx . . $ structSoundFrames#output., iframe);
61 integercxx . . $ integer# startSample = Sampled_xToNearestIndexcxx . . $ Sampled_xToNearestIndex(405c2491bc3636e9). (inputSoundcxx . . $ structSoundFrames#inputSound., midTime - 0.5 * physicalAnalysisWidthcxx . . $ structSoundFrames#physicalAnalysisWidth.); // approximation
62 const integercxx . . $ integer# numberOfChannels = inputSoundcxx . . $ structSoundFrames#inputSound. -> nycxx . . $ structSampledXY#ny.;
63 for (integercxx . . $ integer# ichannel = 1; ichannel <= numberOfChannels; ichannel ++) {
64 VECcxx . . $ VEC# soundChannel = inputSoundcxx . . $ structSoundFrames#inputSound. -> zcxx . . $ structMatrix#z..rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (ichannel), frameChannel = frameAsSoundcxx . . $ structSoundFrames#frameAsSound. ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). zcxx . . $ structMatrix#z..rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (ichannel);
65 integercxx . . $ integer# currentSample = startSample;
66 for (integercxx . . $ integer# i = 1; i <= soundFramecxx . . $ structSoundFrames#soundFrame..sizecxx . . $ autovector#size.; i ++, currentSample ++)
67 frameChannel [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i] = (( currentSample > 0 && currentSample <= inputSoundcxx . . $ structSoundFrames#inputSound. -> nxcxx . . $ structSampled#nx.) ? soundChannel [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).currentSample] : 0.0 );
68
69 if (subtractChannelMeancxx . . $ structSoundFrames#subtractChannelMean.)
70 centre_VEC_inoutcxx . . $ centre_VEC_inout(b915798f9bafc8a). (frameChannelcxx . . $ vectorview#vectorview(eac9d6ec4c4bfecd)., nullptr);
71
72 frameChannelcxx . . $ vectorview#vectorview(eac9d6ec4c4bfecd). *=cxx . . $ `operator*=`(adea042513329390). windowFunctioncxx . . $ constvectorview#constvectorview(eac9d6ec4c4bfecd)..getcxx . . $ autovector#get(e8d1da7fe68a6585).();
73 }
74
75 return frameAsSoundcxx . . $ structSoundFrames#frameAsSound..getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).();
76 }
77
78 VECcxx . . $ VEC# structSoundFramescxx . . $ structSoundFrames# :: getMonoFramecxx . . $ structSoundFrames#getMonoFrame(516a12db1224da40). (integercxx . . $ integer# iframe) {
79 getFramecxx . . $ structSoundFrames#getFrame(4fb1c00207b05668). (iframe);
80 for (integercxx . . $ integer# i = 1; i <= soundFrameSizecxx . . $ structSoundFrames#soundFrameSize.; i ++)
81 soundFramecxx . . $ structSoundFrames#soundFrame. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] = Sampled_getValueAtSamplecxx . . $ Sampled_getValueAtSample(5092633e80007c54). (frameAsSoundcxx . . $ structSoundFrames#frameAsSound..getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), i, 0, 0); // average channels
82 return soundFramecxx . . $ structSoundFrames#soundFrame..getcxx . . $ autovector#get(e8d1da7fe68a6585).();
83 }
84
85 autoSoundFramescxx . . $ autoSoundFrames# SoundFrames_createForIntoSampledcxx . . $ SoundFrames_createForIntoSampled(bc9244df65bbc83e). (constSoundcxx . . $ constSound# input, mutableSampledcxx . . $ mutableSampled# output, double effectiveAnalysisWidth,
86 kSound_windowShapecxx . . $ kSound_windowShape# windowShape, bool subtractFrameMean)
87 {
88 try {
89 autoSoundFramescxx . . $ autoSoundFrames# me = Thing_newcxx . . $ `sys/Thing.h:514:9`! (SoundFrames);
90 mycxx . . $ `melder/melder.h:44:9`! initForIntoSampledcxx . . $ structSoundFrames#initForIntoSampled(ecb22456c6d7c3c). (input, output, effectiveAnalysisWidth, windowShape, subtractFrameMean);
91 return mecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).;
92 } catch (MelderErrorcxx . . $ MelderError#) {
93 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"SoundFrames (with Sampled) could not be created.");
94 }
95 }
96
97 autoSoundFramescxx . . $ autoSoundFrames# SoundFrames_createcxx . . $ SoundFrames_create(5e7f91e561736224). (constSoundcxx . . $ constSound# input, double effectiveAnalysisWidth,
98 double timeStep, kSound_windowShapecxx . . $ kSound_windowShape# windowShape,
99 bool subtractFrameChannelMean)
100 {
101 try {
102 autoSoundFramescxx . . $ autoSoundFrames# me = Thing_newcxx . . $ `sys/Thing.h:514:9`! (SoundFrames);
103 mycxx . . $ `melder/melder.h:44:9`! initForToSampledcxx . . $ structSoundFrames#initForToSampled(b5ea0db16098c158). (input, effectiveAnalysisWidth, timeStep, windowShape, subtractFrameChannelMean);
104 return mecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).;
105 } catch (MelderErrorcxx . . $ MelderError#) {
106 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"SoundFrames could not be created.");
107 }
108 }
109
110 /* End of file SoundFrames.cpp */