Mercurial > audlegacy-plugins
annotate src/musepack/libmpc.cxx @ 1263:458d46e65a86
wav-sndfile: in is_our_file, ensure that filename is not NULL before passing it to sf_open
author | Giacomo Lozito <james@develia.org> |
---|---|
date | Fri, 13 Jul 2007 20:55:42 +0200 |
parents | 6d749f573b3b |
children | f34112ab9101 |
rev | line source |
---|---|
232 | 1 #include "libmpc.h" |
2 | |
3 #define FORCED_THREAD_STACKSIZE 1024 * 1000 | |
4 #define REMOVE_NONEXISTANT_TAG(x) if (!*x) { x = NULL; } | |
5 | |
6 using TagLib::MPC::File; | |
7 using TagLib::Tag; | |
8 using TagLib::String; | |
9 using TagLib::APE::ItemListMap; | |
10 | |
1044
b1128efde471
[svn] - get rid of all warnings gcc 4.2.0 emits with my build configuration.
yaz
parents:
659
diff
changeset
|
11 const gchar *mpc_fmts[] = { "mpc", NULL }; |
372
a157306caf03
[svn] - finalize the plugin-side of the extension-assist ABI
nenolod
parents:
368
diff
changeset
|
12 |
232 | 13 InputPlugin MpcPlugin = { |
14 NULL, //File Handle FILE* handle | |
15 NULL, //Filename char* filename | |
1185 | 16 (gchar *)"Musepack Audio Plugin", |
232 | 17 mpcOpenPlugin, //Open Plugin [CALLBACK] |
18 mpcAboutBox, //Show About box [CALLBACK] | |
19 mpcConfigBox, //Show Configure box [CALLBACK] | |
260
4f7b72c88319
[svn] So input.c wants to have the old-style function available...
chainsaw
parents:
254
diff
changeset
|
20 mpcIsOurFile, //Check if it's our file [CALLBACK] |
232 | 21 NULL, //Scan the directory [UNUSED] |
22 mpcPlay, //Play [CALLBACK] | |
23 mpcStop, //Stop [CALLBACK] | |
24 mpcPause, //Pause [CALLBACK] | |
25 mpcSeek, //Seek [CALLBACK] | |
26 NULL, //Set EQ [CALLBACK] | |
27 mpcGetTime, //Get Time [CALLBACK] | |
28 NULL, //Get Volume [UNUSED] | |
29 NULL, //Set Volume [UNUSED] | |
30 NULL, //Close Plugin [UNUSED] | |
31 NULL, //Obsolete [UNUSED] | |
32 NULL, //Visual plugins add_vis_pcm(int time, AFormat fmt, int nch, int length, void *ptr) | |
33 NULL, //Set Info Settings set_info(char *title, int length, int rate, int freq, int nch) | |
34 NULL, //set Info Text set_info_text(char* text) | |
35 mpcGetSongInfo, //Get Title String callback [CALLBACK] | |
36 mpcFileInfoBox, //Show File Info Box [CALLBACK] | |
37 NULL, //Output Plugin Handle OutputPlugin output | |
254 | 38 mpcGetSongTuple,//Acquire tuple for song [CALLBACK] |
39 NULL, | |
40 NULL, | |
41 mpcIsOurFD, | |
1044
b1128efde471
[svn] - get rid of all warnings gcc 4.2.0 emits with my build configuration.
yaz
parents:
659
diff
changeset
|
42 (gchar **)mpc_fmts |
232 | 43 }; |
44 | |
1079 | 45 InputPlugin *mpc_iplist[] = { &MpcPlugin, NULL }; |
46 | |
47 DECLARE_PLUGIN(musepack, NULL, NULL, mpc_iplist, NULL, NULL, NULL, NULL); | |
232 | 48 |
49 static PluginConfig pluginConfig = {0}; | |
50 static Widgets widgets = {0}; | |
51 static MpcDecoder mpcDecoder = {0}; | |
52 static TrackInfo track = {0}; | |
53 | |
54 static GThread *threadHandle; | |
55 GStaticMutex threadMutex = G_STATIC_MUTEX_INIT; | |
56 | |
57 /* | |
58 * VFS callback implementation, adapted from mpc_reader.c. | |
59 * This _IS_ very sick, but it works. -nenolod | |
60 */ | |
61 static mpc_int32_t | |
62 vfs_fread_impl(void *data, void *ptr, mpc_int32_t size) | |
63 { | |
64 mpc_reader_file *d = (mpc_reader_file *) data; | |
65 VFSFile *file = (VFSFile *) d->file; | |
66 | |
67 return (mpc_int32_t) vfs_fread(ptr, 1, size, file); | |
68 } | |
69 | |
70 static mpc_bool_t | |
71 vfs_fseek_impl(void *data, mpc_int32_t offset) | |
72 { | |
73 mpc_reader_file *d = (mpc_reader_file *) data; | |
74 VFSFile *file = (VFSFile *) d->file; | |
75 | |
76 return d->is_seekable ? vfs_fseek(file, offset, SEEK_SET) == 0 : FALSE; | |
77 } | |
78 | |
79 static mpc_int32_t | |
80 vfs_ftell_impl(void *data) | |
81 { | |
82 mpc_reader_file *d = (mpc_reader_file *) data; | |
83 VFSFile *file = (VFSFile *) d->file; | |
84 | |
85 return vfs_ftell(file); | |
86 } | |
87 | |
88 static mpc_int32_t | |
89 vfs_getsize_impl(void *data) | |
90 { | |
91 mpc_reader_file *d = (mpc_reader_file *) data; | |
92 | |
93 return d->file_size; | |
94 } | |
95 | |
96 static mpc_bool_t | |
97 vfs_canseek_impl(void *data) | |
98 { | |
99 mpc_reader_file *d = (mpc_reader_file *) data; | |
100 | |
101 return d->is_seekable; | |
102 } | |
103 | |
104 /* | |
105 * This sets up an mpc_reader_file object to read from VFS instead of libc. | |
106 * Essentially, we use this instead of the normal constructor. | |
107 * - nenolod | |
108 */ | |
109 void | |
110 mpc_reader_setup_file_vfs(mpc_reader_file *p_reader, VFSFile *input) | |
111 { | |
112 p_reader->reader.seek = vfs_fseek_impl; | |
113 p_reader->reader.read = vfs_fread_impl; | |
114 p_reader->reader.tell = vfs_ftell_impl; | |
115 p_reader->reader.get_size = vfs_getsize_impl; | |
116 p_reader->reader.canseek = vfs_canseek_impl; | |
117 p_reader->reader.data = p_reader; | |
118 | |
119 p_reader->file = (FILE *) input; // no worries, it gets cast back -nenolod | |
120 p_reader->is_seekable = TRUE; // XXX streams | |
121 | |
122 vfs_fseek(input, 0, SEEK_END); | |
123 p_reader->file_size = vfs_ftell(input); | |
124 vfs_fseek(input, 0, SEEK_SET); | |
125 } | |
126 | |
127 static void mpcOpenPlugin() | |
128 { | |
129 ConfigDb *cfg; | |
130 cfg = bmp_cfg_db_open(); | |
131 bmp_cfg_db_get_bool(cfg, "musepack", "clipPrevention", &pluginConfig.clipPrevention); | |
132 bmp_cfg_db_get_bool(cfg, "musepack", "albumGain", &pluginConfig.albumGain); | |
133 bmp_cfg_db_get_bool(cfg, "musepack", "dynamicBitrate", &pluginConfig.dynamicBitrate); | |
134 bmp_cfg_db_get_bool(cfg, "musepack", "replaygain", &pluginConfig.replaygain); | |
135 bmp_cfg_db_close(cfg); | |
136 } | |
137 | |
138 static void mpcAboutBox() | |
139 { | |
140 GtkWidget* aboutBox = widgets.aboutBox; | |
141 if (aboutBox) | |
142 gdk_window_raise(aboutBox->window); | |
143 else | |
144 { | |
145 char* titleText = g_strdup_printf("Musepack Decoder Plugin 1.2"); | |
1044
b1128efde471
[svn] - get rid of all warnings gcc 4.2.0 emits with my build configuration.
yaz
parents:
659
diff
changeset
|
146 const char* contentText = "Plugin code by\nBenoit Amiaux\nMartin Spuler\nKuniklo\n\nGet latest version at http://musepack.net\n"; |
b1128efde471
[svn] - get rid of all warnings gcc 4.2.0 emits with my build configuration.
yaz
parents:
659
diff
changeset
|
147 const char* buttonText = "Nevermind"; |
232 | 148 aboutBox = xmms_show_message(titleText, contentText, buttonText, FALSE, NULL, NULL); |
149 widgets.aboutBox = aboutBox; | |
150 g_signal_connect(G_OBJECT(aboutBox), "destroy", G_CALLBACK(gtk_widget_destroyed), &widgets.aboutBox); | |
151 } | |
152 } | |
153 | |
154 static void mpcConfigBox() | |
155 { | |
156 GtkWidget* configBox = widgets.configBox; | |
157 if(configBox) | |
158 gdk_window_raise(configBox->window); | |
159 else | |
160 { | |
161 configBox = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
162 gtk_window_set_type_hint(GTK_WINDOW(configBox), GDK_WINDOW_TYPE_HINT_DIALOG); | |
163 widgets.configBox = configBox; | |
164 g_signal_connect(G_OBJECT(configBox), "destroy", G_CALLBACK(gtk_widget_destroyed), &widgets.configBox); | |
165 gtk_window_set_title(GTK_WINDOW(configBox), "Musepack Decoder Configuration"); | |
166 gtk_window_set_policy(GTK_WINDOW(configBox), FALSE, FALSE, FALSE); | |
167 gtk_container_border_width(GTK_CONTAINER(configBox), 10); | |
168 | |
169 GtkWidget* notebook = gtk_notebook_new(); | |
170 GtkWidget* vbox = gtk_vbox_new(FALSE, 10); | |
171 gtk_box_pack_start(GTK_BOX(vbox), notebook, TRUE, TRUE, 0); | |
172 gtk_container_add(GTK_CONTAINER(configBox), vbox); | |
173 | |
174 //General Settings Tab | |
175 GtkWidget* generalSet = gtk_frame_new("General Settings"); | |
176 gtk_container_border_width(GTK_CONTAINER(generalSet), 5); | |
177 | |
178 GtkWidget* gSvbox = gtk_vbox_new(FALSE, 10); | |
179 gtk_container_border_width(GTK_CONTAINER(gSvbox), 5); | |
180 gtk_container_add(GTK_CONTAINER(generalSet), gSvbox); | |
181 | |
182 GtkWidget* bitrateCheck = gtk_check_button_new_with_label("Enable Dynamic Bitrate Display"); | |
183 widgets.bitrateCheck = bitrateCheck; | |
184 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(bitrateCheck), pluginConfig.dynamicBitrate); | |
185 gtk_box_pack_start(GTK_BOX(gSvbox), bitrateCheck, FALSE, FALSE, 0); | |
186 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), generalSet, gtk_label_new("Plugin")); | |
187 | |
188 //ReplayGain Settings Tab | |
189 GtkWidget* replaygainSet = gtk_frame_new("ReplayGain Settings"); | |
190 gtk_container_border_width(GTK_CONTAINER(replaygainSet), 5); | |
191 | |
192 GtkWidget* rSVbox = gtk_vbox_new(FALSE, 10); | |
193 gtk_container_border_width(GTK_CONTAINER(rSVbox), 5); | |
194 gtk_container_add(GTK_CONTAINER(replaygainSet), rSVbox); | |
195 | |
196 GtkWidget* clippingCheck = gtk_check_button_new_with_label("Enable Clipping Prevention"); | |
197 widgets.clippingCheck = clippingCheck; | |
198 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(clippingCheck), pluginConfig.clipPrevention); | |
199 gtk_box_pack_start(GTK_BOX(rSVbox), clippingCheck, FALSE, FALSE, 0); | |
200 | |
201 GtkWidget* replaygainCheck = gtk_check_button_new_with_label("Enable ReplayGain"); | |
202 widgets.replaygainCheck = replaygainCheck; | |
203 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(replaygainCheck), pluginConfig.replaygain); | |
204 gtk_box_pack_start(GTK_BOX(rSVbox), replaygainCheck, FALSE, FALSE, 0); | |
205 | |
206 GtkWidget* replaygainType = gtk_frame_new("ReplayGain Type"); | |
207 gtk_box_pack_start(GTK_BOX(rSVbox), replaygainType, FALSE, FALSE, 0); | |
208 g_signal_connect(G_OBJECT(replaygainCheck), "toggled", G_CALLBACK(toggleSwitch), replaygainType); | |
209 | |
210 GtkWidget* rgVbox = gtk_vbox_new(FALSE, 5); | |
211 gtk_container_set_border_width(GTK_CONTAINER(rgVbox), 5); | |
212 gtk_container_add(GTK_CONTAINER(replaygainType), rgVbox); | |
213 | |
214 GtkWidget* trackCheck = gtk_radio_button_new_with_label(NULL, "Use Track Gain"); | |
215 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(trackCheck), !pluginConfig.albumGain); | |
216 gtk_box_pack_start(GTK_BOX(rgVbox), trackCheck, FALSE, FALSE, 0); | |
217 | |
218 GtkWidget* albumCheck = gtk_radio_button_new_with_label(gtk_radio_button_group(GTK_RADIO_BUTTON(trackCheck)), "Use Album Gain"); | |
219 widgets.albumCheck = albumCheck; | |
220 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(albumCheck), pluginConfig.albumGain); | |
221 gtk_box_pack_start(GTK_BOX(rgVbox), albumCheck, FALSE, FALSE, 0); | |
222 gtk_widget_set_sensitive(replaygainType, pluginConfig.replaygain); | |
223 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), replaygainSet, gtk_label_new("ReplayGain")); | |
224 | |
225 //Buttons | |
226 GtkWidget* buttonBox = gtk_hbutton_box_new(); | |
227 gtk_button_box_set_layout(GTK_BUTTON_BOX(buttonBox), GTK_BUTTONBOX_END); | |
228 gtk_button_box_set_spacing(GTK_BUTTON_BOX(buttonBox), 5); | |
229 gtk_box_pack_start(GTK_BOX(vbox), buttonBox, FALSE, FALSE, 0); | |
230 | |
231 GtkWidget* okButton = gtk_button_new_with_label("Ok"); | |
232 g_signal_connect(G_OBJECT(okButton), "clicked", G_CALLBACK(saveConfigBox), NULL); | |
233 GTK_WIDGET_SET_FLAGS(okButton, GTK_CAN_DEFAULT); | |
234 gtk_box_pack_start(GTK_BOX(buttonBox), okButton, TRUE, TRUE, 0); | |
235 | |
236 GtkWidget* cancelButton = gtk_button_new_with_label("Cancel"); | |
237 g_signal_connect_swapped(G_OBJECT(cancelButton), "clicked", G_CALLBACK(gtk_widget_destroy), GTK_OBJECT(widgets.configBox)); | |
238 GTK_WIDGET_SET_FLAGS(cancelButton, GTK_CAN_DEFAULT); | |
239 gtk_widget_grab_default(cancelButton); | |
240 gtk_box_pack_start(GTK_BOX(buttonBox), cancelButton, TRUE, TRUE, 0); | |
241 | |
242 gtk_widget_show_all(configBox); | |
243 } | |
244 } | |
245 | |
246 static void toggleSwitch(GtkWidget* p_Widget, gpointer p_Data) | |
247 { | |
248 gtk_widget_set_sensitive(GTK_WIDGET(p_Data), gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(p_Widget))); | |
249 } | |
250 | |
251 static void saveConfigBox(GtkWidget* p_Widget, gpointer p_Data) | |
252 { | |
253 ConfigDb* cfg; | |
254 GtkToggleButton* tb; | |
255 | |
256 tb = GTK_TOGGLE_BUTTON(widgets.replaygainCheck); | |
257 pluginConfig.replaygain = gtk_toggle_button_get_active(tb); | |
258 tb = GTK_TOGGLE_BUTTON(widgets.clippingCheck); | |
259 pluginConfig.clipPrevention = gtk_toggle_button_get_active(tb); | |
260 tb = GTK_TOGGLE_BUTTON(widgets.bitrateCheck); | |
261 pluginConfig.dynamicBitrate = gtk_toggle_button_get_active(tb); | |
262 tb = GTK_TOGGLE_BUTTON(widgets.albumCheck); | |
263 pluginConfig.albumGain = gtk_toggle_button_get_active(tb); | |
264 | |
265 cfg = bmp_cfg_db_open(); | |
266 | |
267 bmp_cfg_db_set_bool(cfg, "musepack", "clipPrevention", pluginConfig.clipPrevention); | |
268 bmp_cfg_db_set_bool(cfg, "musepack", "albumGain", pluginConfig.albumGain); | |
269 bmp_cfg_db_set_bool(cfg, "musepack", "dynamicBitrate", pluginConfig.dynamicBitrate); | |
270 bmp_cfg_db_set_bool(cfg, "musepack", "replaygain", pluginConfig.replaygain); | |
271 | |
272 bmp_cfg_db_close(cfg); | |
273 | |
274 gtk_widget_destroy (widgets.configBox); | |
275 } | |
276 | |
260
4f7b72c88319
[svn] So input.c wants to have the old-style function available...
chainsaw
parents:
254
diff
changeset
|
277 static int mpcIsOurFile(char* p_Filename) |
4f7b72c88319
[svn] So input.c wants to have the old-style function available...
chainsaw
parents:
254
diff
changeset
|
278 { |
4f7b72c88319
[svn] So input.c wants to have the old-style function available...
chainsaw
parents:
254
diff
changeset
|
279 VFSFile *file; |
4f7b72c88319
[svn] So input.c wants to have the old-style function available...
chainsaw
parents:
254
diff
changeset
|
280 gchar magic[3]; |
4f7b72c88319
[svn] So input.c wants to have the old-style function available...
chainsaw
parents:
254
diff
changeset
|
281 if ((file = vfs_fopen(p_Filename, "rb"))) { |
4f7b72c88319
[svn] So input.c wants to have the old-style function available...
chainsaw
parents:
254
diff
changeset
|
282 vfs_fread(magic, 1, 3, file); |
4f7b72c88319
[svn] So input.c wants to have the old-style function available...
chainsaw
parents:
254
diff
changeset
|
283 if (!memcmp(magic, "MP+", 3)) { |
4f7b72c88319
[svn] So input.c wants to have the old-style function available...
chainsaw
parents:
254
diff
changeset
|
284 vfs_fclose(file); |
4f7b72c88319
[svn] So input.c wants to have the old-style function available...
chainsaw
parents:
254
diff
changeset
|
285 return 1; |
4f7b72c88319
[svn] So input.c wants to have the old-style function available...
chainsaw
parents:
254
diff
changeset
|
286 } |
4f7b72c88319
[svn] So input.c wants to have the old-style function available...
chainsaw
parents:
254
diff
changeset
|
287 vfs_fclose(file); |
4f7b72c88319
[svn] So input.c wants to have the old-style function available...
chainsaw
parents:
254
diff
changeset
|
288 } |
4f7b72c88319
[svn] So input.c wants to have the old-style function available...
chainsaw
parents:
254
diff
changeset
|
289 return 0; |
4f7b72c88319
[svn] So input.c wants to have the old-style function available...
chainsaw
parents:
254
diff
changeset
|
290 } |
4f7b72c88319
[svn] So input.c wants to have the old-style function available...
chainsaw
parents:
254
diff
changeset
|
291 |
254 | 292 static int mpcIsOurFD(char* p_Filename, VFSFile* file) |
232 | 293 { |
254 | 294 gchar magic[3]; |
295 vfs_fread(magic, 1, 3, file); | |
260
4f7b72c88319
[svn] So input.c wants to have the old-style function available...
chainsaw
parents:
254
diff
changeset
|
296 if (!memcmp(magic, "MP+", 3)) |
254 | 297 return 1; |
298 return 0; | |
232 | 299 } |
300 | |
567 | 301 static void mpcPlay(InputPlayback *data) |
232 | 302 { |
303 mpcDecoder.offset = -1; | |
304 mpcDecoder.isAlive = true; | |
305 mpcDecoder.isOutput = false; | |
306 mpcDecoder.isPause = false; | |
567 | 307 threadHandle = g_thread_create(GThreadFunc(decodeStream), (void *) g_strdup(data->filename), TRUE, NULL); |
232 | 308 } |
309 | |
567 | 310 static void mpcStop(InputPlayback *data) |
232 | 311 { |
312 setAlive(false); | |
313 if (threadHandle) | |
314 { | |
315 g_thread_join(threadHandle); | |
316 if (mpcDecoder.isOutput) | |
317 { | |
567 | 318 data->output->buffer_free(); |
319 data->output->close_audio(); | |
232 | 320 mpcDecoder.isOutput = false; |
321 } | |
322 } | |
323 } | |
324 | |
567 | 325 static void mpcPause(InputPlayback *data, short p_Pause) |
232 | 326 { |
327 lockAcquire(); | |
328 mpcDecoder.isPause = p_Pause; | |
567 | 329 data->output->pause(p_Pause); |
232 | 330 lockRelease(); |
331 } | |
332 | |
567 | 333 static void mpcSeek(InputPlayback *data, int p_Offset) |
232 | 334 { |
335 lockAcquire(); | |
336 mpcDecoder.offset = static_cast<double> (p_Offset); | |
567 | 337 data->output->flush(1000 * p_Offset); |
232 | 338 lockRelease(); |
339 } | |
340 | |
567 | 341 static int mpcGetTime(InputPlayback *data) |
232 | 342 { |
343 if(!isAlive()) | |
344 return -1; | |
567 | 345 return data->output->output_time(); |
232 | 346 } |
347 | |
348 static TitleInput *mpcGetSongTuple(char* p_Filename) | |
349 { | |
350 VFSFile *input = vfs_fopen(p_Filename, "rb"); | |
351 TitleInput *tuple = NULL; | |
352 | |
353 if(input) | |
354 { | |
355 tuple = bmp_title_input_new(); | |
356 gchar *filename_proxy = g_strdup(p_Filename); | |
357 | |
358 tuple->file_name = g_path_get_basename(filename_proxy); | |
359 tuple->file_path = g_path_get_dirname(filename_proxy); | |
360 tuple->file_ext = "mpc"; // XXX: I can't be assed. -nenolod | |
361 | |
362 MpcInfo tags = getTags(p_Filename); | |
363 | |
364 tuple->date = g_strdup(tags.date); | |
365 tuple->track_name = g_strdup(tags.title); | |
366 tuple->performer = g_strdup(tags.artist); | |
367 tuple->album_name = g_strdup(tags.album); | |
368 tuple->track_number = tags.track; | |
369 tuple->year = tags.year; | |
370 tuple->genre = g_strdup(tags.genre); | |
371 tuple->comment = g_strdup(tags.comment); | |
372 | |
373 freeTags(tags); | |
374 | |
375 mpc_streaminfo info; | |
376 mpc_reader_file reader; | |
377 mpc_reader_setup_file_vfs(&reader, input); | |
378 mpc_streaminfo_read(&info, &reader.reader); | |
379 | |
380 tuple->length = static_cast<int> (1000 * mpc_streaminfo_get_length(&info)); | |
381 vfs_fclose(input); | |
382 } | |
383 else | |
384 { | |
385 char* temp = g_strdup_printf("[xmms-musepack] mpcGetSongInfo is unable to open %s\n", p_Filename); | |
386 perror(temp); | |
387 free(temp); | |
388 } | |
389 | |
390 return tuple; | |
391 } | |
392 | |
393 static void mpcGetSongInfo(char* p_Filename, char** p_Title, int* p_Length) | |
394 { | |
395 VFSFile *input = vfs_fopen(p_Filename, "rb"); | |
396 if(input) | |
397 { | |
398 MpcInfo tags = getTags(p_Filename); | |
399 *p_Title = mpcGenerateTitle(tags, p_Filename); | |
400 freeTags(tags); | |
401 mpc_streaminfo info; | |
402 mpc_reader_file reader; | |
403 mpc_reader_setup_file_vfs(&reader, input); | |
404 mpc_streaminfo_read(&info, &reader.reader); | |
405 *p_Length = static_cast<int> (1000 * mpc_streaminfo_get_length(&info)); | |
406 vfs_fclose(input); | |
407 } | |
408 else | |
409 { | |
410 char* temp = g_strdup_printf("[xmms-musepack] mpcGetSongInfo is unable to open %s\n", p_Filename); | |
411 perror(temp); | |
412 free(temp); | |
413 } | |
414 } | |
415 | |
416 static void freeTags(MpcInfo& tags) | |
417 { | |
418 free(tags.title); | |
419 free(tags.artist); | |
420 free(tags.album); | |
421 free(tags.comment); | |
422 free(tags.genre); | |
423 free(tags.date); | |
424 } | |
425 | |
426 static MpcInfo getTags(const char* p_Filename) | |
427 { | |
428 File oFile(p_Filename, false); | |
429 Tag* poTag = oFile.tag(); | |
430 MpcInfo tags = {0}; | |
431 tags.title = g_strdup(poTag->title().toCString(true)); | |
432 REMOVE_NONEXISTANT_TAG(tags.title); | |
433 tags.artist = g_strdup(poTag->artist().toCString(true)); | |
434 REMOVE_NONEXISTANT_TAG(tags.artist); | |
435 tags.album = g_strdup(poTag->album().toCString(true)); | |
436 REMOVE_NONEXISTANT_TAG(tags.album); | |
437 tags.genre = g_strdup(poTag->genre().toCString(true)); | |
438 REMOVE_NONEXISTANT_TAG(tags.genre); | |
439 tags.comment = g_strdup(poTag->comment().toCString(true)); | |
440 REMOVE_NONEXISTANT_TAG(tags.comment); | |
441 tags.year = poTag->year(); | |
442 tags.track = poTag->track(); | |
659
d1a03def0021
[svn] - disable broken APETag support for now, can cause crashes
nenolod
parents:
567
diff
changeset
|
443 #if 0 |
232 | 444 TagLib::APE::Tag* ape = oFile.APETag(false); |
445 if(ape) | |
446 { | |
447 ItemListMap map = ape->itemListMap(); | |
448 if(map.contains("YEAR")) | |
449 { | |
450 tags.date = g_strdup(map["YEAR"].toString().toCString(true)); | |
451 } | |
452 else | |
453 { | |
454 tags.date = g_strdup_printf("%d", tags.year); | |
455 } | |
456 } | |
659
d1a03def0021
[svn] - disable broken APETag support for now, can cause crashes
nenolod
parents:
567
diff
changeset
|
457 #endif |
232 | 458 return tags; |
459 } | |
460 | |
461 static void mpcFileInfoBox(char* p_Filename) | |
462 { | |
463 GtkWidget* infoBox = widgets.infoBox; | |
464 | |
465 if(infoBox) | |
466 gdk_window_raise(infoBox->window); | |
467 else | |
468 { | |
469 infoBox = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
470 gtk_window_set_type_hint(GTK_WINDOW(infoBox), GDK_WINDOW_TYPE_HINT_DIALOG); | |
471 widgets.infoBox = infoBox; | |
472 gtk_window_set_policy(GTK_WINDOW(infoBox), FALSE, FALSE, FALSE); | |
473 g_signal_connect(G_OBJECT(infoBox), "destroy", G_CALLBACK(closeInfoBox), NULL); | |
474 gtk_container_set_border_width(GTK_CONTAINER(infoBox), 10); | |
475 | |
476 GtkWidget* iVbox = gtk_vbox_new(FALSE, 10); | |
477 gtk_container_add(GTK_CONTAINER(infoBox), iVbox); | |
478 | |
479 GtkWidget* filenameHbox = gtk_hbox_new(FALSE, 5); | |
480 gtk_box_pack_start(GTK_BOX(iVbox), filenameHbox, FALSE, TRUE, 0); | |
481 | |
482 GtkWidget* fileLabel = gtk_label_new("Filename:"); | |
483 gtk_box_pack_start(GTK_BOX(filenameHbox), fileLabel, FALSE, TRUE, 0); | |
484 | |
485 GtkWidget* fileEntry = gtk_entry_new(); | |
486 widgets.fileEntry = fileEntry; | |
487 gtk_editable_set_editable(GTK_EDITABLE(fileEntry), FALSE); | |
488 gtk_box_pack_start(GTK_BOX(filenameHbox), fileEntry, TRUE, TRUE, 0); | |
489 | |
490 GtkWidget* iHbox = gtk_hbox_new(FALSE, 10); | |
491 gtk_box_pack_start(GTK_BOX(iVbox), iHbox, FALSE, TRUE, 0); | |
492 | |
493 GtkWidget* leftBox = gtk_vbox_new(FALSE, 10); | |
494 gtk_box_pack_start(GTK_BOX(iHbox), leftBox, FALSE, FALSE, 0); | |
495 | |
496 //Tag labels | |
497 GtkWidget* tagFrame = gtk_frame_new("Musepack Tag"); | |
498 gtk_box_pack_start(GTK_BOX(leftBox), tagFrame, FALSE, FALSE, 0); | |
499 gtk_widget_set_sensitive(tagFrame, TRUE); | |
500 | |
501 GtkWidget* iTable = gtk_table_new(5, 5, FALSE); | |
502 gtk_container_set_border_width(GTK_CONTAINER(iTable), 5); | |
503 gtk_container_add(GTK_CONTAINER(tagFrame), iTable); | |
504 | |
505 mpcGtkTagLabel("Title:", 0, 1, 0, 1, iTable); | |
506 GtkWidget* titleEntry = mpcGtkTagEntry(1, 4, 0, 1, 0, iTable); | |
507 widgets.titleEntry = titleEntry; | |
508 | |
509 mpcGtkTagLabel("Artist:", 0, 1, 1, 2, iTable); | |
510 GtkWidget* artistEntry = mpcGtkTagEntry(1, 4, 1, 2, 0, iTable); | |
511 widgets.artistEntry = artistEntry; | |
512 | |
513 mpcGtkTagLabel("Album:", 0, 1, 2, 3, iTable); | |
514 GtkWidget* albumEntry = mpcGtkTagEntry(1, 4, 2, 3, 0, iTable); | |
515 widgets.albumEntry = albumEntry; | |
516 | |
517 mpcGtkTagLabel("Comment:", 0, 1, 3, 4, iTable); | |
518 GtkWidget* commentEntry = mpcGtkTagEntry(1, 4, 3, 4, 0, iTable); | |
519 widgets.commentEntry = commentEntry; | |
520 | |
521 mpcGtkTagLabel("Year:", 0, 1, 4, 5, iTable); | |
522 GtkWidget* yearEntry = mpcGtkTagEntry(1, 2, 4, 5, 4, iTable); | |
523 widgets.yearEntry = yearEntry; | |
524 gtk_widget_set_usize(yearEntry, 4, -1); | |
525 | |
526 mpcGtkTagLabel("Track:", 2, 3, 4, 5, iTable); | |
527 GtkWidget* trackEntry = mpcGtkTagEntry(3, 4, 4, 5, 4, iTable); | |
528 widgets.trackEntry = trackEntry; | |
529 gtk_widget_set_usize(trackEntry, 3, -1); | |
530 | |
531 mpcGtkTagLabel("Genre:", 0, 1, 5, 6, iTable); | |
532 GtkWidget* genreEntry = mpcGtkTagEntry(1, 4, 5, 6, 0, iTable); | |
533 widgets.genreEntry = genreEntry; | |
534 gtk_widget_set_usize(genreEntry, 20, -1); | |
535 | |
536 //Buttons | |
537 GtkWidget* buttonBox = gtk_hbutton_box_new(); | |
538 gtk_button_box_set_layout(GTK_BUTTON_BOX(buttonBox), GTK_BUTTONBOX_END); | |
539 gtk_button_box_set_spacing(GTK_BUTTON_BOX(buttonBox), 5); | |
540 gtk_box_pack_start(GTK_BOX(leftBox), buttonBox, FALSE, FALSE, 0); | |
541 | |
542 GtkWidget* saveButton = mpcGtkButton("Save", buttonBox); | |
543 g_signal_connect(G_OBJECT(saveButton), "clicked", G_CALLBACK(saveTags), NULL); | |
544 | |
545 GtkWidget* removeButton = mpcGtkButton("Remove Tag", buttonBox); | |
546 g_signal_connect_swapped(G_OBJECT(removeButton), "clicked", G_CALLBACK(removeTags), NULL); | |
547 | |
548 GtkWidget* cancelButton = mpcGtkButton("Cancel", buttonBox); | |
549 g_signal_connect_swapped(G_OBJECT(cancelButton), "clicked", G_CALLBACK(closeInfoBox), NULL); | |
550 gtk_widget_grab_default(cancelButton); | |
551 | |
552 //File information | |
553 GtkWidget* infoFrame = gtk_frame_new("Musepack Info"); | |
554 gtk_box_pack_start(GTK_BOX(iHbox), infoFrame, FALSE, FALSE, 0); | |
555 | |
556 GtkWidget* infoVbox = gtk_vbox_new(FALSE, 5); | |
557 gtk_container_add(GTK_CONTAINER(infoFrame), infoVbox); | |
558 gtk_container_set_border_width(GTK_CONTAINER(infoVbox), 10); | |
559 gtk_box_set_spacing(GTK_BOX(infoVbox), 0); | |
560 | |
561 GtkWidget* streamLabel = mpcGtkLabel(infoVbox); | |
562 GtkWidget* encoderLabel = mpcGtkLabel(infoVbox); | |
563 GtkWidget* profileLabel = mpcGtkLabel(infoVbox); | |
564 GtkWidget* bitrateLabel = mpcGtkLabel(infoVbox); | |
565 GtkWidget* rateLabel = mpcGtkLabel(infoVbox); | |
566 GtkWidget* channelsLabel = mpcGtkLabel(infoVbox); | |
567 GtkWidget* lengthLabel = mpcGtkLabel(infoVbox); | |
568 GtkWidget* fileSizeLabel = mpcGtkLabel(infoVbox); | |
569 GtkWidget* trackPeakLabel = mpcGtkLabel(infoVbox); | |
570 GtkWidget* trackGainLabel = mpcGtkLabel(infoVbox); | |
571 GtkWidget* albumPeakLabel = mpcGtkLabel(infoVbox); | |
572 GtkWidget* albumGainLabel = mpcGtkLabel(infoVbox); | |
573 | |
574 VFSFile *input = vfs_fopen(p_Filename, "rb"); | |
575 if(input) | |
576 { | |
577 mpc_streaminfo info; | |
578 mpc_reader_file reader; | |
579 mpc_reader_setup_file_vfs(&reader, input); | |
580 mpc_streaminfo_read(&info, &reader.reader); | |
581 | |
582 int time = static_cast<int> (mpc_streaminfo_get_length(&info)); | |
583 int minutes = time / 60; | |
584 int seconds = time % 60; | |
585 | |
586 mpcGtkPrintLabel(streamLabel, "Streamversion %d", info.stream_version); | |
587 mpcGtkPrintLabel(encoderLabel, "Encoder: \%s", info.encoder); | |
588 mpcGtkPrintLabel(profileLabel, "Profile: \%s", info.profile_name); | |
589 mpcGtkPrintLabel(bitrateLabel, "Average bitrate: \%6.1f kbps", info.average_bitrate * 1.e-3); | |
590 mpcGtkPrintLabel(rateLabel, "Samplerate: \%d Hz", info.sample_freq); | |
591 mpcGtkPrintLabel(channelsLabel, "Channels: \%d", info.channels); | |
592 mpcGtkPrintLabel(lengthLabel, "Length: \%d:\%.2d", minutes, seconds); | |
593 mpcGtkPrintLabel(fileSizeLabel, "File size: \%d Bytes", info.total_file_length); | |
594 mpcGtkPrintLabel(trackPeakLabel, "Track Peak: \%5u", info.peak_title); | |
595 mpcGtkPrintLabel(trackGainLabel, "Track Gain: \%-+2.2f dB", 0.01 * info.gain_title); | |
596 mpcGtkPrintLabel(albumPeakLabel, "Album Peak: \%5u", info.peak_album); | |
597 mpcGtkPrintLabel(albumGainLabel, "Album Gain: \%-+5.2f dB", 0.01 * info.gain_album); | |
598 | |
599 MpcInfo tags = getTags(p_Filename); | |
600 gtk_entry_set_text(GTK_ENTRY(titleEntry), tags.title); | |
601 gtk_entry_set_text(GTK_ENTRY(artistEntry), tags.artist); | |
602 gtk_entry_set_text(GTK_ENTRY(albumEntry), tags.album); | |
603 gtk_entry_set_text(GTK_ENTRY(commentEntry), tags.comment); | |
604 gtk_entry_set_text(GTK_ENTRY(genreEntry), tags.genre); | |
605 char* entry = g_strdup_printf ("%d", tags.track); | |
606 gtk_entry_set_text(GTK_ENTRY(trackEntry), entry); | |
607 free(entry); | |
608 entry = g_strdup_printf ("%d", tags.year); | |
609 gtk_entry_set_text(GTK_ENTRY(yearEntry), entry); | |
610 free(entry); | |
611 entry = g_filename_display_name(p_Filename); | |
612 gtk_entry_set_text(GTK_ENTRY(fileEntry), entry); | |
613 free(entry); | |
614 freeTags(tags); | |
615 vfs_fclose(input); | |
616 } | |
617 else | |
618 { | |
619 char* temp = g_strdup_printf("[xmms-musepack] mpcFileInfoBox is unable to read tags from %s", p_Filename); | |
620 perror(temp); | |
621 free(temp); | |
622 } | |
623 | |
624 char* name = g_filename_display_basename(p_Filename); | |
625 char* text = g_strdup_printf("File Info - %s", name); | |
626 free(name); | |
627 gtk_window_set_title(GTK_WINDOW(infoBox), text); | |
628 free(text); | |
629 | |
630 gtk_widget_show_all(infoBox); | |
631 } | |
632 } | |
633 | |
1044
b1128efde471
[svn] - get rid of all warnings gcc 4.2.0 emits with my build configuration.
yaz
parents:
659
diff
changeset
|
634 static void mpcGtkPrintLabel(GtkWidget* widget, const char* format,...) |
232 | 635 { |
636 va_list args; | |
637 | |
638 va_start(args, format); | |
639 char* temp = g_strdup_vprintf(format, args); | |
640 va_end(args); | |
641 | |
642 gtk_label_set_text(GTK_LABEL(widget), temp); | |
643 free(temp); | |
644 } | |
645 | |
1044
b1128efde471
[svn] - get rid of all warnings gcc 4.2.0 emits with my build configuration.
yaz
parents:
659
diff
changeset
|
646 static GtkWidget* mpcGtkTagLabel(const char* p_Text, int a, int b, int c, int d, GtkWidget* p_Box) |
232 | 647 { |
648 GtkWidget* label = gtk_label_new(p_Text); | |
649 gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5); | |
650 gtk_table_attach(GTK_TABLE(p_Box), label, a, b, c, d, GTK_FILL, GTK_FILL, 5, 5); | |
651 return label; | |
652 } | |
653 | |
654 static GtkWidget* mpcGtkTagEntry(int a, int b, int c, int d, int p_Size, GtkWidget* p_Box) | |
655 { | |
656 GtkWidget* entry; | |
657 if(p_Size == 0) | |
658 entry = gtk_entry_new(); | |
659 else | |
660 entry = gtk_entry_new_with_max_length(p_Size); | |
661 gtk_table_attach(GTK_TABLE(p_Box), entry, a, b, c, d, | |
662 (GtkAttachOptions) (GTK_FILL | GTK_EXPAND | GTK_SHRINK), | |
663 (GtkAttachOptions) (GTK_FILL | GTK_EXPAND | GTK_SHRINK), 0, 5); | |
664 return entry; | |
665 } | |
666 | |
667 static GtkWidget* mpcGtkLabel(GtkWidget* p_Box) | |
668 { | |
669 GtkWidget* label = gtk_label_new(""); | |
670 gtk_misc_set_alignment(GTK_MISC(label), 0, 0); | |
671 gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT); | |
672 gtk_box_pack_start(GTK_BOX(p_Box), label, FALSE, FALSE, 0); | |
673 return label; | |
674 } | |
675 | |
1044
b1128efde471
[svn] - get rid of all warnings gcc 4.2.0 emits with my build configuration.
yaz
parents:
659
diff
changeset
|
676 static GtkWidget* mpcGtkButton(const char* p_Text, GtkWidget* p_Box) |
232 | 677 { |
678 GtkWidget* button = gtk_button_new_with_label(p_Text); | |
679 GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT); | |
680 gtk_box_pack_start(GTK_BOX(p_Box), button, TRUE, TRUE, 0); | |
681 return button; | |
682 } | |
683 | |
684 static void removeTags(GtkWidget * w, gpointer data) | |
685 { | |
686 File oFile(gtk_entry_get_text(GTK_ENTRY(widgets.fileEntry))); | |
687 oFile.remove(); | |
688 oFile.save(); | |
689 closeInfoBox(NULL, NULL); | |
690 } | |
691 | |
692 static void saveTags(GtkWidget* w, gpointer data) | |
693 { | |
694 File oFile(gtk_entry_get_text(GTK_ENTRY(widgets.fileEntry))); | |
695 Tag* poTag = oFile.tag(); | |
696 | |
697 char* cAlbum = g_strdup(gtk_entry_get_text(GTK_ENTRY(widgets.albumEntry))); | |
698 char* cArtist = g_strdup(gtk_entry_get_text(GTK_ENTRY(widgets.artistEntry))); | |
699 char* cTitle = g_strdup(gtk_entry_get_text(GTK_ENTRY(widgets.titleEntry))); | |
700 char* cGenre = g_strdup(gtk_entry_get_text(GTK_ENTRY(widgets.genreEntry))); | |
701 char* cComment = g_strdup(gtk_entry_get_text(GTK_ENTRY(widgets.commentEntry))); | |
702 | |
703 const String album = String(cAlbum, TagLib::String::UTF8); | |
704 const String artist = String(cArtist, TagLib::String::UTF8); | |
705 const String title = String(cTitle, TagLib::String::UTF8); | |
706 const String genre = String(cGenre, TagLib::String::UTF8); | |
707 const String comment = String(cComment, TagLib::String::UTF8); | |
708 | |
709 poTag->setAlbum(album); | |
710 poTag->setArtist(artist); | |
711 poTag->setTitle(title); | |
712 poTag->setGenre(genre); | |
713 poTag->setComment(comment); | |
714 poTag->setYear(atoi(gtk_entry_get_text(GTK_ENTRY(widgets.yearEntry)))); | |
715 poTag->setTrack(atoi(gtk_entry_get_text(GTK_ENTRY(widgets.trackEntry)))); | |
716 | |
717 free(cAlbum); | |
718 free(cArtist); | |
719 free(cTitle); | |
720 free(cGenre); | |
721 free(cComment); | |
722 | |
723 oFile.save(); | |
724 closeInfoBox(NULL, NULL); | |
725 } | |
726 | |
727 static void closeInfoBox(GtkWidget* w, gpointer data) | |
728 { | |
729 gtk_widget_destroy(widgets.infoBox); | |
730 widgets.infoBox = NULL; | |
731 } | |
732 | |
733 static char* mpcGenerateTitle(const MpcInfo& p_Tags, char* p_Filename) | |
734 { | |
735 TitleInput* tuple = mpcGetSongTuple(p_Filename); | |
736 | |
737 char* title = xmms_get_titlestring (xmms_get_gentitle_format(), tuple); | |
738 if(!title) | |
739 title = g_strdup(tuple->file_name); | |
740 else if (!*title) | |
741 title = g_strdup(tuple->file_name); | |
742 | |
743 bmp_title_input_free(tuple); | |
744 return title; | |
745 } | |
746 | |
747 static void* endThread(char* p_FileName, VFSFile * p_FileHandle, bool release) | |
748 { | |
749 free(p_FileName); | |
750 if(release) | |
751 lockRelease(); | |
752 if(mpcDecoder.isError) | |
753 { | |
754 perror(mpcDecoder.isError); | |
755 free(mpcDecoder.isError); | |
756 mpcDecoder.isError = NULL; | |
757 } | |
758 setAlive(false); | |
759 if(p_FileHandle) | |
760 vfs_fclose(p_FileHandle); | |
761 if(track.display) | |
762 { | |
763 free(track.display); | |
764 track.display = NULL; | |
765 } | |
766 g_thread_exit(NULL); | |
767 return 0; | |
768 } | |
769 | |
770 static void* decodeStream(void* data) | |
771 { | |
772 lockAcquire(); | |
773 char* filename = static_cast<char*> (data); | |
774 VFSFile *input = vfs_fopen(filename, "rb"); | |
775 if (!input) | |
776 { | |
777 mpcDecoder.isError = g_strdup_printf("[xmms-musepack] decodeStream is unable to open %s", filename); | |
778 return endThread(filename, input, true); | |
779 } | |
780 | |
781 mpc_reader_file reader; | |
782 mpc_reader_setup_file_vfs(&reader, input); | |
783 | |
784 mpc_streaminfo info; | |
785 if (mpc_streaminfo_read(&info, &reader.reader) != ERROR_CODE_OK) | |
786 { | |
787 mpcDecoder.isError = g_strdup_printf("[xmms-musepack] decodeStream is unable to read %s", filename); | |
788 return endThread(filename, input, true); | |
789 } | |
790 | |
791 MpcInfo tags = getTags(filename); | |
792 track.display = mpcGenerateTitle(tags, filename); | |
793 track.length = static_cast<int> (1000 * mpc_streaminfo_get_length(&info)); | |
794 track.bitrate = static_cast<int> (info.average_bitrate); | |
795 track.sampleFreq = info.sample_freq; | |
796 track.channels = info.channels; | |
797 freeTags(tags); | |
798 | |
799 MpcPlugin.set_info(track.display, track.length, track.bitrate, track.sampleFreq, track.channels); | |
800 | |
801 mpc_decoder decoder; | |
802 mpc_decoder_setup(&decoder, &reader.reader); | |
803 if (!mpc_decoder_initialize(&decoder, &info)) | |
804 { | |
805 mpcDecoder.isError = g_strdup_printf("[xmms-musepack] decodeStream is unable to initialize decoder on %s", filename); | |
806 return endThread(filename, input, true); | |
807 } | |
808 | |
809 setReplaygain(info, decoder); | |
810 | |
811 MPC_SAMPLE_FORMAT sampleBuffer[MPC_DECODER_BUFFER_LENGTH]; | |
812 char xmmsBuffer[MPC_DECODER_BUFFER_LENGTH * 4]; | |
813 | |
814 if (!MpcPlugin.output->open_audio(FMT_S16_LE, track.sampleFreq, track.channels)) | |
815 { | |
816 mpcDecoder.isError = g_strdup_printf("[xmms-musepack] decodeStream is unable to open an audio output"); | |
817 return endThread(filename, input, true); | |
818 } | |
819 else | |
820 { | |
821 mpcDecoder.isOutput = true; | |
822 } | |
823 | |
824 lockRelease(); | |
825 | |
826 int counter = 2 * track.sampleFreq / 3; | |
827 while (isAlive()) | |
828 { | |
829 if (getOffset() != -1) | |
830 { | |
831 mpc_decoder_seek_seconds(&decoder, mpcDecoder.offset); | |
832 setOffset(-1); | |
833 } | |
834 | |
835 lockAcquire(); | |
836 short iPlaying = MpcPlugin.output->buffer_playing()? 1 : 0; | |
837 int iFree = MpcPlugin.output->buffer_free(); | |
838 if (!mpcDecoder.isPause && iFree >= ((1152 * 4) << iPlaying)) | |
839 { | |
840 unsigned status = processBuffer(sampleBuffer, xmmsBuffer, decoder); | |
841 if (status == (unsigned) (-1)) | |
842 { | |
843 mpcDecoder.isError = g_strdup_printf("[xmms-musepack] error from internal decoder on %s", filename); | |
844 return endThread(filename, input, true); | |
845 } | |
846 if (status == 0 && iPlaying == 0) | |
847 return endThread(filename, input, true); | |
848 | |
849 lockRelease(); | |
850 | |
851 if(pluginConfig.dynamicBitrate) | |
852 { | |
853 counter -= status; | |
854 if(counter < 0) | |
855 { | |
856 MpcPlugin.set_info(track.display, track.length, track.bitrate, track.sampleFreq, track.channels); | |
857 counter = 2 * track.sampleFreq / 3; | |
858 } | |
859 } | |
860 } | |
861 else | |
862 { | |
863 lockRelease(); | |
864 xmms_usleep(10000); | |
865 } | |
866 } | |
867 return endThread(filename, input, false); | |
868 } | |
869 | |
870 static int processBuffer(MPC_SAMPLE_FORMAT* sampleBuffer, char* xmmsBuffer, mpc_decoder& decoder) | |
871 { | |
872 mpc_uint32_t vbrAcc = 0; | |
873 mpc_uint32_t vbrUpd = 0; | |
874 | |
875 unsigned status = mpc_decoder_decode(&decoder, sampleBuffer, &vbrAcc, &vbrUpd); | |
876 copyBuffer(sampleBuffer, xmmsBuffer, status); | |
877 | |
878 if (pluginConfig.dynamicBitrate) | |
879 { | |
880 track.bitrate = static_cast<int> (vbrUpd * track.sampleFreq / 1152); | |
881 } | |
882 | |
883 produce_audio(MpcPlugin.output->written_time(), FMT_S16_LE, track.channels, status * 4, xmmsBuffer, NULL); | |
884 return status; | |
885 } | |
886 | |
887 static void setReplaygain(mpc_streaminfo& info, mpc_decoder& decoder) | |
888 { | |
889 if(!pluginConfig.replaygain && !pluginConfig.clipPrevention) | |
890 return; | |
891 | |
892 int peak = pluginConfig.albumGain ? info.peak_album : info.peak_title; | |
893 double gain = pluginConfig.albumGain ? info.gain_album : info.gain_title; | |
894 | |
895 if(!peak) | |
896 peak = 32767; | |
897 if(!gain) | |
898 gain = 1.; | |
899 | |
900 double clip = 32767. / peak; | |
901 gain = exp((M_LN10 / 2000.) * gain); | |
902 | |
903 if(pluginConfig.clipPrevention && !pluginConfig.replaygain) | |
904 gain = clip; | |
905 else if(pluginConfig.replaygain && pluginConfig.clipPrevention) | |
906 if(clip < gain) | |
907 gain = clip; | |
908 | |
909 mpc_decoder_scale_output(&decoder, gain); | |
910 } | |
911 | |
912 inline static void lockAcquire() | |
913 { | |
914 g_static_mutex_lock(&threadMutex); | |
915 } | |
916 | |
917 inline static void lockRelease() | |
918 { | |
919 g_static_mutex_unlock(&threadMutex); | |
920 } | |
921 | |
922 inline static bool isAlive() | |
923 { | |
924 lockAcquire(); | |
925 bool isAlive = mpcDecoder.isAlive; | |
926 lockRelease(); | |
927 return isAlive; | |
928 } | |
929 | |
930 inline static bool isPause() | |
931 { | |
932 lockAcquire(); | |
933 bool isPause = mpcDecoder.isPause; | |
934 lockRelease(); | |
935 return isPause; | |
936 } | |
937 | |
938 inline static void setAlive(bool isAlive) | |
939 { | |
940 lockAcquire(); | |
941 mpcDecoder.isAlive = isAlive; | |
942 lockRelease(); | |
943 } | |
944 | |
945 inline static double getOffset() | |
946 { | |
947 lockAcquire(); | |
948 double offset = mpcDecoder.offset; | |
949 lockRelease(); | |
950 return offset; | |
951 } | |
952 | |
953 inline static void setOffset(double offset) | |
954 { | |
955 lockAcquire(); | |
956 mpcDecoder.offset = offset; | |
957 lockRelease(); | |
958 } |