From b4e70422a3455e327433a7471c929ef100ef3b10 Mon Sep 17 00:00:00 2001 From: Solomon Peachy Date: Sat, 8 Aug 2020 21:56:15 -0400 Subject: mikmod: Upgrade mikmod core from v3.2.0 to v3.3.11 * Get rid of the non-functional GT2 loader * Add the UMX loader * Add HQ mixer routines (and make it configurable) * Allow samplerate to be configured at run/playtime * Support >64KHz mixing/playback * Correctly restore non-boost status (The diff to upstream is much smaller now too!) Change-Id: Iaa4ac901ba9cd4123bb225656976e78271353a72 --- apps/plugins/mikmod/mikmod.c | 133 ++++++++++++++++++++++++++++++++----------- 1 file changed, 100 insertions(+), 33 deletions(-) (limited to 'apps/plugins/mikmod/mikmod.c') diff --git a/apps/plugins/mikmod/mikmod.c b/apps/plugins/mikmod/mikmod.c index 688baed56c..0eba320f18 100644 --- a/apps/plugins/mikmod/mikmod.c +++ b/apps/plugins/mikmod/mikmod.c @@ -25,7 +25,7 @@ /* Persistent configuration */ #define MIKMOD_CONFIGFILE "mikmod.cfg" #define MIKMOD_SETTINGS_MINVERSION 1 -#define MIKMOD_SETTINGS_VERSION 1 +#define MIKMOD_SETTINGS_VERSION 2 #ifdef USETHREADS #define EV_EXIT 9999 @@ -161,7 +161,6 @@ static bool mod_ext(const char ext[]) !rb->strcasecmp(ext,".dsm") || !rb->strcasecmp(ext,".far") || !rb->strcasecmp(ext,".gdm") || - !rb->strcasecmp(ext,".gt2") || !rb->strcasecmp(ext,".imf") || !rb->strcasecmp(ext,".it") || !rb->strcasecmp(ext,".m15") || @@ -174,6 +173,7 @@ static bool mod_ext(const char ext[]) !rb->strcasecmp(ext,".stx") || !rb->strcasecmp(ext,".ult") || !rb->strcasecmp(ext,".uni") || + !rb->strcasecmp(ext,".umx") || !rb->strcasecmp(ext,".xm") ) return true; else @@ -305,7 +305,7 @@ static void showinfo(void) rb->lcd_putsxy(1, 1, statustext); sprintf(statustext, "Type: %s", module->modtype); rb->lcd_putsxy(1, 11, statustext); - + sprintf(statustext, "Samples: %d", module->numsmp); rb->lcd_putsxy(1, 21, statustext); @@ -315,25 +315,25 @@ static void showinfo(void) rb->lcd_putsxy(1, 31, statustext); } - sprintf(statustext, "pat: %03d/%03d %2.2X", + sprintf(statustext, "pat: %03d/%03d %2.2X", module->sngpos, module->numpos - 1, module->patpos); rb->lcd_putsxy(1, 51, statustext); - sprintf(statustext, "spd: %d/%d", + sprintf(statustext, "spd: %d/%d", module->sngspd, module->bpm); rb->lcd_putsxy(1, 61, statustext); sprintf(statustext, "vol: %ddB", rb->global_settings->volume); rb->lcd_putsxy(1, 71, statustext); - sprintf(statustext, "time: %d:%02d", + sprintf(statustext, "time: %d:%02d", (playingtime / 60) % 60, playingtime % 60); rb->lcd_putsxy(1, 81, statustext); if (module->flags & UF_NNA) { sprintf(statustext, "chn: %d/%d+%d->%d", - module->realchn, module->numchn, + module->realchn, module->numchn, module->totalchn - module->realchn, module->totalchn); } @@ -465,32 +465,44 @@ struct mikmod_settings { int pansep; int reverb; + int sample_rate; bool interp; bool reverse; bool surround; + bool hqmixer; +#ifdef HAVE_ADJUSTABLE_CPU_FREQ bool boost; +#endif }; static struct mikmod_settings settings = { - 128, - 0, - 0, - 0, - 1, - 1 + .pansep = 128, + .reverb = 0, + .sample_rate = -1, + .interp = 0, + .reverse = 0, + .surround = 1, + .hqmixer = 0, +#ifdef HAVE_ADJUSTABLE_CPU_FREQ + .boost = 1, +#endif }; static struct mikmod_settings old_settings; -static struct configdata config[] = +static const struct configdata config[] = { { TYPE_INT, 0, 128, { .int_p = &settings.pansep }, "Panning Separation", NULL}, { TYPE_INT, 0, 15, { .int_p = &settings.reverb }, "Reverberation", NULL}, { TYPE_BOOL, 0, 1, { .bool_p = &settings.interp }, "Interpolation", NULL}, { TYPE_BOOL, 0, 1, { .bool_p = &settings.reverse }, "Reverse Channels", NULL}, { TYPE_BOOL, 0, 1, { .bool_p = &settings.surround }, "Surround", NULL}, + { TYPE_BOOL, 0, 1, { .bool_p = &settings.hqmixer }, "HQ Mixer", NULL}, + { TYPE_INT, 0, HW_NUM_FREQ-1, { .int_p = &settings.sample_rate }, "Sample Rate", NULL}, +#ifdef HAVE_ADJUSTABLE_CPU_FREQ { TYPE_BOOL, 0, 1, { .bool_p = &settings.boost }, "CPU Boost", NULL}, +#endif }; static void applysettings(void) @@ -498,6 +510,7 @@ static void applysettings(void) md_pansep = settings.pansep; md_reverb = settings.reverb; md_mode = DMODE_STEREO | DMODE_16BITS | DMODE_SOFT_MUSIC | DMODE_SOFT_SNDFX; + if ( settings.interp ) { md_mode |= DMODE_INTERP; @@ -510,6 +523,21 @@ static void applysettings(void) { md_mode |= DMODE_SURROUND; } +#ifndef NO_HQMIXER + if ( settings.hqmixer ) + { + md_mode |= DMODE_HQMIXER; + } +#endif + + if (md_mixfreq != rb->hw_freq_sampr[settings.sample_rate]) { + md_mixfreq = rb->hw_freq_sampr[settings.sample_rate]; +// MikMod_Reset(""); BROKEN! + rb->pcm_play_stop(); + rb->mixer_set_frequency(md_mixfreq); + rb->mixer_channel_play_data(PCM_MIXER_CHAN_PLAYBACK, get_more, NULL, 0); + } + #ifdef HAVE_ADJUSTABLE_CPU_FREQ if ( Player_Active() ) { @@ -518,6 +546,21 @@ static void applysettings(void) #endif } +static const struct opt_items sr_names[HW_NUM_FREQ] = { + HW_HAVE_96_([HW_FREQ_96] = { "96kHz", TALK_ID(96, UNIT_KHZ) },) + HW_HAVE_88_([HW_FREQ_88] = { "88.2kHz", TALK_ID(88, UNIT_KHZ) },) + HW_HAVE_64_([HW_FREQ_64] = { "64kHz", TALK_ID(64, UNIT_KHZ) },) + HW_HAVE_48_([HW_FREQ_48] = { "48kHz", TALK_ID(48, UNIT_KHZ) },) + HW_HAVE_44_([HW_FREQ_44] = { "44.1kHz", TALK_ID(44, UNIT_KHZ) },) + HW_HAVE_32_([HW_FREQ_32] = { "32kHz", TALK_ID(32, UNIT_KHZ) },) + HW_HAVE_24_([HW_FREQ_24] = { "24kHz", TALK_ID(24, UNIT_KHZ) },) + HW_HAVE_22_([HW_FREQ_22] = { "22.05kHz", TALK_ID(22, UNIT_KHZ) },) + HW_HAVE_16_([HW_FREQ_16] = { "16kHz", TALK_ID(16, UNIT_KHZ) },) + HW_HAVE_12_([HW_FREQ_12] = { "12kHz", TALK_ID(12, UNIT_KHZ) },) + HW_HAVE_11_([HW_FREQ_11] = { "11.025kHz", TALK_ID(11, UNIT_KHZ) },) + HW_HAVE_8_( [HW_FREQ_8 ] = { "8kHz", TALK_ID( 8, UNIT_KHZ) },) +}; + /** Shows the settings menu */ @@ -531,6 +574,8 @@ static int settings_menu(void) ID2P(LANG_INTERPOLATION), ID2P(LANG_SWAP_CHANNELS), ID2P(LANG_MIKMOD_SURROUND), + ID2P(LANG_MIKMOD_HQMIXER), + ID2P(LANG_MIKMOD_SAMPLERATE), #ifdef HAVE_ADJUSTABLE_CPU_FREQ ID2P(LANG_CPU_BOOST) #endif @@ -571,9 +616,22 @@ static int settings_menu(void) break; case 5: + rb->set_bool(rb->str(LANG_MIKMOD_HQMIXER), &(settings.hqmixer)); + applysettings(); + break; + + case 6: + rb->set_option(rb->str(LANG_MIKMOD_SAMPLERATE), &(settings.sample_rate), INT, sr_names, + HW_NUM_FREQ, NULL); + applysettings(); + break; + +#ifdef HAVE_ADJUSTABLE_CPU_FREQ + case 7: rb->set_bool(rb->str(LANG_CPU_BOOST), &(settings.boost)); applysettings(); break; +#endif case MENU_ATTACHED_USB: return PLUGIN_USB_CONNECTED; @@ -675,13 +733,12 @@ static int playfile(char* filename) } #ifdef HAVE_ADJUSTABLE_CPU_FREQ - if ( settings.boost ) - rb->cpu_boost(true); + rb->cpu_boost(settings.boost); #endif #ifdef USETHREADS rb->queue_init(&thread_q, true); if ((thread_id = rb->create_thread(thread, thread_stack, - sizeof(thread_stack), 0, "render buffering thread" + sizeof(thread_stack), 0, "render buffering thread" IF_PRIO(, PRIORITY_PLAYBACK) IF_COP(, CPU))) == 0) { @@ -830,11 +887,11 @@ static int playfile(char* filename) rb->lcd_setfont(FONT_SYSFIXED); screenupdated = false; break; - + case ACTION_WPS_STOP: quit = true; break; - + default: if (rb->default_event_handler(button) == SYS_USB_CONNECTED) { @@ -850,20 +907,19 @@ static int playfile(char* filename) rb->queue_delete(&thread_q); #endif #ifdef HAVE_ADJUSTABLE_CPU_FREQ - if ( settings.boost ) - rb->cpu_boost(false); + rb->cpu_boost(false); #endif Player_Stop(); Player_Free(module); - + memset(gmbuf, '\0', sizeof(gmbuf)); - + if ( retval == PLUGIN_OK && entries > 1 && !quit ) { retval = change_filename(DIR_NEXT); } - + return retval; } @@ -891,10 +947,9 @@ enum plugin_status plugin_start(const void* parameter) rb->audio_set_input_source(AUDIO_SRC_PLAYBACK, SRCF_PLAYBACK); rb->audio_set_output_source(AUDIO_SRC_PLAYBACK); #endif - rb->mixer_set_frequency(SAMPLE_RATE); audio_buffer = rb->plugin_get_audio_buffer((size_t *)&audio_buffer_free); - + rb->strcpy(np_file, parameter); get_mod_list(); if(!entries) { @@ -903,16 +958,29 @@ enum plugin_status plugin_start(const void* parameter) //add_pool(audio_buffer, audio_buffer_free); init_memory_pool(audio_buffer_free, audio_buffer); - + MikMod_RegisterDriver(&drv_nos); MikMod_RegisterAllLoaders(); MikMod_RegisterErrorHandler(mm_errorhandler); - md_mixfreq = SAMPLE_RATE; - configfile_load(MIKMOD_CONFIGFILE, config, ARRAYLEN(config), MIKMOD_SETTINGS_MINVERSION); rb->memcpy(&old_settings, &settings, sizeof (settings)); + + /* If there's no configured rate, use the default */ + if (settings.sample_rate == -1) { + int i; + for (i = 0 ; i < HW_NUM_FREQ ; i++) { + if (rb->hw_freq_sampr[i] == SAMPLE_RATE) { + settings.sample_rate = i; + break; + } + } + if (settings.sample_rate == -1) { + settings.sample_rate = HW_NUM_FREQ -1; + } + } + applysettings(); if (MikMod_Init("")) @@ -934,14 +1002,13 @@ enum plugin_status plugin_start(const void* parameter) if (retval == PLUGIN_OK) { - rb->splash(0, "Saving Settings"); if (rb->memcmp(&settings, &old_settings, sizeof (settings))) { - configfile_save(MIKMOD_CONFIGFILE, config, - ARRAYLEN(config), MIKMOD_SETTINGS_MINVERSION); + configfile_save(MIKMOD_CONFIGFILE, config, + ARRAYLEN(config), MIKMOD_SETTINGS_MINVERSION); } } - + destroy_memory_pool(audio_buffer); return retval; -- cgit v1.2.3