Created
September 22, 2012 22:13
-
-
Save NHQ/3768004 to your computer and use it in GitHub Desktop.
mc hammer javascript cross-compiler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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