p5.js-sound icon indicating copy to clipboard operation
p5.js-sound copied to clipboard

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

Open endurance21 opened this issue 5 years ago • 5 comments

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 avatar Mar 27 '20 01:03 endurance21

@therewasaguy please review this Pr!

endurance21 avatar Mar 27 '20 01:03 endurance21

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 avatar Mar 31 '20 20:03 endurance21

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 avatar Mar 31 '20 20:03 endurance21

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 , https://github.com/processing/p5.js-sound/pull/419#issuecomment-603586872 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 avatar Mar 31 '20 20:03 endurance21

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

endurance21 avatar Jun 06 '20 13:06 endurance21