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