-
Notifications
You must be signed in to change notification settings - Fork 166
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
Customizable windowing function for Analyser node #2421
Comments
Virtual F2F:
|
Proposal: enum WindowFunction {
"blackman",
"rectangular"
};
partial interface AnalyserNode {
attribute WindowFunction windowFunction;
}; From the call, those two are the most important, but we could add others. An |
Something to consider is what to invalidate when changing the mode:
|
See https://en.wikipedia.org/wiki/Window_function for other possibilities. |
Gaussian is a popular one. Kaiser window seems to be a very flexible one, but I don’t know if this is something that should be out-of-the-box for WebAudio. I did short summaries of characteristics and usage of the some of the Windows in this repo: https://github.com/khoin/ExtraWindows |
I take that back. I meant Hann and Hamming are popular ones, not Gaussian. |
Heh. I have no objections to adding Hann and Hamming windows. I think we'll probably want to avoid window functions that have parameters controlling the window function. It's not impossible, but it is kind of hard to come up with a nice way to specify the window and the appropriate parameters. |
I agree with you there. Doesn’t seem like something WebAudio should handle. Providing a way to customize windows (like PeriodicWave) should be enough for devs to utilize the smoothingTimeConstant, min/maxDecibels, binCount (like how they'd utilize custom PeriodicWave with OscillatorNode) |
Do you mean essentially a method that takes a set of Fourier coefficients of the window function? Then the Analyser would do an IFFT of the appropriate size (or interpolate) to get the window function of the correct size? That would also be acceptable to me. But I wonder how much it would be used. I don't recall anyone really asking for new window except rectangular. |
No. I didn't mean that. As far as I know, I have not seen anyone define/generate windowing functions using Fourier coefficients. If there are, they would be the Blackman window families, which are weighted cosines. I meant that the benefits of allowing custom windows is akin to the benefits of custom I imagine custom windows for AnalyserNode to look something like this: let a = aC.createAnalyser(); // default fftSize = 2048 (spec)
a.minDecibels = -120;
a.maxDecibles = 0;
a.timeSmoothingConstant = 0.5;
let win = new Float32Array(a.fftSize);
// win.fill(1); // Rectangular
win = win.map((x,i) => Math.abs(1 - ((i/a.fftSize) - 0.5))); // Barlett (triangle)
a.setWindowingFunction(win); //throws error if win does not match a.fftSize
// a.setWindowFunction ?
// a.setWindow ?
// extending @padenot's proposal
a.windowFunction = "custom";
// Comparing to OscillatorNode.type = "custom"; // throws Invalid State Error if no custom window is set. |
I just realized that something needs to be done if I don't know how the change of Spec says:
And also here: but spec doesn't say how windowing is handled when |
I'm not opposed to the idea, but I wonder how often it would be used. It adds a bit of complexity for something that may not be used. Yeah, I was thinking about what happens when the fftsize changes. Resample the given waveform? Throw an error? Silently fallback to Blackman? Most of the time I see the Analyser used for visualization and not really analysis. In that case the given windows are ok. For more complicated analysis, perhaps a ScriptProcessor or AudioWorklet is the right answer. |
I think custom windows to be handled by WebAudio should not be considered if the majority of use case (do we have surveys?) are visualization. Perhaps rectangular, Han, Blackman is enough. If someone wants to do analysis, they’d be building their own AudioNode already. I mean... there’s lots of consider — padding, even-odd (periodicity/symmetry), etc. Custom windowing support would appear to be a very narrow use case. |
Sounds good to me. Just the two suggested plus Hann and Hamming. No custom windows. Creating a survey is easy. Getting it out to enough people might be hard. But if someone has a solid use case where this is really important, we'd probably consider it. Please speak up if anyone has a solid use case for this! |
Note that https://en.wikipedia.org/wiki/Window_function#Hann_and_Hamming_windows says there's more than one Hamming window. We'd have to arbitrarily pick one of them. |
I can't find the paper where Hamming proposes 25/46. However, if Hamming intended the window to minimize the peak of the largest side-lobe, then perhaps we should pick the coefficient that best matches that intention (i.e. 0.53836 instead of 0.54). comparing JOS: https://ccrma.stanford.edu/~jos/sasp/Hamming_Window.html |
I would guess for our purposes any of them would work. We just need to pick one. We could, I suppose, allow both windows, but that's probably not necessary. |
AudioCG meeting:
|
Resolution:
|
TPAC 2020: Does the window need to be changed? If not, then perhaps the best approach is not to allow the window to be changed. The we don't need to define what happens. |
Virtual F2F 2021: Support the types listed in https://github.com/WebAudio/web-audio-api-v2/issues/19#issuecomment-656237528 Also, the window will be changeable. When it is changed, everything is reset like what happens if you change fftSize. Exact API to be determined still. |
The
AnalyserNode
currently always windows the signal using a Blackman window. It would be nice if other windows could be supported so that the user can tradeoff the smoothing from the window and the spectral resolution.At the very least it's useful if no window (also known as rectangular) were allowed to be specified.
The text was updated successfully, but these errors were encountered: