Mercurial > audlegacy-plugins
annotate src/wavpack/libwavpack.cxx @ 253:ab24cfe495e0 trunk
[svn] Port to NewVFS file probe & add explicit cast to silence warning, thanks to spb.
author | chainsaw |
---|---|
date | Sat, 18 Nov 2006 10:02:24 -0800 |
parents | a1ef3cf974c7 |
children | 7e1d5cc9ef1b |
rev | line source |
---|---|
109 | 1 #include <assert.h> |
2 #include <string.h> | |
3 #include <stdio.h> | |
4 #include <stdlib.h> | |
5 #include <unistd.h> | |
6 #include <wavpack/wputils.h> | |
7 extern "C" { | |
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" | |
20 #ifndef M_LN10 | |
21 #define M_LN10 2.3025850929940456840179914546843642 | |
22 #endif | |
23 | |
112 | 24 #ifdef DEBUG |
25 # define DBG(format, args...) fprintf(stderr, format, ## args) | |
26 #else | |
27 # define DBG(format, args...) | |
28 #endif | |
29 | |
109 | 30 #define BUFFER_SIZE 256 // read buffer size, in samples |
31 | |
32 extern "C" InputPlugin * get_iplugin_info(void); | |
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); |
109 | 35 static void wv_play(char *); |
36 static void wv_stop(void); | |
37 static void wv_pause(short); | |
38 static void wv_seek(int); | |
39 static int wv_get_time(void); | |
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 | |
59 InputPlugin mod = { | |
60 NULL, //handle | |
61 NULL, //filename | |
62 NULL, | |
63 wv_load_config, | |
64 wv_about_box, | |
65 wv_configure, | |
253
ab24cfe495e0
[svn] Port to NewVFS file probe & add explicit cast to silence warning, thanks to spb.
chainsaw
parents:
247
diff
changeset
|
66 NULL, //old style is_our_file |
109 | 67 NULL, //no use |
68 wv_play, | |
69 wv_stop, | |
70 wv_pause, | |
71 wv_seek, | |
72 NULL, //set eq | |
73 wv_get_time, | |
74 NULL, //get volume | |
75 NULL, //set volume | |
76 NULL, //cleanup | |
77 NULL, //obsolete | |
78 NULL, //add_vis | |
79 NULL, | |
80 NULL, | |
81 wv_get_song_info, | |
82 wv_file_info_box, //info box | |
83 NULL, //output | |
114 | 84 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
|
85 NULL, |
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 wv_is_our_fd, |
109 | 88 }; |
89 | |
233
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
90 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
|
91 { |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
92 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
|
93 } |
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 uint32_t get_pos (void *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 return vfs_ftell ((VFSFile *) id); |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
98 } |
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 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
|
101 { |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
102 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
|
103 } |
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 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
|
106 { |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
107 return vfs_fseek ((VFSFile *) id, delta, mode); |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
108 } |
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 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
|
111 { |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
112 return vfs_ungetc (c, (VFSFile *) id); |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
113 } |
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 uint32_t get_length (void *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 VFSFile *file = (VFSFile *) id; |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
118 uint32_t sz = 0; |
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 if (file == NULL) |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
121 return 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 vfs_fseek(file, 0, SEEK_END); |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
124 sz = vfs_ftell(file); |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
125 vfs_fseek(file, 0, SEEK_SET); |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
126 |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
127 return sz; |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
128 } |
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 /* XXX streams?? */ |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
131 int can_seek (void *id) |
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 return 1; |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
134 } |
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 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
|
137 { |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
138 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
|
139 } |
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 WavpackStreamReader reader = { |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
142 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
|
143 write_bytes |
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 |
109 | 146 class WavpackDecoder |
147 { | |
148 public: | |
149 InputPlugin *mod; | |
150 int32_t *input; | |
151 int16_t *output; | |
152 int sample_rate; | |
153 int num_channels; | |
154 WavpackContext *ctx; | |
155 char error_buff[4096]; // TODO: fixme! | |
233
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
156 VFSFile *wv_Input, *wvc_Input; |
109 | 157 |
158 WavpackDecoder(InputPlugin *mod) : mod(mod) | |
159 { | |
160 ctx = NULL; | |
161 input = NULL; | |
162 output = NULL; | |
163 } | |
164 | |
165 ~WavpackDecoder() | |
166 { | |
167 if (input != NULL) { | |
168 free(input); | |
169 input = NULL; | |
170 } | |
171 if (output != NULL) { | |
172 free(output); | |
173 output = NULL; | |
174 } | |
175 if (ctx != NULL) { | |
233
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
176 vfs_fclose(wv_Input); |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
177 vfs_fclose(wvc_Input); |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
178 g_free(ctx); |
109 | 179 ctx = NULL; |
180 } | |
181 } | |
182 | |
183 bool attach(const char *filename) | |
184 { | |
233
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
185 wv_Input = vfs_fopen(filename, "rb"); |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
186 |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
187 char *corrFilename = g_strconcat(filename, "c", NULL); |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
188 |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
189 wvc_Input = vfs_fopen(corrFilename, "rb"); |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
190 |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
191 g_free(corrFilename); |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
192 |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
193 ctx = WavpackOpenFileInputEx(&reader, wv_Input, wvc_Input, error_buff, OPEN_TAGS | OPEN_WVC, 0); |
109 | 194 |
195 if (ctx == NULL) { | |
196 return false; | |
197 } | |
198 | |
237 | 199 return true; |
200 } | |
201 | |
202 bool attach_to_play(const char *filename) | |
203 { | |
204 wv_Input = vfs_fopen(filename, "rb"); | |
205 | |
206 char *corrFilename = g_strconcat(filename, "c", NULL); | |
207 | |
208 wvc_Input = vfs_fopen(corrFilename, "rb"); | |
209 | |
210 g_free(corrFilename); | |
211 | |
212 ctx = WavpackOpenFileInputEx(&reader, wv_Input, wvc_Input, error_buff, OPEN_TAGS | OPEN_WVC, 0); | |
213 | |
214 if (ctx == NULL) { | |
215 return false; | |
216 } | |
217 | |
109 | 218 sample_rate = WavpackGetSampleRate(ctx); |
219 num_channels = WavpackGetNumChannels(ctx); | |
220 input = (int32_t *)calloc(BUFFER_SIZE, num_channels * sizeof(int32_t)); | |
221 output = (int16_t *)calloc(BUFFER_SIZE, num_channels * sizeof(int16_t)); | |
222 mod->set_info(generate_title(filename, ctx), | |
223 (int) (WavpackGetNumSamples(ctx) / sample_rate) * 1000, | |
224 (int) WavpackGetAverageBitrate(ctx, num_channels), | |
225 (int) sample_rate, num_channels); | |
226 return true; | |
227 } | |
228 | |
229 bool open_audio() | |
230 { | |
112 | 231 return mod->output->open_audio(FMT_S16_NE, sample_rate, num_channels); |
109 | 232 } |
233 | |
234 void process_buffer(size_t num_samples) | |
235 { | |
236 for (int i = 0; i < num_samples * num_channels; i++) { | |
237 output[i] = input[i]; | |
238 } | |
112 | 239 produce_audio(mod->output->output_time(), FMT_S16_NE, |
111 | 240 num_channels, |
241 num_samples * num_channels * sizeof(int16_t), | |
242 output, | |
243 NULL); | |
109 | 244 } |
245 }; | |
246 | |
247 extern "C" InputPlugin * | |
248 get_iplugin_info(void) | |
249 { | |
250 mod.description = | |
251 g_strdup_printf(("Wavpack Decoder Plugin %s"), VERSION); | |
252 return &mod; | |
253 } | |
254 | |
255 static int | |
253
ab24cfe495e0
[svn] Port to NewVFS file probe & add explicit cast to silence warning, thanks to spb.
chainsaw
parents:
247
diff
changeset
|
256 wv_is_our_fd(gchar *filename, VFSFile *file) |
109 | 257 { |
253
ab24cfe495e0
[svn] Port to NewVFS file probe & add explicit cast to silence warning, thanks to spb.
chainsaw
parents:
247
diff
changeset
|
258 gchar magic[4]; |
ab24cfe495e0
[svn] Port to NewVFS file probe & add explicit cast to silence warning, thanks to spb.
chainsaw
parents:
247
diff
changeset
|
259 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
|
260 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
|
261 return TRUE; |
109 | 262 return FALSE; |
263 } | |
264 | |
265 void | |
266 load_tag(ape_tag *tag, WavpackContext *ctx) | |
267 { | |
268 memset(tag, 0, sizeof(ape_tag)); | |
269 WavpackGetTagItem(ctx, "Album", tag->album, sizeof(tag->album)); | |
270 WavpackGetTagItem(ctx, "Artist", tag->artist, sizeof(tag->artist)); | |
271 WavpackGetTagItem(ctx, "Comment", tag->comment, sizeof(tag->comment)); | |
272 WavpackGetTagItem(ctx, "Genre", tag->genre, sizeof(tag->genre)); | |
273 WavpackGetTagItem(ctx, "Title", tag->title, sizeof(tag->title)); | |
274 WavpackGetTagItem(ctx, "Track", tag->track, sizeof(tag->track)); | |
275 WavpackGetTagItem(ctx, "Year", tag->year, sizeof(tag->year)); | |
276 } | |
277 | |
278 static void * | |
279 end_thread() | |
280 { | |
281 return 0; | |
282 } | |
283 | |
284 static void * | |
285 DecodeThread(void *a) | |
286 { | |
287 ape_tag tag; | |
288 char *filename = (char *) a; | |
289 int bps_updateCounter = 0; | |
290 int bps; | |
291 int i; | |
292 WavpackDecoder d(&mod); | |
293 | |
237 | 294 if (!d.attach_to_play(filename)) { |
109 | 295 printf("wavpack: Error opening file: \"%s\"\n", filename); |
296 killDecodeThread = true; | |
297 return end_thread(); | |
298 } | |
299 bps = WavpackGetBytesPerSample(d.ctx) * d.num_channels; | |
300 DBG("reading %s at %d rate with %d channels\n", filename, d.sample_rate, d.num_channels); | |
301 | |
302 if (!d.open_audio()) { | |
303 DBG("error opening xmms audio channel\n"); | |
304 killDecodeThread = true; | |
305 AudioError = true; | |
306 openedAudio = false; | |
307 } | |
308 else { | |
309 DBG("opened xmms audio channel\n"); | |
310 openedAudio = true; | |
311 } | |
312 unsigned status; | |
313 char *display = generate_title(filename, d.ctx); | |
314 int length = (int) (1000 * WavpackGetNumSamples(d.ctx)); | |
315 | |
316 while (!killDecodeThread) { | |
317 if (isSeek != -1) { | |
318 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
|
319 WavpackSeekSample(d.ctx, (int)(isSeek * d.sample_rate)); |
109 | 320 isSeek = -1; |
321 } | |
322 if (paused == 0 | |
323 && (mod.output->buffer_free() >= | |
324 (1152 * 2 * | |
325 (16 / 8)) << (mod.output->buffer_playing()? 1 : 0))) { | |
326 status = | |
327 WavpackUnpackSamples(d.ctx, d.input, BUFFER_SIZE); | |
328 if (status == (unsigned) (-1)) { | |
329 printf("wavpack: Error decoding file.\n"); | |
330 break; | |
331 } | |
332 else if (status == 0) { | |
333 killDecodeThread = true; | |
334 break; | |
335 } | |
336 else { | |
337 d.process_buffer(status); | |
338 } | |
339 } | |
340 else { | |
341 xmms_usleep(10000); | |
342 } | |
343 } | |
344 return end_thread(); | |
345 } | |
346 | |
347 static void | |
348 wv_play(char *filename) | |
349 { | |
350 paused = 0; | |
351 isSeek = -1; | |
352 killDecodeThread = false; | |
353 AudioError = false; | |
354 thread_handle = g_thread_create(DecodeThread, (void *) filename, TRUE, NULL); | |
355 return; | |
356 } | |
357 | |
114 | 358 static TitleInput * |
359 tuple_from_WavpackContext(const char *fn, WavpackContext *ctx) | |
360 { | |
361 ape_tag tag; | |
362 TitleInput *ti; | |
363 int sample_rate = WavpackGetSampleRate(ctx); | |
364 | |
365 ti = bmp_title_input_new(); | |
366 | |
130
16e2c64d8b2b
[svn] - provide a complete tuple (fixes albumart and such; path was missing.)
nenolod
parents:
115
diff
changeset
|
367 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
|
368 ti->file_path = g_path_get_dirname(fn); |
114 | 369 ti->file_ext = "wv"; |
370 | |
371 load_tag(&tag, ctx); | |
372 | |
115
2e77e3fdd3c1
[svn] - make sure the tuple data is copied, not referenced (oops)
nenolod
parents:
114
diff
changeset
|
373 ti->track_name = g_strdup(tag.title); |
2e77e3fdd3c1
[svn] - make sure the tuple data is copied, not referenced (oops)
nenolod
parents:
114
diff
changeset
|
374 ti->performer = g_strdup(tag.artist); |
2e77e3fdd3c1
[svn] - make sure the tuple data is copied, not referenced (oops)
nenolod
parents:
114
diff
changeset
|
375 ti->album_name = g_strdup(tag.album); |
2e77e3fdd3c1
[svn] - make sure the tuple data is copied, not referenced (oops)
nenolod
parents:
114
diff
changeset
|
376 ti->date = g_strdup(tag.year); |
114 | 377 ti->track_number = atoi(tag.track); |
378 if (ti->track_number < 0) | |
379 ti->track_number = 0; | |
380 ti->year = atoi(tag.year); | |
381 if (ti->year < 0) | |
382 ti->year = 0; | |
115
2e77e3fdd3c1
[svn] - make sure the tuple data is copied, not referenced (oops)
nenolod
parents:
114
diff
changeset
|
383 ti->genre = g_strdup(tag.genre); |
2e77e3fdd3c1
[svn] - make sure the tuple data is copied, not referenced (oops)
nenolod
parents:
114
diff
changeset
|
384 ti->comment = g_strdup(tag.comment); |
114 | 385 ti->length = (int)(WavpackGetNumSamples(ctx) / sample_rate) * 1000; |
386 | |
387 return ti; | |
388 } | |
389 | |
109 | 390 static char * |
391 generate_title(const char *fn, WavpackContext *ctx) | |
392 { | |
393 static char *displaytitle = NULL; | |
394 TitleInput *ti; | |
395 | |
114 | 396 ti = tuple_from_WavpackContext(fn, ctx); |
109 | 397 |
398 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
|
399 if (!displaytitle || *displaytitle == '\0') |
2e77e3fdd3c1
[svn] - make sure the tuple data is copied, not referenced (oops)
nenolod
parents:
114
diff
changeset
|
400 displaytitle = g_strdup(fn); |
114 | 401 |
402 bmp_title_input_free(ti); | |
109 | 403 |
404 return displaytitle; | |
405 } | |
406 | |
114 | 407 static TitleInput * |
408 wv_get_song_tuple(char *filename) | |
409 { | |
410 TitleInput *ti; | |
233
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
411 WavpackDecoder d(&mod); |
114 | 412 |
233
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
413 if (!d.attach(filename)) { |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
414 printf("wavpack: Error opening file: \"%s\"\n", filename); |
114 | 415 return NULL; |
416 } | |
417 | |
233
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
418 ti = tuple_from_WavpackContext(filename, d.ctx); |
114 | 419 |
420 return ti; | |
421 } | |
422 | |
109 | 423 static void |
424 wv_get_song_info(char *filename, char **title, int *length) | |
425 { | |
426 assert(filename != NULL); | |
233
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
427 WavpackDecoder d(&mod); |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
428 |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
429 if (!d.attach(filename)) { |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
430 printf("wavpack: Error opening file: \"%s\"\n", filename); |
109 | 431 return; |
432 } | |
233
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
433 |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
434 int sample_rate = WavpackGetSampleRate(d.ctx); |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
435 int num_channels = WavpackGetNumChannels(d.ctx); |
109 | 436 DBG("reading %s at %d rate with %d channels\n", filename, sample_rate, num_channels); |
437 | |
233
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
438 *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
|
439 *title = generate_title(filename, d.ctx); |
109 | 440 DBG("title for %s = %s\n", filename, *title); |
441 } | |
442 | |
443 static int | |
444 wv_get_time(void) | |
445 { | |
446 if (!mod.output) | |
447 return -1; | |
448 if (AudioError) | |
449 return -2; | |
450 if (killDecodeThread && !mod.output->buffer_playing()) | |
451 return -1; | |
452 return mod.output->output_time(); | |
453 } | |
454 | |
455 | |
456 static void | |
457 wv_seek(int sec) | |
458 { | |
459 isSeek = sec; | |
460 mod.output->flush((int) (1000 * isSeek)); | |
461 } | |
462 | |
463 static void | |
464 wv_pause(short pause) | |
465 { | |
466 mod.output->pause(paused = pause); | |
467 } | |
468 | |
469 static void | |
470 wv_stop(void) | |
471 { | |
472 killDecodeThread = true; | |
473 if (thread_handle != 0) { | |
474 g_thread_join(thread_handle); | |
475 if (openedAudio) { | |
476 mod.output->buffer_free(); | |
477 mod.output->close_audio(); | |
478 } | |
479 openedAudio = false; | |
480 if (AudioError) | |
481 printf("Could not open Audio\n"); | |
482 } | |
483 | |
484 } | |
485 | |
486 static void | |
487 wv_load_config() | |
488 { | |
489 ConfigDb *cfg; | |
490 | |
491 cfg = bmp_cfg_db_open(); | |
492 | |
493 bmp_cfg_db_get_bool(cfg, "wavpack", "clip_prevention", | |
494 &clipPreventionEnabled); | |
495 bmp_cfg_db_get_bool(cfg, "wavpack", "album_replaygain", | |
496 &albumReplaygainEnabled); | |
497 bmp_cfg_db_get_bool(cfg, "wavpack", "dyn_bitrate", &dynBitrateEnabled); | |
498 bmp_cfg_db_get_bool(cfg, "wavpack", "replaygain", &replaygainEnabled); | |
499 bmp_cfg_db_close(cfg); | |
500 | |
501 openedAudio = false; | |
502 } |