| 1 |
/* Excitations.cpp |
| 2 |
* |
| 3 |
* Copyright (C) 1993-2017 David Weenink, 2016 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. 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 "Excitations.h" |
| 20 |
|
| 21 |
Thing_implement (ExcitationList, Ordered, 0); |
| 22 |
|
| 23 |
void ExcitationList_addItem_copy (ExcitationList me, Excitation you) { |
| 24 |
try { |
| 25 |
if (my size > 0) |
| 26 |
Melder_require (your nx == my at [1] -> nx, |
| 27 |
U"Dimension of ", you, U" should agree with the rest."); |
| 28 |
|
| 29 |
autoExcitation newItem = Data_copy (you); |
| 30 |
my addItem_move (newItem.move()); |
| 31 |
} catch (MelderError) { |
| 32 |
Melder_throw (me, U": item not added."); |
| 33 |
} |
| 34 |
} |
| 35 |
|
| 36 |
void ExcitationList_addItems (ExcitationList me, OrderedOf <structExcitation> * list) { |
| 37 |
for (integer item = 1; item <= list->size; item ++) { |
| 38 |
ExcitationList_addItem_copy (me, list->at [item]); |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
autoExcitationList Excitations_to_ExcitationList (OrderedOf <structExcitation> * me) { |
| 43 |
try { |
| 44 |
autoExcitationList you = ExcitationList_create (); |
| 45 |
ExcitationList_addItems (you.get(), me); |
| 46 |
return you; |
| 47 |
} catch (MelderError) { |
| 48 |
Melder_throw (U"No ExcitationList created from Excitation(s)."); |
| 49 |
} |
| 50 |
} |
| 51 |
|
| 52 |
autoPatternList ExcitationList_to_PatternList (ExcitationList me, integer join) { |
| 53 |
try { |
| 54 |
Melder_assert (my size > 0); |
| 55 |
Excitation excitation = my at [1]; |
| 56 |
if (join < 1) |
| 57 |
join = 1; |
| 58 |
|
| 59 |
Melder_require (my size % join == 0, |
| 60 |
U"Number of rows should be a multiple of the join."); |
| 61 |
|
| 62 |
autoPatternList thee = PatternList_create (my size / join, join * excitation -> nx); |
| 63 |
integer r = 0, c = 1; |
| 64 |
for (integer i = 1; i <= my size; i ++) { |
| 65 |
const constVEC z = my at [i] -> z.row (1); |
| 66 |
if ((i - 1) % join == 0) { |
| 67 |
r ++; |
| 68 |
c = 1; |
| 69 |
} |
| 70 |
for (integer j = 1; j <= excitation -> nx; j ++) |
| 71 |
thy z [r] [c ++] = z [j]; |
| 72 |
} |
| 73 |
return thee; |
| 74 |
} catch (MelderError) { |
| 75 |
Melder_throw (me, U": no PatternList created."); |
| 76 |
} |
| 77 |
} |
| 78 |
|
| 79 |
autoTableOfReal ExcitationList_to_TableOfReal (ExcitationList me) { |
| 80 |
try { |
| 81 |
Melder_assert (my size > 0); |
| 82 |
Excitation excitation = my at [1]; |
| 83 |
autoTableOfReal thee = TableOfReal_create (my size, excitation -> nx); |
| 84 |
for (integer i = 1; i <= my size; i ++) { |
| 85 |
const constVEC z = my at [i] -> z.row (1); |
| 86 |
for (integer j = 1; j <= excitation -> nx; j ++) { |
| 87 |
thy data [i] [j] = z [j]; |
| 88 |
} |
| 89 |
} |
| 90 |
return thee; |
| 91 |
} catch (MelderError) { |
| 92 |
Melder_throw (me, U": TableOfReal not created."); |
| 93 |
} |
| 94 |
} |
| 95 |
|
| 96 |
autoExcitation ExcitationList_extractItem (ExcitationList me, integer item) { |
| 97 |
try { |
| 98 |
Melder_require (item > 0 && item <= my size, |
| 99 |
U"Item number should be in the range [1, ", my size, U"]."); |
| 100 |
|
| 101 |
autoExcitation thee = Data_copy (my at [item]); |
| 102 |
Thing_setName (thee.get(), Thing_getName (my at [item])); |
| 103 |
return thee; |
| 104 |
} catch (MelderError) { |
| 105 |
Melder_throw (me, U": Excitation not extracted."); |
| 106 |
} |
| 107 |
} |
| 108 |
|
| 109 |
/* End of file Excitations.cpp */ |