spectrogram icon indicating copy to clipboard operation
spectrogram copied to clipboard

Display full spectrogram at once instead of buffering ?

Open ghost opened this issue 9 years ago • 5 comments

Is that actually possible with the plugin ? Reading the full audio file, then drawing at once the full spectrogram in canvas ?

(Similar to this solution : http://wavesurfer-js.org/example/spectrogram/)

Thanks,

ghost avatar May 30 '16 15:05 ghost

That would be a good feature to have. At the moment it is not supported. I'm happy to merge in a PR if you or someone else is able to fork it and add this functionality

miguelmota avatar May 31 '16 04:05 miguelmota

@miguelmota Can you give some tips about how to draw at once by reading the full audio file?

night1008 avatar Jan 14 '19 14:01 night1008

I was curious too, so I looked at the wavesurfer's spectrogram example page and set a breakpoint where they grab the audio buffer and calculate the spectrum. When the breakpoint is hit, I follow up the call stack and notice they call a web audio method that ~spectrogram.js doesn't~ (disregard that, it is called and I'm idiot who can't read manuals): decodeAudioData. I'll try to see if I can get spectrogram.js to do the same.

ilovecomputers avatar Jun 21 '19 06:06 ilovecomputers

I was sorely mistaken. Both wavesurfer and spectrogram.js grab the entire audio buffer, so why is wavesurfer drawing the whole spectrum at once while spectogram only draws one at a time as the audio plays? Waverunner grabs the entire PCM data and does it's own FFT calculation while spectrogram.js uses the built in web audio analyser.

Quickly looking at AnalyserNode, I'm not seeing a way to grab the frequency samples for the entire audio buffer. Oh dear 😅

ilovecomputers avatar Jun 21 '19 07:06 ilovecomputers

If you're wondering why Waverunner uses it's own FFT, it's not because AnalyserNode can't sample the entire audio buffer. There is a way to work around that, but it's fraught with error. Waverunner used to use onaudioprocess like spectrogram.js does and that audio process was run in an OfflineAudioContext, which, as the commit notes, has problems on webkit browsers.

Pretty much, if you want to avoid rolling out your own FFT for this use case, we have to wait for AudioWorklets to be supported by both webkit and firefox

ilovecomputers avatar Jun 21 '19 08:06 ilovecomputers