question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

WaveShaperNode outputs incorrect values in Safari

See original GitHub issue

Not 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:closed
  • Created 5 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
chrisguttandincommented, Jan 10, 2019

Version 17.5.6 finally includes the changes.

As always, please let me know if you encounter any bugs or problems.

0reactions
chrisguttandincommented, Jan 8, 2019

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found