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