miguelmota / spectrogram

Audio spectrogram in canvas.
https://lab.miguelmota.com/spectrogram
MIT License
194 stars 41 forks source link

Display full spectrogram at once instead of buffering ? #1

Open ghost opened 8 years ago

ghost commented 8 years ago

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,

miguelmota commented 8 years ago

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

night1008 commented 5 years ago

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

ilovecomputers commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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