1 /*************************************************************************/
2 /*                                                                       */
3 /*                Centre for Speech Technology Research                  */
4 /*                     University of Edinburgh, UK                       */
5 /*                       Copyright (c) 1996,1997                         */
6 /*                        All Rights Reserved.                           */
7 /*                                                                       */
8 /*  Permission is hereby granted, free of charge, to use and distribute  */
9 /*  this software and its documentation without restriction, including   */
10 /*  without limitation the rights to use, copy, modify, merge, publish,  */
11 /*  distribute, sublicense, and/or sell copies of this work, and to      */
12 /*  permit persons to whom this work is furnished to do so, subject to   */
13 /*  the following conditions:                                            */
14 /*   1. The code must retain the above copyright notice, this list of    */
15 /*      conditions and the following disclaimer.                         */
16 /*   2. Any modifications must be clearly marked as such.                */
17 /*   3. Original authors' names are not deleted.                         */
18 /*   4. The authors' names are not used to endorse or promote products   */
19 /*      derived from this software without specific prior written        */
20 /*      permission.                                                      */
21 /*                                                                       */
22 /*  THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK        */
23 /*  DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING      */
24 /*  ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT   */
25 /*  SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE     */
26 /*  FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES    */
27 /*  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN   */
28 /*  AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,          */
29 /*  ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF       */
30 /*  THIS SOFTWARE.                                                       */
31 /*                                                                       */
32 /*************************************************************************/
33 /*             Author :  Alistair Conkie                                 */
34 /*             Date   :  1996                                            */
35 /*  This version was gifted by Alistair for this new                     */
36 /*  copyright, the original retains their original copyright             */
37 /*                                                                       */
38 /*************************************************************************/
39 #include <stdio.h>
40 #include "t2s.h"
41 
42 static int min(int a, int b);
43 static float local_fmax(float a, float b);
44 
durations(SPN * ps,ACOUSTIC * as)45 void durations(SPN *ps, ACOUSTIC *as)
46 {
47 	int durdist;
48 	int interdist;
49 	float multiplier_i;
50 	float proportion;
51 	int i;
52 	int j;
53 
54 	for(i=0;i<ps->p_sz;i++)
55 		ps->scale[i] = (float)ps->duration[i] /
56 		(float)((ps->pb[i+1]-ps->pb[i])*FR_SZ);
57 
58 	ps->cum_dur[0] = 0;  /* do cumulative at same time  */
59 	for(i=0,j=0;i<as->f_sz;i++) {
60 		if(i == ps->pb[j]) {
61 			if(j != 0) {
62 				ps->cum_dur[j] = ps->duration[j-1] + ps->cum_dur[j-1];
63 			}
64 			as->duration[i] = FR_SZ;
65 			ps->duration[j] = FR_SZ; /* saves adding later  */
66 			j++;
67 		} else {
68 			durdist = min(i-ps->pb[j-1],ps->pb[j]-i);
69 			interdist = ps->pb[j] - ps->pb[j-1];
70 			proportion = (float)durdist/(float)interdist;
71 			multiplier_i = local_fmax(0.01,4.0*proportion*(ps->scale[j-1]-1.0)+1.0);
72 			as->duration[i] = FR_SZ*multiplier_i;
73 			ps->duration[j-1] += as->duration[i];
74 		}
75 	}
76 }
77 
min(int a,int b)78 static int min(int a, int b)
79 {
80 	return((a<b)?a:b);
81 }
82 
local_fmax(float a,float b)83 static float local_fmax(float a, float b)
84 {
85 	return((a>b)?a:b);
86 }
87 
88