Rockbox open source high quality audio player as a Music Player Daemon
mpris rockbox mpd libadwaita audio rust zig deno
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

plugins: mikmod: remove hw_freq_sampr usage

TODO:

* Dynamically hide the sample rates that aren't supported
by the current sink
* Better "default" selection based on hardware type/speed

Change-Id: I261544fc3ba78429eaaa81c89aebd2e68106caa3

authored by

mojyack and committed by
Solomon Peachy
012c61ea 27ebdfcb

+72 -56
+72 -32
apps/plugins/mikmod/mikmod.c
··· 502 502 { TYPE_BOOL, 0, 1, { .bool_p = &settings.reverse }, "Reverse Channels", NULL}, 503 503 { TYPE_BOOL, 0, 1, { .bool_p = &settings.surround }, "Surround", NULL}, 504 504 { TYPE_BOOL, 0, 1, { .bool_p = &settings.hqmixer }, "HQ Mixer", NULL}, 505 - { TYPE_INT, 0, HW_NUM_FREQ-1, { .int_p = &settings.sample_rate }, "Sample Rate", NULL}, 505 + { TYPE_INT, 0, SAMPR_NUM_FREQ - 1, { .int_p = &settings.sample_rate }, "Sample Rate", NULL}, 506 506 #ifdef HAVE_ADJUSTABLE_CPU_FREQ 507 507 { TYPE_BOOL, 0, 1, { .bool_p = &settings.boost }, "CPU Boost", NULL}, 508 508 #endif 509 509 }; 510 510 511 + // XXX dynamically generate this list at runtime. 512 + static const struct opt_items sr_names[SAMPR_NUM_FREQ] = { 513 + [FREQ_192] = { "192kHz", TALK_ID(192, UNIT_KHZ) }, 514 + [FREQ_176] = { "176.4kHz", TALK_ID(176, UNIT_KHZ) }, 515 + [FREQ_96] = { "96kHz", TALK_ID(96, UNIT_KHZ) }, 516 + [FREQ_88] = { "88.2kHz", TALK_ID(88, UNIT_KHZ) }, 517 + [FREQ_64] = { "64kHz", TALK_ID(64, UNIT_KHZ) }, 518 + [FREQ_48] = { "48kHz", TALK_ID(48, UNIT_KHZ) }, 519 + [FREQ_44] = { "44.1kHz", TALK_ID(44, UNIT_KHZ) }, 520 + [FREQ_32] = { "32kHz", TALK_ID(32, UNIT_KHZ) }, 521 + [FREQ_24] = { "24kHz", TALK_ID(24, UNIT_KHZ) }, 522 + [FREQ_22] = { "22.05kHz", TALK_ID(22, UNIT_KHZ) }, 523 + [FREQ_16] = { "16kHz", TALK_ID(16, UNIT_KHZ) }, 524 + [FREQ_12] = { "12kHz", TALK_ID(12, UNIT_KHZ) }, 525 + [FREQ_11] = { "11.025kHz", TALK_ID(11, UNIT_KHZ) }, 526 + [FREQ_8 ] = { "8kHz", TALK_ID( 8, UNIT_KHZ) }, 527 + }; 528 + 529 + static const unsigned long sr_nums[SAMPR_NUM_FREQ] = 530 + { 531 + [FREQ_192] = SAMPR_192, 532 + [FREQ_176] = SAMPR_176, 533 + [FREQ_96] = SAMPR_96, 534 + [FREQ_88] = SAMPR_88, 535 + [FREQ_64] = SAMPR_64, 536 + [FREQ_48] = SAMPR_48, 537 + [FREQ_44] = SAMPR_44, 538 + [FREQ_32] = SAMPR_32, 539 + [FREQ_24] = SAMPR_24, 540 + [FREQ_22] = SAMPR_22, 541 + [FREQ_16] = SAMPR_16, 542 + [FREQ_12] = SAMPR_12, 543 + [FREQ_11] = SAMPR_11, 544 + [FREQ_8 ] = SAMPR_8, 545 + }; 546 + 547 + static int sampr_to_setting_index(unsigned long sampr) 548 + { 549 + for(unsigned int i = 0; i < ARRAYLEN(sr_nums); i += 1) 550 + { 551 + if(sr_nums[i] == sampr) 552 + return i; 553 + } 554 + /* no way... */ 555 + return ARRAYLEN(sr_nums) - 1; 556 + } 557 + 511 558 static void applysettings(void) 512 559 { 513 560 md_pansep = settings.pansep; ··· 533 580 } 534 581 #endif 535 582 536 - if (inited && (md_mixfreq != rb->hw_freq_sampr[settings.sample_rate])) { 537 - md_mixfreq = rb->hw_freq_sampr[settings.sample_rate]; 538 - // MikMod_Reset(""); BROKEN! 583 + if (inited && (md_mixfreq != sr_nums[settings.sample_rate])) { 584 + /* validate configured samplerate and set md_mixfreq */ 585 + md_mixfreq = 0; 586 + const struct pcm_sink_caps* caps = rb->pcm_current_sink_caps(); 587 + for(unsigned int i = 0; i < caps->num_samprs; i += 1) 588 + { 589 + if(caps->samprs[i] == sr_nums[settings.sample_rate]) 590 + { 591 + md_mixfreq = sr_nums[settings.sample_rate]; 592 + break; 593 + } 594 + } 595 + if(md_mixfreq == 0) 596 + { 597 + /* unsupported samplerate, use the default */ 598 + md_mixfreq = caps->samprs[caps->default_freq]; 599 + settings.sample_rate = sampr_to_setting_index(md_mixfreq); 600 + } 601 + 602 + // MikMod_Reset(""); BROKEN! 603 + 539 604 rb->mixer_channel_stop(PCM_MIXER_CHAN_PLAYBACK); 540 605 rb->mixer_set_frequency(md_mixfreq); 541 606 rb->mixer_channel_play_data(PCM_MIXER_CHAN_PLAYBACK, get_more, NULL, 0); ··· 548 613 } 549 614 #endif 550 615 } 551 - 552 - static const struct opt_items sr_names[HW_NUM_FREQ] = { 553 - HW_HAVE_192_([HW_FREQ_192] = { "192kHz", TALK_ID(192, UNIT_KHZ) },) 554 - HW_HAVE_176_([HW_FREQ_176] = { "176.4kHz", TALK_ID(176, UNIT_KHZ) },) 555 - HW_HAVE_96_([HW_FREQ_96] = { "96kHz", TALK_ID(96, UNIT_KHZ) },) 556 - HW_HAVE_88_([HW_FREQ_88] = { "88.2kHz", TALK_ID(88, UNIT_KHZ) },) 557 - HW_HAVE_64_([HW_FREQ_64] = { "64kHz", TALK_ID(64, UNIT_KHZ) },) 558 - HW_HAVE_48_([HW_FREQ_48] = { "48kHz", TALK_ID(48, UNIT_KHZ) },) 559 - HW_HAVE_44_([HW_FREQ_44] = { "44.1kHz", TALK_ID(44, UNIT_KHZ) },) 560 - HW_HAVE_32_([HW_FREQ_32] = { "32kHz", TALK_ID(32, UNIT_KHZ) },) 561 - HW_HAVE_24_([HW_FREQ_24] = { "24kHz", TALK_ID(24, UNIT_KHZ) },) 562 - HW_HAVE_22_([HW_FREQ_22] = { "22.05kHz", TALK_ID(22, UNIT_KHZ) },) 563 - HW_HAVE_16_([HW_FREQ_16] = { "16kHz", TALK_ID(16, UNIT_KHZ) },) 564 - HW_HAVE_12_([HW_FREQ_12] = { "12kHz", TALK_ID(12, UNIT_KHZ) },) 565 - HW_HAVE_11_([HW_FREQ_11] = { "11.025kHz", TALK_ID(11, UNIT_KHZ) },) 566 - HW_HAVE_8_( [HW_FREQ_8 ] = { "8kHz", TALK_ID( 8, UNIT_KHZ) },) 567 - }; 568 616 569 617 /** 570 618 Shows the settings menu ··· 626 674 627 675 case 6: 628 676 rb->set_option("Sample Rate", &(settings.sample_rate), RB_INT, sr_names, 629 - HW_NUM_FREQ, NULL); 677 + SAMPR_NUM_FREQ, NULL); 630 678 applysettings(); 631 679 break; 632 680 ··· 992 1040 993 1041 /* If there's no configured rate, use the default */ 994 1042 if (settings.sample_rate == -1) { 995 - int i; 996 - for (i = 0 ; i < HW_NUM_FREQ ; i++) { 997 - if (rb->hw_freq_sampr[i] == SAMPLE_RATE) { 998 - settings.sample_rate = i; 999 - break; 1000 - } 1001 - } 1002 - if (settings.sample_rate == -1) { 1003 - settings.sample_rate = HW_NUM_FREQ -1; 1004 - } 1043 + const struct pcm_sink_caps* caps = rb->pcm_current_sink_caps(); 1044 + settings.sample_rate = sampr_to_setting_index(caps->samprs[caps->default_freq]); 1005 1045 } 1006 1046 1007 1047 applysettings();
-24
apps/plugins/mikmod/mikmod_supp.h
··· 68 68 69 69 extern const struct plugin_api * rb; 70 70 71 - #ifdef SIMULATOR 72 - 73 - #define SAMPLE_RATE SAMPR_44 /* Required by Simulator */ 74 - 75 - #elif ((CONFIG_PLATFORM & PLATFORM_HOSTED) || defined(CPU_MIPS)) 76 - 77 - #define SAMPLE_RATE SAMPR_44 /* All MIPS and hosted targets are fast */ 78 - 79 - #elif defined(CPU_ARM) 80 - 81 - /* Treat ARMv5+ as fast */ 82 - #if (ARM_ARCH >= 5) 83 - #define SAMPLE_RATE SAMPR_44 84 - #else 85 - #define SAMPLE_RATE HW_SAMPR_MIN_GE_22 86 - #endif 87 - 88 - #else /* !CPU_ARM */ 89 - 90 - /* Treat everyone else as slow */ 91 - #define SAMPLE_RATE HW_SAMPR_MIN_GE_22 92 - 93 - #endif /* !SIMULATOR */ 94 - 95 71 #define BUF_SIZE 4096*8 96 72 #define NBUF 2 97 73