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.

doom: Rework audio init to properly respect pcm_sink capabilities

Try to use 11KHz if possible, if that's not an option, fall
back to 44KHz which is always available. Simulators always use
44KHz.

Change-Id: I7547e7c1bddf7ce4634f7fd7bc64d4a5c9b62c29

+24 -14
+24 -14
apps/plugins/doom/i_sound.c
··· 51 51 #define SAMPLECOUNT 128 52 52 53 53 #define NUM_CHANNELS 24 54 - // It is 2 for 16bit, and 2 for two channels. 55 - #define BUFMUL 2 54 + #define BUFMUL 2 // 2 channels 55 + #define SAMPLESIZE sizeof(short) // 16-bit 56 56 #define MIXBUFFERSIZE (SAMPLECOUNT*BUFMUL) 57 57 58 - #ifdef HW_HAVE_11 59 - #define SAMPLERATE SAMPR_11 // 44100 22050 11025 60 - #else 61 - #define SAMPLERATE SAMPR_44 // 44100 22050 11025 62 - #endif 63 - #define SAMPLESIZE 2 // 16bit 58 + static unsigned short samplerate; 64 59 65 60 // The global mixing buffer. 66 61 // Basically, samples from all active internal channels ··· 207 202 // Patched to shift left *then* divide, to minimize roundoff errors 208 203 // as well as to use SAMPLERATE as defined above, not to assume 11025 Hz 209 204 if (pitched_sounds) 210 - channelinfo[slot].step = step + (((channelinfo[slot].samplerate<<16)/SAMPLERATE)-65536); 205 + channelinfo[slot].step = step + (((channelinfo[slot].samplerate<<16)/samplerate)-65536); 211 206 else 212 - channelinfo[slot].step = ((channelinfo[slot].samplerate<<16)/SAMPLERATE); 207 + channelinfo[slot].step = ((channelinfo[slot].samplerate<<16)/samplerate); 213 208 214 209 // Separation, that is, orientation/stereo. 215 210 // range is: 1 - 256 ··· 265 260 // This table provides step widths for pitch parameters. 266 261 for (i=-128 ; i<128 ; i++) 267 262 steptablemid[i]=2; 268 - // steptablemid[i] = (int)(pow(1.2, ((double)i/(64.0*SAMPLERATE/11025)))*65536.0); 263 + // steptablemid[i] = (int)(pow(1.2, ((double)i/(64.0*samplerate/11025)))*65536.0); 269 264 270 265 // Generates volume lookup tables 271 266 // which also turn the unsigned samples ··· 462 457 I_UpdateSound(); // Force sound update 463 458 464 459 *start = mixbuffer; 465 - *size = MIXBUFFERSIZE*sizeof(short); 460 + *size = MIXBUFFERSIZE*SAMPLESIZE; 466 461 } 467 462 468 463 ··· 480 475 rb->mixer_set_frequency(HW_SAMPR_DEFAULT); 481 476 } 482 477 478 + #if defined(SIMULATOR) 479 + #define PREFERRED_SAMPR SAMPR_44 480 + #else 481 + #define PREFERRED_SAMPR SAMPR_11 482 + #endif 483 + 483 484 void I_InitSound() 484 485 { 485 486 int i; 486 487 488 + const struct pcm_sink_caps* caps = rb->pcm_current_sink_caps(); 489 + for (i = 0 ; i < caps->num_samprs; i++) { 490 + if (caps->samprs[i] == PREFERRED_SAMPR) 491 + break; 492 + } 493 + if (i == caps->num_samprs) 494 + i = SAMPR_44; 495 + samplerate = caps->samprs[i]; 496 + 487 497 // Initialize external data (all sounds) at start, keep static. 488 498 printf( "I_InitSound: "); 489 499 rb->audio_stop(); ··· 493 503 rb->audio_set_input_source(AUDIO_SRC_PLAYBACK, SRCF_PLAYBACK); 494 504 rb->audio_set_output_source(AUDIO_SRC_PLAYBACK); 495 505 #endif 496 - rb->mixer_set_frequency(SAMPLERATE); 506 + rb->mixer_set_frequency(samplerate); 497 507 498 508 vol_lookup=malloc(128*256*sizeof(int)); 499 509 500 - mixbuffer=malloc(MIXBUFFERSIZE*sizeof(short)); 510 + mixbuffer=malloc(MIXBUFFERSIZE*SAMPLESIZE); 501 511 steptable=malloc(256*sizeof(int)); 502 512 503 513 for (i=1 ; i<NUMSFX ; i++)