1 /*---------------------------------------------------------------------------*
2 * nisthdr.h *
3 * *
4 * Copyright 2007, 2008 Nuance Communciations, Inc. *
5 * *
6 * Licensed under the Apache License, Version 2.0 (the 'License'); *
7 * you may not use this file except in compliance with the License. *
8 * *
9 * You may obtain a copy of the License at *
10 * http://www.apache.org/licenses/LICENSE-2.0 *
11 * *
12 * Unless required by applicable law or agreed to in writing, software *
13 * distributed under the License is distributed on an 'AS IS' BASIS, *
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
15 * See the License for the specific language governing permissions and *
16 * limitations under the License. *
17 * *
18 *---------------------------------------------------------------------------*/
19
20 #ifndef DO_CLEANUP_20070723
21 #ifndef _NISTHDR_H_
22 #define _NISTHDR_H_
23
24
25
26
27 /**
28 * @todo document
29 */
30 class Nist1AHeader
31 {
32 public:
33 Nist1AHeader(void);
34 ~Nist1AHeader(void);
35
36 int read(PFile* pF); /* returns number of chars read, errno is set
37 // Bug: Reading a header does not mean that you can write it, the read
38 // information does not automatically transfer to the writing data.*/
39
40 int write(PFile* pF); /* returns number of chars written, errno is set*/
41 /*
42 // The fields are not constrained to contain values from these lists,
43 // but the existence of these lists makes it easy to use uniform naming.
44 // Use the enum to index into the matching array of strings.
45 */
46 enum SampleFormatEnum {LINEAR_8BITS, LINEAR_16BITS};
47 static char *mSampleFormatNames[];
48
49 enum SexEnum
50 {
51 FEMALE, MALE
52 };
53 static char *mSexNames[];
54
55 enum SpeakerAccentEnum
56 {
57 AE
58 };
59 static char *mSpeakerAccentNames[];
60
61 enum MicrophoneEnum
62 {
63 SM10, PRIMO, TELEX_STICK, AKG_Q_400
64 };
65 static char *mMicrophoneNames[];
66 /*
67 // The procedure for adding a field to the header is:
68 // 1. add a name in FieldId, make it uppercase version of header entry
69 // 2. add a set function by adding declaration and definition using
70 // macro Nist1AHeaderSetDef
71 // 3. add a FieldDescription in mFieldsInit in .cpp file
72 // If you need a new data type (something besides d, l, f, or s) then
73 // you will also have to alter the union in field description and code
74 // in write() to size and print the type. Please provide predefined
75 // names with matching enums wherever possible as is done for
76 // MicrophoneNames, etc.
77 */
78 enum FieldId
79 {
80 /* CAUTION: this order must match listing order in NistFields in cpp*/
81 WAVE_SIZE,
82 SAMPLE_RATE,
83 SAMPLE_FORMAT,
84 COEF_EMPHASIS,
85 SPEAKER_NAME,
86 SPEAKER_AGE,
87 SPEAKER_SEX,
88 SPEAKER_ACCENT,
89
90 SPEAKING_MODE,
91 CHANNEL_COUNT,
92 SAMPLE_COUNT,
93 SAMPLE_MIN,
94 SAMPLE_MAX,
95 SAMPLE_N_BYTES,
96 SAMPLE_BYTE_FORMAT,
97 RECORD_DATE,
98
99 MICROPHONE,
100 MICROPHONE_POSITION,
101 RECORD_SITE,
102 DOS_PROGRAM,
103 DSP_PROGRAM,
104 LANGUAGE,
105 RECORD_TIME,
106 UTTERANCE_ID,
107 CHECK_SUM,
108 ALL_BYTE_CHECK_SUM,
109 JIN0_FRAME0,
110 AVERAGE_BACKGROUND,
111 AVERAGE_SPEECH,
112 SIGNAL_TO_NOISE,
113 PROMPT_TEXT,
114 PRONUNCIATION_TEXT,
115 RECORDING_MODE,
116 FEP_BEGSIL,
117 FEP_ENDSIL,
118 FEP_XBADJ,
119 END_HEAD /* needed to mark the end of this list*/
120 };
121
122 /* remove a particular field from the header (for writing only)*/
123 void reset(FieldId id);
124
125 /* empties the header (for both reading and writing)*/
126 void reset(void);
127
128 /* CAUTION: strings are not copied, only the pointer is saved*/
129 void setWaveSize(long n);
130 void setSampleRate(int r);/* shouldn't it be double?*/
131 void setSampleFormat(char *format);
132 void setCoefEmphasis(double c);
133 void setSpeakerName(char *name);
134 void setSpeakerAge(char *age);/*shouln't it be int?*/
135 void setSpeakerSex(char *sex);
136 void setSpeakerAccent(char *accent);
137
138 void setSpeakingMode(char *mode);
139 void setChannelCount(int c);
140 void setSampleCount(long c);
141 void setSampleMin(int m);
142 void setSampleMax(int m);
143 void setSampleNBytes(int n);
144 void setSampleByteFormat(char *format);
145 void setRecordDate(char *date);
146
147 void setMicrophone(char *mic);
148 void setMicrophonePosition(char *micPos);
149 void setRecordSite(char *site);
150 void setDosProgram(char *name);
151 void setDspProgram(char *name);
152 void setLanguage(char *lang);
153 void setRecordTime(char *time);
154 void setUtteranceId(int n);
155 void setCheckSum(long sum);
156 void setAllByteCheckSum(long sum);
157 void setJin0Frame0(int n);
158 void setAverageBackground(int n);
159 void setAverageSpeech(int n);
160 void setSignalToNoiseRatio(int n);
161 void setPromptText(char *text);
162 void setPronunciationText(char *text);
163 void setRecordingMode(char *text);
164 void setFepBegSil(int n);
165 void setFepEndSil(int n);
166 void setFepXbadj(int n);
167
168 protected:
169 char mpCurrentTime[32];
170
171 class FieldDescription
172 {
173 public:
174 char *mFormat;
175 char mType;
176 union
177 {
178 int d;
179 unsigned u;
180 long l;
181 double f;
182 char *s;
183 } mValue;
184 BOOL mbInUse;
185 };
186
187 static FieldDescription mFieldsInit[];
188
189 FieldDescription *mpFields; /* each instance gets a copy of mFieldsInit*/
190 };
191
192 inline void
reset(FieldId id)193 Nist1AHeader::reset(FieldId id)
194 {
195 mpFields[id].mbInUse = FALSE;
196 }
197
198 #define Nist1AHeaderSetDef(fname, argType, unionKey, fieldId)\
199 inline void Nist1AHeader::##fname(argType x) {\
200 mpFields[fieldId].mbInUse = TRUE;\
201 mpFields[fieldId].mValue.##unionKey = x;}
202
203 Nist1AHeaderSetDef(setWaveSize, long, l, WAVE_SIZE)
204 Nist1AHeaderSetDef(setSampleRate, int, d, SAMPLE_RATE)
205 Nist1AHeaderSetDef(setSampleFormat, char*, s, SAMPLE_FORMAT)
206 Nist1AHeaderSetDef(setCoefEmphasis, double, f, COEF_EMPHASIS)
207 Nist1AHeaderSetDef(setSpeakerName, char*, s, SPEAKER_NAME)
208 Nist1AHeaderSetDef(setSpeakerAge, char*, s, SPEAKER_AGE)
209 Nist1AHeaderSetDef(setSpeakerSex, char*, s, SPEAKER_SEX)
210 Nist1AHeaderSetDef(setSpeakerAccent, char*, s, SPEAKER_ACCENT)
211
212 Nist1AHeaderSetDef(setSpeakingMode, char*, s, SPEAKING_MODE)
213 Nist1AHeaderSetDef(setChannelCount, int, d, CHANNEL_COUNT)
214 Nist1AHeaderSetDef(setSampleCount, long, l, SAMPLE_COUNT)
215 Nist1AHeaderSetDef(setSampleMin, int, d, SAMPLE_MIN)
216 Nist1AHeaderSetDef(setSampleMax, int, d, SAMPLE_MAX)
217 Nist1AHeaderSetDef(setSampleNBytes, int, d, SAMPLE_N_BYTES)
218 Nist1AHeaderSetDef(setSampleByteFormat, char*, s, SAMPLE_BYTE_FORMAT)
219 Nist1AHeaderSetDef(setRecordDate, char*, s, RECORD_DATE)
220
221 Nist1AHeaderSetDef(setMicrophone, char*, s, MICROPHONE)
222 Nist1AHeaderSetDef(setMicrophonePosition, char*, s, MICROPHONE_POSITION)
223 Nist1AHeaderSetDef(setRecordSite, char*, s, RECORD_SITE)
224 Nist1AHeaderSetDef(setDosProgram, char*, s, DOS_PROGRAM)
225 Nist1AHeaderSetDef(setDspProgram, char*, s, DSP_PROGRAM)
226 Nist1AHeaderSetDef(setLanguage, char*, s, LANGUAGE)
227 Nist1AHeaderSetDef(setRecordTime, char*, s, RECORD_TIME)
228 Nist1AHeaderSetDef(setUtteranceId, int, d, UTTERANCE_ID)
229 Nist1AHeaderSetDef(setCheckSum, long, l, CHECK_SUM)
230 Nist1AHeaderSetDef(setAllByteCheckSum, long, l, ALL_BYTE_CHECK_SUM)
231 Nist1AHeaderSetDef(setJin0Frame0, int, d, JIN0_FRAME0)
232 Nist1AHeaderSetDef(setAverageBackground, int, d, AVERAGE_BACKGROUND)
233 Nist1AHeaderSetDef(setAverageSpeech, int, d, AVERAGE_SPEECH)
234 Nist1AHeaderSetDef(setSignalToNoiseRatio, int, d, SIGNAL_TO_NOISE)
235 Nist1AHeaderSetDef(setPromptText, char*, s, PROMPT_TEXT)
236 Nist1AHeaderSetDef(setPronunciationText, char*, s, PRONUNCIATION_TEXT)
237 Nist1AHeaderSetDef(setRecordingMode, char*, s, RECORDING_MODE)
238 Nist1AHeaderSetDef(setFepBegSil, int, d, FEP_BEGSIL)
239 Nist1AHeaderSetDef(setFepEndSil, int, d, FEP_ENDSIL)
240 Nist1AHeaderSetDef(setFepXbadj, int, d, FEP_XBADJ)
241
242 #undef Nist1AHeaderSetDef
243
244 #endif
245 #endif // DO_CLEANUP_20070723
246