Mercurial > audlegacy-plugins
annotate src/wavpack/libwavpack.cxx @ 1144:359cd2c10405 trunk
[svn] - rootvis: convert to plugin2 architecture
author | nenolod |
---|---|
date | Mon, 28 May 2007 03:05:08 -0700 |
parents | ea77e4df4ce4 |
children | 6d749f573b3b |
rev | line source |
---|---|
109 | 1 #include <assert.h> |
2 #include <string.h> | |
3 #include <stdio.h> | |
4 #include <stdlib.h> | |
5 #include <unistd.h> | |
291
93c0da3f7a86
[svn] - make wavpack/wavpack.h include forced extern "C".
nenolod
parents:
284
diff
changeset
|
6 extern "C" { |
284
72f0de06bb56
[svn] - wavpack/wputils.h is deprecated, wavpack/wavpack.h should be used instead.
nenolod
parents:
264
diff
changeset
|
7 #include <wavpack/wavpack.h> |
109 | 8 #include <audacious/plugin.h> |
111 | 9 #include <audacious/output.h> |
109 | 10 #include <audacious/configdb.h> |
11 #include <audacious/titlestring.h> | |
12 #include <audacious/util.h> | |
233
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
13 #include <audacious/vfs.h> |
109 | 14 } |
15 #include <glib.h> | |
16 #include <gtk/gtk.h> | |
17 #include <iconv.h> | |
18 #include <math.h> | |
19 #include "tags.h" | |
434
7385182ae4b8
[svn] - add missing config.h inclusion for wavpack, null and metronom plugin
giacomo
parents:
372
diff
changeset
|
20 #include "../../config.h" |
109 | 21 #ifndef M_LN10 |
22 #define M_LN10 2.3025850929940456840179914546843642 | |
23 #endif | |
24 | |
112 | 25 #ifdef DEBUG |
26 # define DBG(format, args...) fprintf(stderr, format, ## args) | |
27 #else | |
28 # define DBG(format, args...) | |
29 #endif | |
30 | |
109 | 31 #define BUFFER_SIZE 256 // read buffer size, in samples |
32 | |
33 static void wv_load_config(); | |
253
ab24cfe495e0
[svn] Port to NewVFS file probe & add explicit cast to silence warning, thanks to spb.
chainsaw
parents:
247
diff
changeset
|
34 static int wv_is_our_fd(gchar *filename, VFSFile *file); |
566 | 35 static void wv_play(InputPlayback *); |
36 static void wv_stop(InputPlayback *); | |
37 static void wv_pause(InputPlayback *, short); | |
38 static void wv_seek(InputPlayback *, int); | |
39 static int wv_get_time(InputPlayback *); | |
109 | 40 static void wv_get_song_info(char *, char **, int *); |
41 static char *generate_title(const char *, WavpackContext *ctx); | |
42 static double isSeek; | |
43 static short paused; | |
44 static bool killDecodeThread; | |
45 static bool AudioError; | |
46 static GThread *thread_handle; | |
114 | 47 static TitleInput *wv_get_song_tuple(char *); |
109 | 48 |
49 // in ui.cpp | |
50 void wv_configure(); | |
51 void wv_about_box(void); | |
52 void wv_file_info_box(char *); | |
53 extern gboolean clipPreventionEnabled; | |
54 extern gboolean dynBitrateEnabled; | |
55 extern gboolean replaygainEnabled; | |
56 extern gboolean albumReplaygainEnabled; | |
57 extern gboolean openedAudio; | |
58 | |
1044
b1128efde471
[svn] - get rid of all warnings gcc 4.2.0 emits with my build configuration.
yaz
parents:
566
diff
changeset
|
59 const gchar *wv_fmts[] = { "wv", NULL }; |
372
a157306caf03
[svn] - finalize the plugin-side of the extension-assist ABI
nenolod
parents:
368
diff
changeset
|
60 |
109 | 61 InputPlugin mod = { |
62 NULL, //handle | |
63 NULL, //filename | |
1127 | 64 "WavPack Audio Plugin", |
109 | 65 wv_load_config, |
66 wv_about_box, | |
67 wv_configure, | |
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 NULL, | |
83 wv_get_song_info, | |
263 | 84 wv_file_info_box, //info box |
109 | 85 NULL, //output |
114 | 86 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
|
87 NULL, |
ab24cfe495e0
[svn] Port to NewVFS file probe & add explicit cast to silence warning, thanks to spb.
chainsaw
parents:
247
diff
changeset
|
88 NULL, |
ab24cfe495e0
[svn] Port to NewVFS file probe & add explicit cast to silence warning, thanks to spb.
chainsaw
parents:
247
diff
changeset
|
89 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
|
90 (gchar **)wv_fmts, |
109 | 91 }; |
92 | |
233
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
93 int32_t read_bytes (void *id, void *data, int32_t bcount) |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
94 { |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
95 return vfs_fread (data, 1, bcount, (VFSFile *) id); |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
96 } |
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 uint32_t get_pos (void *id) |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
99 { |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
100 return vfs_ftell ((VFSFile *) id); |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
101 } |
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 int set_pos_abs (void *id, uint32_t pos) |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
104 { |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
105 return vfs_fseek ((VFSFile *) id, pos, SEEK_SET); |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
106 } |
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 int set_pos_rel (void *id, int32_t delta, int mode) |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
109 { |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
110 return vfs_fseek ((VFSFile *) id, delta, mode); |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
111 } |
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 int push_back_byte (void *id, int c) |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
114 { |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
115 return vfs_ungetc (c, (VFSFile *) id); |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
116 } |
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 uint32_t get_length (void *id) |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
119 { |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
120 VFSFile *file = (VFSFile *) id; |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
121 uint32_t sz = 0; |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
122 |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
123 if (file == NULL) |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
124 return 0; |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
125 |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
126 vfs_fseek(file, 0, SEEK_END); |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
127 sz = vfs_ftell(file); |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
128 vfs_fseek(file, 0, SEEK_SET); |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
129 |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
130 return sz; |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
131 } |
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 /* XXX streams?? */ |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
134 int can_seek (void *id) |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
135 { |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
136 return 1; |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
137 } |
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 int32_t write_bytes (void *id, void *data, int32_t bcount) |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
140 { |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
141 return vfs_fwrite (data, 1, bcount, (VFSFile *) id); |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
142 } |
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 WavpackStreamReader reader = { |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
145 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
|
146 write_bytes |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
147 }; |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
148 |
109 | 149 class WavpackDecoder |
150 { | |
151 public: | |
152 InputPlugin *mod; | |
153 int32_t *input; | |
154 int16_t *output; | |
155 int sample_rate; | |
156 int num_channels; | |
157 WavpackContext *ctx; | |
158 char error_buff[4096]; // TODO: fixme! | |
233
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
159 VFSFile *wv_Input, *wvc_Input; |
109 | 160 |
161 WavpackDecoder(InputPlugin *mod) : mod(mod) | |
162 { | |
163 ctx = NULL; | |
164 input = NULL; | |
165 output = NULL; | |
166 } | |
167 | |
168 ~WavpackDecoder() | |
169 { | |
170 if (input != NULL) { | |
171 free(input); | |
172 input = NULL; | |
173 } | |
174 if (output != NULL) { | |
175 free(output); | |
176 output = NULL; | |
177 } | |
178 if (ctx != NULL) { | |
233
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
179 vfs_fclose(wv_Input); |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
180 vfs_fclose(wvc_Input); |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
181 g_free(ctx); |
109 | 182 ctx = NULL; |
183 } | |
184 } | |
185 | |
186 bool attach(const char *filename) | |
187 { | |
233
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
188 wv_Input = vfs_fopen(filename, "rb"); |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
189 |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
190 char *corrFilename = g_strconcat(filename, "c", NULL); |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
191 |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
192 wvc_Input = vfs_fopen(corrFilename, "rb"); |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
193 |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
194 g_free(corrFilename); |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
195 |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
196 ctx = WavpackOpenFileInputEx(&reader, wv_Input, wvc_Input, error_buff, OPEN_TAGS | OPEN_WVC, 0); |
109 | 197 |
198 if (ctx == NULL) { | |
199 return false; | |
200 } | |
201 | |
237 | 202 return true; |
203 } | |
204 | |
205 bool attach_to_play(const char *filename) | |
206 { | |
207 wv_Input = vfs_fopen(filename, "rb"); | |
208 | |
209 char *corrFilename = g_strconcat(filename, "c", NULL); | |
210 | |
211 wvc_Input = vfs_fopen(corrFilename, "rb"); | |
212 | |
213 g_free(corrFilename); | |
214 | |
215 ctx = WavpackOpenFileInputEx(&reader, wv_Input, wvc_Input, error_buff, OPEN_TAGS | OPEN_WVC, 0); | |
216 | |
217 if (ctx == NULL) { | |
218 return false; | |
219 } | |
220 | |
109 | 221 sample_rate = WavpackGetSampleRate(ctx); |
222 num_channels = WavpackGetNumChannels(ctx); | |
223 input = (int32_t *)calloc(BUFFER_SIZE, num_channels * sizeof(int32_t)); | |
224 output = (int16_t *)calloc(BUFFER_SIZE, num_channels * sizeof(int16_t)); | |
225 mod->set_info(generate_title(filename, ctx), | |
226 (int) (WavpackGetNumSamples(ctx) / sample_rate) * 1000, | |
227 (int) WavpackGetAverageBitrate(ctx, num_channels), | |
228 (int) sample_rate, num_channels); | |
229 return true; | |
230 } | |
231 | |
232 bool open_audio() | |
233 { | |
112 | 234 return mod->output->open_audio(FMT_S16_NE, sample_rate, num_channels); |
109 | 235 } |
236 | |
237 void process_buffer(size_t num_samples) | |
238 { | |
239 for (int i = 0; i < num_samples * num_channels; i++) { | |
240 output[i] = input[i]; | |
241 } | |
112 | 242 produce_audio(mod->output->output_time(), FMT_S16_NE, |
111 | 243 num_channels, |
244 num_samples * num_channels * sizeof(int16_t), | |
245 output, | |
246 NULL); | |
109 | 247 } |
248 }; | |
249 | |
1080 | 250 InputPlugin *wv_iplist[] = { &mod, NULL }; |
251 | |
252 DECLARE_PLUGIN(wavpack, NULL, NULL, wv_iplist, NULL, NULL, NULL, NULL); | |
109 | 253 |
254 static int | |
253
ab24cfe495e0
[svn] Port to NewVFS file probe & add explicit cast to silence warning, thanks to spb.
chainsaw
parents:
247
diff
changeset
|
255 wv_is_our_fd(gchar *filename, VFSFile *file) |
109 | 256 { |
253
ab24cfe495e0
[svn] Port to NewVFS file probe & add explicit cast to silence warning, thanks to spb.
chainsaw
parents:
247
diff
changeset
|
257 gchar magic[4]; |
ab24cfe495e0
[svn] Port to NewVFS file probe & add explicit cast to silence warning, thanks to spb.
chainsaw
parents:
247
diff
changeset
|
258 vfs_fread(magic,1,4,file); |
ab24cfe495e0
[svn] Port to NewVFS file probe & add explicit cast to silence warning, thanks to spb.
chainsaw
parents:
247
diff
changeset
|
259 if (!memcmp(magic,"wvpk",4)) |
ab24cfe495e0
[svn] Port to NewVFS file probe & add explicit cast to silence warning, thanks to spb.
chainsaw
parents:
247
diff
changeset
|
260 return TRUE; |
109 | 261 return FALSE; |
262 } | |
263 | |
264 void | |
265 load_tag(ape_tag *tag, WavpackContext *ctx) | |
266 { | |
267 memset(tag, 0, sizeof(ape_tag)); | |
268 WavpackGetTagItem(ctx, "Album", tag->album, sizeof(tag->album)); | |
269 WavpackGetTagItem(ctx, "Artist", tag->artist, sizeof(tag->artist)); | |
270 WavpackGetTagItem(ctx, "Comment", tag->comment, sizeof(tag->comment)); | |
271 WavpackGetTagItem(ctx, "Genre", tag->genre, sizeof(tag->genre)); | |
272 WavpackGetTagItem(ctx, "Title", tag->title, sizeof(tag->title)); | |
273 WavpackGetTagItem(ctx, "Track", tag->track, sizeof(tag->track)); | |
274 WavpackGetTagItem(ctx, "Year", tag->year, sizeof(tag->year)); | |
275 } | |
276 | |
277 static void * | |
278 end_thread() | |
279 { | |
280 return 0; | |
281 } | |
282 | |
283 static void * | |
284 DecodeThread(void *a) | |
285 { | |
286 ape_tag tag; | |
287 char *filename = (char *) a; | |
288 int bps_updateCounter = 0; | |
289 int bps; | |
290 int i; | |
291 WavpackDecoder d(&mod); | |
292 | |
237 | 293 if (!d.attach_to_play(filename)) { |
109 | 294 killDecodeThread = true; |
295 return end_thread(); | |
296 } | |
297 bps = WavpackGetBytesPerSample(d.ctx) * d.num_channels; | |
298 DBG("reading %s at %d rate with %d channels\n", filename, d.sample_rate, d.num_channels); | |
299 | |
300 if (!d.open_audio()) { | |
1128 | 301 DBG("error opening audio channel\n"); |
109 | 302 killDecodeThread = true; |
303 AudioError = true; | |
304 openedAudio = false; | |
305 } | |
306 else { | |
1128 | 307 DBG("opened audio channel\n"); |
109 | 308 openedAudio = true; |
309 } | |
310 unsigned status; | |
311 char *display = generate_title(filename, d.ctx); | |
312 int length = (int) (1000 * WavpackGetNumSamples(d.ctx)); | |
313 | |
314 while (!killDecodeThread) { | |
315 if (isSeek != -1) { | |
316 DBG("seeking to position %d\n", isSeek); | |
253
ab24cfe495e0
[svn] Port to NewVFS file probe & add explicit cast to silence warning, thanks to spb.
chainsaw
parents:
247
diff
changeset
|
317 WavpackSeekSample(d.ctx, (int)(isSeek * d.sample_rate)); |
109 | 318 isSeek = -1; |
319 } | |
320 if (paused == 0 | |
321 && (mod.output->buffer_free() >= | |
322 (1152 * 2 * | |
323 (16 / 8)) << (mod.output->buffer_playing()? 1 : 0))) { | |
324 status = | |
325 WavpackUnpackSamples(d.ctx, d.input, BUFFER_SIZE); | |
326 if (status == (unsigned) (-1)) { | |
327 printf("wavpack: Error decoding file.\n"); | |
328 break; | |
329 } | |
330 else if (status == 0) { | |
331 killDecodeThread = true; | |
332 break; | |
333 } | |
334 else { | |
335 d.process_buffer(status); | |
336 } | |
337 } | |
338 else { | |
339 xmms_usleep(10000); | |
340 } | |
341 } | |
342 return end_thread(); | |
343 } | |
344 | |
345 static void | |
566 | 346 wv_play(InputPlayback *data) |
109 | 347 { |
348 paused = 0; | |
349 isSeek = -1; | |
350 killDecodeThread = false; | |
351 AudioError = false; | |
566 | 352 thread_handle = g_thread_create(DecodeThread, (void *) data->filename, TRUE, NULL); |
109 | 353 return; |
354 } | |
355 | |
114 | 356 static TitleInput * |
357 tuple_from_WavpackContext(const char *fn, WavpackContext *ctx) | |
358 { | |
359 ape_tag tag; | |
360 TitleInput *ti; | |
361 int sample_rate = WavpackGetSampleRate(ctx); | |
362 | |
363 ti = bmp_title_input_new(); | |
364 | |
130
16e2c64d8b2b
[svn] - provide a complete tuple (fixes albumart and such; path was missing.)
nenolod
parents:
115
diff
changeset
|
365 ti->file_name = g_path_get_basename(fn); |
16e2c64d8b2b
[svn] - provide a complete tuple (fixes albumart and such; path was missing.)
nenolod
parents:
115
diff
changeset
|
366 ti->file_path = g_path_get_dirname(fn); |
114 | 367 ti->file_ext = "wv"; |
368 | |
369 load_tag(&tag, ctx); | |
370 | |
115
2e77e3fdd3c1
[svn] - make sure the tuple data is copied, not referenced (oops)
nenolod
parents:
114
diff
changeset
|
371 ti->track_name = g_strdup(tag.title); |
2e77e3fdd3c1
[svn] - make sure the tuple data is copied, not referenced (oops)
nenolod
parents:
114
diff
changeset
|
372 ti->performer = g_strdup(tag.artist); |
2e77e3fdd3c1
[svn] - make sure the tuple data is copied, not referenced (oops)
nenolod
parents:
114
diff
changeset
|
373 ti->album_name = g_strdup(tag.album); |
2e77e3fdd3c1
[svn] - make sure the tuple data is copied, not referenced (oops)
nenolod
parents:
114
diff
changeset
|
374 ti->date = g_strdup(tag.year); |
114 | 375 ti->track_number = atoi(tag.track); |
376 if (ti->track_number < 0) | |
377 ti->track_number = 0; | |
378 ti->year = atoi(tag.year); | |
379 if (ti->year < 0) | |
380 ti->year = 0; | |
115
2e77e3fdd3c1
[svn] - make sure the tuple data is copied, not referenced (oops)
nenolod
parents:
114
diff
changeset
|
381 ti->genre = g_strdup(tag.genre); |
2e77e3fdd3c1
[svn] - make sure the tuple data is copied, not referenced (oops)
nenolod
parents:
114
diff
changeset
|
382 ti->comment = g_strdup(tag.comment); |
114 | 383 ti->length = (int)(WavpackGetNumSamples(ctx) / sample_rate) * 1000; |
384 | |
385 return ti; | |
386 } | |
387 | |
109 | 388 static char * |
389 generate_title(const char *fn, WavpackContext *ctx) | |
390 { | |
391 static char *displaytitle = NULL; | |
392 TitleInput *ti; | |
393 | |
114 | 394 ti = tuple_from_WavpackContext(fn, ctx); |
109 | 395 |
396 displaytitle = xmms_get_titlestring(xmms_get_gentitle_format(), ti); | |
115
2e77e3fdd3c1
[svn] - make sure the tuple data is copied, not referenced (oops)
nenolod
parents:
114
diff
changeset
|
397 if (!displaytitle || *displaytitle == '\0') |
2e77e3fdd3c1
[svn] - make sure the tuple data is copied, not referenced (oops)
nenolod
parents:
114
diff
changeset
|
398 displaytitle = g_strdup(fn); |
114 | 399 |
400 bmp_title_input_free(ti); | |
109 | 401 |
402 return displaytitle; | |
403 } | |
404 | |
114 | 405 static TitleInput * |
406 wv_get_song_tuple(char *filename) | |
407 { | |
408 TitleInput *ti; | |
233
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
409 WavpackDecoder d(&mod); |
114 | 410 |
233
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
411 if (!d.attach(filename)) { |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
412 printf("wavpack: Error opening file: \"%s\"\n", filename); |
114 | 413 return NULL; |
414 } | |
415 | |
233
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
416 ti = tuple_from_WavpackContext(filename, d.ctx); |
114 | 417 |
418 return ti; | |
419 } | |
420 | |
109 | 421 static void |
422 wv_get_song_info(char *filename, char **title, int *length) | |
423 { | |
424 assert(filename != NULL); | |
233
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
425 WavpackDecoder d(&mod); |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
426 |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
427 if (!d.attach(filename)) { |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
428 printf("wavpack: Error opening file: \"%s\"\n", filename); |
109 | 429 return; |
430 } | |
233
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
431 |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
432 int sample_rate = WavpackGetSampleRate(d.ctx); |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
433 int num_channels = WavpackGetNumChannels(d.ctx); |
109 | 434 DBG("reading %s at %d rate with %d channels\n", filename, sample_rate, num_channels); |
435 | |
233
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
436 *length = (int)(WavpackGetNumSamples(d.ctx) / sample_rate) * 1000, |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
437 *title = generate_title(filename, d.ctx); |
109 | 438 DBG("title for %s = %s\n", filename, *title); |
439 } | |
440 | |
441 static int | |
566 | 442 wv_get_time(InputPlayback *data) |
109 | 443 { |
566 | 444 if (data->output == NULL) |
109 | 445 return -1; |
446 if (AudioError) | |
447 return -2; | |
566 | 448 if (killDecodeThread && !data->output->buffer_playing()) |
109 | 449 return -1; |
566 | 450 return data->output->output_time(); |
109 | 451 } |
452 | |
453 static void | |
566 | 454 wv_seek(InputPlayback *data, int sec) |
109 | 455 { |
566 | 456 isSeek = sec; |
457 data->output->flush((int) (1000 * isSeek)); | |
109 | 458 } |
459 | |
460 static void | |
566 | 461 wv_pause(InputPlayback *data, short pause) |
462 { | |
463 data->output->pause(paused = pause); | |
464 } | |
465 | |
466 static void | |
467 wv_stop(InputPlayback *data) | |
109 | 468 { |
469 killDecodeThread = true; | |
470 if (thread_handle != 0) { | |
471 g_thread_join(thread_handle); | |
472 if (openedAudio) { | |
473 mod.output->buffer_free(); | |
474 mod.output->close_audio(); | |
475 } | |
476 openedAudio = false; | |
477 if (AudioError) | |
478 printf("Could not open Audio\n"); | |
479 } | |
480 | |
481 } | |
482 | |
483 static void | |
484 wv_load_config() | |
485 { | |
486 ConfigDb *cfg; | |
487 | |
488 cfg = bmp_cfg_db_open(); | |
489 | |
490 bmp_cfg_db_get_bool(cfg, "wavpack", "clip_prevention", | |
491 &clipPreventionEnabled); | |
492 bmp_cfg_db_get_bool(cfg, "wavpack", "album_replaygain", | |
493 &albumReplaygainEnabled); | |
494 bmp_cfg_db_get_bool(cfg, "wavpack", "dyn_bitrate", &dynBitrateEnabled); | |
495 bmp_cfg_db_get_bool(cfg, "wavpack", "replaygain", &replaygainEnabled); | |
496 bmp_cfg_db_close(cfg); | |
497 | |
498 openedAudio = false; | |
499 } |