crunker icon indicating copy to clipboard operation
crunker copied to clipboard

Please provide documentation for this cryptic lines

Open vitaly-zdanevich opened this issue 6 years ago • 6 comments

https://github.com/jackedgson/crunker/blob/ecaf6f8400c492d0d5c5c4401acc692b1897f8b9/src/crunker.js#L118

vitaly-zdanevich avatar Nov 14 '18 18:11 vitaly-zdanevich

These lines are all setting the correct headers in the raw buffer to export properly to mp3. Without these headers being set it won't export.

jaggad avatar Nov 14 '18 21:11 jaggad

But _writeHeaders() called always, even when we export Ogg?

vitaly-zdanevich avatar Nov 15 '18 09:11 vitaly-zdanevich

Don't think it supports Ogg export, just WAVE(.wav) and derivatives like mp3 files. I've never tested it though.

jaggad avatar Nov 15 '18 09:11 jaggad

These lines are all setting the correct headers in the raw buffer to export properly to mp3.

wav* not mp3.

A comment that _write_headers() is specific to the wave format and perhaps a link to reference what that is so the code is better understood would help. Here's a rather helpful one: http://soundfile.sapp.org/doc/WaveFormat/

BTW, you are calling this method regardless of format, even though it's only for(capable of) exporting WAV(it not only writes this formats headers but also the actual audio data from the audiobuffer, so it's a full export for WAV only).

Don't think it supports Ogg export, just WAVE(.wav) and derivatives like mp3 files.

It's difficult to get data on this, but afaik media that the browsers support reading/using vs storing/saving is not the same. You can see here for example how Chrome and Firefox both have different support, Firefox also mentions in MDN iirc that mp3 can be supported but is dependent upon the OS providing that support(at least for decoding, I don't think encoding was mentioned) external of the browser.

ogg is supported with Firefox, the codec opus is supported with Chrome as well but uses a webm container. So I don't think mp3 support is likely, google searches convey that most need to convert to mp3 either server-side or with JS port or Emscripten versions of lamemp3, WASM is probably another option now too, no native browser support afaik.

Your code explicitly only supports wav.


EDIT: Played with this some more and the type field has no actual effect on the data given to Blob method. It's just a mimetype to hint what the file contents is meant to be, audacity refuses it(tried mp3 and ogg mimetypes in the stackoverflow link I provided), but it'd import it happily as raw data 32-bit float 44.1Khz mono.

polarathene avatar Jan 23 '19 05:01 polarathene

@polarathene Thanks for the information. If there is anything you think could be done to improve the package I'd be happy to accept a PR or any suggestions.

jaggad avatar Jan 23 '19 11:01 jaggad

@jackedgson well you have my suggestions :) I'm not sure when/if I'll find time to sort out a PR, if I did the changes would probably be quite breaking which'd require the appropriate semver bump to avoid existing users being affected.

polarathene avatar Jan 23 '19 14:01 polarathene