diff options
Diffstat (limited to 'apps/plugins/mikmod/mikmod.c')
-rw-r--r-- | apps/plugins/mikmod/mikmod.c | 133 |
1 files changed, 100 insertions, 33 deletions
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 @@ | |||
25 | /* Persistent configuration */ | 25 | /* Persistent configuration */ |
26 | #define MIKMOD_CONFIGFILE "mikmod.cfg" | 26 | #define MIKMOD_CONFIGFILE "mikmod.cfg" |
27 | #define MIKMOD_SETTINGS_MINVERSION 1 | 27 | #define MIKMOD_SETTINGS_MINVERSION 1 |
28 | #define MIKMOD_SETTINGS_VERSION 1 | 28 | #define MIKMOD_SETTINGS_VERSION 2 |
29 | 29 | ||
30 | #ifdef USETHREADS | 30 | #ifdef USETHREADS |
31 | #define EV_EXIT 9999 | 31 | #define EV_EXIT 9999 |
@@ -161,7 +161,6 @@ static bool mod_ext(const char ext[]) | |||
161 | !rb->strcasecmp(ext,".dsm") || | 161 | !rb->strcasecmp(ext,".dsm") || |
162 | !rb->strcasecmp(ext,".far") || | 162 | !rb->strcasecmp(ext,".far") || |
163 | !rb->strcasecmp(ext,".gdm") || | 163 | !rb->strcasecmp(ext,".gdm") || |
164 | !rb->strcasecmp(ext,".gt2") || | ||
165 | !rb->strcasecmp(ext,".imf") || | 164 | !rb->strcasecmp(ext,".imf") || |
166 | !rb->strcasecmp(ext,".it") || | 165 | !rb->strcasecmp(ext,".it") || |
167 | !rb->strcasecmp(ext,".m15") || | 166 | !rb->strcasecmp(ext,".m15") || |
@@ -174,6 +173,7 @@ static bool mod_ext(const char ext[]) | |||
174 | !rb->strcasecmp(ext,".stx") || | 173 | !rb->strcasecmp(ext,".stx") || |
175 | !rb->strcasecmp(ext,".ult") || | 174 | !rb->strcasecmp(ext,".ult") || |
176 | !rb->strcasecmp(ext,".uni") || | 175 | !rb->strcasecmp(ext,".uni") || |
176 | !rb->strcasecmp(ext,".umx") || | ||
177 | !rb->strcasecmp(ext,".xm") ) | 177 | !rb->strcasecmp(ext,".xm") ) |
178 | return true; | 178 | return true; |
179 | else | 179 | else |
@@ -305,7 +305,7 @@ static void showinfo(void) | |||
305 | rb->lcd_putsxy(1, 1, statustext); | 305 | rb->lcd_putsxy(1, 1, statustext); |
306 | sprintf(statustext, "Type: %s", module->modtype); | 306 | sprintf(statustext, "Type: %s", module->modtype); |
307 | rb->lcd_putsxy(1, 11, statustext); | 307 | rb->lcd_putsxy(1, 11, statustext); |
308 | 308 | ||
309 | sprintf(statustext, "Samples: %d", module->numsmp); | 309 | sprintf(statustext, "Samples: %d", module->numsmp); |
310 | rb->lcd_putsxy(1, 21, statustext); | 310 | rb->lcd_putsxy(1, 21, statustext); |
311 | 311 | ||
@@ -315,25 +315,25 @@ static void showinfo(void) | |||
315 | rb->lcd_putsxy(1, 31, statustext); | 315 | rb->lcd_putsxy(1, 31, statustext); |
316 | } | 316 | } |
317 | 317 | ||
318 | sprintf(statustext, "pat: %03d/%03d %2.2X", | 318 | sprintf(statustext, "pat: %03d/%03d %2.2X", |
319 | module->sngpos, module->numpos - 1, module->patpos); | 319 | module->sngpos, module->numpos - 1, module->patpos); |
320 | rb->lcd_putsxy(1, 51, statustext); | 320 | rb->lcd_putsxy(1, 51, statustext); |
321 | 321 | ||
322 | sprintf(statustext, "spd: %d/%d", | 322 | sprintf(statustext, "spd: %d/%d", |
323 | module->sngspd, module->bpm); | 323 | module->sngspd, module->bpm); |
324 | rb->lcd_putsxy(1, 61, statustext); | 324 | rb->lcd_putsxy(1, 61, statustext); |
325 | 325 | ||
326 | sprintf(statustext, "vol: %ddB", rb->global_settings->volume); | 326 | sprintf(statustext, "vol: %ddB", rb->global_settings->volume); |
327 | rb->lcd_putsxy(1, 71, statustext); | 327 | rb->lcd_putsxy(1, 71, statustext); |
328 | 328 | ||
329 | sprintf(statustext, "time: %d:%02d", | 329 | sprintf(statustext, "time: %d:%02d", |
330 | (playingtime / 60) % 60, playingtime % 60); | 330 | (playingtime / 60) % 60, playingtime % 60); |
331 | rb->lcd_putsxy(1, 81, statustext); | 331 | rb->lcd_putsxy(1, 81, statustext); |
332 | 332 | ||
333 | if (module->flags & UF_NNA) | 333 | if (module->flags & UF_NNA) |
334 | { | 334 | { |
335 | sprintf(statustext, "chn: %d/%d+%d->%d", | 335 | sprintf(statustext, "chn: %d/%d+%d->%d", |
336 | module->realchn, module->numchn, | 336 | module->realchn, module->numchn, |
337 | module->totalchn - module->realchn, | 337 | module->totalchn - module->realchn, |
338 | module->totalchn); | 338 | module->totalchn); |
339 | } | 339 | } |
@@ -465,32 +465,44 @@ struct mikmod_settings | |||
465 | { | 465 | { |
466 | int pansep; | 466 | int pansep; |
467 | int reverb; | 467 | int reverb; |
468 | int sample_rate; | ||
468 | bool interp; | 469 | bool interp; |
469 | bool reverse; | 470 | bool reverse; |
470 | bool surround; | 471 | bool surround; |
472 | bool hqmixer; | ||
473 | #ifdef HAVE_ADJUSTABLE_CPU_FREQ | ||
471 | bool boost; | 474 | bool boost; |
475 | #endif | ||
472 | }; | 476 | }; |
473 | 477 | ||
474 | static struct mikmod_settings settings = | 478 | static struct mikmod_settings settings = |
475 | { | 479 | { |
476 | 128, | 480 | .pansep = 128, |
477 | 0, | 481 | .reverb = 0, |
478 | 0, | 482 | .sample_rate = -1, |
479 | 0, | 483 | .interp = 0, |
480 | 1, | 484 | .reverse = 0, |
481 | 1 | 485 | .surround = 1, |
486 | .hqmixer = 0, | ||
487 | #ifdef HAVE_ADJUSTABLE_CPU_FREQ | ||
488 | .boost = 1, | ||
489 | #endif | ||
482 | }; | 490 | }; |
483 | 491 | ||
484 | static struct mikmod_settings old_settings; | 492 | static struct mikmod_settings old_settings; |
485 | 493 | ||
486 | static struct configdata config[] = | 494 | static const struct configdata config[] = |
487 | { | 495 | { |
488 | { TYPE_INT, 0, 128, { .int_p = &settings.pansep }, "Panning Separation", NULL}, | 496 | { TYPE_INT, 0, 128, { .int_p = &settings.pansep }, "Panning Separation", NULL}, |
489 | { TYPE_INT, 0, 15, { .int_p = &settings.reverb }, "Reverberation", NULL}, | 497 | { TYPE_INT, 0, 15, { .int_p = &settings.reverb }, "Reverberation", NULL}, |
490 | { TYPE_BOOL, 0, 1, { .bool_p = &settings.interp }, "Interpolation", NULL}, | 498 | { TYPE_BOOL, 0, 1, { .bool_p = &settings.interp }, "Interpolation", NULL}, |
491 | { TYPE_BOOL, 0, 1, { .bool_p = &settings.reverse }, "Reverse Channels", NULL}, | 499 | { TYPE_BOOL, 0, 1, { .bool_p = &settings.reverse }, "Reverse Channels", NULL}, |
492 | { TYPE_BOOL, 0, 1, { .bool_p = &settings.surround }, "Surround", NULL}, | 500 | { TYPE_BOOL, 0, 1, { .bool_p = &settings.surround }, "Surround", NULL}, |
501 | { TYPE_BOOL, 0, 1, { .bool_p = &settings.hqmixer }, "HQ Mixer", NULL}, | ||
502 | { TYPE_INT, 0, HW_NUM_FREQ-1, { .int_p = &settings.sample_rate }, "Sample Rate", NULL}, | ||
503 | #ifdef HAVE_ADJUSTABLE_CPU_FREQ | ||
493 | { TYPE_BOOL, 0, 1, { .bool_p = &settings.boost }, "CPU Boost", NULL}, | 504 | { TYPE_BOOL, 0, 1, { .bool_p = &settings.boost }, "CPU Boost", NULL}, |
505 | #endif | ||
494 | }; | 506 | }; |
495 | 507 | ||
496 | static void applysettings(void) | 508 | static void applysettings(void) |
@@ -498,6 +510,7 @@ static void applysettings(void) | |||
498 | md_pansep = settings.pansep; | 510 | md_pansep = settings.pansep; |
499 | md_reverb = settings.reverb; | 511 | md_reverb = settings.reverb; |
500 | md_mode = DMODE_STEREO | DMODE_16BITS | DMODE_SOFT_MUSIC | DMODE_SOFT_SNDFX; | 512 | md_mode = DMODE_STEREO | DMODE_16BITS | DMODE_SOFT_MUSIC | DMODE_SOFT_SNDFX; |
513 | |||
501 | if ( settings.interp ) | 514 | if ( settings.interp ) |
502 | { | 515 | { |
503 | md_mode |= DMODE_INTERP; | 516 | md_mode |= DMODE_INTERP; |
@@ -510,6 +523,21 @@ static void applysettings(void) | |||
510 | { | 523 | { |
511 | md_mode |= DMODE_SURROUND; | 524 | md_mode |= DMODE_SURROUND; |
512 | } | 525 | } |
526 | #ifndef NO_HQMIXER | ||
527 | if ( settings.hqmixer ) | ||
528 | { | ||
529 | md_mode |= DMODE_HQMIXER; | ||
530 | } | ||
531 | #endif | ||
532 | |||
533 | if (md_mixfreq != rb->hw_freq_sampr[settings.sample_rate]) { | ||
534 | md_mixfreq = rb->hw_freq_sampr[settings.sample_rate]; | ||
535 | // MikMod_Reset(""); BROKEN! | ||
536 | rb->pcm_play_stop(); | ||
537 | rb->mixer_set_frequency(md_mixfreq); | ||
538 | rb->mixer_channel_play_data(PCM_MIXER_CHAN_PLAYBACK, get_more, NULL, 0); | ||
539 | } | ||
540 | |||
513 | #ifdef HAVE_ADJUSTABLE_CPU_FREQ | 541 | #ifdef HAVE_ADJUSTABLE_CPU_FREQ |
514 | if ( Player_Active() ) | 542 | if ( Player_Active() ) |
515 | { | 543 | { |
@@ -518,6 +546,21 @@ static void applysettings(void) | |||
518 | #endif | 546 | #endif |
519 | } | 547 | } |
520 | 548 | ||
549 | static const struct opt_items sr_names[HW_NUM_FREQ] = { | ||
550 | HW_HAVE_96_([HW_FREQ_96] = { "96kHz", TALK_ID(96, UNIT_KHZ) },) | ||
551 | HW_HAVE_88_([HW_FREQ_88] = { "88.2kHz", TALK_ID(88, UNIT_KHZ) },) | ||
552 | HW_HAVE_64_([HW_FREQ_64] = { "64kHz", TALK_ID(64, UNIT_KHZ) },) | ||
553 | HW_HAVE_48_([HW_FREQ_48] = { "48kHz", TALK_ID(48, UNIT_KHZ) },) | ||
554 | HW_HAVE_44_([HW_FREQ_44] = { "44.1kHz", TALK_ID(44, UNIT_KHZ) },) | ||
555 | HW_HAVE_32_([HW_FREQ_32] = { "32kHz", TALK_ID(32, UNIT_KHZ) },) | ||
556 | HW_HAVE_24_([HW_FREQ_24] = { "24kHz", TALK_ID(24, UNIT_KHZ) },) | ||
557 | HW_HAVE_22_([HW_FREQ_22] = { "22.05kHz", TALK_ID(22, UNIT_KHZ) },) | ||
558 | HW_HAVE_16_([HW_FREQ_16] = { "16kHz", TALK_ID(16, UNIT_KHZ) },) | ||
559 | HW_HAVE_12_([HW_FREQ_12] = { "12kHz", TALK_ID(12, UNIT_KHZ) },) | ||
560 | HW_HAVE_11_([HW_FREQ_11] = { "11.025kHz", TALK_ID(11, UNIT_KHZ) },) | ||
561 | HW_HAVE_8_( [HW_FREQ_8 ] = { "8kHz", TALK_ID( 8, UNIT_KHZ) },) | ||
562 | }; | ||
563 | |||
521 | /** | 564 | /** |
522 | Shows the settings menu | 565 | Shows the settings menu |
523 | */ | 566 | */ |
@@ -531,6 +574,8 @@ static int settings_menu(void) | |||
531 | ID2P(LANG_INTERPOLATION), | 574 | ID2P(LANG_INTERPOLATION), |
532 | ID2P(LANG_SWAP_CHANNELS), | 575 | ID2P(LANG_SWAP_CHANNELS), |
533 | ID2P(LANG_MIKMOD_SURROUND), | 576 | ID2P(LANG_MIKMOD_SURROUND), |
577 | ID2P(LANG_MIKMOD_HQMIXER), | ||
578 | ID2P(LANG_MIKMOD_SAMPLERATE), | ||
534 | #ifdef HAVE_ADJUSTABLE_CPU_FREQ | 579 | #ifdef HAVE_ADJUSTABLE_CPU_FREQ |
535 | ID2P(LANG_CPU_BOOST) | 580 | ID2P(LANG_CPU_BOOST) |
536 | #endif | 581 | #endif |
@@ -571,9 +616,22 @@ static int settings_menu(void) | |||
571 | break; | 616 | break; |
572 | 617 | ||
573 | case 5: | 618 | case 5: |
619 | rb->set_bool(rb->str(LANG_MIKMOD_HQMIXER), &(settings.hqmixer)); | ||
620 | applysettings(); | ||
621 | break; | ||
622 | |||
623 | case 6: | ||
624 | rb->set_option(rb->str(LANG_MIKMOD_SAMPLERATE), &(settings.sample_rate), INT, sr_names, | ||
625 | HW_NUM_FREQ, NULL); | ||
626 | applysettings(); | ||
627 | break; | ||
628 | |||
629 | #ifdef HAVE_ADJUSTABLE_CPU_FREQ | ||
630 | case 7: | ||
574 | rb->set_bool(rb->str(LANG_CPU_BOOST), &(settings.boost)); | 631 | rb->set_bool(rb->str(LANG_CPU_BOOST), &(settings.boost)); |
575 | applysettings(); | 632 | applysettings(); |
576 | break; | 633 | break; |
634 | #endif | ||
577 | 635 | ||
578 | case MENU_ATTACHED_USB: | 636 | case MENU_ATTACHED_USB: |
579 | return PLUGIN_USB_CONNECTED; | 637 | return PLUGIN_USB_CONNECTED; |
@@ -675,13 +733,12 @@ static int playfile(char* filename) | |||
675 | } | 733 | } |
676 | 734 | ||
677 | #ifdef HAVE_ADJUSTABLE_CPU_FREQ | 735 | #ifdef HAVE_ADJUSTABLE_CPU_FREQ |
678 | if ( settings.boost ) | 736 | rb->cpu_boost(settings.boost); |
679 | rb->cpu_boost(true); | ||
680 | #endif | 737 | #endif |
681 | #ifdef USETHREADS | 738 | #ifdef USETHREADS |
682 | rb->queue_init(&thread_q, true); | 739 | rb->queue_init(&thread_q, true); |
683 | if ((thread_id = rb->create_thread(thread, thread_stack, | 740 | if ((thread_id = rb->create_thread(thread, thread_stack, |
684 | sizeof(thread_stack), 0, "render buffering thread" | 741 | sizeof(thread_stack), 0, "render buffering thread" |
685 | IF_PRIO(, PRIORITY_PLAYBACK) | 742 | IF_PRIO(, PRIORITY_PLAYBACK) |
686 | IF_COP(, CPU))) == 0) | 743 | IF_COP(, CPU))) == 0) |
687 | { | 744 | { |
@@ -830,11 +887,11 @@ static int playfile(char* filename) | |||
830 | rb->lcd_setfont(FONT_SYSFIXED); | 887 | rb->lcd_setfont(FONT_SYSFIXED); |
831 | screenupdated = false; | 888 | screenupdated = false; |
832 | break; | 889 | break; |
833 | 890 | ||
834 | case ACTION_WPS_STOP: | 891 | case ACTION_WPS_STOP: |
835 | quit = true; | 892 | quit = true; |
836 | break; | 893 | break; |
837 | 894 | ||
838 | default: | 895 | default: |
839 | if (rb->default_event_handler(button) == SYS_USB_CONNECTED) | 896 | if (rb->default_event_handler(button) == SYS_USB_CONNECTED) |
840 | { | 897 | { |
@@ -850,20 +907,19 @@ static int playfile(char* filename) | |||
850 | rb->queue_delete(&thread_q); | 907 | rb->queue_delete(&thread_q); |
851 | #endif | 908 | #endif |
852 | #ifdef HAVE_ADJUSTABLE_CPU_FREQ | 909 | #ifdef HAVE_ADJUSTABLE_CPU_FREQ |
853 | if ( settings.boost ) | 910 | rb->cpu_boost(false); |
854 | rb->cpu_boost(false); | ||
855 | #endif | 911 | #endif |
856 | 912 | ||
857 | Player_Stop(); | 913 | Player_Stop(); |
858 | Player_Free(module); | 914 | Player_Free(module); |
859 | 915 | ||
860 | memset(gmbuf, '\0', sizeof(gmbuf)); | 916 | memset(gmbuf, '\0', sizeof(gmbuf)); |
861 | 917 | ||
862 | if ( retval == PLUGIN_OK && entries > 1 && !quit ) | 918 | if ( retval == PLUGIN_OK && entries > 1 && !quit ) |
863 | { | 919 | { |
864 | retval = change_filename(DIR_NEXT); | 920 | retval = change_filename(DIR_NEXT); |
865 | } | 921 | } |
866 | 922 | ||
867 | return retval; | 923 | return retval; |
868 | } | 924 | } |
869 | 925 | ||
@@ -891,10 +947,9 @@ enum plugin_status plugin_start(const void* parameter) | |||
891 | rb->audio_set_input_source(AUDIO_SRC_PLAYBACK, SRCF_PLAYBACK); | 947 | rb->audio_set_input_source(AUDIO_SRC_PLAYBACK, SRCF_PLAYBACK); |
892 | rb->audio_set_output_source(AUDIO_SRC_PLAYBACK); | 948 | rb->audio_set_output_source(AUDIO_SRC_PLAYBACK); |
893 | #endif | 949 | #endif |
894 | rb->mixer_set_frequency(SAMPLE_RATE); | ||
895 | 950 | ||
896 | audio_buffer = rb->plugin_get_audio_buffer((size_t *)&audio_buffer_free); | 951 | audio_buffer = rb->plugin_get_audio_buffer((size_t *)&audio_buffer_free); |
897 | 952 | ||
898 | rb->strcpy(np_file, parameter); | 953 | rb->strcpy(np_file, parameter); |
899 | get_mod_list(); | 954 | get_mod_list(); |
900 | if(!entries) { | 955 | if(!entries) { |
@@ -903,16 +958,29 @@ enum plugin_status plugin_start(const void* parameter) | |||
903 | 958 | ||
904 | //add_pool(audio_buffer, audio_buffer_free); | 959 | //add_pool(audio_buffer, audio_buffer_free); |
905 | init_memory_pool(audio_buffer_free, audio_buffer); | 960 | init_memory_pool(audio_buffer_free, audio_buffer); |
906 | 961 | ||
907 | MikMod_RegisterDriver(&drv_nos); | 962 | MikMod_RegisterDriver(&drv_nos); |
908 | MikMod_RegisterAllLoaders(); | 963 | MikMod_RegisterAllLoaders(); |
909 | MikMod_RegisterErrorHandler(mm_errorhandler); | 964 | MikMod_RegisterErrorHandler(mm_errorhandler); |
910 | 965 | ||
911 | md_mixfreq = SAMPLE_RATE; | ||
912 | |||
913 | configfile_load(MIKMOD_CONFIGFILE, config, | 966 | configfile_load(MIKMOD_CONFIGFILE, config, |
914 | ARRAYLEN(config), MIKMOD_SETTINGS_MINVERSION); | 967 | ARRAYLEN(config), MIKMOD_SETTINGS_MINVERSION); |
915 | rb->memcpy(&old_settings, &settings, sizeof (settings)); | 968 | rb->memcpy(&old_settings, &settings, sizeof (settings)); |
969 | |||
970 | /* If there's no configured rate, use the default */ | ||
971 | if (settings.sample_rate == -1) { | ||
972 | int i; | ||
973 | for (i = 0 ; i < HW_NUM_FREQ ; i++) { | ||
974 | if (rb->hw_freq_sampr[i] == SAMPLE_RATE) { | ||
975 | settings.sample_rate = i; | ||
976 | break; | ||
977 | } | ||
978 | } | ||
979 | if (settings.sample_rate == -1) { | ||
980 | settings.sample_rate = HW_NUM_FREQ -1; | ||
981 | } | ||
982 | } | ||
983 | |||
916 | applysettings(); | 984 | applysettings(); |
917 | 985 | ||
918 | if (MikMod_Init("")) | 986 | if (MikMod_Init("")) |
@@ -934,14 +1002,13 @@ enum plugin_status plugin_start(const void* parameter) | |||
934 | 1002 | ||
935 | if (retval == PLUGIN_OK) | 1003 | if (retval == PLUGIN_OK) |
936 | { | 1004 | { |
937 | rb->splash(0, "Saving Settings"); | ||
938 | if (rb->memcmp(&settings, &old_settings, sizeof (settings))) | 1005 | if (rb->memcmp(&settings, &old_settings, sizeof (settings))) |
939 | { | 1006 | { |
940 | configfile_save(MIKMOD_CONFIGFILE, config, | 1007 | configfile_save(MIKMOD_CONFIGFILE, config, |
941 | ARRAYLEN(config), MIKMOD_SETTINGS_MINVERSION); | 1008 | ARRAYLEN(config), MIKMOD_SETTINGS_MINVERSION); |
942 | } | 1009 | } |
943 | } | 1010 | } |
944 | 1011 | ||
945 | destroy_memory_pool(audio_buffer); | 1012 | destroy_memory_pool(audio_buffer); |
946 | 1013 | ||
947 | return retval; | 1014 | return retval; |