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

added check for [bins] argument in fft method of P5, along with unit Test( in es6 style) #440

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

endurance21
Copy link
Collaborator

@endurance21 endurance21 commented Mar 27, 2020

issue :
safebins

the bins arguments is very vulnerable , as there is no check to what user provides as the input to bins argument , suppose the user enters a negative value of bins by mistake , then it's a crash !
so there must be a check to what user gives input as "bins" arguments"

solution :

  • added a filter (safeBins) to what user enters as argument .
    this bins

  • checks are esablished as shown
    safeBins

  • added a unit test for the function
    testSafeBins

@endurance21 endurance21 changed the title added feature of safeBins in fft method of P5 along with unit Test added feature of safeBins in fft method of P5 along with unit Test( in es6 style) Mar 27, 2020
@endurance21 endurance21 changed the title added feature of safeBins in fft method of P5 along with unit Test( in es6 style) added check for Bins argument in fft method of P5, along with unit Test( in es6 style) Mar 27, 2020
@endurance21 endurance21 changed the title added check for Bins argument in fft method of P5, along with unit Test( in es6 style) added check for [bins] argument in fft method of P5, along with unit Test( in es6 style) Mar 27, 2020
@endurance21
Copy link
Collaborator Author

@therewasaguy
please review this Pr!

Copy link
Member

@therewasaguy therewasaguy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest testing the public methods, and making this a private method.

Do you think the functionality of safeBins could be incorporated into safeBufferSize, rather than making it a separate method?

Also, just a note:

In the Web Audio API, the AnalyserNode.frequencyBinCount is Read only (I'm looking at the MDN documentation for reference https://developer.mozilla.org/en-US/docs/Web/API/AnalyserNode). It is always half of the fftSize. So we're kind of doing things backwards in p5.Sound by allowing users to set the binSize directly. We're doing that because it seemed like it would be more intuitive to set a value that represents the array size you get from the analysis, rather than a value that is twice that amount... but I'm having second thoughts about that now.

src/helpers.js Outdated Show resolved Hide resolved
@@ -337,12 +337,27 @@ define(function (require) {

return bufferSize;
}
var safeBins = p5.prototype.safeBins = function(bins) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to add this to the p5 prototype, or can this be a private method that is only used internally?

If it's only added to the prototype for the purpose of writing a test, I think the test should instead be on the public methods that utilize this function behind the scenes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@therewasaguy the main problem i face was using AMD here , I was unable to use safeBins defined in src/helper.js in test/tests/helpers.test.js , so I decided to put this method in prototype object of p5 ,
and I am realising now , that it is not the good way of doing it !,
so I will add tests on public function that will wrap this function ! and remove it from p5.prototype

test/tests/utils/test.helpers.js Show resolved Hide resolved
test/tests/utils/test.helpers.js Show resolved Hide resolved
@endurance21
Copy link
Collaborator Author

Also, just a note:

In the Web Audio API, the AnalyserNode.frequencyBinCount is Read only (I'm looking at the MDN documentation for reference https://developer.mozilla.org/en-US/docs/Web/API/AnalyserNode). It is always half of the fftSize. So we're kind of doing things backwards in p5.Sound by allowing users to set the binSize directly. We're doing that because it seemed like it would be more intuitive to set a value that represents the array size you get from the analysis, rather than a value that is twice that amount... but I'm having second thoughts about that now.

yeah ! you are right ! but it is very intuitive and generous to provide user the flexibilty to choose length of array in which analysed data will be served to them !, and we are no where assigning the value to "AnalyserNode.frequencyBinCount" that means it is good to use ,
infact we are creating a level of abstraction that provides ease to user !, so we don't need to remove that ,however we can rename it , name other than bins because it seem to represent "AnalyserNode.frequencyBinCount"
how about name "length" which represents the length of array !

@endurance21
Copy link
Collaborator Author

endurance21 commented Mar 31, 2020

I suggest testing the public methods, and making this a private method.

i was actually thinking the same , means i need to create a wrapper for this method ? or you have any other suggestions?

@endurance21
Copy link
Collaborator Author

endurance21 commented Mar 31, 2020

Do you think the functionality of safeBins could be incorporated into safeBufferSize, rather than making it a separate method?

safeBufferSize have other checks than safeBIns has
image
Also in ,
#419 (comment)
i have agreed to the w3 specs and not giving our user the ability to change the bufferSIZe() and hence we don't need to add tests for it like in safeBins !! so after your confirmation I will close that PR !(#419)

@endurance21
Copy link
Collaborator Author

i would like to draft this one until the module system work is done !

@endurance21 endurance21 marked this pull request as draft June 9, 2020 15:39
Base automatically changed from master to main March 5, 2021 02:53
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