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

[amdf.js] Possibly faulty minPeriod calculation #21

Open
michaelkaeppler opened this issue May 16, 2019 · 1 comment
Open

[amdf.js] Possibly faulty minPeriod calculation #21

michaelkaeppler opened this issue May 16, 2019 · 1 comment

Comments

@michaelkaeppler
Copy link
Contributor

I wonder whether line 16 in amdf.js does what it is supposed to do:
const minPeriod = Math.round(sampleRate / maxFrequency + 0.5);
As I understand it, this expression calculates the ratio sampleRate / maxFrequency, hence the
amount of samples that would theoretically occur during one cycle of maxFrequency.
The rounding expression then basically truncates all digits right of the decimal point and adds 1.
For the calculation of maxPeriod this makes sense, since one doesn't want to miss a signal at minimum frequency, so the rounded maxPeriod should definitely not be smaller than the "floating-point" maxPeriod.
Doesn't that mean for minPeriod conversely, that it's rounded value should definitely not be greater than the fractional value?
Example: With sampleRate = 44100 and maxFrequency = 400, the ratio sampleRate/maxFrequency is 110,25.
According to the rounding mechanism in line 16 that would yield minPeriod = 111.
In my opinion this should yield 110.

@peterkhayes
Copy link
Owner

That sounds reasonable. Can you submit a PR?

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

No branches or pull requests

2 participants