1305
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1 /* shn.c - main functions for xmms-shn
|
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: shn.c,v 1.38 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 <stdio.h>
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
24 #include <stdlib.h>
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
25 #include <math.h>
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
26 #include <glib.h>
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
27 #include "shorten.h"
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
28
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
29 #ifdef HAVE_CONFIG_H
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
30 #include "config.h"
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
31 #endif
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
32
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
33 static void shn_about(void);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
34 static void shn_configure(void);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
35 static void shn_init(void);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
36 static int shn_is_our_fd(char *, VFSFile *fd);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
37 static void shn_play(InputPlayback *);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
38 static void shn_stop(InputPlayback *);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
39 static void shn_seek(InputPlayback *, int);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
40 static void shn_pause(InputPlayback *, short);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
41 static void shn_get_file_info(char *,char **,int *);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
42 static void shn_display_file_info(char *);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
43
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
44 gchar *shn_fmts[] = { "shn", NULL };
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
45
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
46 InputPlugin shn_ip =
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
47 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
48 NULL,
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
49 NULL,
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
50 "SHN Player " VERSION,
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
51 shn_init,
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
52 shn_about,
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
53 shn_configure,
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
54 NULL,
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
55 NULL,
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
56 shn_play,
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
57 shn_stop,
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
58 shn_pause,
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
59 shn_seek,
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
60 NULL,
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
61 NULL,
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
62 NULL,
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
63 NULL,
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
64 NULL,
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
65 NULL,
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
66 NULL,
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
67 NULL,
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
68 NULL,
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
69 shn_get_file_info,
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
70 shn_display_file_info,
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
71 NULL,
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
72 NULL,
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
73 NULL,
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
74 NULL,
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
75 shn_is_our_fd,
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
76 shn_fmts,
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
77 };
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
78
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
79 InputPlugin *shn_iplist[] = { &shn_ip, NULL };
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
80
|
1395
|
81 DECLARE_PLUGIN(shnplug, NULL, NULL, shn_iplist, NULL, NULL, NULL, NULL, NULL);
|
1305
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
82
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
83 shn_file *shnfile;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
84 shn_config shn_cfg;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
85
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
86 static pthread_t decode_thread;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
87 static gboolean audio_error = FALSE;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
88
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
89 static void shn_init()
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
90 {
|
2523
|
91 mcs_handle_t *cfg;
|
1305
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
92
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
93 shn_cfg.error_output_method = ERROR_OUTPUT_DEVNULL;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
94 shn_cfg.error_output_method_config_name = "error_output_method";
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
95 shn_cfg.seek_tables_path = NULL;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
96 shn_cfg.seek_tables_path_config_name = "seek_tables_path";
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
97 shn_cfg.relative_seek_tables_path = NULL;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
98 shn_cfg.relative_seek_tables_path_config_name = "relative_seek_tables_path";
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
99 shn_cfg.verbose = 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
100 shn_cfg.verbose_config_name = "verbose";
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
101 shn_cfg.swap_bytes = 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
102 shn_cfg.swap_bytes_config_name = "swap_bytes";
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
103 shn_cfg.load_textfiles = FALSE;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
104 shn_cfg.load_textfiles_config_name = "load_textfiles";
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
105 shn_cfg.textfile_extensions = NULL;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
106 shn_cfg.textfile_extensions_config_name = "textfile_extensions";
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
107
|
2124
|
108 if ((cfg = aud_cfg_db_open()) != 0)
|
1305
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
109 {
|
2124
|
110 aud_cfg_db_get_int(cfg, XMMS_SHN_VERSION_TAG, shn_cfg.error_output_method_config_name, &shn_cfg.error_output_method);
|
|
111 aud_cfg_db_get_bool(cfg, XMMS_SHN_VERSION_TAG, shn_cfg.verbose_config_name, &shn_cfg.verbose);
|
|
112 if (!aud_cfg_db_get_string(cfg, XMMS_SHN_VERSION_TAG, shn_cfg.seek_tables_path_config_name, &shn_cfg.seek_tables_path))
|
1305
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
113 shn_cfg.seek_tables_path = g_strdup(g_get_home_dir());
|
2124
|
114 if (!aud_cfg_db_get_string(cfg, XMMS_SHN_VERSION_TAG, shn_cfg.relative_seek_tables_path_config_name, &shn_cfg.relative_seek_tables_path))
|
1305
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
115 shn_cfg.relative_seek_tables_path = g_strdup("");
|
2124
|
116 aud_cfg_db_get_bool(cfg, XMMS_SHN_VERSION_TAG, shn_cfg.swap_bytes_config_name, &shn_cfg.swap_bytes);
|
|
117 aud_cfg_db_get_bool(cfg, XMMS_SHN_VERSION_TAG, shn_cfg.load_textfiles_config_name, &shn_cfg.load_textfiles);
|
|
118 if (!aud_cfg_db_get_string(cfg, XMMS_SHN_VERSION_TAG, shn_cfg.textfile_extensions_config_name, &shn_cfg.textfile_extensions))
|
1305
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
119 shn_cfg.textfile_extensions = g_strdup("txt,nfo");
|
2124
|
120 aud_cfg_db_close(cfg);
|
1305
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
121 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
122 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
123
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
124 static void shn_about()
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
125 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
126 shn_display_about();
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
127 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
128
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
129 static void shn_configure()
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
130 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
131 shn_display_configure();
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
132 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
133
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
134 int init_decode_state(shn_file *this_shn)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
135 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
136 if (this_shn->decode_state)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
137 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
138 if (this_shn->decode_state->getbuf)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
139 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
140 free(this_shn->decode_state->getbuf);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
141 this_shn->decode_state->getbuf = NULL;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
142 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
143
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
144 if (this_shn->decode_state->writebuf)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
145 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
146 free(this_shn->decode_state->writebuf);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
147 this_shn->decode_state->writebuf = NULL;
|
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 if (this_shn->decode_state->writefub)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
151 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
152 free(this_shn->decode_state->writefub);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
153 this_shn->decode_state->writefub = NULL;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
154 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
155
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
156 free(this_shn->decode_state);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
157 this_shn->decode_state = NULL;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
158 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
159
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
160 if (!(this_shn->decode_state = malloc(sizeof(shn_decode_state))))
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
161 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
162 shn_debug("Could not allocate memory for decode state data structure");
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
163 return 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
164 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
165
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
166 this_shn->decode_state->getbuf = NULL;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
167 this_shn->decode_state->getbufp = NULL;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
168 this_shn->decode_state->nbitget = 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
169 this_shn->decode_state->nbyteget = 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
170 this_shn->decode_state->gbuffer = 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
171 this_shn->decode_state->writebuf = NULL;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
172 this_shn->decode_state->writefub = NULL;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
173 this_shn->decode_state->nwritebuf = 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
174
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
175 this_shn->vars.bytes_in_buf = 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
176
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
177 return 1;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
178 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
179
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
180 int get_wave_header(shn_file *this_shn)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
181 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
182 slong **buffer = NULL, **offset = NULL;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
183 slong lpcqoffset = 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
184 int version = FORMAT_VERSION, bitshift = 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
185 int ftype = TYPE_EOF;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
186 char *magic = MAGIC;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
187 int blocksize = DEFAULT_BLOCK_SIZE, nchan = DEFAULT_NCHAN;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
188 int i, chan, nwrap, nskip = DEFAULT_NSKIP;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
189 int *qlpc = NULL, maxnlpc = DEFAULT_MAXNLPC, nmean = UNDEFINED_UINT;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
190 int cmd;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
191 int internal_ftype;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
192 int cklen;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
193 int retval = 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
194
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
195 if (!init_decode_state(this_shn))
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
196 return 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
197
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
198 /***********************/
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
199 /* EXTRACT starts here */
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
200 /***********************/
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
201
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
202 /* read magic number */
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
203 #ifdef STRICT_FORMAT_COMPATABILITY
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
204 if(FORMAT_VERSION < 2)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
205 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
206 for(i = 0; i < strlen(magic); i++) {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
207 if(getc_exit(this_shn->vars.fd) != magic[i])
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
208 return 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
209 this_shn->vars.bytes_read++;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
210 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
211
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
212 /* get version number */
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
213 version = getc_exit(this_shn->vars.fd);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
214 this_shn->vars.bytes_read++;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
215 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
216 else
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
217 #endif /* STRICT_FORMAT_COMPATABILITY */
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
218 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
219 int nscan = 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
220
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
221 version = MAX_VERSION + 1;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
222 while(version > MAX_VERSION)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
223 {
|
1978
|
224 int byte = aud_vfs_getc(this_shn->vars.fd);
|
1305
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
225 this_shn->vars.bytes_read++;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
226 if(byte == EOF)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
227 return 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
228 if(magic[nscan] != '\0' && byte == magic[nscan])
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
229 nscan++;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
230 else
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
231 if(magic[nscan] == '\0' && byte <= MAX_VERSION)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
232 version = byte;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
233 else
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
234 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
235 if(byte == magic[0])
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
236 nscan = 1;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
237 else
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
238 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
239 nscan = 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
240 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
241 version = MAX_VERSION + 1;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
242 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
243 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
244 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
245
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
246 /* check version number */
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
247 if(version > MAX_SUPPORTED_VERSION)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
248 return 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
249
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
250 /* set up the default nmean, ignoring the command line state */
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
251 nmean = (version < 2) ? DEFAULT_V0NMEAN : DEFAULT_V2NMEAN;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
252
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
253 /* initialise the variable length file read for the compressed stream */
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
254 var_get_init(this_shn);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
255 if (this_shn->vars.fatal_error)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
256 return 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
257
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
258 /* initialise the fixed length file write for the uncompressed stream */
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
259 fwrite_type_init(this_shn);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
260
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
261 /* get the internal file type */
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
262 internal_ftype = UINT_GET(TYPESIZE, this_shn);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
263
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
264 /* has the user requested a change in file type? */
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
265 if(internal_ftype != ftype) {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
266 if(ftype == TYPE_EOF) {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
267 ftype = internal_ftype; /* no problems here */
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
268 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
269 else { /* check that the requested conversion is valid */
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
270 if(internal_ftype == TYPE_AU1 || internal_ftype == TYPE_AU2 ||
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
271 internal_ftype == TYPE_AU3 || ftype == TYPE_AU1 ||ftype == TYPE_AU2 || ftype == TYPE_AU3)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
272 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
273 retval = 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
274 goto got_enough_data;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
275 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
276 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
277 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
278
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
279 nchan = UINT_GET(CHANSIZE, this_shn);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
280 this_shn->vars.actual_nchan = nchan;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
281
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
282 /* get blocksize if version > 0 */
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
283 if(version > 0)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
284 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
285 int byte;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
286 blocksize = UINT_GET((int) (log((double) DEFAULT_BLOCK_SIZE) / M_LN2),this_shn);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
287 maxnlpc = UINT_GET(LPCQSIZE, this_shn);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
288 this_shn->vars.actual_maxnlpc = maxnlpc;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
289 nmean = UINT_GET(0, this_shn);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
290 this_shn->vars.actual_nmean = nmean;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
291 nskip = UINT_GET(NSKIPSIZE, this_shn);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
292 for(i = 0; i < nskip; i++)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
293 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
294 byte = uvar_get(XBYTESIZE,this_shn);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
295 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
296 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
297 else
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
298 blocksize = DEFAULT_BLOCK_SIZE;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
299
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
300 nwrap = MAX(NWRAP, maxnlpc);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
301
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
302 /* grab some space for the input buffer */
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
303 buffer = long2d((ulong) nchan, (ulong) (blocksize + nwrap),this_shn);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
304 if (this_shn->vars.fatal_error)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
305 return 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
306 offset = long2d((ulong) nchan, (ulong) MAX(1, nmean),this_shn);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
307 if (this_shn->vars.fatal_error) {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
308 if (buffer) {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
309 free(buffer);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
310 buffer = NULL;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
311 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
312 return 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
313 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
314
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
315 for(chan = 0; chan < nchan; chan++)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
316 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
317 for(i = 0; i < nwrap; i++)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
318 buffer[chan][i] = 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
319 buffer[chan] += nwrap;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
320 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
321
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
322 if(maxnlpc > 0) {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
323 qlpc = (int*) pmalloc((ulong) (maxnlpc * sizeof(*qlpc)),this_shn);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
324 if (this_shn->vars.fatal_error) {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
325 if (buffer) {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
326 free(buffer);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
327 buffer = NULL;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
328 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
329 if (offset) {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
330 free(offset);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
331 buffer = NULL;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
332 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
333 return 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
334 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
335 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
336
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
337 if(version > 1)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
338 lpcqoffset = V2LPCQOFFSET;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
339
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
340 init_offset(offset, nchan, MAX(1, nmean), internal_ftype);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
341
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
342 /* get commands from file and execute them */
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
343 chan = 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
344 while(1)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
345 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
346 this_shn->vars.reading_function_code = 1;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
347 cmd = uvar_get(FNSIZE,this_shn);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
348 this_shn->vars.reading_function_code = 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
349
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
350 switch(cmd)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
351 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
352 case FN_ZERO:
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
353 case FN_DIFF0:
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
354 case FN_DIFF1:
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
355 case FN_DIFF2:
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
356 case FN_DIFF3:
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
357 case FN_QLPC:
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
358 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
359 slong coffset, *cbuffer = buffer[chan];
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
360 int resn = 0, nlpc, j;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
361
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
362 if(cmd != FN_ZERO)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
363 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
364 resn = uvar_get(ENERGYSIZE,this_shn);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
365 if (this_shn->vars.fatal_error) {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
366 retval = 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
367 goto got_enough_data;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
368 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
369 /* this is a hack as version 0 differed in definition of var_get */
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
370 if(version == 0)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
371 resn--;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
372 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
373
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
374 /* find mean offset : N.B. this code duplicated */
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
375 if(nmean == 0)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
376 coffset = offset[chan][0];
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
377 else
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
378 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
379 slong sum = (version < 2) ? 0 : nmean / 2;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
380 for(i = 0; i < nmean; i++)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
381 sum += offset[chan][i];
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
382 if(version < 2)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
383 coffset = sum / nmean;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
384 else
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
385 coffset = ROUNDEDSHIFTDOWN(sum / nmean, bitshift);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
386 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
387
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
388 switch(cmd)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
389 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
390 case FN_ZERO:
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
391 for(i = 0; i < blocksize; i++)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
392 cbuffer[i] = 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
393 break;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
394 case FN_DIFF0:
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
395 for(i = 0; i < blocksize; i++) {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
396 cbuffer[i] = var_get(resn,this_shn) + coffset;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
397 if (this_shn->vars.fatal_error) {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
398 retval = 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
399 goto got_enough_data;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
400 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
401 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
402 break;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
403 case FN_DIFF1:
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
404 for(i = 0; i < blocksize; i++) {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
405 cbuffer[i] = var_get(resn,this_shn) + cbuffer[i - 1];
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
406 if (this_shn->vars.fatal_error) {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
407 retval = 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
408 goto got_enough_data;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
409 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
410 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
411 break;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
412 case FN_DIFF2:
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
413 for(i = 0; i < blocksize; i++) {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
414 cbuffer[i] = var_get(resn,this_shn) + (2 * cbuffer[i - 1] - cbuffer[i - 2]);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
415 if (this_shn->vars.fatal_error) {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
416 retval = 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
417 goto got_enough_data;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
418 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
419 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
420 break;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
421 case FN_DIFF3:
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
422 for(i = 0; i < blocksize; i++) {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
423 cbuffer[i] = var_get(resn,this_shn) + 3 * (cbuffer[i - 1] - cbuffer[i - 2]) + cbuffer[i - 3];
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
424 if (this_shn->vars.fatal_error) {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
425 retval = 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
426 goto got_enough_data;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
427 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
428 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
429 break;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
430 case FN_QLPC:
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
431 nlpc = uvar_get(LPCQSIZE,this_shn);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
432 if (this_shn->vars.fatal_error) {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
433 retval = 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
434 goto got_enough_data;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
435 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
436
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
437 for(i = 0; i < nlpc; i++) {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
438 qlpc[i] = var_get(LPCQUANT,this_shn);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
439 if (this_shn->vars.fatal_error) {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
440 retval = 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
441 goto got_enough_data;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
442 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
443 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
444 for(i = 0; i < nlpc; i++)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
445 cbuffer[i - nlpc] -= coffset;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
446 for(i = 0; i < blocksize; i++)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
447 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
448 slong sum = lpcqoffset;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
449
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
450 for(j = 0; j < nlpc; j++)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
451 sum += qlpc[j] * cbuffer[i - j - 1];
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
452 cbuffer[i] = var_get(resn,this_shn) + (sum >> LPCQUANT);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
453 if (this_shn->vars.fatal_error) {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
454 retval = 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
455 goto got_enough_data;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
456 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
457 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
458 if(coffset != 0)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
459 for(i = 0; i < blocksize; i++)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
460 cbuffer[i] += coffset;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
461 break;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
462 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
463
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
464 /* store mean value if appropriate : N.B. Duplicated code */
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
465 if(nmean > 0)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
466 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
467 slong sum = (version < 2) ? 0 : blocksize / 2;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
468
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
469 for(i = 0; i < blocksize; i++)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
470 sum += cbuffer[i];
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
471
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
472 for(i = 1; i < nmean; i++)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
473 offset[chan][i - 1] = offset[chan][i];
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
474 if(version < 2)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
475 offset[chan][nmean - 1] = sum / blocksize;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
476 else
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
477 offset[chan][nmean - 1] = (sum / blocksize) << bitshift;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
478 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
479
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
480 if (0 == chan) {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
481 this_shn->vars.initial_file_position = this_shn->vars.last_file_position_no_really;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
482 goto got_enough_data;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
483 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
484
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
485 /* do the wrap */
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
486 for(i = -nwrap; i < 0; i++)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
487 cbuffer[i] = cbuffer[i + blocksize];
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
488
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
489 fix_bitshift(cbuffer, blocksize, bitshift, internal_ftype);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
490
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
491 if(chan == nchan - 1)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
492 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
493 fwrite_type(buffer, ftype, nchan, blocksize, this_shn);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
494 this_shn->vars.bytes_in_buf = 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
495 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
496
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
497 chan = (chan + 1) % nchan;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
498 break;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
499 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
500 break;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
501
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
502 case FN_BLOCKSIZE:
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
503 UINT_GET((int) (log((double) blocksize) / M_LN2), this_shn);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
504 break;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
505
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
506 case FN_VERBATIM:
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
507 cklen = uvar_get(VERBATIM_CKSIZE_SIZE,this_shn);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
508
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
509 while (cklen--) {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
510 if (this_shn->vars.bytes_in_header >= OUT_BUFFER_SIZE) {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
511 shn_debug("Unexpectedly large header - " PACKAGE " can only handle a maximum of %d bytes",OUT_BUFFER_SIZE);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
512 goto got_enough_data;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
513 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
514 this_shn->vars.bytes_in_buf = 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
515 this_shn->vars.header[this_shn->vars.bytes_in_header++] = (char)uvar_get(VERBATIM_BYTE_SIZE,this_shn);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
516 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
517 retval = 1;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
518 break;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
519
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
520 case FN_BITSHIFT:
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
521 bitshift = uvar_get(BITSHIFTSIZE,this_shn);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
522 this_shn->vars.actual_bitshift = bitshift;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
523 break;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
524
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
525 default:
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
526 goto got_enough_data;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
527 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
528 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
529
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
530 got_enough_data:
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
531
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
532 /* wind up */
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
533 var_get_quit(this_shn);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
534 fwrite_type_quit(this_shn);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
535
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
536 if (buffer) free((void *) buffer);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
537 if (offset) free((void *) offset);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
538 if(maxnlpc > 0 && qlpc)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
539 free((void *) qlpc);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
540
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
541 this_shn->vars.bytes_in_buf = 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
542
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
543 return retval;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
544 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
545
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
546 void shn_unload(shn_file *this_shn)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
547 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
548 int this_shn_is_shnfile = (this_shn == shnfile) ? 1 : 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
549
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
550 if (this_shn)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
551 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
552 if (this_shn->vars.fd)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
553 {
|
1978
|
554 aud_vfs_fclose(this_shn->vars.fd);
|
1305
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
555 this_shn->vars.fd = NULL;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
556 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
557
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
558 if (this_shn->decode_state)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
559 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
560 if (this_shn->decode_state->getbuf)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
561 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
562 free(this_shn->decode_state->getbuf);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
563 this_shn->decode_state->getbuf = NULL;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
564 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
565
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
566 if (this_shn->decode_state->writebuf)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
567 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
568 free(this_shn->decode_state->writebuf);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
569 this_shn->decode_state->writebuf = NULL;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
570 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
571
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
572 if (this_shn->decode_state->writefub)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
573 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
574 free(this_shn->decode_state->writefub);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
575 this_shn->decode_state->writefub = NULL;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
576 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
577
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
578 free(this_shn->decode_state);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
579 this_shn->decode_state = NULL;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
580 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
581
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
582 if (this_shn->seek_table)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
583 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
584 free(this_shn->seek_table);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
585 this_shn->seek_table = NULL;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
586 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
587
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
588 free(this_shn);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
589 this_shn = NULL;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
590 if (this_shn_is_shnfile)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
591 shnfile = NULL;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
592 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
593 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
594
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
595 shn_file *load_shn(InputPlayback *playback, char *filename, VFSFile *fd)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
596 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
597 shn_file *tmp_file;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
598 shn_seek_entry *first_seek_table;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
599
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
600 shn_debug("Loading file: '%s'", filename);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
601
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
602 if (!(tmp_file = malloc(sizeof(shn_file))))
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
603 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
604 shn_debug("Could not allocate memory for SHN data structure");
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
605 return NULL;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
606 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
607
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
608 memset(tmp_file, 0, sizeof(shn_file));
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
609
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
610 tmp_file->vars.fd = NULL;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
611 tmp_file->vars.seek_to = -1;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
612 tmp_file->vars.eof = 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
613 tmp_file->vars.going = 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
614 tmp_file->vars.playback = playback;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
615 tmp_file->vars.seek_table_entries = NO_SEEK_TABLE;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
616 tmp_file->vars.bytes_in_buf = 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
617 tmp_file->vars.bytes_in_header = 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
618 tmp_file->vars.reading_function_code = 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
619 tmp_file->vars.initial_file_position = 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
620 tmp_file->vars.last_file_position = 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
621 tmp_file->vars.last_file_position_no_really = 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
622 tmp_file->vars.bytes_read = 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
623 tmp_file->vars.actual_bitshift = 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
624 tmp_file->vars.actual_maxnlpc = 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
625 tmp_file->vars.actual_nmean = 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
626 tmp_file->vars.actual_nchan = 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
627 tmp_file->vars.seek_offset = 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
628
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
629 tmp_file->decode_state = NULL;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
630
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
631 tmp_file->wave_header.filename = filename;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
632 tmp_file->wave_header.wave_format = 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
633 tmp_file->wave_header.channels = 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
634 tmp_file->wave_header.block_align = 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
635 tmp_file->wave_header.bits_per_sample = 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
636 tmp_file->wave_header.samples_per_sec = 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
637 tmp_file->wave_header.avg_bytes_per_sec = 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
638 tmp_file->wave_header.rate = 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
639 tmp_file->wave_header.header_size = 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
640 tmp_file->wave_header.data_size = 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
641 tmp_file->wave_header.file_has_id3v2_tag = 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
642 tmp_file->wave_header.id3v2_tag_size = 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
643
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
644 tmp_file->seek_header.version = NO_SEEK_TABLE;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
645 tmp_file->seek_header.shnFileSize = 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
646
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
647 tmp_file->seek_trailer.seekTableSize = 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
648
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
649 tmp_file->seek_table = NULL;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
650
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
651 if (!fd)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
652 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
653 if (!(tmp_file->vars.fd = shn_open_and_discard_id3v2_tag(filename,&tmp_file->wave_header.file_has_id3v2_tag,&tmp_file->wave_header.id3v2_tag_size)))
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
654 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
655 shn_debug("Could not open file: '%s'",filename);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
656 shn_unload(tmp_file);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
657 return NULL;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
658 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
659 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
660 else
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
661 tmp_file->vars.fd = fd;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
662
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
663 if (0 == get_wave_header(tmp_file))
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
664 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
665 shn_debug("Unable to read WAVE header from file '%s'",filename);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
666 shn_unload(tmp_file);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
667 return NULL;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
668 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
669
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
670 if (tmp_file->wave_header.file_has_id3v2_tag)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
671 {
|
1978
|
672 aud_vfs_fseek(tmp_file->vars.fd,tmp_file->wave_header.id3v2_tag_size,SEEK_SET);
|
1305
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
673 tmp_file->vars.bytes_read += tmp_file->wave_header.id3v2_tag_size;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
674 tmp_file->vars.seek_offset = tmp_file->wave_header.id3v2_tag_size;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
675 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
676 else
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
677 {
|
1978
|
678 aud_vfs_fseek(tmp_file->vars.fd,0,SEEK_SET);
|
1305
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
679 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
680
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
681 if (0 == shn_verify_header(tmp_file))
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
682 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
683 shn_debug("Invalid WAVE header in file: '%s'",filename);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
684 shn_unload(tmp_file);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
685 return NULL;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
686 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
687
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
688 if (tmp_file->decode_state)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
689 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
690 free(tmp_file->decode_state);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
691 tmp_file->decode_state = NULL;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
692 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
693
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
694 shn_load_seek_table(tmp_file,filename);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
695
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
696 if (NO_SEEK_TABLE != tmp_file->vars.seek_table_entries)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
697 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
698 /* verify seek tables */
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
699
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
700 first_seek_table = (shn_seek_entry *)tmp_file->seek_table;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
701
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
702 if (tmp_file->vars.actual_bitshift != shn_uchar_to_ushort_le(first_seek_table->data+22))
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
703 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
704 /* initial bitshift value in the file does not match the first bitshift value of the first seektable entry - seeking is broken */
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
705 shn_debug("Broken seek table detected (invalid bitshift) - seeking disabled for this file.");
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
706 tmp_file->vars.seek_table_entries = NO_SEEK_TABLE;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
707 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
708 else if (tmp_file->vars.actual_nchan > 2)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
709 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
710 /* nchan is greater than the number of such entries stored in a seek table entry - seeking won't work */
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
711 shn_debug("Broken seek table detected (nchan %d not in range [1 .. 2]) - seeking disabled for this file.",tmp_file->vars.actual_nchan);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
712 tmp_file->vars.seek_table_entries = NO_SEEK_TABLE;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
713 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
714 else if (tmp_file->vars.actual_maxnlpc > 3)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
715 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
716 /* maxnlpc is greater than the number of such entries stored in a seek table entry - seeking won't work */
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
717 shn_debug("Broken seek table detected (maxnlpc %d not in range [0 .. 3]) - seeking disabled for this file.",tmp_file->vars.actual_maxnlpc);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
718 tmp_file->vars.seek_table_entries = NO_SEEK_TABLE;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
719 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
720 else if (tmp_file->vars.actual_nmean > 4)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
721 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
722 /* nmean is greater than the number of such entries stored in a seek table entry - seeking won't work */
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
723 shn_debug("Broken seek table detected (nmean %d not in range [0 .. 4]) - seeking disabled for this file.",tmp_file->vars.actual_nmean);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
724 tmp_file->vars.seek_table_entries = NO_SEEK_TABLE;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
725 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
726 else
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
727 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
728 /* seek table appears to be valid - now adjust byte offsets in seek table to match the file */
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
729 tmp_file->vars.seek_offset += tmp_file->vars.initial_file_position - shn_uchar_to_ulong_le(first_seek_table->data+8);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
730
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
731 if (0 != tmp_file->vars.seek_offset)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
732 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
733 shn_debug("Adjusting seek table offsets by %ld bytes due to mismatch between seek table values and input file - seeking might not work correctly.",
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
734 tmp_file->vars.seek_offset);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
735 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
736 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
737 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
738
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
739 shn_debug("Successfully loaded file: '%s'",filename);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
740
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
741 return tmp_file;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
742 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
743
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
744 static int shn_is_our_fd(char *fn, VFSFile *fd)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
745 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
746 char data[4];
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
747
|
1978
|
748 if (aud_vfs_fread((void *)data,1,4,fd) != 4)
|
1305
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
749 return FALSE;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
750
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
751 if (memcmp(data,MAGIC,4))
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
752 return FALSE;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
753
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
754 #if 0
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
755 if (!(tmp_file = load_shn(NULL, filename, fd)))
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
756 return FALSE;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
757
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
758 shn_unload(tmp_file);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
759 #endif
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
760
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
761 return TRUE;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
762 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
763
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
764 void swap_bytes(shn_file *this_shn,int bytes)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
765 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
766 int i;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
767 uchar tmp;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
768
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
769 for (i=0;i<bytes;i=i+2) {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
770 tmp = this_shn->vars.buffer[i+1];
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
771 this_shn->vars.buffer[i+1] = this_shn->vars.buffer[i];
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
772 this_shn->vars.buffer[i] = tmp;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
773 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
774 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
775
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
776 void write_and_wait(shn_file *this_shn,int block_size)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
777 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
778 int bytes_to_write,bytes_in_block,i;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
779 InputPlayback *playback = this_shn->vars.playback;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
780
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
781 if (this_shn->vars.bytes_in_buf < block_size)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
782 return;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
783
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
784 bytes_in_block = min(this_shn->vars.bytes_in_buf, block_size);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
785
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
786 if (bytes_in_block <= 0)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
787 return;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
788
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
789 bytes_to_write = bytes_in_block;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
790 while ((bytes_to_write + bytes_in_block) <= this_shn->vars.bytes_in_buf)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
791 bytes_to_write += bytes_in_block;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
792
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
793 shn_ip.add_vis_pcm(shn_ip.output->written_time(), (this_shn->wave_header.bits_per_sample == 16) ? FMT_S16_LE : FMT_U8,
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
794 this_shn->wave_header.channels, bytes_to_write, this_shn->vars.buffer);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
795
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
796 while(shn_ip.output->buffer_free() < bytes_to_write && playback->playing && this_shn->vars.seek_to == -1)
|
1676
|
797 g_usleep(10000);
|
1305
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
798
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
799 if(playback->playing && this_shn->vars.seek_to == -1) {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
800 if (shn_cfg.swap_bytes)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
801 swap_bytes(this_shn, bytes_to_write);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
802 shn_ip.output->write_audio(this_shn->vars.buffer, bytes_to_write);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
803 } else
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
804 return;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
805
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
806 /* shift data from end of buffer to the front */
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
807 this_shn->vars.bytes_in_buf -= bytes_to_write;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
808
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
809 for(i=0;i<this_shn->vars.bytes_in_buf;i++)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
810 this_shn->vars.buffer[i] = this_shn->vars.buffer[i+bytes_to_write];
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
811 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
812
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
813 static void *play_loop_shn(void *arg)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
814 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
815 slong **buffer = NULL, **offset = NULL;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
816 slong lpcqoffset = 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
817 int version = FORMAT_VERSION, bitshift = 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
818 int ftype = TYPE_EOF;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
819 char *magic = MAGIC;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
820 int blocksize = DEFAULT_BLOCK_SIZE, nchan = DEFAULT_NCHAN;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
821 int i, chan, nwrap, nskip = DEFAULT_NSKIP;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
822 int *qlpc = NULL, maxnlpc = DEFAULT_MAXNLPC, nmean = UNDEFINED_UINT;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
823 int cmd;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
824 int internal_ftype;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
825 shn_file *this_shn = shnfile;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
826 int blk_size;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
827 int cklen;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
828 uchar tmp;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
829 ulong seekto_offset;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
830 InputPlayback *playback = this_shn->vars.playback;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
831
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
832 restart:
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
833
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
834 this_shn->vars.bytes_in_buf = 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
835
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
836 if (!init_decode_state(this_shn))
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
837 goto exit_thread;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
838
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
839 blk_size = 512 * (this_shn->wave_header.bits_per_sample / 8) * this_shn->wave_header.channels;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
840
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
841 /***********************/
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
842 /* EXTRACT starts here */
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
843 /***********************/
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
844
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
845 /* read magic number */
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
846 #ifdef STRICT_FORMAT_COMPATABILITY
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
847 if(FORMAT_VERSION < 2)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
848 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
849 for(i = 0; i < strlen(magic); i++)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
850 if(getc_exit(this_shn->vars.fd) != magic[i]) {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
851 shn_error_fatal(this_shn,"Bad magic number");
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
852 goto exit_thread;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
853 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
854
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
855 /* get version number */
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
856 version = getc_exit(this_shn->vars.fd);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
857 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
858 else
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
859 #endif /* STRICT_FORMAT_COMPATABILITY */
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
860 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
861 int nscan = 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
862
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
863 version = MAX_VERSION + 1;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
864 while(version > MAX_VERSION)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
865 {
|
1978
|
866 int byte = aud_vfs_getc(this_shn->vars.fd);
|
1305
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
867 if(byte == EOF) {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
868 shn_error_fatal(this_shn,"No magic number");
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
869 goto exit_thread;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
870 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
871 if(magic[nscan] != '\0' && byte == magic[nscan])
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
872 nscan++;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
873 else
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
874 if(magic[nscan] == '\0' && byte <= MAX_VERSION)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
875 version = byte;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
876 else
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
877 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
878 if(byte == magic[0])
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
879 nscan = 1;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
880 else
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
881 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
882 nscan = 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
883 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
884 version = MAX_VERSION + 1;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
885 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
886 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
887 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
888
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
889 /* check version number */
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
890 if(version > MAX_SUPPORTED_VERSION) {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
891 shn_error_fatal(this_shn,"Can't decode version %d", version);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
892 goto exit_thread;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
893 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
894
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
895 /* set up the default nmean, ignoring the command line state */
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
896 nmean = (version < 2) ? DEFAULT_V0NMEAN : DEFAULT_V2NMEAN;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
897
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
898 /* initialise the variable length file read for the compressed stream */
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
899 var_get_init(this_shn);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
900 if (this_shn->vars.fatal_error)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
901 goto exit_thread;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
902
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
903 /* initialise the fixed length file write for the uncompressed stream */
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
904 fwrite_type_init(this_shn);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
905
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
906 /* get the internal file type */
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
907 internal_ftype = UINT_GET(TYPESIZE, this_shn);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
908
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
909 /* has the user requested a change in file type? */
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
910 if(internal_ftype != ftype) {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
911 if(ftype == TYPE_EOF)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
912 ftype = internal_ftype; /* no problems here */
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
913 else /* check that the requested conversion is valid */
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
914 if(internal_ftype == TYPE_AU1 || internal_ftype == TYPE_AU2 ||
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
915 internal_ftype == TYPE_AU3 || ftype == TYPE_AU1 ||ftype == TYPE_AU2 || ftype == TYPE_AU3) {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
916 shn_error_fatal(this_shn,"Not able to perform requested output format conversion");
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
917 goto cleanup;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
918 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
919 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
920
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
921 nchan = UINT_GET(CHANSIZE, this_shn);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
922
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
923 /* get blocksize if version > 0 */
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
924 if(version > 0)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
925 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
926 int byte;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
927 blocksize = UINT_GET((int) (log((double) DEFAULT_BLOCK_SIZE) / M_LN2),this_shn);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
928 maxnlpc = UINT_GET(LPCQSIZE, this_shn);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
929 nmean = UINT_GET(0, this_shn);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
930 nskip = UINT_GET(NSKIPSIZE, this_shn);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
931 for(i = 0; i < nskip; i++)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
932 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
933 byte = uvar_get(XBYTESIZE,this_shn);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
934 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
935 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
936 else
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
937 blocksize = DEFAULT_BLOCK_SIZE;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
938
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
939 nwrap = MAX(NWRAP, maxnlpc);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
940
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
941 /* grab some space for the input buffer */
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
942 buffer = long2d((ulong) nchan, (ulong) (blocksize + nwrap),this_shn);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
943 if (this_shn->vars.fatal_error)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
944 goto exit_thread;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
945 offset = long2d((ulong) nchan, (ulong) MAX(1, nmean),this_shn);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
946 if (this_shn->vars.fatal_error) {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
947 if (buffer) {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
948 free(buffer);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
949 buffer = NULL;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
950 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
951 goto exit_thread;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
952 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
953
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
954 for(chan = 0; chan < nchan; chan++)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
955 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
956 for(i = 0; i < nwrap; i++)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
957 buffer[chan][i] = 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
958 buffer[chan] += nwrap;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
959 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
960
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
961 if(maxnlpc > 0) {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
962 qlpc = (int*) pmalloc((ulong) (maxnlpc * sizeof(*qlpc)),this_shn);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
963 if (this_shn->vars.fatal_error) {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
964 if (buffer) {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
965 free(buffer);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
966 buffer = NULL;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
967 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
968 if (offset) {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
969 free(offset);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
970 buffer = NULL;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
971 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
972 goto exit_thread;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
973 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
974 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
975
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
976 if(version > 1)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
977 lpcqoffset = V2LPCQOFFSET;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
978
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
979 init_offset(offset, nchan, MAX(1, nmean), internal_ftype);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
980
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
981 /* get commands from file and execute them */
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
982 chan = 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
983 while(1)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
984 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
985 cmd = uvar_get(FNSIZE,this_shn);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
986 if (this_shn->vars.fatal_error)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
987 goto cleanup;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
988
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
989 switch(cmd)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
990 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
991 case FN_ZERO:
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
992 case FN_DIFF0:
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
993 case FN_DIFF1:
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
994 case FN_DIFF2:
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
995 case FN_DIFF3:
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
996 case FN_QLPC:
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
997 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
998 slong coffset, *cbuffer = buffer[chan];
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
999 int resn = 0, nlpc, j;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1000
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1001 if(cmd != FN_ZERO)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1002 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1003 resn = uvar_get(ENERGYSIZE,this_shn);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1004 if (this_shn->vars.fatal_error)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1005 goto cleanup;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1006 /* this is a hack as version 0 differed in definition of var_get */
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1007 if(version == 0)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1008 resn--;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1009 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1010
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1011 /* find mean offset : N.B. this code duplicated */
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1012 if(nmean == 0)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1013 coffset = offset[chan][0];
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1014 else
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1015 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1016 slong sum = (version < 2) ? 0 : nmean / 2;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1017 for(i = 0; i < nmean; i++)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1018 sum += offset[chan][i];
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1019 if(version < 2)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1020 coffset = sum / nmean;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1021 else
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1022 coffset = ROUNDEDSHIFTDOWN(sum / nmean, bitshift);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1023 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1024
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1025 switch(cmd)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1026 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1027 case FN_ZERO:
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1028 for(i = 0; i < blocksize; i++)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1029 cbuffer[i] = 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1030 break;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1031 case FN_DIFF0:
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1032 for(i = 0; i < blocksize; i++) {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1033 cbuffer[i] = var_get(resn,this_shn) + coffset;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1034 if (this_shn->vars.fatal_error)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1035 goto cleanup;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1036 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1037 break;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1038 case FN_DIFF1:
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1039 for(i = 0; i < blocksize; i++) {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1040 cbuffer[i] = var_get(resn,this_shn) + cbuffer[i - 1];
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1041 if (this_shn->vars.fatal_error)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1042 goto cleanup;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1043 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1044 break;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1045 case FN_DIFF2:
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1046 for(i = 0; i < blocksize; i++) {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1047 cbuffer[i] = var_get(resn,this_shn) + (2 * cbuffer[i - 1] - cbuffer[i - 2]);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1048 if (this_shn->vars.fatal_error)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1049 goto cleanup;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1050 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1051 break;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1052 case FN_DIFF3:
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1053 for(i = 0; i < blocksize; i++) {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1054 cbuffer[i] = var_get(resn,this_shn) + 3 * (cbuffer[i - 1] - cbuffer[i - 2]) + cbuffer[i - 3];
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1055 if (this_shn->vars.fatal_error)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1056 goto cleanup;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1057 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1058 break;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1059 case FN_QLPC:
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1060 nlpc = uvar_get(LPCQSIZE,this_shn);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1061 if (this_shn->vars.fatal_error)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1062 goto cleanup;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1063
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1064 for(i = 0; i < nlpc; i++) {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1065 qlpc[i] = var_get(LPCQUANT,this_shn);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1066 if (this_shn->vars.fatal_error)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1067 goto cleanup;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1068 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1069 for(i = 0; i < nlpc; i++)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1070 cbuffer[i - nlpc] -= coffset;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1071 for(i = 0; i < blocksize; i++)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1072 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1073 slong sum = lpcqoffset;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1074
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1075 for(j = 0; j < nlpc; j++)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1076 sum += qlpc[j] * cbuffer[i - j - 1];
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1077 cbuffer[i] = var_get(resn,this_shn) + (sum >> LPCQUANT);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1078 if (this_shn->vars.fatal_error)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1079 goto cleanup;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1080 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1081 if(coffset != 0)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1082 for(i = 0; i < blocksize; i++)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1083 cbuffer[i] += coffset;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1084 break;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1085 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1086
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1087 /* store mean value if appropriate : N.B. Duplicated code */
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1088 if(nmean > 0)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1089 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1090 slong sum = (version < 2) ? 0 : blocksize / 2;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1091
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1092 for(i = 0; i < blocksize; i++)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1093 sum += cbuffer[i];
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1094
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1095 for(i = 1; i < nmean; i++)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1096 offset[chan][i - 1] = offset[chan][i];
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1097 if(version < 2)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1098 offset[chan][nmean - 1] = sum / blocksize;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1099 else
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1100 offset[chan][nmean - 1] = (sum / blocksize) << bitshift;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1101 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1102
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1103 /* do the wrap */
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1104 for(i = -nwrap; i < 0; i++)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1105 cbuffer[i] = cbuffer[i + blocksize];
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1106
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1107 fix_bitshift(cbuffer, blocksize, bitshift, internal_ftype);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1108
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1109 if(chan == nchan - 1)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1110 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1111 if (!playback->playing || this_shn->vars.fatal_error)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1112 goto cleanup;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1113
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1114 fwrite_type(buffer, ftype, nchan, blocksize, this_shn);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1115
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1116 write_and_wait(this_shn,blk_size);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1117
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1118 if (this_shn->vars.seek_to != -1)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1119 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1120 shn_seek_entry *seek_info;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1121 int j;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1122
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1123 shn_debug("Seeking to %d:%02d",this_shn->vars.seek_to/60,this_shn->vars.seek_to%60);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1124
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1125 seek_info = shn_seek_entry_search(this_shn->seek_table,this_shn->vars.seek_to * (ulong)this_shn->wave_header.samples_per_sec,0,
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1126 (ulong)(this_shn->vars.seek_table_entries - 1),this_shn->vars.seek_resolution);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1127
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1128 /* loop through number of channels in this file */
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1129 for (i=0;i<nchan;i++) {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1130 /* load the three sample buffer values for this channel */
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1131 for (j=0;j<3;j++)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1132 buffer[i][j-3] = shn_uchar_to_slong_le(seek_info->data+32+12*i-4*j);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1133
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1134 /* load the variable number of offset history values for this channel */
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1135 for (j=0;j<MAX(1,nmean);j++)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1136 offset[i][j] = shn_uchar_to_slong_le(seek_info->data+48+16*i+4*j);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1137 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1138
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1139 bitshift = shn_uchar_to_ushort_le(seek_info->data+22);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1140
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1141 seekto_offset = shn_uchar_to_ulong_le(seek_info->data+8) + this_shn->vars.seek_offset;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1142
|
1978
|
1143 aud_vfs_fseek(this_shn->vars.fd,(slong)seekto_offset,SEEK_SET);
|
|
1144 aud_vfs_fread((uchar*) this_shn->decode_state->getbuf, 1, BUFSIZ, this_shn->vars.fd);
|
1305
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1145
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1146 this_shn->decode_state->getbufp = this_shn->decode_state->getbuf + shn_uchar_to_ushort_le(seek_info->data+14);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1147 this_shn->decode_state->nbitget = shn_uchar_to_ushort_le(seek_info->data+16);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1148 this_shn->decode_state->nbyteget = shn_uchar_to_ushort_le(seek_info->data+12);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1149 this_shn->decode_state->gbuffer = shn_uchar_to_ulong_le(seek_info->data+18);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1150
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1151 this_shn->vars.bytes_in_buf = 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1152
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1153 shn_ip.output->flush(this_shn->vars.seek_to * 1000);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1154 this_shn->vars.seek_to = -1;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1155 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1156
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1157 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1158 chan = (chan + 1) % nchan;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1159 break;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1160 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1161
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1162 break;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1163
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1164 case FN_QUIT:
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1165 /* empty out last of buffer */
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1166 write_and_wait(this_shn,this_shn->vars.bytes_in_buf);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1167
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1168 playback->eof = TRUE;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1169
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1170 while (1)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1171 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1172 if (!playback->playing)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1173 goto finish;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1174 if (this_shn->vars.seek_to != -1)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1175 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1176 var_get_quit(this_shn);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1177 fwrite_type_quit(this_shn);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1178
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1179 if (buffer) free((void *) buffer);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1180 if (offset) free((void *) offset);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1181 if(maxnlpc > 0 && qlpc)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1182 free((void *) qlpc);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1183
|
1978
|
1184 aud_vfs_fseek(this_shn->vars.fd,0,SEEK_SET);
|
1305
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1185 goto restart;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1186 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1187 else
|
1676
|
1188 g_usleep(10000);
|
1305
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1189 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1190
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1191 goto cleanup;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1192 break;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1193
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1194 case FN_BLOCKSIZE:
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1195 blocksize = UINT_GET((int) (log((double) blocksize) / M_LN2), this_shn);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1196 if (this_shn->vars.fatal_error)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1197 goto cleanup;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1198 break;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1199 case FN_BITSHIFT:
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1200 bitshift = uvar_get(BITSHIFTSIZE,this_shn);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1201 if (this_shn->vars.fatal_error)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1202 goto cleanup;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1203 break;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1204 case FN_VERBATIM:
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1205 cklen = uvar_get(VERBATIM_CKSIZE_SIZE,this_shn);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1206 if (this_shn->vars.fatal_error)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1207 goto cleanup;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1208
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1209 while (cklen--) {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1210 tmp = (uchar)uvar_get(VERBATIM_BYTE_SIZE,this_shn);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1211 if (this_shn->vars.fatal_error)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1212 goto cleanup;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1213 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1214
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1215 break;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1216
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1217 default:
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1218 shn_error_fatal(this_shn,"Sanity check fails trying to decode function: %d",cmd);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1219 goto cleanup;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1220 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1221 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1222
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1223 cleanup:
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1224
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1225 write_and_wait(this_shn,this_shn->vars.bytes_in_buf);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1226 shn_ip.output->buffer_free();
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1227 shn_ip.output->buffer_free();
|
1676
|
1228 g_usleep(10000);
|
1305
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1229
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1230 finish:
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1231
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1232 this_shn->vars.seek_to = -1;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1233 playback->eof = TRUE;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1234
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1235 /* wind up */
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1236 var_get_quit(this_shn);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1237 fwrite_type_quit(this_shn);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1238
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1239 if (buffer) free((void *) buffer);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1240 if (offset) free((void *) offset);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1241 if(maxnlpc > 0 && qlpc)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1242 free((void *) qlpc);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1243
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1244 exit_thread:
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1245
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1246 pthread_exit(NULL);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1247 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1248
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1249 static void shn_play(InputPlayback *playback)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1250 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1251 char *name, *temp;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1252 char *filename = playback->filename;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1253
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1254 audio_error = FALSE;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1255
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1256 if (!(shnfile = load_shn(playback, playback->filename, NULL)))
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1257 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1258 shn_debug("Could not load file for playing: '%s'", playback->filename);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1259 return;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1260 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1261
|
1978
|
1262 aud_vfs_fseek(shnfile->vars.fd,0,SEEK_SET);
|
1305
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1263
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1264 playback->playing = TRUE;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1265
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1266 if (shn_ip.output->open_audio((shnfile->wave_header.bits_per_sample == 16) ? FMT_S16_LE : FMT_U8, shnfile->wave_header.samples_per_sec, shnfile->wave_header.channels) == 0)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1267 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1268 audio_error = TRUE;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1269 shn_debug("Could not open audio device for playback (check your output plugin configuration)");
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1270 return;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1271 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1272 temp = strrchr(filename, '/');
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1273 if (!temp)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1274 temp = filename;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1275 else
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1276 temp++;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1277 name = malloc(strlen(temp) + 1);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1278 strcpy(name, temp);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1279 if (shn_filename_contains_a_dot(name))
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1280 *(strrchr(name,'.')) = '\0';
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1281 shn_ip.set_info(name, 1000 * shnfile->wave_header.length, 8 * shnfile->wave_header.rate, shnfile->wave_header.samples_per_sec, shnfile->wave_header.channels);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1282 free(name);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1283 shnfile->vars.seek_to = -1;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1284 pthread_create(&decode_thread, NULL, play_loop_shn, NULL);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1285 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1286
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1287 static void shn_stop(InputPlayback *playback)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1288 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1289 int was_fatal;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1290 char error_msg[BUF_SIZE];
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1291
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1292 if (!shnfile)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1293 return;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1294
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1295 if ((was_fatal = shnfile->vars.fatal_error))
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1296 shn_snprintf(error_msg,BUF_SIZE,"%s.\nAffected file was:\n%s",shnfile->vars.fatal_error_msg,shnfile->wave_header.filename);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1297
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1298 if (playback->playing || was_fatal)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1299 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1300 playback->playing = FALSE;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1301 pthread_join(decode_thread, NULL);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1302 shn_ip.output->close_audio();
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1303 shn_unload(shnfile);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1304 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1305
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1306 if (was_fatal)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1307 shn_error(error_msg);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1308 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1309
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1310 static void shn_pause(InputPlayback *playback, short p)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1311 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1312 playback->output->pause(p);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1313 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1314
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1315 static void shn_seek(InputPlayback *playback, int time)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1316 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1317 if (NULL == shnfile)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1318 return;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1319
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1320 if (shnfile->vars.seek_table_entries == NO_SEEK_TABLE)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1321 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1322 shn_error("Cannot seek to %d:%02d because there is no seek information for this file.",time/60,time%60);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1323 return;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1324 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1325
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1326 shnfile->vars.seek_to = time;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1327
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1328 while (shnfile->vars.seek_to != -1)
|
1676
|
1329 g_usleep(10000);
|
1305
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1330 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1331
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1332 static void shn_get_file_info(char *filename, char **title, int *length)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1333 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1334 char *name, *temp;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1335 shn_file *tmp_file;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1336
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1337 temp = strrchr(filename, '/');
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1338 if (!temp)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1339 temp = filename;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1340 else
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1341 temp++;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1342
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1343 name = g_malloc(strlen(temp) + 1);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1344 strcpy(name, temp);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1345
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1346 if (shn_filename_contains_a_dot(name))
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1347 *(strrchr(name,'.')) = '\0';
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1348
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1349 *title = name;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1350
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1351 *length = 0;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1352
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1353 if (!(tmp_file = load_shn(NULL, filename, NULL)))
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1354 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1355 shn_debug("Could not get information from file: '%s'",filename);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1356 return;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1357 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1358
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1359 *length = 1000 * tmp_file->wave_header.length;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1360
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1361 shn_unload(tmp_file);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1362 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1363
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1364 static void shn_display_file_info(char *filename)
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1365 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1366 shn_file *tmp_file;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1367
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1368 if (!(tmp_file = load_shn(NULL, filename, NULL)))
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1369 {
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1370 shn_debug("Could not get information from file: '%s'",filename);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1371 return;
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1372 }
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1373
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1374 shn_display_info(tmp_file);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1375
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1376 shn_unload(tmp_file);
|
William Pitcock <nenolod@atheme-project.org>
parents:
diff
changeset
|
1377 }
|