Question

I've discovered (at least in chrome) web audio resamples wav files to 48k when using decodeAudioData. Any way to prevent this and force it to use the file's original sample rate? I'm sure this is fine for game development, but i'm trying to write some audio editing tools and this sort of thing isn't cool. I'd like to be fully in control of when/if resampling occurs.

Was it helpful?

Solution

As far as I know, you're just going to get whatever sampling rate your AudioContext is using (which will be determined by your sound card, I believe).

They lay out the steps here: https://dvcs.w3.org/hg/audio/raw-file/tip/webaudio/specification.html#dfn-decodeAudioData

"The decoding thread will take the result, representing the decoded linear PCM audio data, and resample it to the sample-rate of the AudioContext if it is different from the sample-rate of audioData. The final result (after possibly sample-rate converting) will be stored in an AudioBuffer."

OTHER TIPS

Nope, you can't prevent the resampling of decodeAudioData into the AudioContext's sampleRate. Load and create AudioBuffers yourself, or decode the file into a buffer in an OfflineAudioContext that is fixed to the rate it was originally set to (although it's going to be hard to tell what that is, I imagine).

There is discussion on this point - https://github.com/WebAudio/web-audio-api/issues/30.

There is now an webcomponent for loading audio using sox : https://www.npmjs.com/package/sox-element

It allows you to decode audio at the original sample rate. The data is unaltered form the original.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top