jsantell / dancer.js

high-level audio API, designed to make sweet visualizations
jsantell.github.com/dancer.js
MIT License
2.11k stars 211 forks source link

Get Raw Complete Waveform Data #55

Closed jackrugile closed 8 years ago

jackrugile commented 10 years ago

Hey, thank you for the amazing plugin.

This might already exist, but I couldn't find it. I am looking to process and store the waveform data for different audio tracks. I can get access to the current waveform data with .getWaveform(), but it is in real time. I'd love to be able to process a song in its entirety, store it in a JSON file, and then reference that data for my own purposes from the JSON data file, outside of dancer.js.

This would of course have to omit many samples to get a set of data that is manageable, and I was thinking that would be some sort of argument passed in. Such as, number of samples.

Does this exist? If not, is it in the works?

I've found command line tools that can get waveform data from files, but I'd rather keep it all in the browser. Thanks!

likethemammal commented 8 years ago

I tried this at some point. The Web Audio API doesn't process audio data all at once, its only in real-time while the song is playing.

I've also searched and come across one possible workaround using some sort of image processing function after get the song as an ArrayBuffer from an AJAX call or the like. I don't remember the exact function calls, but I know it didn't work, otherwise I would've documented lol.

I've also tried pushing the limit of the "real-time" processing. Changing the playbackRate of any audio source will speed up the Web Audio API's processing of audio data. IDK if this means theres less precision in the data, but either way you can get it back multitudes faster. However, though I didn't see any documented limit, it seems that the browser vendors don't implement a large enough playbackRate to decode a 2:00 minute song in less than 30 seconds or so. No where near worth it.

As far as I know, there is no known way to decode all at once in the browser, without having a server help decode at some point.

jackrugile commented 8 years ago

Hey, thanks so much for the response on this. That playbackRate trick is super interesting :) Looks like I'll just stick with the server for now. Take care!