Skip to content

Conversation

@cataldor
Copy link

Hello everyone,
i think i found an off-by-one issue on locredit calculation, assuming that the intent of ceil was to always round up.
Let me know if you all agree.

If I am wrong, i still think we should add a comment since ceil() may not behave as "expected".


The locredit parameter is a rounded up integer from a floating-point division. Unfortunately, locredit is a negative number (as it is derived from sendslope), and the rounding up python function employed (math.ceil()) provides the relative (not absolute) rounded up value.

Thus, math.ceil(-4.2) is -4 and not -5.

Use math.floor() for this specific case.

Before this patch:
$ ./calc-cbs-params.py --stream class=a,transport=avtp-aaf,rate=8000,psize=384
Class A: idleslope 28800 sendslope -971200 hicredit 45 locredit -437
(...)

After this patch:
$ ./calc-cbs-params.py --stream class=a,transport=avtp-aaf,rate=8000,psize=384
Class A: idleslope 28800 sendslope -971200 hicredit 45 locredit -438
(...)

The locredit parameter is a rounded up integer from a floating-point
division. Unfortunately, locredit is a negative number (as it is derived
from sendslope), and the rounding up python function employed
(math.ceil()) provides the relative (not absolute) rounded up value.

Thus, math.ceil(-4.2) is -4 and not -5.

Use math.floor() for this specific case.

Before this patch:
$ ./calc-cbs-params.py --stream class=a,transport=avtp-aaf,rate=8000,psize=384
Class A: idleslope 28800 sendslope -971200 hicredit 45 locredit -437
(...)

After this patch:
$ ./calc-cbs-params.py --stream class=a,transport=avtp-aaf,rate=8000,psize=384
Class A: idleslope 28800 sendslope -971200 hicredit 45 locredit -438
(...)

Signed-off-by: Rodrigo Cataldo <rodrigo.cadore@l-acoustics.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants