Skip to content

Instantly share code, notes, and snippets.

@zeke
Created September 11, 2012 01:25
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 zeke/3695283 to your computer and use it in GitHub Desktop.
Save zeke/3695283 to your computer and use it in GitHub Desktop.
mc hammer javascript cross-compiler
#!/usr/bin/env node
// mc hammer javascript cross-compiler
// 1. youtube-dl http://www.youtube.com/watch?v=otCpCn0l4Wo -o cant_touch_this.flv
// 2. avconf -o cant_touch_this.flv cant_touch_this.wav
// 3. sox cant_touch_this.wav -t s16 -r 8k -o cant_touch_this.raw
// 4. run this file (node make_touch_this.js)
// 5. npm install -g baudio-party
// 6. baudio-party &
// 7. curl -sSNT cant_touch_this.js http://localhost:5000/0
// 8. ♫ CANT TOUCH THIS ♫
var fs = require('fs');
var file = process.argv[2];
var ws = fs.createWriteStream(file.replace(/\.raw/, '.js'));
ws.write('var music = new Buffer("');
ws.write(fs.readFileSync(file, 'base64')
.slice(2 * 65 * 8000, 2 * 70 * 8000)
);
ws.write('", "base64");\n');
ws.write('return ' + function (t, i) {
if (t % 10 > music.length / 2 / 2 / 8000) return 0;
var offset = 2 * Math.floor(t * 2 * 8000) % music.length;
var x = music.readInt16LE(offset);
return Math.max(-1, Math.min(1, x / Math.pow(2, 15)));
} + '\n');
ws.end();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment