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