Skip to content

Commit 64ef0da

Browse files
Jaska Uimonenjajanusz
authored andcommitted
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 <jaska.uimonen@intel.com>
1 parent 39ed9d6 commit 64ef0da

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

src/audio/pipeline.c

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <sof/lib/cache.h>
1818
#include <sof/lib/cpu.h>
1919
#include <sof/list.h>
20+
#include <sof/math/numbers.h>
2021
#include <sof/schedule/schedule.h>
2122
#include <sof/schedule/task.h>
2223
#include <sof/spinlock.h>
@@ -246,6 +247,25 @@ int pipeline_free(struct pipeline *p)
246247
return 0;
247248
}
248249

250+
static int pipeline_comp_period_frames(struct comp_dev *current)
251+
{
252+
int samplerate;
253+
int period;
254+
255+
period = current->pipeline->ipc_pipe.period;
256+
257+
if (current->output_rate)
258+
samplerate = current->output_rate;
259+
else
260+
samplerate = current->params.rate;
261+
262+
/* Samplerate is in kHz and period in microseconds.
263+
* As we don't have floats use scale divider 1000000.
264+
* Also integer round up the result.
265+
*/
266+
return ceil_divide(samplerate * period, 1000000);
267+
}
268+
249269
static int pipeline_comp_params(struct comp_dev *current, void *data, int dir)
250270
{
251271
struct pipeline_data *ppl_data = data;
@@ -285,16 +305,8 @@ static int pipeline_comp_params(struct comp_dev *current, void *data, int dir)
285305
/* send current params to the component */
286306
current->params = ppl_data->params->params;
287307

288-
/* set frames from samplerate/period, but round integer up */
289-
if (current->output_rate != 0) {
290-
current->frames = (current->output_rate +
291-
current->pipeline->ipc_pipe.period - 1) /
292-
current->pipeline->ipc_pipe.period;
293-
} else {
294-
current->frames = (current->params.rate +
295-
current->pipeline->ipc_pipe.period - 1) /
296-
current->pipeline->ipc_pipe.period;
297-
}
308+
/* set frames from samplerate/period */
309+
current->frames = pipeline_comp_period_frames(current);
298310

299311
err = comp_params(current);
300312
if (err < 0 || err == PPL_STATUS_PATH_STOP)

0 commit comments

Comments
 (0)