Skip to content

Commit

Permalink
audio: add function audio_pcm_hw_conv_in()
Browse files Browse the repository at this point in the history
Add a function audio_pcm_hw_conv_in() similar to the existing
counterpart function audio_pcm_hw_clip_out(). This function reduces
the number of calls to the pcm_ops functions get_buffer_in() and
put_buffer_in(). That's one less call to get_buffer_in() and
put_buffer_in() every time the conv_buffer wraps around.

Signed-off-by: Volker Rümelin <vr_qemu@t-online.de>
Message-Id: <20220301191311.26695-3-vr_qemu@t-online.de>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
  • Loading branch information
Volker Rümelin authored and kraxel committed Mar 4, 2022
1 parent 8e56a17 commit 251f154
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions audio/audio.c
Expand Up @@ -548,6 +548,24 @@ static size_t audio_pcm_hw_get_live_in(HWVoiceIn *hw)
return live;
}

static size_t audio_pcm_hw_conv_in(HWVoiceIn *hw, void *pcm_buf, size_t samples)
{
size_t conv = 0;
STSampleBuffer *conv_buf = hw->conv_buf;

while (samples) {
uint8_t *src = advance(pcm_buf, conv * hw->info.bytes_per_frame);
size_t proc = MIN(samples, conv_buf->size - conv_buf->pos);

hw->conv(conv_buf->samples + conv_buf->pos, src, proc);
conv_buf->pos = (conv_buf->pos + proc) % conv_buf->size;
samples -= proc;
conv += proc;
}

return conv;
}

/*
* Soft voice (capture)
*/
Expand Down Expand Up @@ -1219,7 +1237,6 @@ static void audio_run_out (AudioState *s)
static size_t audio_pcm_hw_run_in(HWVoiceIn *hw, size_t samples)
{
size_t conv = 0;
STSampleBuffer *conv_buf = hw->conv_buf;

if (hw->pcm_ops->run_buffer_in) {
hw->pcm_ops->run_buffer_in(hw);
Expand All @@ -1235,11 +1252,7 @@ static size_t audio_pcm_hw_run_in(HWVoiceIn *hw, size_t samples)
break;
}

proc = MIN(size / hw->info.bytes_per_frame,
conv_buf->size - conv_buf->pos);

hw->conv(conv_buf->samples + conv_buf->pos, buf, proc);
conv_buf->pos = (conv_buf->pos + proc) % conv_buf->size;
proc = audio_pcm_hw_conv_in(hw, buf, size / hw->info.bytes_per_frame);

samples -= proc;
conv += proc;
Expand Down

0 comments on commit 251f154

Please sign in to comment.