Hi,
I’m working on a web project that plays audio files from different sources through the same player.
I have a MediaElementAudioSourceNode, created by an AudioContext with an initial sample rate of 48,000 Hz.
When setting the source of the audioElement to an audio file with a known sample rate of 8,000 Hz, my understanding is that the file will be upsampled to 48,000 Hz or to the native sample rate of the output device.
When does this upsampling occur?
Is it possible to measure the time it takes?
Can I verify what sample rate the audio element will actually play at (or upsample to)?
How can I ensure that I don’t degrade audio quality if the AudioContext is initialized at too low a sample rate?
Thanks,
Mike
--
You received this message because you are subscribed to the Google Groups "media-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to media-dev+...@chromium.org.
To view this discussion visit https://groups.google.com/a/chromium.org/d/msgid/media-dev/36d9dd4e-dd3b-42b9-8475-aae172818b11n%40chromium.org.
On Mon, Sep 8, 2025 at 10:32 AM Mike Segal <mi...@segalcon.com> wrote:Hi,
I’m working on a web project that plays audio files from different sources through the same player.
I have a MediaElementAudioSourceNode, created by an AudioContext with an initial sample rate of 48,000 Hz.
When setting the source of the audioElement to an audio file with a known sample rate of 8,000 Hz, my understanding is that the file will be upsampled to 48,000 Hz or to the native sample rate of the output device.
When does this upsampling occur?
Is it possible to measure the time it takes?
Can I verify what sample rate the audio element will actually play at (or upsample to)?
How can I ensure that I don’t degrade audio quality if the AudioContext is initialized at too low a sample rate?
Hello again,
Thank you for your previous helpful replies.
I noticed a discrepancy when playing audio through an AudioContext at 48,000 Hz. The original file at 8,000 Hz sounds different from the same file upsampled to 48,000 Hz using Adobe Audition.
Could this difference be caused by the browser’s resampling algorithm? Would using OfflineAudioContext produce a closer result to the high-quality offline upsampling?
Thanks again,
Mike
So there are a couple of issues here:
The tested sound is a consistent 3,990 Hz tone. One file is at 8,000 Hz, the other is the same file, but upsampled to 48,000 Hz (using Adobe Audition). When played in the same AudioContext, the two files sound noticeably different. Spectrogram analysis of recorded output shows clear differences in the high frequencies and the intensity of the tone.
Determining the actual sample rate of a media file on the client is not straightforward, as Hongchan noted.
Even if this were simple, the media player instance is not recreated between files - the same instance is reused (like a playlist in Spotify). Changing the file alone does not change the player instance.
Other than that, my main question remains: Is there a difference between the resampling performed by OfflineAudioContext and the resampling of the main AudioContext?