Skip to content

Commit a82618b

Browse files
dp: use 64bit integers for period calculation
for some huge bitrates there was an overflow in 32bit numbers in period calculations, i.e: dev->period = 1000000 * sink_get_min_free_space(sink) for 192000-32-7 format it was 5824000000, more than maxint32bit Signed-off-by: Marcin Szkudlinski <marcin.szkudlinski@intel.com>
1 parent 73366d9 commit a82618b

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/audio/module_adapter/module_adapter.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,10 @@ static void module_adapter_calculate_dp_period(struct comp_dev *dev)
139139
unsigned int period = UINT32_MAX;
140140

141141
for (int i = 0; i < mod->num_of_sinks; i++) {
142-
/* calculate time required the module to provide OBS data portion - a period */
143-
unsigned int sink_period = 1000000 * sink_get_min_free_space(mod->sinks[i]) /
142+
/* calculate time required the module to provide OBS data portion - a period
143+
* use 64bit integers to avoid overflows
144+
*/
145+
unsigned int sink_period = 1000000ULL * sink_get_min_free_space(mod->sinks[i]) /
144146
(sink_get_frame_bytes(mod->sinks[i]) *
145147
sink_get_rate(mod->sinks[i]));
146148
/* note the minimal period for the module */

src/audio/src/src_ipc4.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,10 @@ int src_set_params(struct processing_module *mod, struct sof_sink *sink)
105105
* according to OBS size and data rate
106106
* as SRC uses period value to calculate its internal buffers,
107107
* it must be done here, right after setting sink parameters
108+
*
109+
* calculate period using 64bit integer to avoid overflows
108110
*/
109-
dev->period = 1000000 * sink_get_min_free_space(sink) /
111+
dev->period = 1000000ULL * sink_get_min_free_space(sink) /
110112
(sink_get_frame_bytes(sink) * sink_get_rate(sink));
111113
/* align down period to LL cycle time */
112114
dev->period /= LL_TIMER_PERIOD_US;

0 commit comments

Comments
 (0)