Created
February 24, 2013 05:26
-
-
Save bklimt/5022739 to your computer and use it in GitHub Desktop.
Output Macintosh boot beep as a WAVE file.
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
/** | |
* Runs the bootbeepASM methods and then converts the audio data to a WAVE file. | |
* @returns {Buffer} a Buffer containing the contents of a WAVE file. | |
*/ | |
var bootbeep = function() { | |
// 22050 Hz is an approximation of the Mac's 370 * 60.15 Hz = 22255.5 Hz. | |
var writer = new WaveWriter(1.5, 22050, 8); | |
var samples = bootbeepASM(); | |
console.log("Copying samples to WAVE."); | |
var i = 0; | |
var sample = 0; | |
do { | |
if ((i * 2) < samples.length) { | |
sample = (samples.readUInt8(i * 2) / 128) - 1.0; | |
} | |
i++; | |
} while (writer.writeSample(sample)); | |
writer.close(); | |
return writer.buffer(); | |
}; | |
Parse.Cloud.define('bootbeep', function(request, response) { | |
response.success(bootbeep().toString('base64')); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment