Vorbis encoding using JavaScript

Mateusz Wielgos <[email protected]> Tue, 12 Feb 2013 23:41:34 -0600
Newsgroups gmane.comp.multimedia.ogg.vorbis.general
Message-ID <CAOxAYbXDj77N5VwDAyso_APn=3cBW7Ro1Dnw0KMasFvk0qCV1A@mail.gmail.com>
Hello,

First of all, I am a complete newblet to anything dealing with audio (a lot
of the vocabulary is still rather mysterious to me). I also don't often
program in C so please don't throw too many stones if my workflow is less
than ideal. :)

I would like to port the vorbis encoder to JavaScript. Instead of porting
everything by hand from ground up, which would take who-knows-how-long, I
am using a tool called emscripten (https://github.com/kripken/emscripten).
From the docs:

Emscripten is an LLVM-to-JavaScript compiler. It takes LLVM bitcode - which
can be generated from C/C++, using llvm-gcc or clang, or any other language
that can be converted into LLVM - and compiles that into JavaScript, which
can be run on the web (or anywhere else JavaScript can run).

I was able to successfully build libogg, libvorbis and libvorbis examples
using this tool and generate valid JavaScript (hopefully working as
intended also...).

In JavaScript, once I obtain the left and right channel audio data (using
W3C web audio api) I pass this data into the JavaScript encoder as command
line arguments. This data is then read, each string converted to a float,
and the vorbis_analysis_buffer is filled with this "parsed" data.
Similarly, I pass the quality as an argument and run vorbis_encode_init_vbr
accordingly.

One last thing that I pass in is a "state" of a stream - either the
beginning, middle, or end so I can handle these cases differently (for
example, at the start of the stream I set all necessary headers).

The generated file, however, does not seem to be valid and does not play.

Could somebody verify that my encoding logic is sound? Here is the C source
on GitHub (based on libvorbis encoder_example.c) :
https://github.com/mateusz-/vorbisenc.js/blob/master/encoder_example.c
And, if it helps, here is the corrupted/invalid Ogg file :
https://raw.github.com/mateusz-/vorbisenc.js/master/audio.ogg

Thank you,
Mateusz

_______________________________________________
Vorbis mailing list
[email protected]
http://lists.xiph.org/mailman/listinfo/vorbis