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