| 1 | /* Sound_PointProcess.cpp |
| 2 | * |
| 3 | * Copyright (C) 2010-2011,2015,2017 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 2010/12/09 created |
| 21 | * pb 2011/06/08 C++ |
| 22 | */ |
| 23 | |
| 24 | #include "Sound_PointProcess.h"cxx . . $ `<file>/fon/Sound_PointProcess.h`/ |
| 25 | |
| 26 | autoSoundcxx . . $ autoSound# Sound_PointProcess_to_SoundEnsemble_correlatecxx . . $ Sound_PointProcess_to_SoundEnsemble_correlate(51c9260185a6cd72). (Soundcxx . . $ Sound# me, PointProcesscxx . . $ PointProcess# thee, double fromLag, double toLag) { |
| 27 | try { |
| 28 | if (mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny. > 1) |
| 29 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Sound should be mono."); |
| 30 | integercxx . . $ integer# numberOfPoints = thycxx . . $ `melder/melder.h:45:9`! ntcxx . . $ structPointProcess#nt.; |
| 31 | double hisDuration = toLag - fromLag; |
| 32 | integercxx . . $ integer# numberOfSamples = Melder_ifloorcxx . . $ `melder/melder_ftoi.h:33:9`! (hisDuration / mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx.) + 1; |
| 33 | if (numberOfSamples < 1) |
| 34 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Time window too short."); |
| 35 | double midTime = 0.5 * (fromLag + toLag); |
| 36 | double hisPhysicalDuration = numberOfSamples * mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx.; |
| 37 | double firstTime = midTime - 0.5 * hisPhysicalDuration + 0.5 * mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx.; // distribute the samples evenly over the time domain |
| 38 | autoSoundcxx . . $ autoSound# him = Sound_createcxx . . $ Sound_create(39ab106d6b9a0135). (numberOfPoints, fromLag, toLag, numberOfSamples, mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx., firstTime); |
| 39 | for (integercxx . . $ integer# ipoint = 1; ipoint <= numberOfPoints; ipoint ++) { |
| 40 | double myTimeOfPoint = thycxx . . $ `melder/melder.h:45:9`! tcxx . . $ structPointProcess#t. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).ipoint]; |
| 41 | double hisTimeOfPoint = 0.0; |
| 42 | double mySample = 1.0 + (myTimeOfPoint - mycxx . . $ `melder/melder.h:44:9`! x1cxx . . $ structSampled#x1.) / mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx.; |
| 43 | double hisSample = 1.0 + (hisTimeOfPoint - hiscxx . . $ `melder/melder.h:47:9`! x1cxx . . $ structSampled#x1.) / mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx.; |
| 44 | integercxx . . $ integer# sampleDifference = Melder_iround_tieDowncxx . . $ Melder_iround_tieDown(a6e4a4c8b00c35a3). (mySample - hisSample); |
| 45 | for (integercxx . . $ integer# isample = 1; isample <= numberOfSamples; isample ++) { |
| 46 | integercxx . . $ integer# jsample = isample + sampleDifference; |
| 47 | hiscxx . . $ `melder/melder.h:47:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).ipoint] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).isample] = jsample < 1 || jsample > mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx. ? 0.0 : mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).jsample]; |
| 48 | } |
| 49 | } |
| 50 | return himcxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 51 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 52 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U" & ", thee, U": Sound ensemble not created."); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | /* End of file Sound_PointProcess.cpp */ |