Mercurial > audlegacy-plugins
annotate src/wavpack/libwavpack.cxx @ 372:a157306caf03 trunk
[svn] - finalize the plugin-side of the extension-assist ABI
author | nenolod |
---|---|
date | Tue, 12 Dec 2006 19:43:23 -0800 |
parents | c812e846b84e |
children | 7385182ae4b8 |
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" | |
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 | |
372
a157306caf03
[svn] - finalize the plugin-side of the extension-assist ABI
nenolod
parents:
368
diff
changeset
|
59 gchar *wv_fmts[] = { "wv", NULL }; |
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 | |
64 NULL, | |
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, |
372
a157306caf03
[svn] - finalize the plugin-side of the extension-assist ABI
nenolod
parents:
368
diff
changeset
|
90 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 | |
250 extern "C" InputPlugin * | |
251 get_iplugin_info(void) | |
252 { | |
253 mod.description = | |
254 g_strdup_printf(("Wavpack Decoder Plugin %s"), VERSION); | |
255 return &mod; | |
256 } | |
257 | |
258 static int | |
253
ab24cfe495e0
[svn] Port to NewVFS file probe & add explicit cast to silence warning, thanks to spb.
chainsaw
parents:
247
diff
changeset
|
259 wv_is_our_fd(gchar *filename, VFSFile *file) |
109 | 260 { |
253
ab24cfe495e0
[svn] Port to NewVFS file probe & add explicit cast to silence warning, thanks to spb.
chainsaw
parents:
247
diff
changeset
|
261 gchar magic[4]; |
ab24cfe495e0
[svn] Port to NewVFS file probe & add explicit cast to silence warning, thanks to spb.
chainsaw
parents:
247
diff
changeset
|
262 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
|
263 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
|
264 return TRUE; |
109 | 265 return FALSE; |
266 } | |
267 | |
268 void | |
269 load_tag(ape_tag *tag, WavpackContext *ctx) | |
270 { | |
271 memset(tag, 0, sizeof(ape_tag)); | |
272 WavpackGetTagItem(ctx, "Album", tag->album, sizeof(tag->album)); | |
273 WavpackGetTagItem(ctx, "Artist", tag->artist, sizeof(tag->artist)); | |
274 WavpackGetTagItem(ctx, "Comment", tag->comment, sizeof(tag->comment)); | |
275 WavpackGetTagItem(ctx, "Genre", tag->genre, sizeof(tag->genre)); | |
276 WavpackGetTagItem(ctx, "Title", tag->title, sizeof(tag->title)); | |
277 WavpackGetTagItem(ctx, "Track", tag->track, sizeof(tag->track)); | |
278 WavpackGetTagItem(ctx, "Year", tag->year, sizeof(tag->year)); | |
279 } | |
280 | |
281 static void * | |
282 end_thread() | |
283 { | |
284 return 0; | |
285 } | |
286 | |
287 static void * | |
288 DecodeThread(void *a) | |
289 { | |
290 ape_tag tag; | |
291 char *filename = (char *) a; | |
292 int bps_updateCounter = 0; | |
293 int bps; | |
294 int i; | |
295 WavpackDecoder d(&mod); | |
296 | |
237 | 297 if (!d.attach_to_play(filename)) { |
109 | 298 printf("wavpack: Error opening file: \"%s\"\n", filename); |
299 killDecodeThread = true; | |
300 return end_thread(); | |
301 } | |
302 bps = WavpackGetBytesPerSample(d.ctx) * d.num_channels; | |
303 DBG("reading %s at %d rate with %d channels\n", filename, d.sample_rate, d.num_channels); | |
304 | |
305 if (!d.open_audio()) { | |
306 DBG("error opening xmms audio channel\n"); | |
307 killDecodeThread = true; | |
308 AudioError = true; | |
309 openedAudio = false; | |
310 } | |
311 else { | |
312 DBG("opened xmms audio channel\n"); | |
313 openedAudio = true; | |
314 } | |
315 unsigned status; | |
316 char *display = generate_title(filename, d.ctx); | |
317 int length = (int) (1000 * WavpackGetNumSamples(d.ctx)); | |
318 | |
319 while (!killDecodeThread) { | |
320 if (isSeek != -1) { | |
321 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
|
322 WavpackSeekSample(d.ctx, (int)(isSeek * d.sample_rate)); |
109 | 323 isSeek = -1; |
324 } | |
325 if (paused == 0 | |
326 && (mod.output->buffer_free() >= | |
327 (1152 * 2 * | |
328 (16 / 8)) << (mod.output->buffer_playing()? 1 : 0))) { | |
329 status = | |
330 WavpackUnpackSamples(d.ctx, d.input, BUFFER_SIZE); | |
331 if (status == (unsigned) (-1)) { | |
332 printf("wavpack: Error decoding file.\n"); | |
333 break; | |
334 } | |
335 else if (status == 0) { | |
336 killDecodeThread = true; | |
337 break; | |
338 } | |
339 else { | |
340 d.process_buffer(status); | |
341 } | |
342 } | |
343 else { | |
344 xmms_usleep(10000); | |
345 } | |
346 } | |
347 return end_thread(); | |
348 } | |
349 | |
350 static void | |
351 wv_play(char *filename) | |
352 { | |
353 paused = 0; | |
354 isSeek = -1; | |
355 killDecodeThread = false; | |
356 AudioError = false; | |
357 thread_handle = g_thread_create(DecodeThread, (void *) filename, TRUE, NULL); | |
358 return; | |
359 } | |
360 | |
114 | 361 static TitleInput * |
362 tuple_from_WavpackContext(const char *fn, WavpackContext *ctx) | |
363 { | |
364 ape_tag tag; | |
365 TitleInput *ti; | |
366 int sample_rate = WavpackGetSampleRate(ctx); | |
367 | |
368 ti = bmp_title_input_new(); | |
369 | |
130
16e2c64d8b2b
[svn] - provide a complete tuple (fixes albumart and such; path was missing.)
nenolod
parents:
115
diff
changeset
|
370 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
|
371 ti->file_path = g_path_get_dirname(fn); |
114 | 372 ti->file_ext = "wv"; |
373 | |
374 load_tag(&tag, ctx); | |
375 | |
115
2e77e3fdd3c1
[svn] - make sure the tuple data is copied, not referenced (oops)
nenolod
parents:
114
diff
changeset
|
376 ti->track_name = g_strdup(tag.title); |
2e77e3fdd3c1
[svn] - make sure the tuple data is copied, not referenced (oops)
nenolod
parents:
114
diff
changeset
|
377 ti->performer = g_strdup(tag.artist); |
2e77e3fdd3c1
[svn] - make sure the tuple data is copied, not referenced (oops)
nenolod
parents:
114
diff
changeset
|
378 ti->album_name = g_strdup(tag.album); |
2e77e3fdd3c1
[svn] - make sure the tuple data is copied, not referenced (oops)
nenolod
parents:
114
diff
changeset
|
379 ti->date = g_strdup(tag.year); |
114 | 380 ti->track_number = atoi(tag.track); |
381 if (ti->track_number < 0) | |
382 ti->track_number = 0; | |
383 ti->year = atoi(tag.year); | |
384 if (ti->year < 0) | |
385 ti->year = 0; | |
115
2e77e3fdd3c1
[svn] - make sure the tuple data is copied, not referenced (oops)
nenolod
parents:
114
diff
changeset
|
386 ti->genre = g_strdup(tag.genre); |
2e77e3fdd3c1
[svn] - make sure the tuple data is copied, not referenced (oops)
nenolod
parents:
114
diff
changeset
|
387 ti->comment = g_strdup(tag.comment); |
114 | 388 ti->length = (int)(WavpackGetNumSamples(ctx) / sample_rate) * 1000; |
389 | |
390 return ti; | |
391 } | |
392 | |
109 | 393 static char * |
394 generate_title(const char *fn, WavpackContext *ctx) | |
395 { | |
396 static char *displaytitle = NULL; | |
397 TitleInput *ti; | |
398 | |
114 | 399 ti = tuple_from_WavpackContext(fn, ctx); |
109 | 400 |
401 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
|
402 if (!displaytitle || *displaytitle == '\0') |
2e77e3fdd3c1
[svn] - make sure the tuple data is copied, not referenced (oops)
nenolod
parents:
114
diff
changeset
|
403 displaytitle = g_strdup(fn); |
114 | 404 |
405 bmp_title_input_free(ti); | |
109 | 406 |
407 return displaytitle; | |
408 } | |
409 | |
114 | 410 static TitleInput * |
411 wv_get_song_tuple(char *filename) | |
412 { | |
413 TitleInput *ti; | |
233
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
414 WavpackDecoder d(&mod); |
114 | 415 |
233
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
416 if (!d.attach(filename)) { |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
417 printf("wavpack: Error opening file: \"%s\"\n", filename); |
114 | 418 return NULL; |
419 } | |
420 | |
233
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
421 ti = tuple_from_WavpackContext(filename, d.ctx); |
114 | 422 |
423 return ti; | |
424 } | |
425 | |
109 | 426 static void |
427 wv_get_song_info(char *filename, char **title, int *length) | |
428 { | |
429 assert(filename != NULL); | |
233
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
430 WavpackDecoder d(&mod); |
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 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); |
109 | 434 return; |
435 } | |
233
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
436 |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
437 int sample_rate = WavpackGetSampleRate(d.ctx); |
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
438 int num_channels = WavpackGetNumChannels(d.ctx); |
109 | 439 DBG("reading %s at %d rate with %d channels\n", filename, sample_rate, num_channels); |
440 | |
233
7b7660c9f31c
[svn] - rewrite to take advantage of already existant object-oriented framework
nenolod
parents:
130
diff
changeset
|
441 *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
|
442 *title = generate_title(filename, d.ctx); |
109 | 443 DBG("title for %s = %s\n", filename, *title); |
444 } | |
445 | |
446 static int | |
447 wv_get_time(void) | |
448 { | |
449 if (!mod.output) | |
450 return -1; | |
451 if (AudioError) | |
452 return -2; | |
453 if (killDecodeThread && !mod.output->buffer_playing()) | |
454 return -1; | |
455 return mod.output->output_time(); | |
456 } | |
457 | |
458 | |
459 static void | |
460 wv_seek(int sec) | |
461 { | |
462 isSeek = sec; | |
463 mod.output->flush((int) (1000 * isSeek)); | |
464 } | |
465 | |
466 static void | |
467 wv_pause(short pause) | |
468 { | |
469 mod.output->pause(paused = pause); | |
470 } | |
471 | |
472 static void | |
473 wv_stop(void) | |
474 { | |
475 killDecodeThread = true; | |
476 if (thread_handle != 0) { | |
477 g_thread_join(thread_handle); | |
478 if (openedAudio) { | |
479 mod.output->buffer_free(); | |
480 mod.output->close_audio(); | |
481 } | |
482 openedAudio = false; | |
483 if (AudioError) | |
484 printf("Could not open Audio\n"); | |
485 } | |
486 | |
487 } | |
488 | |
489 static void | |
490 wv_load_config() | |
491 { | |
492 ConfigDb *cfg; | |
493 | |
494 cfg = bmp_cfg_db_open(); | |
495 | |
496 bmp_cfg_db_get_bool(cfg, "wavpack", "clip_prevention", | |
497 &clipPreventionEnabled); | |
498 bmp_cfg_db_get_bool(cfg, "wavpack", "album_replaygain", | |
499 &albumReplaygainEnabled); | |
500 bmp_cfg_db_get_bool(cfg, "wavpack", "dyn_bitrate", &dynBitrateEnabled); | |
501 bmp_cfg_db_get_bool(cfg, "wavpack", "replaygain", &replaygainEnabled); | |
502 bmp_cfg_db_close(cfg); | |
503 | |
504 openedAudio = false; | |
505 } |