48#include "EST_track_aux.h"
49#include "EST_TrackMap.h"
50#include "EST_cutils.h"
53#include "EST_string_aux.h"
54#include "EST_walloc.h"
55#include "EST_TrackFile.h"
56#include "EST_FileType.h"
58EST_read_status EST_TrackFile::load_ssff(
const EST_String filename,
63 if (((filename ==
"-") ?
ts.open(
cin) :
ts.open(filename)) != 0)
65 cerr <<
"Can't open track file " << filename <<
endl;
66 return misc_read_error;
68 tr.set_name(filename);
76 int num_frames, num_channels;
86 num_frames = num_channels = 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")
111 else if (c ==
"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")
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;
169 fp =
ts.filedescriptor();
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);
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);
237 if (
tr.equal_space() != 1)
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)
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"));
256 else if (
tr.num_frames() < 2)
257 fprintf(fp,
"Record_Freq %d\n", 100);
259 fprintf(fp,
"Record_Freq %g\n", 1/(
tr.t(1)-
tr.t(0)));
261 for (i = 0; i <
tr.num_channels(); ++i)
262 fprintf(fp,
"Column %s DOUBLE 1\n",(
const char *)(
tr.channel_name(i)));
264 if ((
tr.num_channels() == 1) &&
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");
282 for (i=0; i<
tr.num_frames(); i++)
286 for (
j=0;
j<
tr.num_channels();
j++)
void set(const EST_String &name, int ival)
const EST_String S(const EST_String &path) const