Skip to content

Commit

Permalink
pipeline: fix period frame size calculation
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Jaska Uimonen authored and jajanusz committed Aug 30, 2019
1 parent 39ed9d6 commit 64ef0da
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions src/audio/pipeline.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <sof/lib/cache.h>
#include <sof/lib/cpu.h>
#include <sof/list.h>
#include <sof/math/numbers.h>
#include <sof/schedule/schedule.h>
#include <sof/schedule/task.h>
#include <sof/spinlock.h>
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 64ef0da

Please sign in to comment.