| 1 |
/* IntensityTier.cpp |
| 2 |
* |
| 3 |
* Copyright (C) 1992-2005,2007,2008,2010-2012,2015-2018,2020-2022,2024 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 |
#include "IntensityTier.h" |
| 20 |
|
| 21 |
Thing_implement (IntensityTier, RealTier, 0); |
| 22 |
|
| 23 |
autoIntensityTier IntensityTier_create (double tmin, double tmax) { |
| 24 |
try { |
| 25 |
autoIntensityTier me = Thing_new (IntensityTier); |
| 26 |
RealTier_init (me.get(), tmin, tmax); |
| 27 |
return me; |
| 28 |
} catch (MelderError) { |
| 29 |
Melder_throw (U"IntensityTier not created."); |
| 30 |
} |
| 31 |
} |
| 32 |
|
| 33 |
void IntensityTier_draw (IntensityTier me, Graphics g, double tmin, double tmax, |
| 34 |
double ymin, double ymax, conststring32 method, bool garnish) |
| 35 |
{ |
| 36 |
RealTier_draw (me, g, tmin, tmax, ymin, ymax, garnish, method, U"Intensity (dB)"); |
| 37 |
} |
| 38 |
|
| 39 |
autoIntensityTier PointProcess_upto_IntensityTier (PointProcess me, double intensity) { |
| 40 |
try { |
| 41 |
autoIntensityTier thee = PointProcess_upto_RealTier (me, intensity, classIntensityTier).static_cast_move <structIntensityTier>(); |
| 42 |
return thee; |
| 43 |
} catch (MelderError) { |
| 44 |
Melder_throw (me, U": not converted to IntensityTier."); |
| 45 |
} |
| 46 |
} |
| 47 |
|
| 48 |
autoIntensityTier Intensity_downto_IntensityTier (Intensity me) { |
| 49 |
try { |
| 50 |
autoIntensityTier thee = Vector_to_RealTier (me, 1, classIntensityTier).static_cast_move <structIntensityTier>(); |
| 51 |
return thee; |
| 52 |
} catch (MelderError) { |
| 53 |
Melder_throw (me, U": not converted to IntensityTier."); |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
autoIntensityTier Intensity_to_IntensityTier_peaks (Intensity me) { |
| 58 |
try { |
| 59 |
autoIntensityTier thee = Vector_to_RealTier_peaks (me, 1, classIntensityTier).static_cast_move <structIntensityTier>(); |
| 60 |
return thee; |
| 61 |
} catch (MelderError) { |
| 62 |
Melder_throw (me, U": peaks not converted to IntensityTier."); |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
autoIntensityTier Intensity_to_IntensityTier_valleys (Intensity me) { |
| 67 |
try { |
| 68 |
autoIntensityTier thee = Vector_to_RealTier_valleys (me, 1, classIntensityTier).static_cast_move <structIntensityTier>(); |
| 69 |
return thee; |
| 70 |
} catch (MelderError) { |
| 71 |
Melder_throw (me, U": valleys not converted to IntensityTier."); |
| 72 |
} |
| 73 |
} |
| 74 |
|
| 75 |
autoIntensityTier Intensity_PointProcess_to_IntensityTier (Intensity me, PointProcess pp) { |
| 76 |
try { |
| 77 |
autoIntensityTier temp = Intensity_downto_IntensityTier (me); |
| 78 |
autoIntensityTier thee = IntensityTier_PointProcess_to_IntensityTier (temp.get(), pp); |
| 79 |
return thee; |
| 80 |
} catch (MelderError) { |
| 81 |
Melder_throw (me, U" & ", pp, U": not converted to IntensityTier."); |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
autoIntensityTier IntensityTier_PointProcess_to_IntensityTier (IntensityTier me, PointProcess pp) { |
| 86 |
try { |
| 87 |
if (my points.size == 0) |
| 88 |
Melder_throw (U"No intensity points."); |
| 89 |
autoIntensityTier thee = IntensityTier_create (pp -> xmin, pp -> xmax); |
| 90 |
RealTier_PointProcess_into_RealTier (me, pp, thee.get()); |
| 91 |
return thee; |
| 92 |
} catch (MelderError) { |
| 93 |
Melder_throw (me, U" & ", pp, U": not converted to IntensityTier."); |
| 94 |
} |
| 95 |
} |
| 96 |
|
| 97 |
autoTableOfReal IntensityTier_downto_TableOfReal (IntensityTier me) { |
| 98 |
return RealTier_downto_TableOfReal (me, U"Time (s)", U"Intensity (dB)"); |
| 99 |
} |
| 100 |
|
| 101 |
void Sound_IntensityTier_multiply_inplace (Sound me, IntensityTier intensity) { |
| 102 |
if (intensity -> points.size == 0) |
| 103 |
return; |
| 104 |
for (integer isamp = 1; isamp <= my nx; isamp ++) { |
| 105 |
const double t = my x1 + (isamp - 1) * my dx; |
| 106 |
const double factor = pow (10.0, RealTier_getValueAtTime (intensity, t) / 20.0); |
| 107 |
for (integer channel = 1; channel <= my ny; channel ++) |
| 108 |
my z [channel] [isamp] *= factor; |
| 109 |
} |
| 110 |
} |
| 111 |
|
| 112 |
autoSound Sound_IntensityTier_multiply (Sound me, IntensityTier intensity, bool scaleTo09) { |
| 113 |
try { |
| 114 |
autoSound thee = Data_copy (me); |
| 115 |
Sound_IntensityTier_multiply_inplace (thee.get(), intensity); |
| 116 |
if (scaleTo09) |
| 117 |
Vector_scale (thee.get(), 0.9); |
| 118 |
return thee; |
| 119 |
} catch (MelderError) { |
| 120 |
Melder_throw (me, U": not multiplied with ", intensity, U"."); |
| 121 |
} |
| 122 |
} |
| 123 |
|
| 124 |
autoIntensityTier RealTier_to_IntensityTier (RealTier me) { |
| 125 |
try { |
| 126 |
autoIntensityTier thee = Thing_new (IntensityTier); |
| 127 |
my structRealTier :: v1_copy (thee.get()); |
| 128 |
return thee; |
| 129 |
} catch (MelderError) { |
| 130 |
Melder_throw (me, U": not converted to IntensityTier."); |
| 131 |
} |
| 132 |
} |
| 133 |
|
| 134 |
/* End of file IntensityTier.cpp */ |