WaveShaperNode outputs incorrect values in Safari
See original GitHub issueNot sure if the intention of this library is to normalize the functionality as well as the interface of Web Audio across implementations, but there a known issue with the WaveShaperNode in Safari that i’ll point out in case you want to include the fix somehow:
Try running this code:
import {OfflineAudioContext} from 'standardized-audio-context'
const context = new OfflineAudioContext(1, 441, 44100)
const waveshaper = context.createWaveShaper()
waveshaper.curve = Float32Array.from([0, 0.25, 0.5, 0.75, 1])
const signal = context.createConstantSource()
signal.offset.value = 0
signal.start(0)
signal.connect(waveshaper).connect(context.destination)
context.startRendering().then(buffer => {
console.log(buffer.getChannelData(0)[0])
})
You’ll see in Chrome and Firefox, the output is 0.5
, while in Safari the output is 0.625
.
I’ve found that a simple fix to this issue is to increase the curve array length in Safari and repeat the first value. Something like this:
function setCurve(curve){
var array = new Float32Array(curve.length+1);
array.set(curve, 1);
array[0] = curve[0];
_internalNode.curve = array;
}
One issue is that this is a hard thing to test for without using the OfflineAudioContext like i did above, so the only way to know when to add the polyfill is by testing the userAgent which is often not the best practice.
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
WaveShaperNode - Web APIs | MDN
Chrome Edge
WaveShaperNode Full support. Chrome14. Toggle history Full support. Edge1...
WaveShaperNode() constructor Full support. Chrome55. Toggle history Full support. Edge7...
curve Full support. Chrome14. Toggle...
Read more >WaveShaperNode
The WaveShaperNode interface represents a non-linear distorter. It is an AudioNode that uses a curve to apply a wave shaping distortion to ...
Read more >WaveShaperNode - Web APIs - W3cubDocs
A WaveShaperNode always has exactly one input and one output. ... Is an enumerated value indicating if oversampling must be used.
Read more >Why aren't Safari or Firefox able to process audio data from ...
This answer is quoted almost exactly from my answer to a related question: Firefox 25 and AudioContext createJavaScriptNote not a function ...
Read more >Web Audio API performance and debugging notes
CPU: This node essentially copies input data into a buffer, and reads from this buffer at a different location to compute its output...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Version 17.5.6 finally includes the changes.
As always, please let me know if you encounter any bugs or problems.
Hi @tambien, I’m sorry I initially planned to release a patch version, but now I have a problem with the tests running on Travis. I have to fix this first.