| 1 |
/* --------------------------------------------------------------- */ |
| 2 |
/* The HMM-Based Speech Synthesis System (HTS): version 1.1b */ |
| 3 |
/* HTS Working Group */ |
| 4 |
/* */ |
| 5 |
/* Department of Computer Science */ |
| 6 |
/* Nagoya Institute of Technology */ |
| 7 |
/* and */ |
| 8 |
/* Interdisciplinary Graduate School of Science and Engineering */ |
| 9 |
/* Tokyo Institute of Technology */ |
| 10 |
/* Copyright (c) 2001-2003 */ |
| 11 |
/* All Rights Reserved. */ |
| 12 |
/* */ |
| 13 |
/* Permission is hereby granted, free of charge, to use and */ |
| 14 |
/* distribute this software and its documentation without */ |
| 15 |
/* restriction, including without limitation the rights to use, */ |
| 16 |
/* copy, modify, merge, publish, distribute, sublicense, and/or */ |
| 17 |
/* sell copies of this work, and to permit persons to whom this */ |
| 18 |
/* work is furnished to do so, subject to the following conditions: */ |
| 19 |
/* */ |
| 20 |
/* 1. The code must retain the above copyright notice, this list */ |
| 21 |
/* of conditions and the following disclaimer. */ |
| 22 |
/* */ |
| 23 |
/* 2. Any modifications must be clearly marked as such. */ |
| 24 |
/* */ |
| 25 |
/* NAGOYA INSTITUTE OF TECHNOLOGY, TOKYO INSITITUTE OF TECHNOLOGY, */ |
| 26 |
/* HTS WORKING GROUP, AND THE CONTRIBUTORS TO THIS WORK DISCLAIM */ |
| 27 |
/* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL */ |
| 28 |
/* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */ |
| 29 |
/* SHALL NAGOYA INSTITUTE OF TECHNOLOGY, TOKYO INSITITUTE OF */ |
| 30 |
/* TECHNOLOGY, HTS WORKING GROUP, NOR THE CONTRIBUTORS BE LIABLE */ |
| 31 |
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY */ |
| 32 |
/* DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, */ |
| 33 |
/* WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTUOUS */ |
| 34 |
/* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR */ |
| 35 |
/* PERFORMANCE OF THIS SOFTWARE. */ |
| 36 |
/* */ |
| 37 |
/* --------------------------------------------------------------- */ |
| 38 |
/* This is Zen's MLSA filter as ported by Toda to festvox vc */ |
| 39 |
/* and back ported into hts/festival so we can do MLSA filtering */ |
| 40 |
/* If I took more time I could probably make this use the same as */ |
| 41 |
/* as the other code in this directory -- [email protected] 03JAN06 */ |
| 42 |
/* --------------------------------------------------------------- */ |
| 43 |
/* and then ported into Flite (November 2007 [email protected]) */ |
| 44 |
|
| 45 |
/*********************************************************************/ |
| 46 |
/* */ |
| 47 |
/* vector (etc) code common to mlpg and mlsa */ |
| 48 |
/*-------------------------------------------------------------------*/ |
| 49 |
|
| 50 |
#include "cst_alloc.h" |
| 51 |
#include "cst_string.h" |
| 52 |
#include "cst_math.h" |
| 53 |
#include "cst_vc.h" |
| 54 |
|
| 55 |
/* from vector.cc */ |
| 56 |
|
| 57 |
LVECTOR xlvalloc(long length) |
| 58 |
{ |
| 59 |
LVECTOR x; |
| 60 |
|
| 61 |
length = MAX(length, 0); |
| 62 |
x = cst_alloc(struct LVECTOR_STRUCT,1); |
| 63 |
x->data = cst_alloc(long,MAX(length, 1)); |
| 64 |
x->imag = NULL; |
| 65 |
x->length = length; |
| 66 |
|
| 67 |
return x; |
| 68 |
} |
| 69 |
|
| 70 |
void xlvfree(LVECTOR x) |
| 71 |
{ |
| 72 |
if (x != NULL) { |
| 73 |
if (x->data != NULL) { |
| 74 |
cst_free(x->data); |
| 75 |
} |
| 76 |
if (x->imag != NULL) { |
| 77 |
cst_free(x->imag); |
| 78 |
} |
| 79 |
cst_free(x); |
| 80 |
} |
| 81 |
|
| 82 |
return; |
| 83 |
} |
| 84 |
|
| 85 |
DVECTOR xdvalloc(long length) |
| 86 |
{ |
| 87 |
DVECTOR x; |
| 88 |
|
| 89 |
length = MAX(length, 0); |
| 90 |
x = cst_alloc(struct DVECTOR_STRUCT,1); |
| 91 |
x->data = cst_alloc(double,MAX(length, 1)); |
| 92 |
x->imag = NULL; |
| 93 |
x->length = length; |
| 94 |
|
| 95 |
return x; |
| 96 |
} |
| 97 |
|
| 98 |
void xdvfree(DVECTOR x) |
| 99 |
{ |
| 100 |
if (x != NULL) { |
| 101 |
if (x->data != NULL) { |
| 102 |
cst_free(x->data); |
| 103 |
} |
| 104 |
if (x->imag != NULL) { |
| 105 |
cst_free(x->imag); |
| 106 |
} |
| 107 |
cst_free(x); |
| 108 |
} |
| 109 |
|
| 110 |
return; |
| 111 |
} |
| 112 |
|
| 113 |
void dvialloc(DVECTOR x) |
| 114 |
{ |
| 115 |
if (x->imag != NULL) { |
| 116 |
cst_free(x->imag); |
| 117 |
} |
| 118 |
x->imag = cst_alloc(double,x->length); |
| 119 |
|
| 120 |
return; |
| 121 |
} |
| 122 |
|
| 123 |
DVECTOR xdvcut(DVECTOR x, long offset, long length) |
| 124 |
{ |
| 125 |
long k; |
| 126 |
long pos; |
| 127 |
DVECTOR y; |
| 128 |
|
| 129 |
y = xdvalloc(length); |
| 130 |
if (x->imag != NULL) { |
| 131 |
dvialloc(y); |
| 132 |
} |
| 133 |
|
| 134 |
for (k = 0; k < y->length; k++) { |
| 135 |
pos = k + offset; |
| 136 |
if (pos >= 0 && pos < x->length) { |
| 137 |
y->data[k] = x->data[pos]; |
| 138 |
if (y->imag != NULL) { |
| 139 |
y->imag[k] = x->imag[pos]; |
| 140 |
} |
| 141 |
} else { |
| 142 |
y->data[k] = 0.0; |
| 143 |
if (y->imag != NULL) { |
| 144 |
y->imag[k] = 0.0; |
| 145 |
} |
| 146 |
} |
| 147 |
} |
| 148 |
|
| 149 |
return y; |
| 150 |
} |
| 151 |
|
| 152 |
DMATRIX xdmalloc(long row, long col) |
| 153 |
{ |
| 154 |
DMATRIX matrix; |
| 155 |
int i; |
| 156 |
|
| 157 |
matrix = cst_alloc(struct DMATRIX_STRUCT,1); |
| 158 |
matrix->data = cst_alloc(double *,row); |
| 159 |
for (i=0; i<row; i++) |
| 160 |
matrix->data[i] = cst_alloc(double,col); |
| 161 |
matrix->imag = NULL; |
| 162 |
matrix->row = row; |
| 163 |
matrix->col = col; |
| 164 |
|
| 165 |
return matrix; |
| 166 |
} |
| 167 |
|
| 168 |
void xdmfree(DMATRIX matrix) |
| 169 |
{ |
| 170 |
int i; |
| 171 |
|
| 172 |
if (matrix != NULL) { |
| 173 |
if (matrix->data != NULL) { |
| 174 |
for (i=0; i<matrix->row; i++) |
| 175 |
cst_free(matrix->data[i]); |
| 176 |
cst_free(matrix->data); |
| 177 |
} |
| 178 |
if (matrix->imag != NULL) { |
| 179 |
for (i=0; i<matrix->row; i++) |
| 180 |
cst_free(matrix->imag[i]); |
| 181 |
cst_free(matrix->imag); |
| 182 |
} |
| 183 |
cst_free(matrix); |
| 184 |
} |
| 185 |
|
| 186 |
return; |
| 187 |
} |
| 188 |
|
| 189 |
DVECTOR xdvinit(double j, double incr, double n) |
| 190 |
{ |
| 191 |
long k; |
| 192 |
long num; |
| 193 |
DVECTOR x; |
| 194 |
|
| 195 |
if ((incr > 0.0 && j > n) || (incr < 0.0 && j < n)) { |
| 196 |
x = xdvnull(); |
| 197 |
return x; |
| 198 |
} |
| 199 |
if (incr == 0.0) { |
| 200 |
num = (long)n; |
| 201 |
if (num <= 0) { |
| 202 |
x = xdvnull(); |
| 203 |
return x; |
| 204 |
} |
| 205 |
} else { |
| 206 |
num = LABS((long)((n - j) / incr)) + 1; |
| 207 |
} |
| 208 |
|
| 209 |
/* memory allocate */ |
| 210 |
x = xdvalloc(num); |
| 211 |
|
| 212 |
/* initailize data */ |
| 213 |
for (k = 0; k < x->length; k++) { |
| 214 |
x->data[k] = j + (k * incr); |
| 215 |
} |
| 216 |
|
| 217 |
return x; |
| 218 |
} |
| 219 |
|
| 220 |
/* from voperate.cc */ |
| 221 |
double dvmax(DVECTOR x, long *index) |
| 222 |
{ |
| 223 |
long k; |
| 224 |
long ind; |
| 225 |
double max; |
| 226 |
|
| 227 |
ind = 0; |
| 228 |
max = x->data[ind]; |
| 229 |
for (k = 1; k < x->length; k++) { |
| 230 |
if (max < x->data[k]) { |
| 231 |
ind = k; |
| 232 |
max = x->data[k]; |
| 233 |
} |
| 234 |
} |
| 235 |
|
| 236 |
if (index != NULL) { |
| 237 |
*index = ind; |
| 238 |
} |
| 239 |
|
| 240 |
return max; |
| 241 |
} |
| 242 |
|
| 243 |
double dvmin(DVECTOR x, long *index) |
| 244 |
{ |
| 245 |
long k; |
| 246 |
long ind; |
| 247 |
double min; |
| 248 |
|
| 249 |
ind = 0; |
| 250 |
min = x->data[ind]; |
| 251 |
for (k = 1; k < x->length; k++) { |
| 252 |
if (min > x->data[k]) { |
| 253 |
ind = k; |
| 254 |
min = x->data[k]; |
| 255 |
} |
| 256 |
} |
| 257 |
|
| 258 |
if (index != NULL) { |
| 259 |
*index = ind; |
| 260 |
} |
| 261 |
|
| 262 |
return min; |
| 263 |
} |
| 264 |
|
| 265 |
double dvsum(DVECTOR x) |
| 266 |
{ |
| 267 |
long k; |
| 268 |
double sum; |
| 269 |
|
| 270 |
for (k = 0, sum = 0.0; k < x->length; k++) { |
| 271 |
sum += x->data[k]; |
| 272 |
} |
| 273 |
|
| 274 |
return sum; |
| 275 |
} |