Debian Codegraph @

src/wavesynth/cst_sts.c

raw
1 /*************************************************************************/
2 /* */
3 /* Language Technologies Institute */
4 /* Carnegie Mellon University */
5 /* Copyright (c) 2008 */
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 /* CARNEGIE MELLON UNIVERSITY 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 CARNEGIE MELLON UNIVERSITY 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: Alan W Black ([email protected]) */
34 /* Date: May 2008 */
35 /*************************************************************************/
36 /* */
37 /* Removed the Cepstral copyrighted version (which was also free) and */
38 /* reverted to the flite-1.0-beta version, the other code had support */
39 /* for things not in flite and the original is sufficient */
40 /* */
41 /*************************************************************************/
42
43 #include "cst_math.h"
44 #include "cst_hrg.h"
45 #include "cst_wave.h"
46 #include "cst_sigpr.h"
47 #include "cst_sts.h"
48
49 CST_VAL_REGISTER_TYPE_NODEL(sts_list,cst_sts_list)
50
51 cst_sts_list *new_sts_list()
52 {
53 cst_sts_list *l = cst_alloc(struct cst_sts_list_struct,1);
54 return l;
55 }
56
57 void delete_sts_list(cst_sts_list *l)
58 {
59 if (l)
60 {
61 /* sub data is always const so can't free it */
62 cst_free(l);
63 }
64 return;
65 }
66
67 int get_unit_size(const cst_sts_list *s,int start, int end)
68 {
69 /* returns size (in samples) of unit */
70 int i,size;
71
72 for (i=start,size=0; i<end; i++)
73 size += get_frame_size(s, i);
74
75 return size;
76 }
77
78 int get_frame_size(const cst_sts_list *sts_list, int frame)
79 {
80 if (sts_list->sts)
81 {
82 return sts_list->sts[frame].size;
83 }
84 else if (sts_list->sts_paged)
85 {
86 return sts_list->sts_paged[frame].res_size;
87 }
88 else if (sts_list->ressizes)
89 return sts_list->ressizes[frame];
90 else
91 {
92 /* This assumes that the voice compiler has generated an extra
93 offset at the end of the array. */
94 return sts_list->resoffs[frame+1] - sts_list->resoffs[frame];
95 }
96 }
97
98 const unsigned short * get_sts_frame(const cst_sts_list *sts_list, int frame)
99 {
100 if (sts_list->sts)
101 return sts_list->sts[frame].frame;
102 else if (sts_list->sts_paged)
103 return &sts_list->sts_paged[frame].frame_page[sts_list->num_channels * sts_list->sts_paged[frame].frame_offset];
104 else
105 return sts_list->frames + (frame * sts_list->num_channels);
106 }
107
108 const unsigned char * get_sts_residual(const cst_sts_list *sts_list, int frame)
109 {
110 if (sts_list->sts)
111 return sts_list->sts[frame].residual;
112 else if (sts_list->sts_paged)
113 return &sts_list->sts_paged[frame].res_page[sts_list->sts_paged[frame].res_offset];
114 else
115 return sts_list->residuals + sts_list->resoffs[frame];
116 }
117
118 const unsigned char *get_sts_residual_fixed(const cst_sts_list *sts_list, int frame)
119 {
120 /* Actually for mceps */
121 if (sts_list->sts)
122 return sts_list->sts[frame].residual;
123 else if (sts_list->sts_paged)
124 return &sts_list->sts_paged[frame].res_page[sts_list->sts_paged[frame].res_offset];
125 else
126 return
127 (const unsigned char *)sts_list->residuals
128 + (frame * sts_list->num_channels);
129
130 }
131