From 509f3c75a241357fb67a3373b3d6a86317837d94 Mon Sep 17 00:00:00 2001 From: Ibrahn Sahir Date: Fri, 29 Oct 2021 22:37:49 +0100 Subject: [PATCH] AudioDriverPulseAudio: move Vector Cow access outside tight loop. Replaced some in-loop uses of Vector.write with an out of loop ptrw, to avoid a lot of superfluous reads on the CowData ref count. (cherry picked from commit 47496a55bc54dd1aca15d30158e14703b0670f36) --- drivers/pulseaudio/audio_driver_pulseaudio.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/pulseaudio/audio_driver_pulseaudio.cpp b/drivers/pulseaudio/audio_driver_pulseaudio.cpp index 0853ad521a5..765f3fb09d2 100644 --- a/drivers/pulseaudio/audio_driver_pulseaudio.cpp +++ b/drivers/pulseaudio/audio_driver_pulseaudio.cpp @@ -381,16 +381,18 @@ void AudioDriverPulseAudio::thread_func(void *p_udata) { ad->lock(); ad->start_counting_ticks(); + int16_t *out_ptr = ad->samples_out.ptrw(); + if (!ad->active) { for (unsigned int i = 0; i < ad->pa_buffer_size; i++) { - ad->samples_out.write[i] = 0; + out_ptr[i] = 0; } } else { ad->audio_server_process(ad->buffer_frames, ad->samples_in.ptrw()); if (ad->channels == ad->pa_map.channels) { for (unsigned int i = 0; i < ad->pa_buffer_size; i++) { - ad->samples_out.write[i] = ad->samples_in[i] >> 16; + out_ptr[i] = ad->samples_in[i] >> 16; } } else { // Uneven amount of channels @@ -399,11 +401,11 @@ void AudioDriverPulseAudio::thread_func(void *p_udata) { for (unsigned int i = 0; i < ad->buffer_frames; i++) { for (int j = 0; j < ad->pa_map.channels - 1; j++) { - ad->samples_out.write[out_idx++] = ad->samples_in[in_idx++] >> 16; + out_ptr[out_idx++] = ad->samples_in[in_idx++] >> 16; } uint32_t l = ad->samples_in[in_idx++] >> 16; uint32_t r = ad->samples_in[in_idx++] >> 16; - ad->samples_out.write[out_idx++] = (l + r) / 2; + out_ptr[out_idx++] = (l + r) / 2; } } }