Mercurial > audlegacy-plugins
annotate src/wavpack/libwavpack.cxx @ 2511:da7e2ec2ea27
Use macro wrapping for Gtk+ v1 vs v2 differences, yet again.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 03 Apr 2008 00:59:00 +0300 |
parents | 4d6045c20cc5 |
children | 769e17da93dd |
rev | line source |
---|---|
2430
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
1 //#define AUD_DEBUG |
2233 | 2 |
1436
0ff7d08693f6
wavpack: update to new tuple API, use std::string more.
William Pitcock <nenolod@atheme-project.org>
parents:
1395
diff
changeset
|
3 #include <string> |
0ff7d08693f6
wavpack: update to new tuple API, use std::string more.
William Pitcock <nenolod@atheme-project.org>
parents:
1395
diff
changeset
|
4 |
109 | 5 #include <assert.h> |
6 #include <string.h> | |
7 #include <stdio.h> | |
8 #include <stdlib.h> | |
9 #include <unistd.h> | |
291
93c0da3f7a86
[svn] - make wavpack/wavpack.h include forced extern "C".
nenolod
parents:
284
diff
changeset
|
10 extern "C" { |
284
72f0de06bb56
[svn] - wavpack/wputils.h is deprecated, wavpack/wavpack.h should be used instead.
nenolod
parents:
264
diff
changeset
|
11 #include <wavpack/wavpack.h> |
109 | 12 #include <audacious/plugin.h> |
111 | 13 #include <audacious/output.h> |
109 | 14 #include <audacious/util.h> |
15 } | |
16 #include <glib.h> | |
17 #include <gtk/gtk.h> | |
18 #include <iconv.h> | |
19 #include <math.h> | |
20 #include "tags.h" | |
434
7385182ae4b8
[svn] - add missing config.h inclusion for wavpack, null and metronom plugin
giacomo
parents:
372
diff
changeset
|
21 #include "../../config.h" |
109 | 22 #ifndef M_LN10 |
23 #define M_LN10 2.3025850929940456840179914546843642 | |
24 #endif | |
25 | |
26 #define BUFFER_SIZE 256 // read buffer size, in samples | |
2429
b6f09d280f2c
Add support for 24-bit wavpack files. (Bugzilla #190)
Michał Lipski <tallica@o2.pl>
parents:
2233
diff
changeset
|
27 #define SAMPLE_SIZE(a) (a == 8 ? sizeof(guint8) : (a == 16 ? sizeof(guint16) : sizeof(guint32))) |
b6f09d280f2c
Add support for 24-bit wavpack files. (Bugzilla #190)
Michał Lipski <tallica@o2.pl>
parents:
2233
diff
changeset
|
28 #define SAMPLE_FMT(a) (a == 8 ? FMT_S8 : (a == 16 ? FMT_S16_NE : (a == 24 ? FMT_S24_NE : FMT_S32_NE))) |
109 | 29 |
30 static void wv_load_config(); | |
2430
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
31 static gint wv_is_our_fd(gchar *filename, VFSFile *file); |
1526
56b0d46a02f6
wavpack: Implement InputPlugin::probe_for_tuple.
William Pitcock <nenolod@atheme-project.org>
parents:
1521
diff
changeset
|
32 static Tuple *wv_probe_for_tuple(gchar *filename, VFSFile *file); |
566 | 33 static void wv_play(InputPlayback *); |
34 static void wv_stop(InputPlayback *); | |
2430
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
35 static void wv_pause(InputPlayback *, gshort); |
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
36 static void wv_seek(InputPlayback *, gint); |
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
37 static gint wv_get_time(InputPlayback *); |
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
38 static void wv_get_song_info(gchar *, gchar **, gint *); |
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
39 static gchar *generate_title(const gchar *, WavpackContext *ctx); |
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
40 static gint isSeek; |
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
41 static gshort paused; |
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
42 static gboolean killDecodeThread; |
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
43 static gboolean AudioError; |
109 | 44 static GThread *thread_handle; |
2430
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
45 static Tuple *wv_get_song_tuple(gchar *); |
109 | 46 |
2430
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
47 // in ui.cxx |
109 | 48 void wv_configure(); |
49 void wv_about_box(void); | |
2430
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
50 void wv_file_info_box(gchar *); |
109 | 51 extern gboolean clipPreventionEnabled; |
52 extern gboolean dynBitrateEnabled; | |
53 extern gboolean replaygainEnabled; | |
54 extern gboolean albumReplaygainEnabled; | |
55 extern gboolean openedAudio; | |
56 | |
1044
b1128efde471
[svn] - get rid of all warnings gcc 4.2.0 emits with my build configuration.
yaz
parents:
566
diff
changeset
|
57 const gchar *wv_fmts[] = { "wv", NULL }; |
372
a157306caf03
[svn] - finalize the plugin-side of the extension-assist ABI
nenolod
parents:
368
diff
changeset
|
58 |
2430
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
59 InputPlugin wvpack = { |
109 | 60 NULL, //handle |
61 NULL, //filename | |
1185 | 62 (gchar *)"WavPack Audio Plugin", |
109 | 63 wv_load_config, |
1620
87a52bc00926
wavpack: I need a rewrite.
William Pitcock <nenolod@atheme.org>
parents:
1526
diff
changeset
|
64 NULL, |
109 | 65 wv_about_box, |
66 wv_configure, | |
1620
87a52bc00926
wavpack: I need a rewrite.
William Pitcock <nenolod@atheme.org>
parents:
1526
diff
changeset
|
67 FALSE, |
332
626f9f4d79a8
[svn] Remove old-style is_our_file() where a new-style is_our_fd() exists
kiyoshi
parents:
291
diff
changeset
|
68 NULL, |
109 | 69 NULL, //no use |
70 wv_play, | |
71 wv_stop, | |
72 wv_pause, | |
73 wv_seek, | |
74 NULL, //set eq | |
75 wv_get_time, | |
76 NULL, //get volume | |
77 NULL, //set volume | |
78 NULL, //cleanup | |
79 NULL, //obsolete | |
80 NULL, //add_vis | |
81 NULL, | |
82 wv_get_song_info, | |
263 | 83 wv_file_info_box, //info box |
109 | 84 NULL, //output |
114 | 85 wv_get_song_tuple, |
253
ab24cfe495e0
[svn] Port to NewVFS file probe & add explicit cast to silence warning, thanks to spb.
chainsaw
parents:
247
diff
changeset
|
86 NULL, |
ab24cfe495e0
[svn] Port to NewVFS file probe & add explicit cast to silence warning, thanks to spb.
chainsaw
parents:
247
diff
changeset
|
87 NULL, |
ab24cfe495e0
[svn] Port to NewVFS file probe & add explicit cast to silence warning, thanks to spb.
chainsaw
parents:
247
diff
changeset
|
88 wv_is_our_fd, |
1044
b1128efde471
[svn] - get rid of all warnings gcc 4.2.0 emits with my build configuration.
yaz
parents:
566
diff
changeset
|
89 (gchar **)wv_fmts, |
1526
56b0d46a02f6
wavpack: Implement InputPlugin::probe_for_tuple.
William Pitcock <nenolod@atheme-project.org>
parents:
1521
diff
changeset
|
90 NULL, // high precision seeking |
56b0d46a02f6
wavpack: Implement InputPlugin::probe_for_tuple.
William Pitcock <nenolod@atheme-project.org>
parents:
1521
diff
changeset
|
91 wv_probe_for_tuple // probe for a tuple |
109 | 92 }; |
93 | |
2430
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
94 gint32 read_bytes (void *id, void *data, gint32 bcount) |
233
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
95 { |
1978 | 96 return aud_vfs_fread (data, 1, bcount, (VFSFile *) id); |
233
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
97 } |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
98 |
2430
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
99 guint32 get_pos (void *id) |
233
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
100 { |
1978 | 101 return aud_vfs_ftell ((VFSFile *) id); |
233
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
102 } |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
103 |
2430
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
104 gint set_pos_abs (void *id, guint32 pos) |
233
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
105 { |
1978 | 106 return aud_vfs_fseek ((VFSFile *) id, pos, SEEK_SET); |
233
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
107 } |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
108 |
2430
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
109 gint set_pos_rel (void *id, gint32 delta, gint mode) |
233
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
110 { |
1978 | 111 return aud_vfs_fseek ((VFSFile *) id, delta, mode); |
233
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
112 } |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
113 |
2430
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
114 gint push_back_byte (void *id, gint c) |
233
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
115 { |
1978 | 116 return aud_vfs_ungetc (c, (VFSFile *) id); |
233
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
117 } |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
118 |
2430
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
119 guint32 get_length (void *id) |
233
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
120 { |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
121 VFSFile *file = (VFSFile *) id; |
2430
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
122 guint32 sz = 0; |
233
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
123 |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
124 if (file == NULL) |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
125 return 0; |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
126 |
1978 | 127 aud_vfs_fseek(file, 0, SEEK_END); |
128 sz = aud_vfs_ftell(file); | |
129 aud_vfs_fseek(file, 0, SEEK_SET); | |
233
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
130 |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
131 return sz; |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
132 } |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
133 |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
134 /* XXX streams?? */ |
2430
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
135 gint can_seek (void *id) |
233
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
136 { |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
137 return 1; |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
138 } |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
139 |
2430
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
140 gint32 write_bytes (void *id, void *data, gint32 bcount) |
233
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
141 { |
1978 | 142 return aud_vfs_fwrite (data, 1, bcount, (VFSFile *) id); |
233
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
143 } |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
144 |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
145 WavpackStreamReader reader = { |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
146 read_bytes, get_pos, set_pos_abs, set_pos_rel, push_back_byte, get_length, can_seek, |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
147 write_bytes |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
148 }; |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
149 |
109 | 150 class WavpackDecoder |
151 { | |
152 public: | |
2430
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
153 InputPlugin *wvpack; |
2429
b6f09d280f2c
Add support for 24-bit wavpack files. (Bugzilla #190)
Michał Lipski <tallica@o2.pl>
parents:
2233
diff
changeset
|
154 gint32 *input; |
b6f09d280f2c
Add support for 24-bit wavpack files. (Bugzilla #190)
Michał Lipski <tallica@o2.pl>
parents:
2233
diff
changeset
|
155 void *output; |
b6f09d280f2c
Add support for 24-bit wavpack files. (Bugzilla #190)
Michał Lipski <tallica@o2.pl>
parents:
2233
diff
changeset
|
156 gint sample_rate; |
b6f09d280f2c
Add support for 24-bit wavpack files. (Bugzilla #190)
Michał Lipski <tallica@o2.pl>
parents:
2233
diff
changeset
|
157 gint num_channels; |
2430
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
158 guint num_samples; |
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
159 guint length; |
2429
b6f09d280f2c
Add support for 24-bit wavpack files. (Bugzilla #190)
Michał Lipski <tallica@o2.pl>
parents:
2233
diff
changeset
|
160 gint bits_per_sample; |
109 | 161 WavpackContext *ctx; |
2430
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
162 gchar error_buff[80]; //string space is allocated by the caller and must be at least 80 chars |
233
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
163 VFSFile *wv_Input, *wvc_Input; |
109 | 164 |
2430
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
165 WavpackDecoder(InputPlugin *wvpack) : wvpack(wvpack) |
109 | 166 { |
167 ctx = NULL; | |
168 input = NULL; | |
169 output = NULL; | |
1520
2ed7413c199a
wavpack fixes
William Pitcock <nenolod@atheme-project.org>
parents:
1501
diff
changeset
|
170 wv_Input = NULL; |
2ed7413c199a
wavpack fixes
William Pitcock <nenolod@atheme-project.org>
parents:
1501
diff
changeset
|
171 wvc_Input = NULL; |
109 | 172 } |
173 | |
174 ~WavpackDecoder() | |
175 { | |
176 if (input != NULL) { | |
177 free(input); | |
178 input = NULL; | |
179 } | |
180 if (output != NULL) { | |
181 free(output); | |
182 output = NULL; | |
183 } | |
184 if (ctx != NULL) { | |
1520
2ed7413c199a
wavpack fixes
William Pitcock <nenolod@atheme-project.org>
parents:
1501
diff
changeset
|
185 if (wv_Input) |
1978 | 186 aud_vfs_fclose(wv_Input); |
1520
2ed7413c199a
wavpack fixes
William Pitcock <nenolod@atheme-project.org>
parents:
1501
diff
changeset
|
187 |
2ed7413c199a
wavpack fixes
William Pitcock <nenolod@atheme-project.org>
parents:
1501
diff
changeset
|
188 if (wvc_Input) |
1978 | 189 aud_vfs_fclose(wvc_Input); |
233
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
190 g_free(ctx); |
109 | 191 ctx = NULL; |
192 } | |
193 } | |
194 | |
2430
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
195 gboolean attach(const gchar *filename) |
109 | 196 { |
1978 | 197 wv_Input = aud_vfs_fopen(filename, "rb"); |
233
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
198 |
2430
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
199 gchar *corrFilename = g_strconcat(filename, "c", NULL); |
233
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
200 |
1978 | 201 wvc_Input = aud_vfs_fopen(corrFilename, "rb"); |
233
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
202 |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
203 g_free(corrFilename); |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
204 |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
205 ctx = WavpackOpenFileInputEx(&reader, wv_Input, wvc_Input, error_buff, OPEN_TAGS | OPEN_WVC, 0); |
109 | 206 |
207 if (ctx == NULL) { | |
208 return false; | |
209 } | |
210 | |
237 | 211 return true; |
212 } | |
213 | |
2430
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
214 gboolean attach(gchar *filename, VFSFile *wvi) |
1501
04f8c7624ea3
Support Wavpack ".exe" executables, by using the Wavpack decoder to validate.
William Pitcock <nenolod@atheme-project.org>
parents:
1465
diff
changeset
|
215 { |
1520
2ed7413c199a
wavpack fixes
William Pitcock <nenolod@atheme-project.org>
parents:
1501
diff
changeset
|
216 ctx = WavpackOpenFileInputEx(&reader, wvi, NULL, error_buff, OPEN_TAGS, 0); |
1501
04f8c7624ea3
Support Wavpack ".exe" executables, by using the Wavpack decoder to validate.
William Pitcock <nenolod@atheme-project.org>
parents:
1465
diff
changeset
|
217 |
04f8c7624ea3
Support Wavpack ".exe" executables, by using the Wavpack decoder to validate.
William Pitcock <nenolod@atheme-project.org>
parents:
1465
diff
changeset
|
218 if (ctx == NULL) |
04f8c7624ea3
Support Wavpack ".exe" executables, by using the Wavpack decoder to validate.
William Pitcock <nenolod@atheme-project.org>
parents:
1465
diff
changeset
|
219 return false; |
04f8c7624ea3
Support Wavpack ".exe" executables, by using the Wavpack decoder to validate.
William Pitcock <nenolod@atheme-project.org>
parents:
1465
diff
changeset
|
220 |
04f8c7624ea3
Support Wavpack ".exe" executables, by using the Wavpack decoder to validate.
William Pitcock <nenolod@atheme-project.org>
parents:
1465
diff
changeset
|
221 return true; |
04f8c7624ea3
Support Wavpack ".exe" executables, by using the Wavpack decoder to validate.
William Pitcock <nenolod@atheme-project.org>
parents:
1465
diff
changeset
|
222 } |
04f8c7624ea3
Support Wavpack ".exe" executables, by using the Wavpack decoder to validate.
William Pitcock <nenolod@atheme-project.org>
parents:
1465
diff
changeset
|
223 |
2430
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
224 gboolean attach_to_play(InputPlayback *playback) |
237 | 225 { |
1989
1bd99632fc4d
wavpack: set_params()
William Pitcock <nenolod@atheme.org>
parents:
1978
diff
changeset
|
226 wv_Input = aud_vfs_fopen(playback->filename, "rb"); |
237 | 227 |
2430
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
228 gchar *corrFilename = g_strconcat(playback->filename, "c", NULL); |
237 | 229 |
1978 | 230 wvc_Input = aud_vfs_fopen(corrFilename, "rb"); |
237 | 231 |
232 g_free(corrFilename); | |
233 | |
234 ctx = WavpackOpenFileInputEx(&reader, wv_Input, wvc_Input, error_buff, OPEN_TAGS | OPEN_WVC, 0); | |
235 | |
1501
04f8c7624ea3
Support Wavpack ".exe" executables, by using the Wavpack decoder to validate.
William Pitcock <nenolod@atheme-project.org>
parents:
1465
diff
changeset
|
236 if (ctx == NULL) |
237 | 237 return false; |
238 | |
109 | 239 sample_rate = WavpackGetSampleRate(ctx); |
240 num_channels = WavpackGetNumChannels(ctx); | |
2429
b6f09d280f2c
Add support for 24-bit wavpack files. (Bugzilla #190)
Michał Lipski <tallica@o2.pl>
parents:
2233
diff
changeset
|
241 bits_per_sample = WavpackGetBitsPerSample(ctx); |
2430
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
242 num_samples = WavpackGetNumSamples(ctx); |
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
243 length = num_samples / sample_rate; |
2429
b6f09d280f2c
Add support for 24-bit wavpack files. (Bugzilla #190)
Michał Lipski <tallica@o2.pl>
parents:
2233
diff
changeset
|
244 input = (gint32 *) malloc(BUFFER_SIZE * num_channels * sizeof(guint32)); |
b6f09d280f2c
Add support for 24-bit wavpack files. (Bugzilla #190)
Michał Lipski <tallica@o2.pl>
parents:
2233
diff
changeset
|
245 output = malloc(BUFFER_SIZE * num_channels * SAMPLE_SIZE(bits_per_sample)); |
2001
aa8bd7b56cda
make wavpack compile again.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1998
diff
changeset
|
246 playback->set_params(playback, generate_title(playback->filename, ctx), |
2430
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
247 length * 1000, |
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
248 (gint) WavpackGetAverageBitrate(ctx, num_channels), |
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
249 (gint) sample_rate, num_channels); |
109 | 250 return true; |
251 } | |
252 | |
2430
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
253 gboolean open_audio() |
109 | 254 { |
2430
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
255 return wvpack->output->open_audio(SAMPLE_FMT(bits_per_sample), sample_rate, num_channels); |
109 | 256 } |
257 | |
2430
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
258 void process_buffer(InputPlayback *playback, guint32 num_samples) |
109 | 259 { |
2430
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
260 guint32 i; |
2429
b6f09d280f2c
Add support for 24-bit wavpack files. (Bugzilla #190)
Michał Lipski <tallica@o2.pl>
parents:
2233
diff
changeset
|
261 gint32* rp = input; |
b6f09d280f2c
Add support for 24-bit wavpack files. (Bugzilla #190)
Michał Lipski <tallica@o2.pl>
parents:
2233
diff
changeset
|
262 gint8* wp = reinterpret_cast<gint8*>(output); |
b6f09d280f2c
Add support for 24-bit wavpack files. (Bugzilla #190)
Michał Lipski <tallica@o2.pl>
parents:
2233
diff
changeset
|
263 gint16* wp2 = reinterpret_cast<gint16*>(output); |
b6f09d280f2c
Add support for 24-bit wavpack files. (Bugzilla #190)
Michał Lipski <tallica@o2.pl>
parents:
2233
diff
changeset
|
264 gint32* wp4 = reinterpret_cast<gint32*>(output); |
b6f09d280f2c
Add support for 24-bit wavpack files. (Bugzilla #190)
Michał Lipski <tallica@o2.pl>
parents:
2233
diff
changeset
|
265 |
b6f09d280f2c
Add support for 24-bit wavpack files. (Bugzilla #190)
Michał Lipski <tallica@o2.pl>
parents:
2233
diff
changeset
|
266 if (bits_per_sample % 8 != 0) { |
b6f09d280f2c
Add support for 24-bit wavpack files. (Bugzilla #190)
Michał Lipski <tallica@o2.pl>
parents:
2233
diff
changeset
|
267 AUDDBG("Can not convert to %d bps: not a multiple of 8\n", bits_per_sample); |
b6f09d280f2c
Add support for 24-bit wavpack files. (Bugzilla #190)
Michał Lipski <tallica@o2.pl>
parents:
2233
diff
changeset
|
268 } |
1501
04f8c7624ea3
Support Wavpack ".exe" executables, by using the Wavpack decoder to validate.
William Pitcock <nenolod@atheme-project.org>
parents:
1465
diff
changeset
|
269 |
2429
b6f09d280f2c
Add support for 24-bit wavpack files. (Bugzilla #190)
Michał Lipski <tallica@o2.pl>
parents:
2233
diff
changeset
|
270 if (bits_per_sample == 8) { |
b6f09d280f2c
Add support for 24-bit wavpack files. (Bugzilla #190)
Michał Lipski <tallica@o2.pl>
parents:
2233
diff
changeset
|
271 for (i=0; i<num_samples * num_channels; i++, wp++, rp++) { |
b6f09d280f2c
Add support for 24-bit wavpack files. (Bugzilla #190)
Michał Lipski <tallica@o2.pl>
parents:
2233
diff
changeset
|
272 *wp = *rp & 0xff; |
b6f09d280f2c
Add support for 24-bit wavpack files. (Bugzilla #190)
Michał Lipski <tallica@o2.pl>
parents:
2233
diff
changeset
|
273 } |
b6f09d280f2c
Add support for 24-bit wavpack files. (Bugzilla #190)
Michał Lipski <tallica@o2.pl>
parents:
2233
diff
changeset
|
274 } else if (bits_per_sample == 16) { |
b6f09d280f2c
Add support for 24-bit wavpack files. (Bugzilla #190)
Michał Lipski <tallica@o2.pl>
parents:
2233
diff
changeset
|
275 for (i=0; i<num_samples * num_channels; i++, wp2++, rp++) { |
b6f09d280f2c
Add support for 24-bit wavpack files. (Bugzilla #190)
Michał Lipski <tallica@o2.pl>
parents:
2233
diff
changeset
|
276 *wp2 = *rp & 0xffff; |
b6f09d280f2c
Add support for 24-bit wavpack files. (Bugzilla #190)
Michał Lipski <tallica@o2.pl>
parents:
2233
diff
changeset
|
277 } |
b6f09d280f2c
Add support for 24-bit wavpack files. (Bugzilla #190)
Michał Lipski <tallica@o2.pl>
parents:
2233
diff
changeset
|
278 } else if (bits_per_sample == 24 || bits_per_sample == 32) { /* 24bit value stored in lowest 3 bytes */ |
b6f09d280f2c
Add support for 24-bit wavpack files. (Bugzilla #190)
Michał Lipski <tallica@o2.pl>
parents:
2233
diff
changeset
|
279 for (i=0; i<num_samples * num_channels; i++, wp4++, rp++) { |
b6f09d280f2c
Add support for 24-bit wavpack files. (Bugzilla #190)
Michał Lipski <tallica@o2.pl>
parents:
2233
diff
changeset
|
280 *wp4 = *rp; |
b6f09d280f2c
Add support for 24-bit wavpack files. (Bugzilla #190)
Michał Lipski <tallica@o2.pl>
parents:
2233
diff
changeset
|
281 } |
b6f09d280f2c
Add support for 24-bit wavpack files. (Bugzilla #190)
Michał Lipski <tallica@o2.pl>
parents:
2233
diff
changeset
|
282 } |
b6f09d280f2c
Add support for 24-bit wavpack files. (Bugzilla #190)
Michał Lipski <tallica@o2.pl>
parents:
2233
diff
changeset
|
283 |
b6f09d280f2c
Add support for 24-bit wavpack files. (Bugzilla #190)
Michał Lipski <tallica@o2.pl>
parents:
2233
diff
changeset
|
284 playback->pass_audio(playback, SAMPLE_FMT(bits_per_sample), |
111 | 285 num_channels, |
2429
b6f09d280f2c
Add support for 24-bit wavpack files. (Bugzilla #190)
Michał Lipski <tallica@o2.pl>
parents:
2233
diff
changeset
|
286 num_samples * num_channels * SAMPLE_SIZE(bits_per_sample), |
111 | 287 output, |
288 NULL); | |
109 | 289 } |
290 }; | |
291 | |
2430
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
292 InputPlugin *wv_iplist[] = { &wvpack, NULL }; |
1080 | 293 |
1395
761e17b23e0c
added Discovery plugin type
Cristi Magherusan <majeru@atheme-project.org>
parents:
1354
diff
changeset
|
294 DECLARE_PLUGIN(wavpack, NULL, NULL, wv_iplist, NULL, NULL, NULL, NULL,NULL); |
109 | 295 |
2430
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
296 static gint |
253
ab24cfe495e0
[svn] Port to NewVFS file probe & add explicit cast to silence warning, thanks to spb.
chainsaw
parents:
247
diff
changeset
|
297 wv_is_our_fd(gchar *filename, VFSFile *file) |
109 | 298 { |
2430
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
299 WavpackDecoder d(&wvpack); |
1501
04f8c7624ea3
Support Wavpack ".exe" executables, by using the Wavpack decoder to validate.
William Pitcock <nenolod@atheme-project.org>
parents:
1465
diff
changeset
|
300 |
04f8c7624ea3
Support Wavpack ".exe" executables, by using the Wavpack decoder to validate.
William Pitcock <nenolod@atheme-project.org>
parents:
1465
diff
changeset
|
301 if (d.attach(filename, file)) |
253
ab24cfe495e0
[svn] Port to NewVFS file probe & add explicit cast to silence warning, thanks to spb.
chainsaw
parents:
247
diff
changeset
|
302 return TRUE; |
1501
04f8c7624ea3
Support Wavpack ".exe" executables, by using the Wavpack decoder to validate.
William Pitcock <nenolod@atheme-project.org>
parents:
1465
diff
changeset
|
303 |
109 | 304 return FALSE; |
305 } | |
306 | |
307 void | |
308 load_tag(ape_tag *tag, WavpackContext *ctx) | |
309 { | |
310 memset(tag, 0, sizeof(ape_tag)); | |
311 WavpackGetTagItem(ctx, "Album", tag->album, sizeof(tag->album)); | |
312 WavpackGetTagItem(ctx, "Artist", tag->artist, sizeof(tag->artist)); | |
313 WavpackGetTagItem(ctx, "Comment", tag->comment, sizeof(tag->comment)); | |
314 WavpackGetTagItem(ctx, "Genre", tag->genre, sizeof(tag->genre)); | |
315 WavpackGetTagItem(ctx, "Title", tag->title, sizeof(tag->title)); | |
316 WavpackGetTagItem(ctx, "Track", tag->track, sizeof(tag->track)); | |
317 WavpackGetTagItem(ctx, "Year", tag->year, sizeof(tag->year)); | |
318 } | |
319 | |
320 static void * | |
321 end_thread() | |
322 { | |
323 return 0; | |
324 } | |
325 | |
326 static void * | |
1989
1bd99632fc4d
wavpack: set_params()
William Pitcock <nenolod@atheme.org>
parents:
1978
diff
changeset
|
327 DecodeThread(InputPlayback *playback) |
109 | 328 { |
2430
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
329 gint bps; |
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
330 WavpackDecoder d(&wvpack); |
109 | 331 |
1989
1bd99632fc4d
wavpack: set_params()
William Pitcock <nenolod@atheme.org>
parents:
1978
diff
changeset
|
332 if (!d.attach_to_play(playback)) { |
109 | 333 killDecodeThread = true; |
334 return end_thread(); | |
335 } | |
336 bps = WavpackGetBytesPerSample(d.ctx) * d.num_channels; | |
2430
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
337 |
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
338 AUDDBG("reading WavPack file, %dHz, %d channels and %dbits\n", d.sample_rate, d.num_channels, d.bits_per_sample); |
109 | 339 |
340 if (!d.open_audio()) { | |
2233 | 341 AUDDBG("error opening audio channel\n"); |
109 | 342 killDecodeThread = true; |
343 AudioError = true; | |
344 openedAudio = false; | |
345 } | |
346 else { | |
2233 | 347 AUDDBG("opened audio channel\n"); |
109 | 348 openedAudio = true; |
349 } | |
2430
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
350 guint32 status; |
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
351 guint samples_left; |
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
352 |
109 | 353 while (!killDecodeThread) { |
354 if (isSeek != -1) { | |
2233 | 355 AUDDBG("seeking to position %d\n", isSeek); |
2430
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
356 WavpackSeekSample(d.ctx, (gint)(isSeek * d.sample_rate)); |
109 | 357 isSeek = -1; |
358 } | |
2430
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
359 |
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
360 samples_left = d.num_samples-WavpackGetSampleIndex(d.ctx); |
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
361 //AUDDBG("samples left: %d\n", samples_left); |
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
362 if (paused == 0) { |
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
363 status = WavpackUnpackSamples(d.ctx, d.input, BUFFER_SIZE); |
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
364 if (status == (guint32) -1) { |
109 | 365 printf("wavpack: Error decoding file.\n"); |
366 break; | |
367 } | |
2430
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
368 else if (samples_left == 0 && wvpack.output->buffer_playing() == 0) { |
109 | 369 killDecodeThread = true; |
370 break; | |
371 } | |
372 else { | |
1998
8f3188746b64
chase last changeset in aud
William Pitcock <nenolod@atheme.org>
parents:
1989
diff
changeset
|
373 d.process_buffer(playback, status); |
109 | 374 } |
375 } | |
376 else { | |
1676
aee4ebea943a
xmms_usleep() was removed, use g_usleep()
Matti Hamalainen <ccr@tnsp.org>
parents:
1620
diff
changeset
|
377 g_usleep(10000); |
109 | 378 } |
379 } | |
380 return end_thread(); | |
381 } | |
382 | |
383 static void | |
566 | 384 wv_play(InputPlayback *data) |
109 | 385 { |
386 paused = 0; | |
387 isSeek = -1; | |
388 killDecodeThread = false; | |
389 AudioError = false; | |
1354
b670d1f3c2e4
wavpack: new threading model
William Pitcock <nenolod@atheme-project.org>
parents:
1185
diff
changeset
|
390 thread_handle = g_thread_self(); |
1447
195b5657303e
updated input plugins to use set_pb_ready to signal to the core that they're ready for playback
Giacomo Lozito <james@develia.org>
parents:
1445
diff
changeset
|
391 data->set_pb_ready(data); |
1989
1bd99632fc4d
wavpack: set_params()
William Pitcock <nenolod@atheme.org>
parents:
1978
diff
changeset
|
392 DecodeThread(data); |
109 | 393 return; |
394 } | |
395 | |
1436
0ff7d08693f6
wavpack: update to new tuple API, use std::string more.
William Pitcock <nenolod@atheme-project.org>
parents:
1395
diff
changeset
|
396 static std::string |
0ff7d08693f6
wavpack: update to new tuple API, use std::string more.
William Pitcock <nenolod@atheme-project.org>
parents:
1395
diff
changeset
|
397 WavpackPluginGetQualityString(WavpackContext *ctx) |
0ff7d08693f6
wavpack: update to new tuple API, use std::string more.
William Pitcock <nenolod@atheme-project.org>
parents:
1395
diff
changeset
|
398 { |
0ff7d08693f6
wavpack: update to new tuple API, use std::string more.
William Pitcock <nenolod@atheme-project.org>
parents:
1395
diff
changeset
|
399 int mode = WavpackGetMode(ctx); |
0ff7d08693f6
wavpack: update to new tuple API, use std::string more.
William Pitcock <nenolod@atheme-project.org>
parents:
1395
diff
changeset
|
400 |
0ff7d08693f6
wavpack: update to new tuple API, use std::string more.
William Pitcock <nenolod@atheme-project.org>
parents:
1395
diff
changeset
|
401 if (mode & MODE_LOSSLESS) |
0ff7d08693f6
wavpack: update to new tuple API, use std::string more.
William Pitcock <nenolod@atheme-project.org>
parents:
1395
diff
changeset
|
402 return "lossless"; |
0ff7d08693f6
wavpack: update to new tuple API, use std::string more.
William Pitcock <nenolod@atheme-project.org>
parents:
1395
diff
changeset
|
403 |
0ff7d08693f6
wavpack: update to new tuple API, use std::string more.
William Pitcock <nenolod@atheme-project.org>
parents:
1395
diff
changeset
|
404 if (mode & MODE_HYBRID) |
0ff7d08693f6
wavpack: update to new tuple API, use std::string more.
William Pitcock <nenolod@atheme-project.org>
parents:
1395
diff
changeset
|
405 return "lossy (hybrid)"; |
0ff7d08693f6
wavpack: update to new tuple API, use std::string more.
William Pitcock <nenolod@atheme-project.org>
parents:
1395
diff
changeset
|
406 |
0ff7d08693f6
wavpack: update to new tuple API, use std::string more.
William Pitcock <nenolod@atheme-project.org>
parents:
1395
diff
changeset
|
407 return "lossy"; |
0ff7d08693f6
wavpack: update to new tuple API, use std::string more.
William Pitcock <nenolod@atheme-project.org>
parents:
1395
diff
changeset
|
408 } |
0ff7d08693f6
wavpack: update to new tuple API, use std::string more.
William Pitcock <nenolod@atheme-project.org>
parents:
1395
diff
changeset
|
409 |
0ff7d08693f6
wavpack: update to new tuple API, use std::string more.
William Pitcock <nenolod@atheme-project.org>
parents:
1395
diff
changeset
|
410 static Tuple * |
2430
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
411 aud_tuple_from_WavpackContext(const gchar *fn, WavpackContext *ctx) |
114 | 412 { |
413 ape_tag tag; | |
1436
0ff7d08693f6
wavpack: update to new tuple API, use std::string more.
William Pitcock <nenolod@atheme-project.org>
parents:
1395
diff
changeset
|
414 Tuple *ti; |
2430
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
415 gint sample_rate = WavpackGetSampleRate(ctx); |
114 | 416 |
1976
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1699
diff
changeset
|
417 ti = aud_tuple_new_from_filename(fn); |
114 | 418 |
419 load_tag(&tag, ctx); | |
420 | |
1976
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1699
diff
changeset
|
421 aud_tuple_associate_string(ti, FIELD_TITLE, NULL, tag.title); |
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1699
diff
changeset
|
422 aud_tuple_associate_string(ti, FIELD_ARTIST, NULL, tag.artist); |
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1699
diff
changeset
|
423 aud_tuple_associate_string(ti, FIELD_ALBUM, NULL, tag.album); |
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1699
diff
changeset
|
424 aud_tuple_associate_string(ti, FIELD_GENRE, NULL, tag.genre); |
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1699
diff
changeset
|
425 aud_tuple_associate_string(ti, FIELD_COMMENT, NULL, tag.comment); |
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1699
diff
changeset
|
426 aud_tuple_associate_string(ti, FIELD_DATE, NULL, tag.year); |
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1699
diff
changeset
|
427 aud_tuple_associate_string(ti, FIELD_QUALITY, NULL, WavpackPluginGetQualityString(ctx).c_str()); |
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1699
diff
changeset
|
428 aud_tuple_associate_string(ti, FIELD_CODEC, NULL, "WavPack"); |
1436
0ff7d08693f6
wavpack: update to new tuple API, use std::string more.
William Pitcock <nenolod@atheme-project.org>
parents:
1395
diff
changeset
|
429 |
1976
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1699
diff
changeset
|
430 aud_tuple_associate_int(ti, FIELD_TRACK_NUMBER, NULL, atoi(tag.track)); |
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1699
diff
changeset
|
431 aud_tuple_associate_int(ti, FIELD_YEAR, NULL, atoi(tag.year)); |
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1699
diff
changeset
|
432 aud_tuple_associate_int(ti, FIELD_LENGTH, NULL, (int)(WavpackGetNumSamples(ctx) / sample_rate) * 1000); |
114 | 433 |
434 return ti; | |
435 } | |
436 | |
2430
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
437 static gchar * |
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
438 generate_title(const gchar *fn, WavpackContext *ctx) |
109 | 439 { |
2430
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
440 static gchar *displaytitle = NULL; |
1436
0ff7d08693f6
wavpack: update to new tuple API, use std::string more.
William Pitcock <nenolod@atheme-project.org>
parents:
1395
diff
changeset
|
441 Tuple *ti; |
109 | 442 |
1976
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1699
diff
changeset
|
443 ti = aud_tuple_from_WavpackContext(fn, ctx); |
109 | 444 |
2059
70b1f1fc4804
use aud_cfg in some places
William Pitcock <nenolod@atheme.org>
parents:
2001
diff
changeset
|
445 displaytitle = aud_tuple_formatter_make_title_string(ti, aud_get_gentitle_format()); |
115
2e77e3fdd3c1
[svn] - make sure the tuple data is copied, not referenced (oops)
nenolod
parents:
114
diff
changeset
|
446 if (!displaytitle || *displaytitle == '\0') |
2e77e3fdd3c1
[svn] - make sure the tuple data is copied, not referenced (oops)
nenolod
parents:
114
diff
changeset
|
447 displaytitle = g_strdup(fn); |
114 | 448 |
1976
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1699
diff
changeset
|
449 aud_tuple_free((void *) ti); |
109 | 450 |
451 return displaytitle; | |
452 } | |
453 | |
1436
0ff7d08693f6
wavpack: update to new tuple API, use std::string more.
William Pitcock <nenolod@atheme-project.org>
parents:
1395
diff
changeset
|
454 static Tuple * |
2430
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
455 wv_get_song_tuple(gchar *filename) |
114 | 456 { |
1436
0ff7d08693f6
wavpack: update to new tuple API, use std::string more.
William Pitcock <nenolod@atheme-project.org>
parents:
1395
diff
changeset
|
457 Tuple *ti; |
2430
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
458 WavpackDecoder d(&wvpack); |
114 | 459 |
233
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
460 if (!d.attach(filename)) { |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
461 printf("wavpack: Error opening file: \"%s\"\n", filename); |
114 | 462 return NULL; |
463 } | |
464 | |
1976
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1699
diff
changeset
|
465 ti = aud_tuple_from_WavpackContext(filename, d.ctx); |
114 | 466 |
467 return ti; | |
468 } | |
469 | |
1526
56b0d46a02f6
wavpack: Implement InputPlugin::probe_for_tuple.
William Pitcock <nenolod@atheme-project.org>
parents:
1521
diff
changeset
|
470 static Tuple * |
56b0d46a02f6
wavpack: Implement InputPlugin::probe_for_tuple.
William Pitcock <nenolod@atheme-project.org>
parents:
1521
diff
changeset
|
471 wv_probe_for_tuple(gchar *filename, VFSFile *file) |
56b0d46a02f6
wavpack: Implement InputPlugin::probe_for_tuple.
William Pitcock <nenolod@atheme-project.org>
parents:
1521
diff
changeset
|
472 { |
56b0d46a02f6
wavpack: Implement InputPlugin::probe_for_tuple.
William Pitcock <nenolod@atheme-project.org>
parents:
1521
diff
changeset
|
473 Tuple *ti; |
2430
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
474 WavpackDecoder d(&wvpack); |
1526
56b0d46a02f6
wavpack: Implement InputPlugin::probe_for_tuple.
William Pitcock <nenolod@atheme-project.org>
parents:
1521
diff
changeset
|
475 |
56b0d46a02f6
wavpack: Implement InputPlugin::probe_for_tuple.
William Pitcock <nenolod@atheme-project.org>
parents:
1521
diff
changeset
|
476 if (!d.attach(filename, file)) |
56b0d46a02f6
wavpack: Implement InputPlugin::probe_for_tuple.
William Pitcock <nenolod@atheme-project.org>
parents:
1521
diff
changeset
|
477 return NULL; |
56b0d46a02f6
wavpack: Implement InputPlugin::probe_for_tuple.
William Pitcock <nenolod@atheme-project.org>
parents:
1521
diff
changeset
|
478 |
1976
5fa26178eaef
s/tuple_/aud_tuple_/g
William Pitcock <nenolod@atheme.org>
parents:
1699
diff
changeset
|
479 ti = aud_tuple_from_WavpackContext(filename, d.ctx); |
1526
56b0d46a02f6
wavpack: Implement InputPlugin::probe_for_tuple.
William Pitcock <nenolod@atheme-project.org>
parents:
1521
diff
changeset
|
480 |
56b0d46a02f6
wavpack: Implement InputPlugin::probe_for_tuple.
William Pitcock <nenolod@atheme-project.org>
parents:
1521
diff
changeset
|
481 return ti; |
56b0d46a02f6
wavpack: Implement InputPlugin::probe_for_tuple.
William Pitcock <nenolod@atheme-project.org>
parents:
1521
diff
changeset
|
482 } |
56b0d46a02f6
wavpack: Implement InputPlugin::probe_for_tuple.
William Pitcock <nenolod@atheme-project.org>
parents:
1521
diff
changeset
|
483 |
109 | 484 static void |
2430
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
485 wv_get_song_info(gchar *filename, gchar **title, gint *length) |
109 | 486 { |
487 assert(filename != NULL); | |
2430
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
488 WavpackDecoder d(&wvpack); |
233
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
489 |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
490 if (!d.attach(filename)) { |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
491 printf("wavpack: Error opening file: \"%s\"\n", filename); |
109 | 492 return; |
493 } | |
233
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
494 |
2430
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
495 gint sample_rate = WavpackGetSampleRate(d.ctx); |
2233 | 496 #ifdef AUD_DEBUG |
2430
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
497 gint num_channels = WavpackGetNumChannels(d.ctx); |
2233 | 498 #endif |
499 AUDDBG("reading %s at %d rate with %d channels\n", filename, sample_rate, num_channels); | |
109 | 500 |
2430
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
501 *length = (gint)(WavpackGetNumSamples(d.ctx) / sample_rate) * 1000, |
233
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
502 *title = generate_title(filename, d.ctx); |
2233 | 503 AUDDBG("title for %s = %s\n", filename, *title); |
109 | 504 } |
505 | |
2430
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
506 static gint |
566 | 507 wv_get_time(InputPlayback *data) |
109 | 508 { |
566 | 509 if (data->output == NULL) |
109 | 510 return -1; |
511 if (AudioError) | |
512 return -2; | |
566 | 513 if (killDecodeThread && !data->output->buffer_playing()) |
109 | 514 return -1; |
566 | 515 return data->output->output_time(); |
109 | 516 } |
517 | |
518 static void | |
2430
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
519 wv_seek(InputPlayback *data, gint sec) |
109 | 520 { |
566 | 521 isSeek = sec; |
2430
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
522 data->output->flush((gint) (1000 * isSeek)); |
109 | 523 } |
524 | |
525 static void | |
2430
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
526 wv_pause(InputPlayback *data, gshort pause) |
566 | 527 { |
528 data->output->pause(paused = pause); | |
529 } | |
530 | |
531 static void | |
532 wv_stop(InputPlayback *data) | |
109 | 533 { |
534 killDecodeThread = true; | |
535 if (thread_handle != 0) { | |
536 g_thread_join(thread_handle); | |
537 if (openedAudio) { | |
2430
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
538 wvpack.output->buffer_free(); |
99864aafd655
fix cutoff in wavpack plugin. (Bugzilla #194)
Michal Lipski <tallica@o2.pl>
parents:
2429
diff
changeset
|
539 wvpack.output->close_audio(); |
109 | 540 } |
541 openedAudio = false; | |
542 if (AudioError) | |
543 printf("Could not open Audio\n"); | |
544 } | |
545 | |
546 } | |
547 | |
548 static void | |
549 wv_load_config() | |
550 { | |
551 ConfigDb *cfg; | |
552 | |
2124 | 553 cfg = aud_cfg_db_open(); |
109 | 554 |
2124 | 555 aud_cfg_db_get_bool(cfg, "wavpack", "clip_prevention", |
109 | 556 &clipPreventionEnabled); |
2124 | 557 aud_cfg_db_get_bool(cfg, "wavpack", "album_replaygain", |
109 | 558 &albumReplaygainEnabled); |
2124 | 559 aud_cfg_db_get_bool(cfg, "wavpack", "dyn_bitrate", &dynBitrateEnabled); |
560 aud_cfg_db_get_bool(cfg, "wavpack", "replaygain", &replaygainEnabled); | |
561 aud_cfg_db_close(cfg); | |
109 | 562 |
563 openedAudio = false; | |
564 } |