1 /*********************************************************************/ 2 /* */ 3 /* Nagoya Institute of Technology, Aichi, Japan, */ 4 /* Nara Institute of Science and Technology, Nara, Japan */ 5 /* and */ 6 /* Carnegie Mellon University, Pittsburgh, PA */ 7 /* Copyright (c) 2003-2004 */ 8 /* All Rights Reserved. */ 9 /* */ 10 /* Permission is hereby granted, free of charge, to use and */ 11 /* distribute this software and its documentation without */ 12 /* restriction, including without limitation the rights to use, */ 13 /* copy, modify, merge, publish, distribute, sublicense, and/or */ 14 /* sell copies of this work, and to permit persons to whom this */ 15 /* work is furnished to do so, subject to the following conditions: */ 16 /* */ 17 /* 1. The code must retain the above copyright notice, this list */ 18 /* of conditions and the following disclaimer. */ 19 /* 2. Any modifications must be clearly marked as such. */ 20 /* 3. Original authors' names are not deleted. */ 21 /* */ 22 /* NAGOYA INSTITUTE OF TECHNOLOGY, NARA INSTITUTE OF SCIENCE AND */ 23 /* TECHNOLOGY, CARNEGIE MELLON UNIVERSITY, AND THE CONTRIBUTORS TO */ 24 /* THIS WORK DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, */ 25 /* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, */ 26 /* IN NO EVENT SHALL NAGOYA INSTITUTE OF TECHNOLOGY, NARA */ 27 /* INSTITUTE OF SCIENCE AND TECHNOLOGY, CARNEGIE MELLON UNIVERSITY, */ 28 /* NOR THE CONTRIBUTORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR */ 29 /* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM */ 30 /* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, */ 31 /* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN */ 32 /* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ 33 /* */ 34 /*********************************************************************/ 35 /* */ 36 /* Author : Tomoki Toda (tomoki@ics.nitech.ac.jp) */ 37 /* Date : June 2004 */ 38 /* */ 39 /* Modified by Alan W Black (awb@cs.cmu.edu) Jan 2006 */ 40 /* taken from festvox/src/vc/ back into Festival */ 41 /*-------------------------------------------------------------------*/ 42 /* */ 43 /* Subroutine for Speech Synthesis */ 44 /* */ 45 /*-------------------------------------------------------------------*/ 46 47 #ifndef __MLSA_RESYNTHESIS_H 48 #define __MLSA_RESYNTHESIS_H 49 50 #define ALPHA 0.42 51 52 typedef struct DVECTOR_STRUCT { 53 long length; 54 double *data; 55 double *imag; 56 } *DVECTOR; 57 58 typedef struct DMATRIX_STRUCT { 59 long row; 60 long col; 61 double **data; 62 double **imag; 63 } *DMATRIX; 64 65 #define XBOOL int 66 #define XTRUE 1 67 #define XFALSE 0 68 69 #define NODATA NULL 70 71 #define FABS(x) ((x) >= 0.0 ? (x) : -(x)) 72 #define MAX(a, b) ((a) > (b) ? (a) : (b)) 73 74 static DVECTOR xdvalloc(long length); 75 static DVECTOR xdvcut(DVECTOR x, long offset, long length); 76 static void xdvfree(DVECTOR vector); 77 static double dvmax(DVECTOR x, long *index); 78 static double dvmin(DVECTOR x, long *index); 79 static DMATRIX xdmalloc(long row, long col); 80 static void xdmfree(DMATRIX matrix); 81 82 DVECTOR synthesis_body(DMATRIX mcep, DVECTOR f0v, DVECTOR dpow, 83 double fs, double framem); 84 static void waveampcheck(DVECTOR wav, XBOOL msg_flag); 85 86 #define RANDMAX 32767 87 #define B0 0x00000001 88 #define B28 0x10000000 89 #define B31 0x80000000 90 #define B31_ 0x7fffffff 91 #define Z 0x00000000 92 93 typedef enum {MFALSE, MTRUE} Boolean; 94 95 typedef struct _VocoderSetup { 96 97 int fprd; 98 int iprd; 99 int seed; 100 int pd; 101 unsigned long next; 102 Boolean gauss; 103 double p1; 104 double pc; 105 double pj; 106 double pade[21]; 107 double *ppade; 108 double *c, *cc, *cinc, *d1; 109 double rate; 110 111 int sw; 112 double r1, r2, s; 113 114 int x; 115 116 /* for postfiltering */ 117 int size; 118 double *d; 119 double *g; 120 double *mc; 121 double *cep; 122 double *ir; 123 int o; 124 int irleng; 125 126 } VocoderSetup; 127 128 static void init_vocoder(double fs, int framel, int m, VocoderSetup *vs); 129 static void vocoder(double p, double *mc, int m, double a, double beta, 130 VocoderSetup *vs, double *wav, long *pos); 131 static void vocoder(double p, double *mc, double dpow, int m, double a, 132 double beta, VocoderSetup *vs, double *wav, long *pos); 133 static double mlsadf(double x, double *b, int m, double a, int pd, double *d, 134 VocoderSetup *vs); 135 static double mlsadf1(double x, double *b, int m, double a, int pd, double *d, 136 VocoderSetup *vs); 137 static double mlsadf2(double x, double *b, int m, double a, int pd, double *d, 138 VocoderSetup *vs); 139 static double mlsafir (double x, double *b, int m, double a, double *d); 140 static double nrandom (VocoderSetup *vs); 141 static double rnd (unsigned long *next); 142 static unsigned long srnd (unsigned long seed); 143 static int mseq (VocoderSetup *vs); 144 static void mc2b (double *mc, double *b, int m, double a); 145 static double b2en (double *b, int m, double a, VocoderSetup *vs); 146 static void b2mc (double *b, double *mc, int m, double a); 147 static void freqt (double *c1, int m1, double *c2, int m2, double a, 148 VocoderSetup *vs); 149 static void c2ir (double *c, int nc, double *h, int leng); 150 151 152 #if 0 153 static DVECTOR get_dpowvec(DMATRIX rmcep, DMATRIX cmcep); 154 static double get_dpow(double *rmcep, double *cmcep, int m, double a, 155 VocoderSetup *vs); 156 #endif 157 static void free_vocoder(VocoderSetup *vs); 158 159 #endif /* __RESYNTHESIS_SUB_H */ 160