46 #include "EST_types.h"
47 #include "EST_Track.h"
48 #include "EST_track_aux.h"
49 #include "EST_TrackMap.h"
50 #include "EST_cutils.h"
51 #include "EST_Token.h"
52 #include "EST_TList.h"
53 #include "EST_string_aux.h"
54 #include "EST_walloc.h"
55 #include "EST_TrackFile.h"
56 #include "EST_FileType.h"
58 EST_read_status EST_TrackFile::load_ssff(
const EST_String filename,
59 EST_Track &tr,
float ishift,
float startt)
63 if (((filename ==
"-") ? ts.
open(cin) : ts.
open(filename)) != 0)
65 cerr <<
"Can't open track file " << filename << endl;
66 return misc_read_error;
69 return load_ssff_ts(ts, tr, ishift, startt);
76 int num_frames, num_channels;
79 float Start_Time, Record_Freq;
86 num_frames = num_channels = 0;
87 Start_Time = Record_Freq = 0;
89 if (ts.
get() !=
"SSFF")
92 if ((ts.
get() !=
"--") ||
93 (ts.
get() !=
"(c)") ||
94 (ts.
get() !=
"SHLRC"))
96 cerr <<
"ssff load track \"" << ts.
filename() <<
"\": bad header"
98 return misc_read_error;
101 while (ts.
peek() !=
"-----------------")
106 else if (c ==
"Start_Time")
108 Start_Time = atof(ts.
get().string());
109 tr.f_set(
"Start_Time",Start_Time);
111 else if (c ==
"Record_Freq")
113 Record_Freq = atof(ts.
get().string());
114 tr.f_set(
"Record_Freq",Record_Freq);
116 else if (c ==
"Machine")
118 if (ts.
get() ==
"SPARC")
120 if (EST_NATIVE_BO != bo_big)
123 else if (EST_NATIVE_BO == bo_big)
126 else if (c ==
"Column")
131 cname =
EST_String(
"Channel_")+itoString(num_channels);
132 channels.
set(cname+
".name",name);
133 channels.
set(cname+
".type",type);
134 channels.
set(cname+
".size",atoi(size));
137 else if ((c ==
"window_type") ||
138 (c ==
"window_duration") ||
139 (c ==
"lpc_order") ||
142 (c ==
"preemphasis") ||
143 (c ==
"frame_duration"))
147 tr.f_set(c,atoi(ts.
get().string()));
148 else if (type ==
"DOUBLE")
149 tr.f_set(c,(
float)atof(ts.
get().string()));
151 tr.f_set(c,ts.
get().string());
155 cerr <<
"ssff load track \"" << ts.
filename() <<
156 "\": bad header unexpected eof" << endl;
157 return misc_read_error;
171 fseek(fp,0,SEEK_END);
173 fseek(fp,pos,SEEK_SET);
174 num_frames = (end - pos)/(num_channels*
sizeof(
double));
177 tr.
resize(num_frames,num_channels);
179 tr.set_equal_space(
true);
181 for (i=0; i<num_channels; i++)
183 itoString(i)+
".name"),i);
185 for (i=0; i < num_frames; i++)
186 for (j=0; j<num_channels; j++)
188 type = channels.
S(
EST_String(
"Channel_")+ itoString(j)+
".type");
189 if (type ==
"DOUBLE")
191 ts.
fread(dbuff,
sizeof(
double),1);
193 swap_bytes_double(dbuff,1);
196 else if (type ==
"SHORT")
198 ts.
fread(sbuff,
sizeof(
short),1);
200 swap_bytes_short(sbuff,1);
201 tr(i,j) = (float)(*sbuff);
205 cerr <<
"ssff load track \"" << ts.
filename() <<
206 "\": unknown channel type value \"" << type <<
"\"" << endl;
207 return misc_read_error;
221 else if ((fd = fopen(filename,
"wb")) == NULL)
224 r = save_ssff_ts(fd,tr);
232 EST_write_status EST_TrackFile::save_ssff_ts(FILE *fp,
EST_Track tr)
235 int need_prob_voice = 0;
239 cerr <<
"ssf save track: can't save variable spaced track as SSFF"
244 fprintf(fp,
"SSFF -- (c) SHLRC\n");
245 if (EST_NATIVE_BO == bo_big)
246 fprintf(fp,
"Machine SPARC\n");
248 fprintf(fp,
"Machine IBM-PC\n");
249 if (tr.f_present(
"Start_Time"))
250 fprintf(fp,
"Start_Time %g\n",(
double)tr.f_F(
"Start_Time"));
252 fprintf(fp,
"Start_Time 0.000000\n");
254 if (tr.f_present(
"Record_Freq"))
255 fprintf(fp,
"Record_Freq %g\n",(
double)tr.f_F(
"Record_Freq"));
257 fprintf(fp,
"Record_Freq %d\n", 100);
259 fprintf(fp,
"Record_Freq %g\n", 1/(tr.
t(1)-tr.
t(0)));
262 fprintf(fp,
"Column %s DOUBLE 1\n",(
const char *)(tr.channel_name(i)));
265 (tr.channel_name(0) ==
"F0"))
268 fprintf(fp,
"Column prob_voice DOUBLE 1\n");
272 for (p.
begin(tr); p; ++p)
274 if ((p->k ==
"Start_Time") ||
275 (p->k ==
"Record_Freq"))
278 fprintf(fp,
"%s DOUBLE %s\n", (
const char *)p->k,
279 (
const char *) p->v.String());
281 fprintf(fp,
"-----------------\n");
289 fwrite(&dd,
sizeof(
double),1,fp);
297 fwrite(&prob_voice,
sizeof(
double),1,fp);