From 64ef0da440e4e285f7e4243ac0de637c4410fc4e Mon Sep 17 00:00:00 2001 From: Jaska Uimonen Date: Wed, 28 Aug 2019 17:48:09 +0300 Subject: [PATCH] pipeline: fix period frame size calculation The period frame size calculation has issues by doing division instead of multiplication. So fix this by introducing new function for buffer period frames calculation where we multiply samplerate and schedule_period and divide by 1000000. Also round up the result. Signed-off-by: Jaska Uimonen --- src/audio/pipeline.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/src/audio/pipeline.c b/src/audio/pipeline.c index 529d78caa880..b14cba6cfa79 100644 --- a/src/audio/pipeline.c +++ b/src/audio/pipeline.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -246,6 +247,25 @@ int pipeline_free(struct pipeline *p) return 0; } +static int pipeline_comp_period_frames(struct comp_dev *current) +{ + int samplerate; + int period; + + period = current->pipeline->ipc_pipe.period; + + if (current->output_rate) + samplerate = current->output_rate; + else + samplerate = current->params.rate; + + /* Samplerate is in kHz and period in microseconds. + * As we don't have floats use scale divider 1000000. + * Also integer round up the result. + */ + return ceil_divide(samplerate * period, 1000000); +} + static int pipeline_comp_params(struct comp_dev *current, void *data, int dir) { struct pipeline_data *ppl_data = data; @@ -285,16 +305,8 @@ static int pipeline_comp_params(struct comp_dev *current, void *data, int dir) /* send current params to the component */ current->params = ppl_data->params->params; - /* set frames from samplerate/period, but round integer up */ - if (current->output_rate != 0) { - current->frames = (current->output_rate + - current->pipeline->ipc_pipe.period - 1) / - current->pipeline->ipc_pipe.period; - } else { - current->frames = (current->params.rate + - current->pipeline->ipc_pipe.period - 1) / - current->pipeline->ipc_pipe.period; - } + /* set frames from samplerate/period */ + current->frames = pipeline_comp_period_frames(current); err = comp_params(current); if (err < 0 || err == PPL_STATUS_PATH_STOP)