annotate src/shnplug/wave.c @ 1882:eed7c270e8dd

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