From afe41bcd53439294bd2ea4cac6dfbf8afdeaf40a Mon Sep 17 00:00:00 2001 From: Marcin Rajwa Date: Wed, 1 Apr 2020 12:32:32 +0200 Subject: [PATCH] kpb: simplify calculation of buffered data This patch reworks the calculation of buffered data. NOTE! We only keep record of buffered data up to the size of history buffer as there is no usecase beyond that. Signed-off-by: Marcin Rajwa --- src/audio/kpb.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/audio/kpb.c b/src/audio/kpb.c index 0014dbe62814..ce46d91aea76 100644 --- a/src/audio/kpb.c +++ b/src/audio/kpb.c @@ -610,7 +610,6 @@ static int kpb_copy(struct comp_dev *dev) struct comp_buffer *sink = NULL; size_t copy_bytes = 0; size_t sample_width = kpb->config.sampling_width; - uint32_t hb_free_space; uint32_t flags = 0; comp_dbg(dev, "kpb_copy()"); @@ -679,13 +678,13 @@ static int kpb_copy(struct comp_dev *dev) comp_err(dev, "kpb_copy(): internal buffering failed."); goto out; } - if (kpb->buffered_data < kpb->buffer_size) { - hb_free_space = kpb->buffer_size - - kpb->buffered_data; - kpb->hd.buffered += - MIN(copy_bytes, hb_free_space); - } + /* Update buffered size. NOTE! We only record buffered + * data up to the size of history buffer. + */ + kpb->hd.buffered += MIN(kpb->hd.buffer_size - + kpb->hd.buffered, + copy_bytes); } else { comp_err(dev, "kpb_copy(): too much data to buffer."); }