On July 26, 2021 8:18:19 PM PDT, Chengyi Zhao <zhaochengyi@xxxxxxxxxxxxx> wrote: >Hi guys, > >I found the following logic when I change the volume while playing >audio.I guess there is some audio expertise here, would you please tell > >me the principle, thanks a lot! > >In the file sink-input.c(./src/pulsecore/sink-input.c), why does pa >need >to invoke the function pa_sink_input_request_rewind to rewrite and >rewind the data? > >void pa_sink_input_set_volume(...) { > ... > > pa_assert_se(pa_asyncmsgq_send(i->sink->asyncmsgq, PA_MSGOBJECT(i), >PA_SINK_INPUT_MESSAGE_SET_SOFT_VOLUME, NULL, 0, NULL) == 0); > } > > ... >} > >int pa_sink_input_process_msg(...) { > ... > > switch (code) { > > case PA_SINK_INPUT_MESSAGE_SET_SOFT_VOLUME: > if (!pa_cvolume_equal(&i->thread_info.soft_volume, >&i->soft_volume)) { > i->thread_info.soft_volume = i->soft_volume; > pa_sink_input_request_rewind(i, 0, true, false, false); > } > > return 0; > > ... >} There's some helpful docs about what rewinding is in the context of pulseaudio here: https://www.freedesktop.org/wiki/Software/PulseAudio/Documentation/Developer/Rewinding/ But in summary, pulse will try to get ahead of things by buffering up processed audio data. When the requested processing changes, for example a new volume level is requested, rewinding clears out the (now out of date) buffered audio samples and rewrites them with the new processing. --Sean