Mercurial > audlegacy-plugins
comparison src/madplug/plugin.c @ 2390:bd9673d8b7d5
converted to new sound engine scheme.
| author | Yoshiki Yazawa <yaz@cc.rim.or.jp> |
|---|---|
| date | Fri, 15 Feb 2008 19:10:19 +0900 |
| parents | fd8271f07747 |
| children | 4ad6e7dfb389 |
comparison
equal
deleted
inserted
replaced
| 2389:46d3e970f0a5 | 2390:bd9673d8b7d5 |
|---|---|
| 32 #include <audacious/configdb.h> | 32 #include <audacious/configdb.h> |
| 33 #include <stdarg.h> | 33 #include <stdarg.h> |
| 34 #include <fcntl.h> | 34 #include <fcntl.h> |
| 35 #include <audacious/vfs.h> | 35 #include <audacious/vfs.h> |
| 36 #include <sys/stat.h> | 36 #include <sys/stat.h> |
| 37 #include "SFMT.h" | |
| 38 #include "tuple.h" | 37 #include "tuple.h" |
| 39 | 38 |
| 40 /* | 39 /* |
| 41 * Global variables | 40 * Global variables |
| 42 */ | 41 */ |
| 89 | 88 |
| 90 return ext; | 89 return ext; |
| 91 } | 90 } |
| 92 | 91 |
| 93 | 92 |
| 94 void | |
| 95 audmad_config_compute(audmad_config_t *config) | |
| 96 { | |
| 97 /* set some config parameters by parsing text fields | |
| 98 (RG default gain, etc..) | |
| 99 */ | |
| 100 const gchar *text; | |
| 101 gdouble x; | |
| 102 | |
| 103 text = config->replaygain.preamp0_db; | |
| 104 if ( text != NULL ) | |
| 105 x = g_strtod(text, NULL); | |
| 106 else | |
| 107 x = 0; | |
| 108 config->replaygain.preamp0_scale = (x != 0) ? pow(10.0, x / 20) : 1; | |
| 109 AUDDBG("RG.preamp0=[%s] -> %g -> %g\n", text, x, config->preamp0_scale); | |
| 110 | |
| 111 text = config->replaygain.preamp1_db; | |
| 112 if ( text != NULL ) | |
| 113 x = g_strtod(text, NULL); | |
| 114 else | |
| 115 x = 0; | |
| 116 config->replaygain.preamp1_scale = (x != 0) ? pow(10.0, x / 20) : 1; | |
| 117 AUDDBG("RG.preamp1=[%s] -> %g -> %g\n", text, x, | |
| 118 config->replaygain.preamp1_scale); | |
| 119 | |
| 120 text = config->replaygain.preamp2_db; | |
| 121 if ( text != NULL ) | |
| 122 x = g_strtod(text, NULL); | |
| 123 else | |
| 124 x = 0; | |
| 125 config->replaygain.preamp2_scale = (x != 0) ? pow(10.0, x / 20) : 1; | |
| 126 AUDDBG("RG.preamp2=[%s] -> %g -> %g\n", text, x, | |
| 127 config->replaygain.preamp2_scale); | |
| 128 } | |
| 129 | |
| 130 static void | 93 static void |
| 131 audmad_init() | 94 audmad_init() |
| 132 { | 95 { |
| 133 ConfigDb *db = NULL; | 96 ConfigDb *db = NULL; |
| 134 | 97 |
| 138 audmad_config->force_reopen_audio = FALSE; | 101 audmad_config->force_reopen_audio = FALSE; |
| 139 audmad_config->fast_play_time_calc = TRUE; | 102 audmad_config->fast_play_time_calc = TRUE; |
| 140 audmad_config->use_xing = TRUE; | 103 audmad_config->use_xing = TRUE; |
| 141 audmad_config->sjis = FALSE; | 104 audmad_config->sjis = FALSE; |
| 142 audmad_config->show_avg_vbr_bitrate = TRUE; | 105 audmad_config->show_avg_vbr_bitrate = TRUE; |
| 143 audmad_config->replaygain.enable = TRUE; | |
| 144 audmad_config->replaygain.track_mode = FALSE; | |
| 145 audmad_config->replaygain.anti_clip = FALSE; | |
| 146 audmad_config->replaygain.adaptive_scaler = FALSE; | |
| 147 audmad_config->title_override = FALSE; | 106 audmad_config->title_override = FALSE; |
| 148 | 107 |
| 149 | 108 |
| 150 db = aud_cfg_db_open(); | 109 db = aud_cfg_db_open(); |
| 151 if (db) { | 110 if (db) { |
| 163 | 122 |
| 164 //misc | 123 //misc |
| 165 aud_cfg_db_get_bool(db, "MAD", "show_avg_vbr_bitrate", | 124 aud_cfg_db_get_bool(db, "MAD", "show_avg_vbr_bitrate", |
| 166 &audmad_config->show_avg_vbr_bitrate); | 125 &audmad_config->show_avg_vbr_bitrate); |
| 167 | 126 |
| 168 //gain control | |
| 169 aud_cfg_db_get_string(db, "MAD", "RG.preamp0_db", | |
| 170 &audmad_config->replaygain.preamp0_db); | |
| 171 aud_cfg_db_get_bool(db, "MAD", "RG.enable", | |
| 172 &audmad_config->replaygain.enable); | |
| 173 aud_cfg_db_get_bool(db, "MAD", "RG.track_mode", | |
| 174 &audmad_config->replaygain.track_mode); | |
| 175 aud_cfg_db_get_string(db, "MAD", "RG.preamp1_db", | |
| 176 &audmad_config->replaygain.preamp1_db); | |
| 177 aud_cfg_db_get_string(db, "MAD", "RG.preamp2_db", | |
| 178 &audmad_config->replaygain.preamp2_db); | |
| 179 aud_cfg_db_get_bool(db, "MAD", "RG.anti_clip", | |
| 180 &audmad_config->replaygain.anti_clip); | |
| 181 aud_cfg_db_get_bool(db, "MAD", "RG.adaptive_scaler", | |
| 182 &audmad_config->replaygain.adaptive_scaler); | |
| 183 | |
| 184 //text | 127 //text |
| 185 aud_cfg_db_get_bool(db, "MAD", "title_override", | 128 aud_cfg_db_get_bool(db, "MAD", "title_override", |
| 186 &audmad_config->title_override); | 129 &audmad_config->title_override); |
| 187 aud_cfg_db_get_string(db, "MAD", "id3_format", | 130 aud_cfg_db_get_string(db, "MAD", "id3_format", |
| 188 &audmad_config->id3_format); | 131 &audmad_config->id3_format); |
| 191 } | 134 } |
| 192 | 135 |
| 193 mad_mutex = g_mutex_new(); | 136 mad_mutex = g_mutex_new(); |
| 194 pb_mutex = g_mutex_new(); | 137 pb_mutex = g_mutex_new(); |
| 195 mad_cond = g_cond_new(); | 138 mad_cond = g_cond_new(); |
| 196 audmad_config_compute(audmad_config); | |
| 197 | |
| 198 if (!audmad_config->replaygain.preamp0_db) | |
| 199 audmad_config->replaygain.preamp0_db = g_strdup("+0.00"); | |
| 200 | |
| 201 if (!audmad_config->replaygain.preamp1_db) | |
| 202 audmad_config->replaygain.preamp1_db = g_strdup("+6.00"); | |
| 203 if (!audmad_config->replaygain.preamp2_db) | |
| 204 audmad_config->replaygain.preamp2_db = g_strdup("+0.00"); | |
| 205 | 139 |
| 206 if (!audmad_config->id3_format) | 140 if (!audmad_config->id3_format) |
| 207 audmad_config->id3_format = g_strdup("(none)"); | 141 audmad_config->id3_format = g_strdup("(none)"); |
| 208 | 142 |
| 209 init_gen_rand(4357); | |
| 210 | |
| 211 aud_mime_set_plugin("audio/mpeg", mad_plugin); | 143 aud_mime_set_plugin("audio/mpeg", mad_plugin); |
| 212 } | 144 } |
| 213 | 145 |
| 214 static void | 146 static void |
| 215 audmad_cleanup() | 147 audmad_cleanup() |
| 216 { | 148 { |
| 217 g_free(audmad_config->replaygain.preamp0_db); | |
| 218 g_free(audmad_config->replaygain.preamp1_db); | |
| 219 g_free(audmad_config->replaygain.preamp2_db); | |
| 220 g_free(audmad_config->id3_format); | 149 g_free(audmad_config->id3_format); |
| 221 g_free(audmad_config); | 150 g_free(audmad_config); |
| 222 | 151 |
| 223 g_cond_free(mad_cond); | 152 g_cond_free(mad_cond); |
| 224 g_mutex_free(mad_mutex); | 153 g_mutex_free(mad_mutex); |
| 456 static void | 385 static void |
| 457 audmad_play_file(InputPlayback *playback) | 386 audmad_play_file(InputPlayback *playback) |
| 458 { | 387 { |
| 459 gboolean rtn; | 388 gboolean rtn; |
| 460 gchar *url = playback->filename; | 389 gchar *url = playback->filename; |
| 390 ReplayGainInfo rg_info; | |
| 461 | 391 |
| 462 #ifdef AUD_DEBUG | 392 #ifdef AUD_DEBUG |
| 463 { | 393 { |
| 464 gchar *tmp = g_filename_to_utf8(url, -1, NULL, NULL, NULL); | 394 gchar *tmp = g_filename_to_utf8(url, -1, NULL, NULL, NULL); |
| 465 AUDDBG("playing %s\n", tmp); | 395 AUDDBG("playing %s\n", tmp); |
| 481 * return; | 411 * return; |
| 482 * commenting this return seems to be a hacky fix for the damn lastfm plugin playback | 412 * commenting this return seems to be a hacky fix for the damn lastfm plugin playback |
| 483 * that used to work only for nenolod because of his fsck-ing lastfm subscription :p | 413 * that used to work only for nenolod because of his fsck-ing lastfm subscription :p |
| 484 */ | 414 */ |
| 485 } | 415 } |
| 416 | |
| 417 rg_info.track_gain = info.replaygain_track_scale; | |
| 418 rg_info.track_peak = info.replaygain_track_peak; | |
| 419 rg_info.album_gain = info.replaygain_album_scale; | |
| 420 rg_info.album_peak = info.replaygain_album_peak; | |
| 421 playback->set_replaygain_info(playback, &rg_info); | |
| 422 | |
| 486 g_mutex_lock(pb_mutex); | 423 g_mutex_lock(pb_mutex); |
| 487 info.playback = playback; | 424 info.playback = playback; |
| 488 info.playback->playing = 1; | 425 info.playback->playing = 1; |
| 489 g_mutex_unlock(pb_mutex); | 426 g_mutex_unlock(pb_mutex); |
| 490 | 427 |
| 811 } | 748 } |
| 812 | 749 |
| 813 static gchar *fmts[] = { "mp3", "mp2", "mpg", "bmu", NULL }; | 750 static gchar *fmts[] = { "mp3", "mp2", "mpg", "bmu", NULL }; |
| 814 | 751 |
| 815 InputPlugin mad_ip = { | 752 InputPlugin mad_ip = { |
| 816 .description = "MPEG Audio Plugin", | 753 .description = "MPEG Audio Plugin (experimental)", |
| 817 .init = audmad_init, | 754 .init = audmad_init, |
| 818 .about = audmad_about, | 755 .about = audmad_about, |
| 819 .configure = audmad_configure, | 756 .configure = audmad_configure, |
| 820 .is_our_file = audmad_is_our_file, | 757 .is_our_file = audmad_is_our_file, |
| 821 .play_file = audmad_play_file, | 758 .play_file = audmad_play_file, |
