1305
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1 /* wave.c - functions to parse and verify WAVE headers
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
2 * Copyright (C) 2000-2007 Jason Jordan <shnutils@freeshell.org>
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
3 *
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
4 * This program is free software; you can redistribute it and/or modify
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
5 * it under the terms of the GNU General Public License as published by
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
6 * the Free Software Foundation; either version 2 of the License, or
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
7 * (at your option) any later version.
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
8 *
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
9 * This program is distributed in the hope that it will be useful,
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
12 * GNU General Public License for more details.
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
13 *
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
14 * You should have received a copy of the GNU General Public License
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
15 * along with this program; if not, write to the Free Software
|
2835
|
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
1305
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
17 */
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
18
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
19 /*
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
20 * $Id: wave.c,v 1.13 2007/03/23 05:49:48 jason Exp $
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
21 */
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
22
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
23 #include <stdlib.h>
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
24 #include <string.h>
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
25 #include <errno.h>
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
26 #include <sys/stat.h>
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
27 #include <glib.h>
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
28 #include "shorten.h"
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
29
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
30 #ifdef HAVE_CONFIG_H
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
31 #include "config.h"
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
32 #endif
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
33
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
34 int is_valid_file(shn_file *info)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
35 /* determines whether the given filename (info->filename) is a regular file, and is readable */
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
36 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
37 struct stat sz;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
38 FILE *f;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
39
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
40 if (0 != stat(info->wave_header.filename,&sz)) {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
41 if (errno == ENOENT)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
42 shn_error("cannot open '%s' because it does not exist",info->wave_header.filename);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
43 else if (errno == EACCES)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
44 shn_error("cannot open '%s' due to insufficient permissions",info->wave_header.filename);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
45 else if (errno == EFAULT)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
46 shn_error("cannot open '%s' due to bad address",info->wave_header.filename);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
47 else if (errno == ENOMEM)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
48 shn_error("cannot open '%s' because the kernel ran out of memory",info->wave_header.filename);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
49 else if (errno == ENAMETOOLONG)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
50 shn_error("cannot open '%s' because the file name is too long",info->wave_header.filename);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
51 else
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
52 shn_error("cannot open '%s' due to an unknown problem",info->wave_header.filename);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
53 return 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
54 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
55 if (0 == S_ISREG(sz.st_mode)) {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
56 if (S_ISLNK(sz.st_mode))
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
57 shn_error("'%s' is a symbolic link, not a regular file",info->wave_header.filename);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
58 else if (S_ISDIR(sz.st_mode))
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
59 shn_error("'%s' is a directory, not a regular file",info->wave_header.filename);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
60 else if (S_ISCHR(sz.st_mode))
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
61 shn_error("'%s' is a character device, not a regular file",info->wave_header.filename);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
62 else if (S_ISBLK(sz.st_mode))
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
63 shn_error("'%s' is a block device, not a regular file",info->wave_header.filename);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
64 else if (S_ISFIFO(sz.st_mode))
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
65 shn_error("'%s' is a fifo, not a regular file",info->wave_header.filename);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
66 else if (S_ISSOCK(sz.st_mode))
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
67 shn_error("'%s' is a socket, not a regular file",info->wave_header.filename);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
68 return 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
69 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
70 info->wave_header.actual_size = (ulong)sz.st_size;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
71
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
72 if (NULL == (f = fopen(info->wave_header.filename,"rb"))) {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
73 shn_error("could not open '%s': %s",info->wave_header.filename,strerror(errno));
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
74 return 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
75 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
76 fclose(f);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
77
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
78 return 1;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
79 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
80
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
81 int shn_verify_header(shn_file *this_shn)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
82 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
83 ulong l;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
84 int cur = 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
85
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
86 if (0 == is_valid_file(this_shn))
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
87 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
88 shn_debug("while processing '%s': something went wrong while opening this file, see above",this_shn->wave_header.filename);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
89 return 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
90 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
91
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
92 if (this_shn->vars.bytes_in_header < CANONICAL_HEADER_SIZE) {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
93 shn_debug("while processing '%s': header is only %d bytes (should be at least %d bytes)",
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
94 this_shn->wave_header.filename,this_shn->vars.bytes_in_header,CANONICAL_HEADER_SIZE);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
95 return 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
96 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
97
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
98 if (WAVE_RIFF != shn_uchar_to_ulong_le(this_shn->vars.header+cur))
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
99 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
100 if (AIFF_FORM == shn_uchar_to_ulong_le(this_shn->vars.header+cur))
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
101 shn_debug("while processing '%s': file contains AIFF data, which is currently not supported",this_shn->wave_header.filename);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
102 else
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
103 shn_debug("while processing '%s': WAVE header is missing RIFF tag - possible corrupt file",this_shn->wave_header.filename);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
104 return 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
105 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
106 cur += 4;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
107
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
108 this_shn->wave_header.chunk_size = shn_uchar_to_ulong_le(this_shn->vars.header+cur);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
109 cur += 4;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
110
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
111 if (WAVE_WAVE != shn_uchar_to_ulong_le(this_shn->vars.header+cur))
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
112 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
113 shn_debug("while processing '%s': WAVE header is missing WAVE tag",this_shn->wave_header.filename);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
114 return 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
115 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
116 cur += 4;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
117
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
118 for (;;)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
119 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
120 cur += 4;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
121
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
122 l = shn_uchar_to_ulong_le(this_shn->vars.header+cur);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
123 cur += 4;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
124
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
125 if (WAVE_FMT == shn_uchar_to_ulong_le(this_shn->vars.header+cur-8))
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
126 break;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
127
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
128 cur += l;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
129 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
130
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
131 if (l < 16)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
132 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
133 shn_debug("while processing '%s': fmt chunk in WAVE header was too short",this_shn->wave_header.filename);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
134 return 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
135 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
136
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
137 this_shn->wave_header.wave_format = shn_uchar_to_ushort_le(this_shn->vars.header+cur);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
138 cur += 2;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
139
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
140 switch (this_shn->wave_header.wave_format)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
141 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
142 case WAVE_FORMAT_PCM:
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
143 break;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
144 default:
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
145 shn_debug("while processing '%s': unsupported format 0x%04x (%s) - only PCM data is supported at this time",
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
146 this_shn->wave_header.filename,this_shn->wave_header.wave_format,shn_format_to_str(this_shn->wave_header.wave_format));
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
147 return 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
148 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
149
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
150 this_shn->wave_header.channels = shn_uchar_to_ushort_le(this_shn->vars.header+cur);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
151 cur += 2;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
152 this_shn->wave_header.samples_per_sec = shn_uchar_to_ulong_le(this_shn->vars.header+cur);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
153 cur += 4;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
154 this_shn->wave_header.avg_bytes_per_sec = shn_uchar_to_ulong_le(this_shn->vars.header+cur);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
155 cur += 4;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
156 this_shn->wave_header.block_align = shn_uchar_to_ushort_le(this_shn->vars.header+cur);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
157 cur += 2;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
158 this_shn->wave_header.bits_per_sample = shn_uchar_to_ushort_le(this_shn->vars.header+cur);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
159 cur += 2;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
160
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
161 if (this_shn->wave_header.bits_per_sample != 8 && this_shn->wave_header.bits_per_sample != 16)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
162 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
163 shn_debug("while processing '%s': bits per sample is neither 8 nor 16",this_shn->wave_header.filename);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
164 return 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
165 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
166
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
167 l -= 16;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
168
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
169 if (l > 0)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
170 cur += l;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
171
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
172 for (;;)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
173 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
174 cur += 4;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
175
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
176 l = shn_uchar_to_ulong_le(this_shn->vars.header+cur);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
177 cur += 4;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
178
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
179 if (WAVE_DATA == shn_uchar_to_ulong_le(this_shn->vars.header+cur-8))
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
180 break;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
181
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
182 cur += l;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
183 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
184
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
185 this_shn->wave_header.rate = ((uint)this_shn->wave_header.samples_per_sec *
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
186 (uint)this_shn->wave_header.channels *
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
187 (uint)this_shn->wave_header.bits_per_sample) / 8;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
188 this_shn->wave_header.header_size = cur;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
189 this_shn->wave_header.data_size = l;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
190 this_shn->wave_header.total_size = this_shn->wave_header.chunk_size + 8;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
191 this_shn->wave_header.length = this_shn->wave_header.data_size / this_shn->wave_header.rate;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
192 this_shn->wave_header.exact_length = (double)this_shn->wave_header.data_size / (double)this_shn->wave_header.rate;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
193
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
194 if (this_shn->wave_header.channels == CD_CHANNELS &&
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
195 this_shn->wave_header.bits_per_sample == CD_BITS_PER_SAMPLE &&
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
196 this_shn->wave_header.samples_per_sec == CD_SAMPLES_PER_SEC &&
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
197 this_shn->wave_header.avg_bytes_per_sec == CD_RATE &&
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
198 this_shn->wave_header.rate == CD_RATE)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
199 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
200 if (this_shn->wave_header.data_size < CD_MIN_BURNABLE_SIZE)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
201 this_shn->wave_header.problems |= PROBLEM_CD_BUT_TOO_SHORT;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
202 if (this_shn->wave_header.data_size % CD_BLOCK_SIZE != 0)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
203 this_shn->wave_header.problems |= PROBLEM_CD_BUT_BAD_BOUND;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
204 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
205 else
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
206 this_shn->wave_header.problems |= PROBLEM_NOT_CD_QUALITY;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
207
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
208 if (this_shn->wave_header.header_size != CANONICAL_HEADER_SIZE)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
209 this_shn->wave_header.problems |= PROBLEM_HEADER_NOT_CANONICAL;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
210
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
211 if ((ulong)this_shn->wave_header.header_size + this_shn->wave_header.data_size > this_shn->wave_header.total_size)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
212 this_shn->wave_header.problems |= PROBLEM_HEADER_INCONSISTENT;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
213
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
214 if ((ulong)this_shn->wave_header.header_size + this_shn->wave_header.data_size < this_shn->wave_header.total_size)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
215 this_shn->wave_header.problems |= PROBLEM_EXTRA_CHUNKS;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
216
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
217 shn_length_to_str(this_shn);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
218
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
219 /* header looks ok */
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
220 return 1;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
221 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
222
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
223 char *shn_format_to_str(ushort format)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
224 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
225 switch (format) {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
226 case WAVE_FORMAT_UNKNOWN:
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
227 return "Microsoft Official Unknown";
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
228 case WAVE_FORMAT_PCM:
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
229 return "Microsoft PCM";
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
230 case WAVE_FORMAT_ADPCM:
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
231 return "Microsoft ADPCM";
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
232 case WAVE_FORMAT_IEEE_FLOAT:
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
233 return "IEEE Float";
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
234 case WAVE_FORMAT_ALAW:
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
235 return "Microsoft A-law";
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
236 case WAVE_FORMAT_MULAW:
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
237 return "Microsoft U-law";
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
238 case WAVE_FORMAT_OKI_ADPCM:
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
239 return "OKI ADPCM format";
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
240 case WAVE_FORMAT_IMA_ADPCM:
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
241 return "IMA ADPCM";
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
242 case WAVE_FORMAT_DIGISTD:
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
243 return "Digistd format";
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
244 case WAVE_FORMAT_DIGIFIX:
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
245 return "Digifix format";
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
246 case WAVE_FORMAT_DOLBY_AC2:
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
247 return "Dolby AC2";
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
248 case WAVE_FORMAT_GSM610:
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
249 return "GSM 6.10";
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
250 case WAVE_FORMAT_ROCKWELL_ADPCM:
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
251 return "Rockwell ADPCM";
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
252 case WAVE_FORMAT_ROCKWELL_DIGITALK:
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
253 return "Rockwell DIGITALK";
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
254 case WAVE_FORMAT_G721_ADPCM:
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
255 return "G.721 ADPCM";
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
256 case WAVE_FORMAT_G728_CELP:
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
257 return "G.728 CELP";
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
258 case WAVE_FORMAT_MPEG:
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
259 return "MPEG";
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
260 case WAVE_FORMAT_MPEGLAYER3:
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
261 return "MPEG Layer 3";
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
262 case WAVE_FORMAT_G726_ADPCM:
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
263 return "G.726 ADPCM";
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
264 case WAVE_FORMAT_G722_ADPCM:
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
265 return "G.722 ADPCM";
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
266 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
267 return "Unknown";
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
268 }
|