|
17 | 17 | #include <sof/lib/cache.h> |
18 | 18 | #include <sof/lib/cpu.h> |
19 | 19 | #include <sof/list.h> |
| 20 | +#include <sof/math/numbers.h> |
20 | 21 | #include <sof/schedule/schedule.h> |
21 | 22 | #include <sof/schedule/task.h> |
22 | 23 | #include <sof/spinlock.h> |
@@ -246,6 +247,25 @@ int pipeline_free(struct pipeline *p) |
246 | 247 | return 0; |
247 | 248 | } |
248 | 249 |
|
| 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 | + |
249 | 269 | static int pipeline_comp_params(struct comp_dev *current, void *data, int dir) |
250 | 270 | { |
251 | 271 | struct pipeline_data *ppl_data = data; |
@@ -285,16 +305,8 @@ static int pipeline_comp_params(struct comp_dev *current, void *data, int dir) |
285 | 305 | /* send current params to the component */ |
286 | 306 | current->params = ppl_data->params->params; |
287 | 307 |
|
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); |
298 | 310 |
|
299 | 311 | err = comp_params(current); |
300 | 312 | if (err < 0 || err == PPL_STATUS_PATH_STOP) |
|
0 commit comments