arseneyr / wasm-media-encoders

MP3 and Ogg Vorbis encoders for the browser and Node
MIT License
34 stars 4 forks source link

Add support for WAV #10

Closed cdauth closed 4 months ago

cdauth commented 10 months ago

Thank you for this amazing library.

In my app, I'm providing MP3 and WAV export. The purpose of the WAV export is that if users need the audio in a format that my app doesn't provide, the WAV export makes more sense than the MP3 export, because it is lossless and much faster to generate, so it is better to integrate into a workflow where the exported audio is converted into another format using an external tool.

Right now I'm using wav-encoder to generate the WAV. It has two drawbacks:

This is why I would like to see WAV support in this library. Unfortunately I have no expertise with WASM, so I'm not able to contribute an implementation.

arseneyr commented 9 months ago

WAV files can be as simple as a header prefixing PCM audio data in a certain format (bit width + signedness). Generating WAV files from raw PCM samples is relatively easy: see the tiny wav-encoder source.

I think you want to slightly modify the wav-encoder source to work incrementally in chunks, maybe even implementing a Streams interface for maximum interop. WASM won't help here as there is almost nothing to compute and all the time would be spent copying data back and forth between JS and the WASM memory.