1 /*************************************************************************/
2 /*                                                                       */
3 /*                  Language Technologies Institute                      */
4 /*                     Carnegie Mellon University                        */
5 /*                        Copyright (c) 2017                             */
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 (awb@cs.cmu.edu)                    */
34 /*               Date:  June 2017                                        */
35 /*************************************************************************/
36 /*                                                                       */
37 /*  Some clustergen model manipulation code                              */
38 /*************************************************************************/
39 #include <stdio.h>
40 #include "flite.h"
41 #include "cst_track.h"
42 #include "cst_ss.h"
43 #include "cst_tokenstream.h"
44 #include "cst_args.h"
45 #include "cst_math.h"
46 
main(int argc,char ** argv)47 int main(int argc, char **argv)
48 {
49     cst_track *bt, *nd, *ot;
50     cst_val *files;
51     cst_features *args;
52     cst_ss ***sss;
53     int i, j, f;
54     const char *btf, *ndf, *otf;
55 
56     args = new_features();
57     files =
58         cst_args(argv,argc,
59                  "usage: tris1 -base_track BT -new_data ND -out_track OT\n"
60                  "Build a new param file from data\n"
61                  "-base_track <string> original params file\n"
62                  "-new_data <string> new data for params\n"
63                  "-out_track <string> new params output file\n",
64                  args);
65 
66     btf = flite_get_param_string(args,"-base_track","bt.track");
67     ndf = flite_get_param_string(args,"-new_data","nd.track");
68     otf = flite_get_param_string(args,"-out_track","new.track");
69 
70     bt = new_track();
71     if (cst_track_load_est(bt,btf) != CST_OK_FORMAT)
72     {
73         fprintf(stderr,
74                 "tris1: can't read file or wrong format \"%s\"\n",
75                 btf);
76         return -1;
77     }
78     nd = new_track();
79     if (cst_track_load_est(nd,ndf) != CST_OK_FORMAT)
80     {
81         fprintf(stderr,
82                 "tris1: can't read file or wrong format \"%s\"\n",
83                 ndf);
84         return -1;
85     }
86     ot = cst_track_copy(bt);
87 
88     sss = cst_alloc(cst_ss **,ot->num_frames);
89     for (i=0; i<ot->num_frames; i++)
90     {
91         sss[i] = cst_alloc(cst_ss *,nd->num_channels-1);
92         for (j=0; j<nd->num_channels-1; j++)
93             sss[i][j] = new_ss();
94     }
95 
96     for (i=0; i<nd->num_frames; i++)
97     {
98         f = nd->frames[i][0];
99         /* For each coef in the frame */
100         for (j=1; j<nd->num_channels; j++)
101             ss_cummulate(sss[f][j-1],nd->frames[i][j]);
102     }
103 
104     for (i=0; i<ot->num_frames; i++)
105     {
106         if (sss[i][0]->num_samples > 5)  /* enough to get some variance */
107         {
108             printf("awb_debug: %d %d new data\n",i,(int)sss[i][0]->num_samples);
109             for (j=0; j<nd->num_channels-1; j++)
110             {
111                 ot->frames[i][j*2] = ss_mean(sss[i][j]);
112                 ot->frames[i][(j*2)+1] = ss_stddev(sss[i][j]);
113             }
114         }
115         else if (sss[i][0]->num_samples > 0)  /* enough to get some mean */
116         {
117             printf("awb_debug: %d %d new mean\n",i,(int)sss[i][0]->num_samples);
118             for (j=0; j<nd->num_channels-1; j++)
119             {
120                 ot->frames[i][j*2] = ss_mean(sss[i][j]);
121             }
122         }
123         else
124             printf("awb_debug: %d %d no new data\n",i,(int)sss[i][0]->num_samples);
125         /* else no examples so don't update */
126     }
127 
128     cst_track_save_est_binary(ot,otf);
129 
130     delete_track(ot);
131     delete_track(nd);
132     delete_track(bt);
133 
134     return 0;
135 }
136