Giter VIP home page Giter VIP logo

webassembly-wavpack's Introduction

////////////////////////////////////////////////////////////////////////////////////////////////
//                            WavPack WebAssembly Decoder/Player                              //
//                          Copyright (c)2021-2022 Peter McQuillan                            //
//                                  All Rights Reserved.                                      //
//      Distributed under the BSD Software License (see wavpack_webassembly_license.txt)      //
////////////////////////////////////////////////////////////////////////////////////////////////

This package contains the source code for a WebAssembly decoder (and very simple player) for
WavPack files. This version is built on top of the WavPack Tiny Decoder, so it will not decode
(very old) version 3 files. This will also not decode DSD WavPack files.

The main WebAssembly code is written in C and emscripten is used to generate the WebAssembly
output. Javascript is used to communicate with the WebAssembly code.

To compile the C code, you can look at the included mybuild.bat file, though obviously this 
would need to be modified to point at the location on your local machine to emcc (Emscripten
compiler).
This will generate 2 files, wavpack.js and wavpack.wasm

There are 3 versions of HTML/JavaScript for interfacing with the WebAssembly code that you
can try:

A version where we're filling a buffer and using Web Audio to play the buffer.
For this version mywavpack.htm is the HTML file, this will let you try out the decoder.
This HTML file calls mywavpack.js which is the main JavaScript code, this calls the 
WebAssembly code. This version of the code may give small audio glitches when playing 
back some WavPack files.

A version using an AudioWorklet interface to Web Audio
For this version the HTML to load is index.htm
This HTML file calls mywavpack_worklet.js which in turn calls messenger-processor.js
This version is a more modern approach to Web Audio and should give more consistent results on 
supported browsers.

There is also a very simple/basic benchmark interface. This is accessed via timer.htm
With this version, there is no playback of the actual music, you simply select the file you wish
to test, wait a bit and it will show you how many seconds (milliseconds) it took to decode the 
file. This can be interesting if you want to see the speed differences between different browsers
or you want to see the speed difference between running a decoder 'natively' and decoding via
a web browser.
 
The HTML files have to be called via a web server, due to security issues it will not work by
simply opening the file with your web browser - however you can call it from any webserver 
including one on your own machine - for development purposes I used one from python, called 
(in the directory where I have all these files) with:
python -m http.server

I use a simple 'hack' in order to allow the WebAssembly code to read the contents of
the WavPack file you choose to play, it makes a copy of the file which is in the correct 
security context that the WebAssembly file can read from.
The buffer it uses to retrieve the decoded PCM data is shared with the WebAssembly code - I
use a malloc in the code to reserve a small amount of memory - I don't use a corresponding 
'free' as this reserved memory gets re-used if you load/play subsequent WavPack files.

My code is built on top of the WavPack tiny decoder, however this could probably be modified 
to use the full WavPack source code if you wanted to!

Please direct any questions or comments to [email protected]

webassembly-wavpack's People

Contributors

soiaf avatar

Stargazers

英博 avatar t3nzin avatar David Bryant avatar

Watchers

 avatar David Bryant avatar

Forkers

baadc0de

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.