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

Implement WaveShaper node #205

Closed
jdm opened this issue Feb 15, 2019 · 12 comments
Closed

Implement WaveShaper node #205

jdm opened this issue Feb 15, 2019 · 12 comments
Labels

Comments

@jdm
Copy link
Member

jdm commented Feb 15, 2019

Spec: https://webaudio.github.io/web-audio-api/#waveshapernode

Reference processing code: https://searchfox.org/mozilla-central/source/dom/media/webaudio/WaveShaperNode.cpp

@jdm
Copy link
Member Author

jdm commented Feb 15, 2019

For ease of implementation, don't both supporting oversampling at first.

bors-servo pushed a commit that referenced this issue Jul 10, 2019
WaveShaper node implementation without oversampling

Issue at hand: #205
@khodzha
Copy link
Contributor

khodzha commented Jul 10, 2019

I'd like to take a shot at oversampling, but how should it be implemented? Is adapting speex resampler code ok? Or maybe its better to use some existing lib?

@jdm
Copy link
Member Author

jdm commented Jul 10, 2019

Adapting the speex code seems like a reasonable choice.

@khodzha
Copy link
Contributor

khodzha commented Jul 10, 2019

Ok, thanks, I'm not sure in my ability but I'll try.

@jdm
Copy link
Member Author

jdm commented Jul 10, 2019

@khodzha
Copy link
Contributor

khodzha commented Jan 23, 2020

@jdm i arrived at some 2x upsampling implementation but im not sure how to structure Block with 2x buffer len.

Right now block's buffer is hardcoded to store channels*FRAMES_PER_BLOCK_USIZE (so channels*128) elements.
I suppose I could store Tick(256) inside an upsampled block; but since this comment says Tick is time taken for a single frame using Tick(256) looks wrong to me, since this is just 2x more samples per same Tick(128).

So idk how to proceed here, should I store something like frequency multiplier in a block?

@Manishearth
Copy link
Member

@khodzha don't, use 2x or 4x the blocks before wave shaping. Firefox does something similar. WaveShaper is supposed to downsample after upsampling so it's fine if a block is temporarily representing only half or quarter of a frame.

@khodzha
Copy link
Contributor

khodzha commented Jan 26, 2020

To be honest I'm kind of stuck wondering if my oversampling is useful at all, probably I'm missing something? I dont have any experience with digital signal processing

Right now my 2x oversampling implementation upsamples like in https://github.com/suhr/resample/blob/master/src/lib.rs using method described here: https://ccrma.stanford.edu/~jos/resample/
(basically every even output sample is a copy of corresponding input sample; every odd sample is linear combination of input samples weighted with kaiser-windowed sincs)

So I upsample with this process, apply waveshaping curve and then downsample by simply throwing out every odd sample.

The problem is since both upsampling and downsampling leave every even sample as it is this whole process outputs same numbers whether there is oversampling or not.

@Manishearth
Copy link
Member

Huh. This is true, the spec slightly mentions that filters can be applied but it's frustratingly vague.

Perhaps file a spec bug? And/or look at the Firefox code.

@khodzha
Copy link
Contributor

khodzha commented Jan 28, 2020

I want to try out oversampling with libspeex-dsp first

@khodzha
Copy link
Contributor

khodzha commented Jan 31, 2020

Using https://github.com/rust-av/speexdsp-rs I get noise with 2x oversampling (and even more with 4x) both with quality=0 (used in firefox) and quality=5 (and right-padding a block with 0f32 since quality=5 requires more than 128 insamples to produce 256 outsamples) 😞

bors-servo pushed a commit that referenced this issue Feb 15, 2020
2x and 4x oversampling for WaveShaperNode

Issue #205
Finally managed to defeat the noise I mentioned in the issue

I'm not sure if ditching FrameIterator and operating on raw vecs was a good thing 🤷‍♂️

Also spec mentions tail-time but I'm not sure how to handle that
@khodzha
Copy link
Contributor

khodzha commented Feb 17, 2020

@Manishearth should we close this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants