annotate src/shnplug/shn.c @ 3052:95b34f46a231

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