Debian Codegraph @

util/wavinfo.c

raw
1 /**
2 * Console WAV File Info Utility
3 *
4 * Copyright (c) 2006 Justin Ruggles
5 */
6
7 #include "common.h"
8
9 #include "wav.h"
10
11 static char *
12 get_format_name(int id)
13 {
14 if(id < 0x0000 || id > 0xFFFF) return NULL;
15 switch(id) {
16 case 0x0000: return "Microsoft Unknown Wave Format";
17 case 0x0001: return "Microsoft PCM";
18 case 0x0002: return "Microsoft ADPCM";
19 case 0x0003: return "IEEE Float";
20 case 0x0004: return "Compaq Computer VSELP";
21 case 0x0005: return "IBM CVSD";
22 case 0x0006: return "Microsoft A-Law";
23 case 0x0007: return "Microsoft mu-Law";
24 case 0x0008: return "Microsoft DTS";
25 case 0x0009: return "Microsoft DRM Encrypted Audio";
26 case 0x000A: return "Windows Media Audio 9 Voice";
27 case 0x000B: return "Windows Media RT Voice";
28
29 case 0x0010: return "OKI ADPCM";
30 case 0x0011: return "Intel DVI/IMA ADPCM";
31 case 0x0012: return "Videologic MediaSpace ADPCM";
32 case 0x0013: return "Sierra ADPCM";
33 case 0x0014: return "Antex G.723 ADPCM";
34 case 0x0015: return "DSP Solutions DigiSTD";
35 case 0x0016: return "DSP Solutions DigiFIX";
36 case 0x0017: return "Dialogic OKI ADPCM";
37 case 0x0018: return "MediaVision ADPCM";
38 case 0x0019: return "Hewlett-Packard CU";
39
40 case 0x0020: return "Yamaha ADPCM";
41 case 0x0021: return "Speech Compression Sonarc";
42 case 0x0022: return "DSP Group TrueSpeech";
43 case 0x0023: return "Echo Speech EchoSC1";
44 case 0x0024: return "Audiofile AF36";
45 case 0x0025: return "Audio Processing Technology APTX";
46 case 0x0026: return "AudioFile AF10";
47 case 0x0027: return "Prosody 1612";
48 case 0x0028: return "LRC";
49
50 case 0x0030: return "Dolby AC2";
51 case 0x0031: return "Microsoft GSM 6.10";
52 case 0x0032: return "MSNAudio";
53 case 0x0033: return "Antex ADPCME";
54 case 0x0034: return "Control Resources VQLPC";
55 case 0x0035: return "DigiREAL";
56 case 0x0036: return "DigiADPCM";
57 case 0x0037: return "Control Resources CR10";
58 case 0x0038: return "Natural MicroSystems VBXADPCM";
59 case 0x0039: return "Crystal IMA ADPCM";
60 case 0x003A: return "EchoSC3";
61 case 0x003B: return "Rockwell ADPCM";
62 case 0x003C: return "Rockwell Digit LK";
63 case 0x003D: return "Xebec";
64
65 case 0x0040: return "Antex Electronics G.721 ADPCM";
66 case 0x0041: return "G.728 CELP";
67 case 0x0042: return "MS G.723";
68 case 0x0043: return "MS G.723.1";
69 case 0x0044: return "MS G.729";
70 case 0x0045: return "SP G.726";
71
72 case 0x0050: return "MPEG Layer-2 or Layer-1";
73
74 case 0x0052: return "RT24";
75 case 0x0053: return "PAC";
76
77 case 0x0055: return "MPEG Layer-3";
78
79 case 0x0059: return "Lucent G.723";
80
81 case 0x0060: return "Cirrus";
82 case 0x0061: return "ESPCM";
83 case 0x0062: return "Voxware";
84 case 0x0063: return "Canopus Atrac";
85 case 0x0064: return "G.726 ADPCM";
86 case 0x0065: return "G.722 ADPCM";
87 case 0x0066: return "DSAT";
88 case 0x0067: return "DSAT Display";
89
90 case 0x0069: return "Voxware Byte Aligned";
91
92 case 0x0070: return "Voxware AC8";
93 case 0x0071: return "Voxware AC10";
94 case 0x0072: return "Voxware AC16";
95 case 0x0073: return "Voxware AC20";
96 case 0x0074: return "Voxware MetaVoice";
97 case 0x0075: return "Voxware MetaSound";
98 case 0x0076: return "Voxware RT29HW";
99 case 0x0077: return "Voxware VR12";
100 case 0x0078: return "Voxware VR18";
101 case 0x0079: return "Voxware TQ40";
102
103 case 0x0080: return "Softsound";
104 case 0x0081: return "Voxware TQ60";
105 case 0x0082: return "MSRT24";
106 case 0x0083: return "G.729A";
107 case 0x0084: return "MVI MV12";
108 case 0x0085: return "DF G.726";
109 case 0x0086: return "DF GSM610";
110
111 case 0x0088: return "ISIAudio";
112 case 0x0089: return "Onlive";
113
114 case 0x0091: return "SBC24";
115 case 0x0092: return "Dolby AC3 SPDIF";
116 case 0x0093: return "MediaSonic G.723";
117 case 0x0094: return "Aculab PLC Prosody 8kbps";
118
119 case 0x0097: return "ZyXEL ADPCM";
120 case 0x0098: return "Philips LPCBB";
121 case 0x0099: return "Packed";
122
123 case 0x00FF: return "AAC";
124
125 case 0x0100: return "Rhetorex ADPCM";
126 case 0x0101: return "IBM mu-law";
127 case 0x0102: return "IBM A-law";
128 case 0x0103: return "IBM AVC ADPCM";
129
130 case 0x0111: return "Vivo G.723";
131 case 0x0112: return "Vivo Siren";
132
133 case 0x0123: return "Digital G.723";
134
135 case 0x0125: return "Sanyo LD ADPCM";
136
137 case 0x0130: return "Sipro Lab Telecom ACELP NET / RealAudio 4.0/5.0)";
138 case 0x0131: return "Sipro Lab Telecom ACELP 4800";
139 case 0x0132: return "Sipro Lab Telecom ACELP 8V3";
140 case 0x0133: return "Sipro Lab Telecom G.729";
141 case 0x0134: return "Sipro Lab Telecom G.729A";
142 case 0x0135: return "Sipro Lab Telecom Kelvin";
143
144 case 0x0140: return "Windows Media Video V8";
145
146 case 0x0150: return "Qualcomm PureVoice";
147 case 0x0151: return "Qualcomm HalfRate";
148
149 case 0x0155: return "Ring Zero Systems TUB GSM";
150
151 case 0x0160: return "Microsoft Audio 1";
152 case 0x0161: return "Windows Media 7/8/9";
153 case 0x0162: return "Windows Media 9 Professional";
154 case 0x0163: return "Windows Media 9 Lossess";
155 case 0x0164: return "Windows Media Professional over S/PDIF";
156
157 case 0x0180: return "MPEG-2 AAC";
158
159 case 0x0190: return "DTS";
160
161 case 0x0200: return "Creative Labs ADPCM";
162
163 case 0x0202: return "Creative Labs FastSpeech8";
164 case 0x0203: return "Creative Labs FastSpeech10";
165
166 case 0x0210: return "UHER Informatic GmbH ADPCM";
167
168 case 0x0215: return "Ulead DV Audio NTSC";
169 case 0x0216: return "Ulead DV Audio PAL";
170
171 case 0x0220: return "Quarterdeck";
172
173 case 0x0230: return "I-link Worldwide VC";
174
175 case 0x0240: return "Aureal RAW Sport";
176
177 case 0x0250: return "Interactive Products HSX";
178 case 0x0251: return "Interactive Products RPELP";
179
180 case 0x0260: return "Consistent Software CS2";
181
182 case 0x0270: return "Sony SCX / RealAudio 8.0";
183 case 0x0271: return "Sony SCY";
184 case 0x0272: return "Sony ATRAC3";
185 case 0x0273: return "Sony SPC";
186
187 case 0x0300: return "Fujitsu FM Towns Snd";
188
189 case 0x0400: return "BTV Digital";
190 case 0x0401: return "Intel Music Coder";
191
192 case 0x0450: return "QDesign Music";
193
194 case 0x0680: return "VME VMPCM";
195 case 0x0681: return "AT&T Labs TPC";
196
197 case 0x08AE: return "ClearJump LiteWave";
198
199 case 0x1000: return "Olivetti GSM";
200 case 0x1001: return "Olivetti ADPCM";
201 case 0x1002: return "Olivetti CELP";
202 case 0x1003: return "Olivetti SBC";
203 case 0x1004: return "Olivetti OPR";
204
205 case 0x1100: return "L&H Codec";
206 case 0x1101: return "L&H CELP";
207 case 0x1102: return "L&H SBC 0x1102";
208 case 0x1103: return "L&H SBC 0x1103";
209 case 0x1104: return "L&H SBC 0x1104";
210
211 case 0x1400: return "Norris";
212 case 0x1401: return "AT&T ISIAudio";
213
214 case 0x1500: return "Soundspace Music Compression";
215
216 case 0x181C: return "VoxWare RT24 Speech";
217
218 case 0x1971: return "Sonic Foundry Perfect Clarity Audio (PCA)";
219
220 case 0x1FC4: return "NCT Soft ALF2CD";
221
222 case 0x2000: return "Dolby AC3";
223 case 0x2001: return "Dolby DTS";
224 case 0x2002: return "RealAudio 1.0 (14.4K)";
225 case 0x2003: return "RealAudio 2.0 (28.8K)";
226 case 0x2004: return "RealAudio G2 (Cook)";
227 case 0x2005: return "RealAudio 3.0 (DolbyNet AC3)";
228 case 0x2006: return "RealAudio 10.0 (LC-AAC)";
229 case 0x2007: return "RealAudio 10.0 (HE-AAC)";
230
231 case 0x2048: return "Sonic";
232
233 case 0x4143: return "Divio AAC";
234
235 case 0x4201: return "Nokia AMR";
236
237 case 0x566F: return "Vorbis";
238
239 case 0x5756: return "WavPack";
240
241 case 0x674F: return "Ogg Vorbis 1";
242 case 0x6750: return "Ogg Vorbis 2";
243 case 0x6751: return "Ogg Vorbis 3";
244 case 0x676F: return "Ogg Vorbis 1+";
245 case 0x6770: return "Ogg Vorbis 2+";
246 case 0x6771: return "Ogg Vorbis 3+";
247
248 case 0x7A21: return "Adaptive Multirate";
249 case 0x7A22: return "Adaptive Multirate w/ silence detection";
250
251 case 0x706D: return "AAC";
252
253 case 0x77A1: return "TTA";
254
255 case 0xA106: return "MPEG-4 AAC";
256
257 case 0xA109: return "Speex";
258
259 case 0xF1AC: return "FLAC";
260
261 case 0xFFFE: return "{ Extensible }";
262 case 0xFFFF: return "{ Development }";
263
264 default: return NULL;
265 }
266 }
267
268 typedef struct WavInfo {
269 char *fname;
270 WavFile wf;
271 } WavInfo;
272
273 static void
274 wavinfo_print(WavInfo *wi)
275 {
276 char *type;
277 int samples, leftover;
278 float playtime;
279 WavFile *wf = &wi->wf;
280
281 type = get_format_name(wf->format);
282
283 printf("\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n");
284 printf("File:\n");
285 printf(" Name: %s\n", wi->fname);
286 if(wf->seekable) {
287 printf(" File Size: %d\n", wf->file_size);
288 } else {
289 printf(" File Size: unknown\n");
290 }
291 printf("Format:\n");
292 if(type == NULL) {
293 printf(" Type: unknown - 0x%04X\n", wf->format);
294 } else {
295 printf(" Type: %s\n", type);
296 }
297 printf(" Channels: %d\n", wf->channels);
298 printf(" Sample Rate: %d Hz\n", wf->sample_rate);
299 printf(" Avg bytes/sec: %d\n", wf->bytes_per_sec);
300 printf(" Block Align: %d bytes\n", wf->block_align);
301 printf(" Bit Width: %d\n", wf->bit_width);
302 printf("Data:\n");
303 printf(" Start: %d\n", wf->data_start);
304 printf(" Data Size: %d\n", wf->data_size);
305 leftover = wf->file_size - wf->data_size - wf->data_start;
306 if(leftover < 0) {
307 if(!wf->seekable) {
308 printf(" [ warning! unable to verify true data size ]\n");
309 } else {
310 printf(" [ warning! reported data size is larger than file size ]\n");
311 }
312 } else if(leftover > 0) {
313 printf(" Leftover: %d bytes\n", leftover);
314 }
315 if(wf->format == 0x0001 || wf->format == 0x0003) {
316 samples = wf->data_size / wf->block_align;
317 playtime = (float)samples / (float)wf->sample_rate;
318 printf(" Samples: %d\n", samples);
319 printf(" Playing Time: %0.2f sec\n", playtime);
320 } else {
321 printf(" Samples: unknown\n");
322 printf(" Playing Time: unknown\n");
323 }
324 printf("=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n");
325 }
326
327 static void
328 wavfile_error(char *msg)
329 {
330 if(msg != NULL) {
331 fprintf(stderr, "%s\n", msg);
332 }
333 exit(1);
334 }
335
336 int
337 main(int argc, char **argv)
338 {
339 FILE *fp;
340 WavInfo wi;
341 WavFile *wf = &wi.wf;
342
343 // initialize WavInfo to zero
344 memset(&wi, 0, sizeof(WavInfo));
345
346 // open file
347 if(argc > 2) {
348 wavfile_error("\nusage: wavinfo [test.wav]\n");
349 }
350 if(argc == 2) {
351 wi.fname = argv[1];
352 fp = fopen(wi.fname, "rb");
353 } else {
354 wi.fname = "[stdin]";
355 fp = stdin;
356 }
357 if(!fp) wavfile_error("cannot open file");
358
359 wavfile_init(wf, fp);
360
361 // print info
362 wavinfo_print(&wi);
363
364 fclose(fp);
365
366 return 0;
367 }