Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

calc-cbs-params: fix off-by-one on locredit calculation #37

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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.

1 participant