Skip to content

Instantly share code, notes, and snippets.

@dtudury
Created May 5, 2016 21:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dtudury/d2f7b3c97d2d3d903a084ad6b4b4fbc0 to your computer and use it in GitHub Desktop.
Save dtudury/d2f7b3c97d2d3d903a084ad6b4b4fbc0 to your computer and use it in GitHub Desktop.
emscripten notes and direction from Julian for Cosmin

get the repo and tools

I've run this so it should be mostly (hopefully) okay

  • setup emscripten (I think you already have)
  • install sox; if you use homebrew: brew install sox
  • get Julian's WIP: git clone git@github.com:Voxer/voxer2mp3.git and git checkout jg-emscripten
  • do the magic:
    • ./buildvoxencode.sh
      • jgautier: "so you have a VoxEncode.js file now?"
      • me: "yep"
      • jgautier: "sweet. you're done"
  • to test out the C transcoders call ./build.sh .
    • if you need to, brew install wget first
    • it warns a bunch and ends with ./build.sh: line 43: sha256sum: command not found
    • make sure it works:
      • record a temp.pcm file to play:
        • rec -t raw -b 16 -e signed-integer -r 16000 -c 1 temp.pcm
        • (Ctrl-C to stop recording)
      • test your temp.pcm file:
        • play -t raw -b 16 -e signed-integer -r 16000 -c 1 temp.pcm
      • convert your temp.pcm to silk and back using the C transcoders:
        • cat temp.pcm | ./bin/pcm2vox > temp_C.vox (transcode to silk)
          • ignore Encode Error -1
          • you should have a temp_C.vox file now
        • cat temp_C.vox | bin/vox2pcm > temp_C.pcm (transcode to pcm)
        • play -t raw -b 16 -e signed-integer -r 16000 -c 1 temp_C.pcm (play it)

task: make Julian's wrapper work from javascript-land

this is transcribed from a somewhat train-of-though conversation I had with Julian (so the comments might make more sense than the code)

Julian's copied pcm2vox and pasted into a C++ class to make it play nice with javascript. pcm2vox uses SKP_int16 arrays but for some reason emscripten doesnt like that so he had to use vectors and then convert the vectors to arrays in code. The problem is the code that exports stuff to JS isn't able to get the data passed back correctly so for demos he's had to write to a file.

What he thinks we need is a .js file that does something like

var VoxEncode = require("./VoxEncode.js");
var voxEncode = new VoxEncode.VoxEncode();
//the vector size when you call encode has to be 320 (or maybe just a multiple of 20...)
voxEncode.encode(vector);

//you also have to populate the vector you cant just use JS arrays:
var pcmvector = new voxEncode.VectorInt();
pcmvector.set(index, value);

//its expecting an int16 so read the file into a buffer
buffer.readInt16LE(offset);

I'd read the emscripten Connecting C++ and JavaScript page and Julian claims theres "code samples of using the web audio api in the C code" so maybe search for that :)

good luck!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment