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: introduce mixer_play_cbs

the added sampr_changed callback can be used to notify the mixer user of
frequency changes

Change-Id: I309db76576090fd5c019a1ba082af446129dd4a3

authored by

mojyack and committed by
Solomon Peachy
cb04b816 86639acc

+128 -47
+3 -3
apps/beep.c
··· 97 97 beep_get_more(&start, &size); 98 98 99 99 mixer_channel_set_amplitude(PCM_MIXER_CHAN_BEEP, MIX_AMP_UNITY); 100 - mixer_channel_play_data(PCM_MIXER_CHAN_BEEP, 101 - beep_count ? beep_get_more : NULL, 102 - start, size); 100 + static struct mixer_play_cbs cbs; 101 + cbs.get_more = beep_count ? beep_get_more : NULL; 102 + mixer_channel_play_data(PCM_MIXER_CHAN_BEEP, &cbs, start, size); 103 103 }
+12 -2
apps/pcmbuf.c
··· 29 29 #include "pcmbuf.h" 30 30 #include "dsp-util.h" 31 31 #include "playback.h" 32 + #include "dsp_core.h" 32 33 #include "codec_thread.h" 33 34 34 35 /* Define LOGF_ENABLE to enable logf output in this file */ ··· 836 837 } 837 838 } 838 839 840 + static void pcmbuf_sampr_callback(uint32_t sampr) 841 + { 842 + struct dsp_config* dsp = dsp_get_config(CODEC_IDX_AUDIO); 843 + dsp_configure(dsp, DSP_SET_OUT_FREQUENCY, sampr); 844 + } 845 + 839 846 /* Force playback */ 840 847 void pcmbuf_play_start(void) 841 848 { ··· 845 852 chunk_widx != chunk_ridx) 846 853 { 847 854 current_desc = NULL; 848 - mixer_channel_play_data(PCM_MIXER_CHAN_PLAYBACK, pcmbuf_pcm_callback, 849 - NULL, 0); 855 + static const struct mixer_play_cbs cbs = { 856 + .get_more = pcmbuf_pcm_callback, 857 + .sampr_changed = pcmbuf_sampr_callback, 858 + }; 859 + mixer_channel_play_data(PCM_MIXER_CHAN_PLAYBACK, &cbs, NULL, 0); 850 860 } 851 861 } 852 862
+1 -1
apps/plugin.h
··· 782 782 void (*mixer_channel_calculate_peaks)(enum pcm_mixer_channel channel, 783 783 struct pcm_peaks *peaks); 784 784 void (*mixer_channel_play_data)(enum pcm_mixer_channel channel, 785 - pcm_play_callback_type get_more, 785 + const struct mixer_play_cbs* cbs, 786 786 const void *start, size_t size); 787 787 void (*mixer_channel_play_pause)(enum pcm_mixer_channel channel, bool play); 788 788 void (*mixer_channel_stop)(enum pcm_mixer_channel channel);
+4 -1
apps/plugins/doom/i_sound.c
··· 466 466 if (!enable_sound) 467 467 return; 468 468 469 - rb->mixer_channel_play_data(PCM_MIXER_CHAN_PLAYBACK, &get_more, NULL, 0); 469 + static const struct mixer_play_cbs cbs = { 470 + .get_more = get_more, 471 + }; 472 + rb->mixer_channel_play_data(PCM_MIXER_CHAN_PLAYBACK, &cbs, NULL, 0); 470 473 } 471 474 472 475 void I_ShutdownSound(void)
+7 -3
apps/plugins/midi/midiplay.c
··· 507 507 return ret; 508 508 } 509 509 510 + static const struct mixer_play_cbs mixer_cbs = { 511 + .get_more = get_more, 512 + }; 513 + 510 514 static int midimain(const void * filename) 511 515 { 512 516 int a, notes_used, vol; ··· 625 629 #endif 626 630 627 631 rb->pcmbuf_fade(false, true); 628 - rb->mixer_channel_play_data(PCM_MIXER_CHAN_PLAYBACK, get_more, NULL, 0); 632 + rb->mixer_channel_play_data(PCM_MIXER_CHAN_PLAYBACK, &mixer_cbs, NULL, 0); 629 633 630 634 while (!quit) 631 635 { ··· 684 688 #endif 685 689 midi_debug("Rewind to %d:%02d\n", playing_time/60, playing_time%60); 686 690 if (is_playing) 687 - rb->mixer_channel_play_data(PCM_MIXER_CHAN_PLAYBACK, get_more, NULL, 0); 691 + rb->mixer_channel_play_data(PCM_MIXER_CHAN_PLAYBACK, &mixer_cbs, NULL, 0); 688 692 break; 689 693 } 690 694 ··· 706 710 #endif 707 711 midi_debug("Skip to %d:%02d\n", playing_time/60, playing_time%60); 708 712 if (is_playing) 709 - rb->mixer_channel_play_data(PCM_MIXER_CHAN_PLAYBACK, get_more, NULL, 0); 713 + rb->mixer_channel_play_data(PCM_MIXER_CHAN_PLAYBACK, &mixer_cbs, NULL, 0); 710 714 break; 711 715 } 712 716
+7 -4
apps/plugins/mikmod/mikmod.c
··· 292 292 #endif 293 293 } 294 294 295 + static const struct mixer_play_cbs mixer_cbs = { 296 + .get_more = get_more, 297 + }; 298 + 295 299 static void showinfo(void) 296 300 { 297 301 char statustext[LINE_LENGTH]; ··· 600 604 } 601 605 602 606 // MikMod_Reset(""); BROKEN! 603 - 604 607 rb->mixer_channel_stop(PCM_MIXER_CHAN_PLAYBACK); 605 - rb->mixer_set_frequency(md_mixfreq); 606 - rb->mixer_channel_play_data(PCM_MIXER_CHAN_PLAYBACK, get_more, NULL, 0); 608 + rb->mixer_set_frequency(md_mixfreq); 609 + rb->mixer_channel_play_data(PCM_MIXER_CHAN_PLAYBACK, &mixer_cbs, NULL, 0); 607 610 } 608 611 609 612 #ifdef HAVE_ADJUSTABLE_CPU_FREQ ··· 810 813 display = DISPLAY_INFO; 811 814 Player_Start(module); 812 815 rb->pcmbuf_fade(false, true); 813 - rb->mixer_channel_play_data(PCM_MIXER_CHAN_PLAYBACK, get_more, NULL, 0); 816 + rb->mixer_channel_play_data(PCM_MIXER_CHAN_PLAYBACK, &mixer_cbs, NULL, 0); 814 817 } 815 818 816 819 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
+6 -4
apps/plugins/mpegplayer/pcm_output.c
··· 173 173 pcmbuf_read = pcmbuf_written; 174 174 } 175 175 176 + static const struct mixer_play_cbs mixer_cbs = { 177 + .get_more = get_more, 178 + }; 179 + 176 180 /** Public interface **/ 177 181 178 182 /* Return a buffer pointer if at least size bytes are available and if so, ··· 236 240 237 241 /* Restart if playing state was current */ 238 242 if (status == CHANNEL_PLAYING) 239 - rb->mixer_channel_play_data(MPEG_PCM_CHANNEL, 240 - get_more, NULL, 0); 243 + rb->mixer_channel_play_data(MPEG_PCM_CHANNEL, &mixer_cbs, NULL, 0); 241 244 } 242 245 243 246 /* Seek the reference clock to the specified time - next audio data ready to ··· 318 321 if (play) 319 322 { 320 323 rb->mixer_channel_set_amplitude(MPEG_PCM_CHANNEL, MIX_AMP_UNITY); 321 - rb->mixer_channel_play_data(MPEG_PCM_CHANNEL, 322 - get_more, NULL, 0); 324 + rb->mixer_channel_play_data(MPEG_PCM_CHANNEL, &mixer_cbs, NULL, 0); 323 325 } 324 326 } 325 327 }
+4 -1
apps/plugins/pacbox/pacbox.c
··· 407 407 408 408 wsg3_set_sampling_rate(caps->samprs[sr_index]); 409 409 410 + static const struct mixer_play_cbs cbs = { 411 + .get_more = get_more, 412 + }; 410 413 rb->mixer_set_frequency(caps->samprs[sr_index]); 411 - rb->mixer_channel_play_data(PCM_MIXER_CHAN_PLAYBACK, get_more, NULL, 0); 414 + rb->mixer_channel_play_data(PCM_MIXER_CHAN_PLAYBACK, &cbs, NULL, 0); 412 415 413 416 sound_playing = true; 414 417 }
+4 -1
apps/plugins/pdbox/PDa/src/s_audio_rockbox.c
··· 181 181 if(!playing && outbuf_fill > 0) 182 182 { 183 183 /* Start playing. */ 184 - rb->mixer_channel_play_data(PCM_MIXER_CHAN_PLAYBACK, pdbox_get_more, NULL, 0); 184 + static const struct mixer_play_cbs cbs = { 185 + .get_more = pdbox_get_more, 186 + }; 187 + rb->mixer_channel_play_data(PCM_MIXER_CHAN_PLAYBACK, &cbs, NULL, 0); 185 188 186 189 /* Set status flag. */ 187 190 playing = true;
+4 -1
apps/plugins/rockboy/rbsound.c
··· 73 73 74 74 if(newly_started) 75 75 { 76 - rb->mixer_channel_play_data(PCM_MIXER_CHAN_PLAYBACK, &get_more, NULL, 0); 76 + static const struct mixer_play_cbs cbs = { 77 + .get_more = get_more, 78 + }; 79 + rb->mixer_channel_play_data(PCM_MIXER_CHAN_PLAYBACK, &cbs, NULL, 0); 77 80 newly_started = false; 78 81 } 79 82
+4 -1
apps/plugins/sdl/src/audio/rockbox/SDL_rockboxaudio.c
··· 288 288 289 289 rbaud_underruns = 0; 290 290 291 - rb->mixer_channel_play_data(PCM_MIXER_CHAN_PLAYBACK, get_more, NULL, 0); 291 + static const struct mixer_play_cbs cbs = { 292 + .get_more = get_more, 293 + }; 294 + rb->mixer_channel_play_data(PCM_MIXER_CHAN_PLAYBACK, &cbs, NULL, 0); 292 295 293 296 /* We're ready to rock and roll. :-) */ 294 297 return(0);
+4 -1
apps/plugins/test_sampr.c
··· 237 237 IF_PRIO(, PRIORITY_PLAYBACK) 238 238 IF_COP(, CPU)); 239 239 240 - rb->mixer_channel_play_data(PCM_MIXER_CHAN_PLAYBACK, get_more, NULL, 0); 240 + static const struct mixer_play_cbs cbs = { 241 + .get_more = get_more, 242 + }; 243 + rb->mixer_channel_play_data(PCM_MIXER_CHAN_PLAYBACK, &cbs, NULL, 0); 241 244 242 245 #ifndef HAVE_VOLUME_IN_LIST 243 246 if (volume_set)
+4 -1
apps/plugins/xrick/system/syssnd_rockbox.c
··· 222 222 223 223 if (!isAudioPlaying && fillCount > 0) 224 224 { 225 + static const struct mixer_play_cbs cbs = { 226 + .get_more = get_more, 227 + }; 225 228 isAudioPlaying = true; 226 - rb->mixer_channel_play_data(PCM_MIXER_CHAN_PLAYBACK, get_more, NULL, 0); 229 + rb->mixer_channel_play_data(PCM_MIXER_CHAN_PLAYBACK, &cbs, NULL, 0); 227 230 } 228 231 } 229 232 }
+4 -1
apps/plugins/xworld/sys.c
··· 1029 1029 audio_param = param; 1030 1030 audio_sys = sys; 1031 1031 1032 - rb->mixer_channel_play_data(PCM_MIXER_CHAN_PLAYBACK, get_more, NULL, 0); 1032 + static const struct mixer_play_cbs cbs = { 1033 + .get_more = get_more, 1034 + }; 1035 + rb->mixer_channel_play_data(PCM_MIXER_CHAN_PLAYBACK, &cbs, NULL, 0); 1033 1036 } 1034 1037 1035 1038 void sys_stopAudio(struct System* sys)
+4 -1
apps/plugins/zxbox/spsound.c
··· 212 212 = my_buf[j+10] = my_buf[j+11] \ 213 213 = (((byte)sp_sound_buf[i])<<8) >> settings.volume; 214 214 215 - rb->mixer_channel_play_data(PCM_MIXER_CHAN_PLAYBACK, get_more, (unsigned char*)(my_buf),TMNUM*4*3*2); 215 + static const struct mixer_play_cbs cbs = { 216 + .get_more = get_more, 217 + }; 218 + rb->mixer_channel_play_data(PCM_MIXER_CHAN_PLAYBACK, &cbs, (unsigned char*)(my_buf),TMNUM*4*3*2); 216 219 217 220 #if 0 218 221 /* can use to save and later analyze what we produce */
+4 -2
apps/voice_thread.c
··· 245 245 struct voice_pcm_frame *frame = 246 246 &voice_buf->frames[voice_buf->frame_out % VOICE_FRAMES]; 247 247 248 - mixer_channel_play_data(PCM_MIXER_CHAN_VOICE, voice_pcm_callback, 249 - frame->pcm, frame->size); 248 + static const struct mixer_play_cbs cbs = { 249 + .get_more = voice_pcm_callback, 250 + }; 251 + mixer_channel_play_data(PCM_MIXER_CHAN_VOICE, &cbs, frame->pcm, frame->size); 250 252 } 251 253 252 254 /* Stop the voice channel */
+2 -2
docs/PLUGIN_API
··· 1607 1607 \return 1608 1608 \description 1609 1609 1610 - void mixer_channel_play_data(enum pcm_mixer_channel channel, pcm_play_callback_type get_more, const void *start, size_t size) 1610 + void mixer_channel_play_data(enum pcm_mixer_channel channel, const struct mixer_play_cbs* cbs, const void *start, size_t size) 1611 1611 \param channel 1612 - \param get_more 1612 + \param cbs 1613 1613 \param start 1614 1614 \param size 1615 1615 \description
+6 -1
firmware/export/pcm_mixer.h
··· 96 96 /** Public interfaces **/ 97 97 98 98 /* Start playback on a channel */ 99 + struct mixer_play_cbs { 100 + void (*get_more)(const void **start, size_t *size); 101 + void (*sampr_changed)(uint32_t sampr); 102 + }; 103 + 99 104 void mixer_channel_play_data(enum pcm_mixer_channel channel, 100 - pcm_play_callback_type get_more, 105 + const struct mixer_play_cbs* cbs, 101 106 const void *start, size_t size); 102 107 103 108 /* Pause or resume a channel (when started) */
+40 -15
firmware/pcm_mixer.c
··· 42 42 /* Descriptor for each channel */ 43 43 struct mixer_channel 44 44 { 45 - const void *start; /* Buffer pointer */ 46 - size_t size; /* Bytes remaining */ 47 - size_t last_size; /* Size of consumed data in prev. cycle */ 48 - pcm_play_callback_type get_more; /* Registered callback */ 49 - enum channel_status status; /* Playback status */ 50 - uint32_t amplitude; /* Amp. factor: 0x0000 = mute, 0x10000 = unity */ 45 + const void *start; /* Buffer pointer */ 46 + size_t size; /* Bytes remaining */ 47 + size_t last_size; /* Size of consumed data in prev. cycle */ 48 + const struct mixer_play_cbs* cbs; /* Registered callbacks */ 49 + enum channel_status status; /* Playback status */ 50 + uint32_t amplitude; /* Amp. factor: 0x0000 = mute, 0x10000 = unity */ 51 51 chan_buffer_hook_fn_type buffer_hook; /* Callback for new buffer */ 52 52 }; 53 53 ··· 154 154 155 155 if (chan->size == 0) 156 156 { 157 - if (chan->get_more) 157 + if (chan->cbs->get_more) 158 158 { 159 - chan->get_more(&chan->start, &chan->size); 159 + chan->cbs->get_more(&chan->start, &chan->size); 160 160 ALIGN_AUDIOBUF(chan->start, chan->size); 161 161 } 162 162 ··· 287 287 288 288 /* Start playback on a channel */ 289 289 void mixer_channel_play_data(enum pcm_mixer_channel channel, 290 - pcm_play_callback_type get_more, 290 + const struct mixer_play_cbs* cbs, 291 291 const void *start, size_t size) 292 292 { 293 293 struct mixer_channel *chan = &channels[channel]; 294 294 295 295 ALIGN_AUDIOBUF(start, size); 296 296 297 - if (!(start && size) && get_more) 297 + if (!(start && size) && cbs && cbs->get_more) 298 298 { 299 299 /* Initial buffer not passed - call the callback now */ 300 300 pcm_play_lock(); ··· 304 304 pcm_play_unlock(); /* Allow playback while doing callback */ 305 305 306 306 size = 0; 307 - get_more(&start, &size); 307 + cbs->get_more(&start, &size); 308 308 ALIGN_AUDIOBUF(start, size); 309 309 } 310 310 ··· 317 317 chan->start = start; 318 318 chan->size = size; 319 319 chan->last_size = 0; 320 - chan->get_more = get_more; 320 + chan->cbs = cbs; 321 321 322 322 mixer_activate_channel(chan); 323 323 chan_call_buffer_hook(chan); ··· 464 464 465 465 if (samplerate == mixer_sampr) 466 466 return; 467 + mixer_sampr = samplerate; 467 468 468 - /* All data is now invalid */ 469 - mixer_reset(); 470 - mixer_sampr = samplerate; 469 + for (size_t i = 0; i < ARRAYLEN(active_channels) && active_channels[i]; i += 1) 470 + { 471 + struct mixer_channel* chan = active_channels[i]; 472 + 473 + /* Notify upstreams */ 474 + if (chan->cbs) 475 + { 476 + if (chan->cbs->sampr_changed) 477 + { 478 + chan->cbs->sampr_changed(samplerate); 479 + } 480 + if (chan->cbs->get_more) 481 + { 482 + /* Remake buffer */ 483 + const void *start = NULL; 484 + size_t size; 485 + chan->cbs->get_more(&start, &size); 486 + if (start && size) { 487 + chan->start = start; 488 + chan->size = size; 489 + chan->last_size = 0; 490 + } else { 491 + channel_stopped(chan); 492 + } 493 + } 494 + } 495 + } 471 496 472 497 /* Work out how much space we really need */ 473 498 if (samplerate > SAMPR_96)
+4 -1
firmware/usbstack/usb_audio.c
··· 1337 1337 logf("usbaudio: prebuffering done"); 1338 1338 playback_audio_underflow = false; 1339 1339 usb_rx_overflow = false; 1340 - mixer_channel_play_data(PCM_MIXER_CHAN_USBAUDIO, playback_audio_get_more, NULL, 0); 1340 + static const struct mixer_play_cbs cbs = { 1341 + .get_more = playback_audio_get_more, 1342 + }; 1343 + mixer_channel_play_data(PCM_MIXER_CHAN_USBAUDIO, &cbs, NULL, 0); 1341 1344 } 1342 1345 restore_irq(oldlevel); 1343 1346 retval = true;