| 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" |
| 25 |
|
| 26 |
autoSound Sound_PointProcess_to_SoundEnsemble_correlate (Sound me, PointProcess thee, double fromLag, double toLag) { |
| 27 |
try { |
| 28 |
if (my ny > 1) |
| 29 |
Melder_throw (U"Sound should be mono."); |
| 30 |
integer numberOfPoints = thy nt; |
| 31 |
double hisDuration = toLag - fromLag; |
| 32 |
integer numberOfSamples = Melder_ifloor (hisDuration / my dx) + 1; |
| 33 |
if (numberOfSamples < 1) |
| 34 |
Melder_throw (U"Time window too short."); |
| 35 |
double midTime = 0.5 * (fromLag + toLag); |
| 36 |
double hisPhysicalDuration = numberOfSamples * my dx; |
| 37 |
double firstTime = midTime - 0.5 * hisPhysicalDuration + 0.5 * my dx; // distribute the samples evenly over the time domain |
| 38 |
autoSound him = Sound_create (numberOfPoints, fromLag, toLag, numberOfSamples, my dx, firstTime); |
| 39 |
for (integer ipoint = 1; ipoint <= numberOfPoints; ipoint ++) { |
| 40 |
double myTimeOfPoint = thy t [ipoint]; |
| 41 |
double hisTimeOfPoint = 0.0; |
| 42 |
double mySample = 1.0 + (myTimeOfPoint - my x1) / my dx; |
| 43 |
double hisSample = 1.0 + (hisTimeOfPoint - his x1) / my dx; |
| 44 |
integer sampleDifference = Melder_iround_tieDown (mySample - hisSample); |
| 45 |
for (integer isample = 1; isample <= numberOfSamples; isample ++) { |
| 46 |
integer jsample = isample + sampleDifference; |
| 47 |
his z [ipoint] [isample] = jsample < 1 || jsample > my nx ? 0.0 : my z [1] [jsample]; |
| 48 |
} |
| 49 |
} |
| 50 |
return him; |
| 51 |
} catch (MelderError) { |
| 52 |
Melder_throw (me, U" & ", thee, U": Sound ensemble not created."); |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
/* End of file Sound_PointProcess.cpp */ |