wasmboy icon indicating copy to clipboard operation
wasmboy copied to clipboard

Fix crackling in audio

Open torch2424 opened this issue 6 years ago • 2 comments

Quite a strange thing I noticed. It's kind of hard to notice, but I got the music ear so it bugs me haha!

Anyways, seems like there is some popping/crackling on the square waves.

So usually cracking happens from drops in the signal, thus, incorrect PCM samples. But I did the following screenshot last night:

Screen Shot 2019-04-23 at 1 54 48 AM

So I know it's not the square wave, but you would hear it. And what I am trying to show is that there is no crazy spikes, and it's just binary (high / low) values. Thus crackling doesn't make sense.

One theory is I need to smooth the wave, and not instantly drop for the square waves and things. Which when I made a Jsfiddle (and accidentally closed the tab and lost it), the built in oscillator does a very slight diagnonal from high/low.

But a PR linked below, I simply changed the sample rate to match Elmboy, and things still crackled, but slightly less pronounced. So I may either be going crazy, or possibly it is an issue with an uneven sample rate vs. how often we produce samples.

torch2424 avatar Apr 24 '19 06:04 torch2424

So this mostly bugs me, as I want to sample using the audio recorder for music I want to make :joy:

Did some more random late night research. Audacity has a nice sample data export, which just exports the levels of each PCM Sample like:

0.00000
0.00000
0.00000
0.10077
0.10077
0.10077
0.10077

Doing a quick scan, there is not a single sample for a square wave that is not either 0 0r 0.10777. Thus the wave is correct. but let's write a node script that will go and make sure everything length is the same. E.g something like:

0: 27 in a row
0.10077: 27 in a row
0: 27 in a row
0.10077: 27 in a row

Because I bet if the sample lenghts aren't the exact same. Maybe that causes the crackling? :thinking: Which would kind of make sense, since as we stated before, the sample rate seems to affect this...

torch2424 avatar Feb 04 '20 09:02 torch2424

Maybe it's because we need a gain node? https://7tonshark.com/2018-09-16-web-audio-part-1/#

torch2424 avatar Sep 11 '20 09:09 torch2424