Skip to content

Commit 6728a75

Browse files
kv2019ilgirdwood
authored andcommitted
topology1: fix buffer size calculation if period-size >44ms
Calculation of SOF_TKN_BUF_SIZE in COMP_PERIOD_FRAMES() macro led to incorrect results with large period size values. For example at 48000Hz sampling rate, period size larger than 44739us would be incorrectly calculated. This happens as m4 eval does arithmetic in 32bit signed values and multiplication of period size and sampling rate can easily exceed 2^31. Fix the issue by splitting the arithmetic in steps that fit available value range. Link: #7476 Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com> (cherry picked from commit be43b4e)
1 parent 64968ee commit 6728a75

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

tools/topology/topology1/m4/buffer.m4

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ dnl COMP_BUFFER_SIZE( num_periods, sample_size, channels, fmames)
4444
define(`COMP_BUFFER_SIZE', `eval(`$1 * $2 * $3 * $4')')
4545

4646
dnl COMP_PERIOD_FRAMES( sample_rate, period_us)
47-
define(`COMP_PERIOD_FRAMES', `eval(`($1 * $2) / 1000000')')
47+
dnl note: m4 eval arithmetic is 32bit signed, so split the 10^6
48+
dnl division to avoid overflow.
49+
define(`COMP_PERIOD_FRAMES', `eval(`$1 / 100 * $2 / 10000')')
4850

4951
divert(0)dnl

0 commit comments

Comments
 (0)