62 EST_Track &tr,
float ishift,
float startt)
66 if (((filename ==
"-") ? ts.
open(cin) : ts.
open(filename)) != 0)
68 cerr <<
"Can't open track file " << filename << endl;
72 return load_ssff_ts(ts, tr, ishift, startt);
79 ssize_t num_frames, num_channels;
83 float Start_Time, Record_Freq;
90 num_frames = num_channels = 0;
91 Start_Time = Record_Freq = 0;
93 if (ts.
get() !=
"SSFF")
96 if ((ts.
get() !=
"--") ||
97 (ts.
get() !=
"(c)") ||
98 (ts.
get() !=
"SHLRC"))
100 cerr <<
"ssff load track \"" << ts.
filename() <<
"\": bad header" 105 while (ts.
peek() !=
"-----------------")
110 else if (c ==
"Start_Time")
112 Start_Time = atof(ts.
get().string());
113 tr.
f_set(
"Start_Time",Start_Time);
115 else if (c ==
"Record_Freq")
117 Record_Freq = atof(ts.
get().string());
118 tr.
f_set(
"Record_Freq",Record_Freq);
120 else if (c ==
"Machine")
122 if (ts.
get() ==
"SPARC")
130 else if (c ==
"Column")
136 channels.
set(cname+
".name",name);
137 channels.
set(cname+
".type",type);
138 channels.
set(cname+
".size",atoi(size));
141 else if ((c ==
"window_type") ||
142 (c ==
"window_duration") ||
143 (c ==
"lpc_order") ||
146 (c ==
"preemphasis") ||
147 (c ==
"frame_duration"))
151 tr.
f_set(c,atoi(ts.
get().string()));
152 else if (type ==
"DOUBLE")
153 tr.
f_set(c,(
float)atof(ts.
get().string()));
159 cerr <<
"ssff load track \"" << ts.
filename() <<
160 "\": bad header unexpected eof" << endl;
178 if (num_channels == 0) {
181 num_frames = (end - pos)/(num_channels*
sizeof(
double));
185 tr.
resize(num_frames,num_channels);
189 for (i=0; i<num_channels; i++)
193 for (i=0; i < num_frames; i++)
194 for (j=0; j<num_channels; j++)
197 if (type ==
"DOUBLE")
199 if (ts.
fread(dbuff,
sizeof(
double),1) != 1)
201 cerr <<
"Failed to read frame " << i <<
", channel " <<
209 else if (type ==
"SHORT")
211 if (ts.
fread(sbuff,
sizeof(
short),1) != 1)
213 cerr <<
"Failed to read short from frame" << i <<
214 ", channel " << j << endl;
219 tr(i,j) = (float)(*sbuff);
223 cerr <<
"ssff load track \"" << ts.
filename() <<
224 "\": unknown channel type value \"" << type <<
"\"" << endl;
239 else if ((fd = fopen(filename,
"wb")) ==
NULL)
242 r = save_ssff_ts(fd,tr);
253 int need_prob_voice = 0;
257 cerr <<
"ssf save track: can't save variable spaced track as SSFF" 262 fprintf(fp,
"SSFF -- (c) SHLRC\n");
264 fprintf(fp,
"Machine SPARC\n");
266 fprintf(fp,
"Machine IBM-PC\n");
268 fprintf(fp,
"Start_Time %g\n",(
double)tr.
f_F(
"Start_Time"));
270 fprintf(fp,
"Start_Time 0.000000\n");
273 fprintf(fp,
"Record_Freq %g\n",(
double)tr.
f_F(
"Record_Freq"));
275 fprintf(fp,
"Record_Freq %d\n", 100);
277 fprintf(fp,
"Record_Freq %g\n", 1/(tr.
t(1)-tr.
t(0)));
280 fprintf(fp,
"Column %s DOUBLE 1\n",(
const char *)(tr.
channel_name(i)));
286 fprintf(fp,
"Column prob_voice DOUBLE 1\n");
290 for (p.
begin(tr); p; ++p)
292 if ((p->k ==
"Start_Time") ||
293 (p->k ==
"Record_Freq"))
296 fprintf(fp,
"%s DOUBLE %s\n", (
const char *)p->k,
297 (
const char *) p->v.String());
299 fprintf(fp,
"-----------------\n");
307 fwrite(&dd,
sizeof(
double),1,fp);
315 fwrite(&prob_voice,
sizeof(
double),1,fp);
EST_TokenStream & get(EST_Token &t)
get next token in stream
float end(const EST_Item &item)
FILE * filedescriptor()
For the people who need the actual description (if possible)
EST_FilePos EST_ftell(FILE *fp)
int fread(void *buff, int size, int nitems) EST_WARN_UNUSED_RESULT
Reading binary data, (don't use peek() immediately beforehand)
void set_channel_name(const EST_String &name, int channel)
set the name of the channel.
int num_channels() const
return number of channels in track
static EST_write_status save_ssff_ts(SaveTrac_TokenStreamArgs)
const EST_String filename() const
The originating filename (if there is one)
EST_String itoString(int n)
Make a EST_String object from an integer.
void swap_bytes_double(double *data, int length)
void set(const EST_String &name, int ival)
void resize(ssize_t num_frames, int num_channels, bool preserve=1)
int open(const EST_String &filename)
open a EST_TokenStream for a file.
const EST_String S(const EST_String &path) const
static EST_read_status load_ssff_ts(LoadTrack_TokenStreamArgs)
int f_present(const EST_String name) const
The file was not written successfully.
bool equal_space() const
return true if track has equal (i.e. fixed) frame spacing */
float & t(ssize_t i=0)
return time position of frame i
The file was written successfully.
void set_name(const EST_String &n)
set name of track - redundant use access to features
void swap_bytes_short(short *data, int length)
int EST_fseek(FILE *fp, EST_FilePos offset, int whence)
ssize_t num_frames() const
return number of frames in track
EST_Token & peek(void)
peek at next token
The file was not written successfully.
const EST_String channel_name(int channel, const EST_ChannelNameMap &map, int strings_override=1) const
void begin(const Container &over)
Set the iterator ready to run over this container.
EST_Token get_upto_eoln(void)
get up to s in end of line as a single token.
static EST_write_status save_ssff(SaveTrackFileArgs)
static EST_read_status load_ssff(LoadTrackFileArgs)
void set_equal_space(bool t)
void fill_time(float t, int start=1)
void f_set(const EST_String name, int val)
float f_F(const char *name, float def) const
Utility EST_String Functions header file.