jmoenig / Snap

a visual programming language inspired by Scratch
http://snap.berkeley.edu
GNU Affero General Public License v3.0
1.49k stars 744 forks source link

`AudioContext.decodeAudioData()` function always resamples every audio file to 96000 sample rate #3397

Open ego-lay-atman-bay opened 4 days ago

ego-lay-atman-bay commented 4 days ago

While working on my audio processing library, I discovered that every sound I imported (and created in snap) has the same constant sample rate, 96000, even though the sample rate was explicitly something else.

After doing some digging, I found that the AudioContext.decodeAudioData() function now converts all audio files to have a 96000 sample rate, resulting in weird inconsistencies.

Just to be clear, this is not necessarily an issue with snap, it's an issue with browsers changing how audio data is handled.

I don't currently know how to get the audio samples and the correct sample rate, but I feel like it might be good to ditch the AudioContext class, since it messes with audio data.

jmoenig commented 4 days ago

yeah, I've been noticing this also. Here's a little trick I use / built into Snap: If you access the microphone sensing reporter, e.g. to get the volume, it will adjust the sampling rate to whatever your hardware / browser currently uses. Although it tends to "forget" this quickly, sometimes :(

ego-lay-atman-bay commented 4 days ago

It seems like my device sample rate is 96000, so it didn't change anything.

Since I am creating an audio processing library, I want to be able to work with different sample rates, not dependent on the device settings (specifically so I can compare snap to my audio processing library in python).

jmoenig commented 4 days ago

yes, I'm finding the web audio api to be really frustrating for this. There doesn't seem to be any way to query the client's sample rate.