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.

pcm_mixer: implement mixer_switch_sink

Change-Id: I1549470774f96a6f470817cbc5fe4611812de6fa

mojyack 9ffc8a00 be4b0591

+68 -47
+4
firmware/export/pcm_mixer.h
··· 23 23 #define PCM_MIXER_H 24 24 25 25 #include <sys/types.h> 26 + #include "pcm_sink.h" 26 27 27 28 /** Simple config **/ 28 29 ··· 110 111 111 112 /* Stop playback on a channel */ 112 113 void mixer_channel_stop(enum pcm_mixer_channel channel); 114 + 115 + /* Switch playback sink */ 116 + bool mixer_switch_sink(enum pcm_sink_ids sink); 113 117 114 118 /* Set channel's amplitude factor */ 115 119 void mixer_channel_set_amplitude(enum pcm_mixer_channel channel,
+64 -47
firmware/pcm_mixer.c
··· 286 286 start, mix_frame_size); 287 287 } 288 288 289 + /* Notify users of samplerate change */ 290 + static void mixer_handle_sampr_change(unsigned int sampr) 291 + { 292 + for (size_t i = 0; i < ARRAYLEN(active_channels) && active_channels[i]; i += 1) 293 + { 294 + struct mixer_channel* chan = active_channels[i]; 295 + 296 + /* Notify upstreams */ 297 + if (chan->play_cbs) 298 + { 299 + if (chan->play_cbs->sampr_changed) 300 + { 301 + chan->play_cbs->sampr_changed(sampr); 302 + } 303 + if (chan->play_cbs->get_more) 304 + { 305 + /* Remake buffer */ 306 + const void *start = NULL; 307 + size_t size; 308 + chan->play_cbs->get_more(&start, &size); 309 + if (start && size) { 310 + chan->start = start; 311 + chan->size = size; 312 + chan->last_size = 0; 313 + } else { 314 + channel_stopped(chan); 315 + } 316 + } 317 + } 318 + /* Notify buffer monitor */ 319 + if (chan->buf_cbs) 320 + { 321 + if (chan->buf_cbs->sampr_changed) 322 + { 323 + chan->buf_cbs->sampr_changed(sampr); 324 + } 325 + } 326 + } 327 + 328 + /* Work out how much space we really need */ 329 + if (sampr > SAMPR_96) 330 + mix_frame_size = 4; 331 + else if (sampr > SAMPR_48) 332 + mix_frame_size = 2; 333 + else 334 + mix_frame_size = 1; 335 + 336 + mix_frame_size *= MIX_FRAME_SAMPLES * 4; 337 + } 338 + 289 339 /** Public interfaces **/ 290 340 291 341 /* Start playback on a channel */ ··· 371 421 pcm_play_unlock(); 372 422 } 373 423 424 + /* Switch playback sink */ 425 + bool mixer_switch_sink(enum pcm_sink_ids sink) 426 + { 427 + if(pcm_current_sink() == sink) 428 + return true; 429 + 430 + if(!pcm_switch_sink(sink)) 431 + return false; 432 + 433 + mixer_handle_sampr_change(SAMPR_NUM(pcm_get_frequency())); 434 + return true; 435 + } 436 + 374 437 /* Set channel's amplitude factor */ 375 438 void mixer_channel_set_amplitude(enum pcm_mixer_channel channel, 376 439 unsigned int amplitude) ··· 461 524 return; 462 525 463 526 pcm_set_frequency(samplerate); 464 - 465 - for (size_t i = 0; i < ARRAYLEN(active_channels) && active_channels[i]; i += 1) 466 - { 467 - struct mixer_channel* chan = active_channels[i]; 468 - 469 - /* Notify upstreams */ 470 - if (chan->play_cbs) 471 - { 472 - if (chan->play_cbs->sampr_changed) 473 - { 474 - chan->play_cbs->sampr_changed(SAMPR_NUM(samplerate)); 475 - } 476 - if (chan->play_cbs->get_more) 477 - { 478 - /* Remake buffer */ 479 - const void *start = NULL; 480 - size_t size; 481 - chan->play_cbs->get_more(&start, &size); 482 - if (start && size) { 483 - chan->start = start; 484 - chan->size = size; 485 - chan->last_size = 0; 486 - } else { 487 - channel_stopped(chan); 488 - } 489 - } 490 - } 491 - /* Notify buffer monitor */ 492 - if (chan->buf_cbs) 493 - { 494 - if (chan->buf_cbs->sampr_changed) 495 - { 496 - chan->buf_cbs->sampr_changed(SAMPR_NUM(samplerate)); 497 - } 498 - } 499 - } 500 - 501 - /* Work out how much space we really need */ 502 - if (SAMPR_NUM(samplerate) > SAMPR_96) 503 - mix_frame_size = 4; 504 - else if (SAMPR_NUM(samplerate) > SAMPR_48) 505 - mix_frame_size = 2; 506 - else 507 - mix_frame_size = 1; 508 - 509 - mix_frame_size *= MIX_FRAME_SAMPLES * 4; 510 - 527 + mixer_handle_sampr_change(SAMPR_NUM(pcm_get_frequency())); 511 528 if (pcm_is_initialized()) 512 529 pcm_apply_settings(); 513 530 }