Edinburgh Speech Tools  2.1-release
esps_utils.h
Go to the documentation of this file.
1 /*************************************************************************/
2 /* */
3 /* Centre for Speech Technology Research */
4 /* University of Edinburgh, UK */
5 /* Copyright (c) 1996 */
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 /* THE UNIVERSITY OF EDINBURGH 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 THE UNIVERSITY OF EDINBURGH 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 Black */
34 /* Date : June 1996 */
35 /*-----------------------------------------------------------------------*/
36 /* Licence free version of esps file i/o functions: headers */
37 /* */
38 /*=======================================================================*/
39 #ifndef __ESPS_IO_H__
40 #define __ESPS_IO_H__
41 
42 #include <cstdio>
43 #include "EST_TrackFile.h"
44 #define ESPS_MAGIC 27162
45 struct ESPS_PREAMBLE {
46  int machine_code; /* the machine that generated this (4 is sun) */
47  int check_code; /* dunno */
48  int data_offset; /* offset from start to start of data records */
49  int record_size; /* data record size in bytes */
50  int check; /* ESPS magic number */
51  int edr; /* byte order independent order or native */
52  int fil1; /* dunno */
53  int foreign_hd; /* foreign header -- not supported */
54 };
56  short thirteen; /* seems to be always 13 */
57  short sdr_size; /* always 0 */
58  int magic; /* magic number again */
59  char date[26]; /* file creation date */
60  char version[8]; /* header version */
61  char prog[16]; /* program used to create file */
62  char vers[8]; /* program version */
63  char progcompdate[26]; /* when that program was compile d */
64  int num_samples; /* number of samples (can be 0) */
65  int filler;
66  int num_doubles; /* num of doubles in record */
68  int num_ints;
69  int num_shorts;
70  int num_chars;
71  int fsize; /* always 40 */
72  int hsize; /* wish I knew, it does vary */
73  char username[8]; /* user who created this file */
74  int fil1[5]; /* dunno */
75  short fea_type; /* may be */
76  short fil2;
77  short num_fields; /* number of fields in a record */
78  short fil3;
79  int fil4[9]; /* a bunch of numbers that look like addresses */
80  int fil5[8]; /* all zeros */
81 };
82 
84  short type;
85  short clength;
86  char *name;
87  int count;
88  short dtype;
89  union
90  {
91  int *ival;
92  char *cval;
93  float *fval;
94  double *dval;
95  short *sval;
96  } v;
98 };
99 typedef struct ESPS_FEA_struct *esps_fea;
100 
101 /* FEA files consist of record which can contain fields (off different */
102 /* data types) The following is used to represent arbitrary records */
103 /* names of the records are given in the header structure */
105  int type;
107  union
108  {
109  int *ival;
110  char *cval;
111  float *fval;
112  double *dval;
113  short *sval;
114  } v;
115 };
116 typedef struct ESPS_FIELD_struct *esps_field;
117 
120  int size;
121  esps_field *field;
122 };
123 typedef struct ESPS_REC_struct *esps_rec;
124 
126 
127 /* This is what the user gets/gives, just the useful information */
129  enum esps_file_type file_type;
130  int swapped; /* byte order in file */
131  int hdr_size; /* full size of file header in bytes */
134  char **field_name;
135  short *field_type;
137  esps_fea fea; /* list of FEA */
138 };
139 typedef struct ESPS_HDR_struct *esps_hdr;
140 
141 #define ESPS_DOUBLE 1
142 #define ESPS_FLOAT 2
143 #define ESPS_INT 3
144 #define ESPS_SHORT 4
145 #define ESPS_CHAR 5 /* I doubt I'm treating char and byte appropriately */
146 #define ESPS_CODED 7 /* enumerated type. Same size as short */
147 #define ESPS_BYTE 8
148 /* There are others too including COMPLEX ones */
149 
150 /* Some random numbers on FEA records */
151 #define ESPS_FEA_FILE 1
152 #define ESPS_FEA_DIRECTORY 15
153 #define ESPS_FEA_COMMAND 11
154 
155 esps_fea new_esps_fea(void);
156 void delete_esps_fea(esps_fea r);
157 void print_esps_fea(esps_fea r);
158 esps_fea read_esps_fea(FILE *fd, esps_hdr hdr);
159 void write_esps_fea(FILE *fd, esps_fea t, esps_hdr hdr);
160 esps_hdr make_esps_hdr(void);
161 esps_hdr make_esps_sd_hdr(void);
162 void delete_esps_hdr(esps_hdr h);
163 enum EST_read_status read_esps_hdr(esps_hdr *hdr,FILE *fd);
164 enum EST_write_status write_esps_hdr(esps_hdr hdr,FILE *fd);
165 
166 int fea_value_d(const char *name,int pos,esps_hdr hdr,double *d);
167 int fea_value_f(const char *name,int pos,esps_hdr hdr,float *d);
168 int fea_value_s(const char *name,int pos,esps_hdr hdr,short *d);
169 int fea_value_i(const char *name,int pos,esps_hdr hdr,int *d);
170 int fea_value_c(const char *name,int pos,esps_hdr hdr,char *d);
171 
172 double get_field_d(esps_rec r, int field, int pos);
173 float get_field_f(esps_rec r, int field, int pos);
174 int get_field_i(esps_rec r, int field, int pos);
175 short get_field_s(esps_rec r, int field, int pos);
176 char get_field_c(esps_rec r, int field, int pos);
177 void set_field_d(esps_rec r, int field, int pos, double d);
178 void set_field_f(esps_rec r, int field, int pos, float d);
179 void set_field_i(esps_rec r, int field, int pos, int d);
180 void set_field_s(esps_rec r, int field, int pos, short d);
181 void set_field_c(esps_rec r, int field, int pos, char d);
182 esps_rec new_esps_rec(const esps_hdr hdr);
183 void delete_esps_rec(esps_rec r);
184 int read_esps_rec(esps_rec r, esps_hdr h, FILE *fd);
185 int write_esps_rec(esps_rec r, esps_hdr h, FILE *fd);
186 
187 void add_field(esps_hdr hdr,const char *name, int type, int dimension);
188 void add_fea_d(esps_hdr hdr,const char *name, int pos, double d);
189 void add_fea_s(esps_hdr hdr,const char *name, int pos, short d);
190 void add_fea_i(esps_hdr hdr,const char *name, int pos, int d);
191 void add_fea_f(esps_hdr hdr,const char *name, int pos, float d);
192 void add_fea_c(esps_hdr hdr,const char *name, int pos, char d);
193 void add_fea_special(esps_hdr hdr,int type,const char *name);
194 
195 #endif /* __ESPS_IO_H__ */
196 
197 
char ** field_name
Definition: esps_utils.h:134
esps_fea new_esps_fea(void)
Definition: esps_utils.cc:84
int write_esps_rec(esps_rec r, esps_hdr h, FILE *fd)
Definition: esps_utils.cc:512
void set_field_c(esps_rec r, int field, int pos, char d)
Definition: esps_utils.cc:943
esps_field * field
Definition: esps_utils.h:121
int fea_value_s(const char *name, int pos, esps_hdr hdr, short *d)
Definition: esps_utils.cc:380
void set_field_f(esps_rec r, int field, int pos, float d)
Definition: esps_utils.cc:931
float * fval
Definition: esps_utils.h:93
EST_write_status
void add_fea_d(esps_hdr hdr, const char *name, int pos, double d)
Definition: esps_utils.cc:167
int * field_dimension
Definition: esps_utils.h:136
int machine_code
Definition: esps_utils.h:46
int fea_value_i(const char *name, int pos, esps_hdr hdr, int *d)
Definition: esps_utils.cc:401
void set_field_d(esps_rec r, int field, int pos, double d)
Definition: esps_utils.cc:927
esps_file_type
Definition: esps_utils.h:125
esps_hdr make_esps_sd_hdr(void)
Definition: esps_utils.cc:971
int fea_value_c(const char *name, int pos, esps_hdr hdr, char *d)
Definition: esps_utils.cc:422
int fea_value_d(const char *name, int pos, esps_hdr hdr, double *d)
Definition: esps_utils.cc:338
short fea_type
Definition: esps_utils.h:75
void add_fea_i(esps_hdr hdr, const char *name, int pos, int d)
Definition: esps_utils.cc:226
int read_esps_rec(esps_rec r, esps_hdr h, FILE *fd)
Definition: esps_utils.cc:838
enum EST_read_status read_esps_hdr(esps_hdr *hdr, FILE *fd)
Definition: esps_utils.cc:989
short thirteen
Definition: esps_utils.h:56
void add_fea_s(esps_hdr hdr, const char *name, int pos, short d)
Definition: esps_utils.cc:264
short sdr_size
Definition: esps_utils.h:57
int fea_value_f(const char *name, int pos, esps_hdr hdr, float *d)
Definition: esps_utils.cc:359
esps_rec new_esps_rec(const esps_hdr hdr)
Definition: esps_utils.cc:775
char get_field_c(esps_rec r, int field, int pos)
Definition: esps_utils.cc:923
void delete_esps_hdr(esps_hdr h)
Definition: esps_utils.cc:760
void add_fea_f(esps_hdr hdr, const char *name, int pos, float d)
Definition: esps_utils.cc:197
float get_field_f(esps_rec r, int field, int pos)
Definition: esps_utils.cc:911
int get_field_i(esps_rec r, int field, int pos)
Definition: esps_utils.cc:915
double * dval
Definition: esps_utils.h:94
double get_field_d(esps_rec r, int field, int pos)
Definition: esps_utils.cc:907
short num_fields
Definition: esps_utils.h:77
esps_hdr make_esps_hdr(void)
Definition: esps_utils.cc:980
void print_esps_fea(esps_fea r)
Definition: esps_utils.cc:111
esps_fea fea
Definition: esps_utils.h:137
void write_esps_fea(FILE *fd, esps_fea t, esps_hdr hdr)
Definition: esps_utils.cc:467
EST_read_status
enum EST_write_status write_esps_hdr(esps_hdr hdr, FILE *fd)
Definition: esps_utils.cc:1242
short get_field_s(esps_rec r, int field, int pos)
Definition: esps_utils.cc:919
void set_field_i(esps_rec r, int field, int pos, int d)
Definition: esps_utils.cc:935
short * field_type
Definition: esps_utils.h:135
void add_field(esps_hdr hdr, const char *name, int type, int dimension)
Definition: esps_utils.cc:138
void delete_esps_rec(esps_rec r)
Definition: esps_utils.cc:824
struct ESPS_FEA_struct * next
Definition: esps_utils.h:97
esps_fea read_esps_fea(FILE *fd, esps_hdr hdr)
Definition: esps_utils.cc:549
short * sval
Definition: esps_utils.h:95
void add_fea_c(esps_hdr hdr, const char *name, int pos, char d)
Definition: esps_utils.cc:293
void add_fea_special(esps_hdr hdr, int type, const char *name)
Definition: esps_utils.cc:322
void delete_esps_fea(esps_fea r)
Definition: esps_utils.cc:96
void set_field_s(esps_rec r, int field, int pos, short d)
Definition: esps_utils.cc:939