Generate commands onload
Rather an on user input. Removes lag from click to camera firing.
This commit is contained in:
parent
04f654cc95
commit
187da0f140
|
@ -22,7 +22,7 @@
|
||||||
<div class="row_f">
|
<div class="row_f">
|
||||||
<div class="for" title="f" onclick="ctrl.set(this);">0</div>
|
<div class="for" title="f" onclick="ctrl.set(this);">0</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row_B">
|
<div class="row_b">
|
||||||
<div class="back" title="b" onclick="ctrl.set(this);">0</div>
|
<div class="back" title="b" onclick="ctrl.set(this);">0</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row_x">
|
<div class="row_x">
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
var dataURI, audio, myAudioContext, mySource, myBuffer;
|
var dataURI, audio, myAudioContext, mySource, myBuffer, bufferArray={};
|
||||||
|
|
||||||
if ('AudioContext' in window) {
|
if ('AudioContext' in window) {
|
||||||
myAudioContext = new AudioContext();
|
myAudioContext = new AudioContext();
|
||||||
|
@ -51,6 +51,7 @@ var fsk = {};
|
||||||
|
|
||||||
fsk.generate = function (str) {
|
fsk.generate = function (str) {
|
||||||
if (str.length === 0) return;
|
if (str.length === 0) return;
|
||||||
|
//console.time('generate');
|
||||||
var utf8 = toUTF8(str);
|
var utf8 = toUTF8(str);
|
||||||
//console.log(utf8);
|
//console.log(utf8);
|
||||||
|
|
||||||
|
@ -66,7 +67,7 @@ fsk.generate = function (str) {
|
||||||
var data = "RIFF" + chr32(size + 36) + "WAVE" +
|
var data = "RIFF" + chr32(size + 36) + "WAVE" +
|
||||||
"fmt " + chr32(16, 0x00010001, sampleRate, sampleRate, 0x00080001) +
|
"fmt " + chr32(16, 0x00010001, sampleRate, sampleRate, 0x00080001) +
|
||||||
"data" + chr32(size);
|
"data" + chr32(size);
|
||||||
|
|
||||||
var pushData = function (freq, samples) {
|
var pushData = function (freq, samples) {
|
||||||
for (var i = 0; i < samples; i++) {
|
for (var i = 0; i < samples; i++) {
|
||||||
var v = 128 + 127 * Math.sin((2 * Math.PI) * (i / sampleRate) * freq);
|
var v = 128 + 127 * Math.sin((2 * Math.PI) * (i / sampleRate) * freq);
|
||||||
|
@ -87,13 +88,17 @@ fsk.generate = function (str) {
|
||||||
|
|
||||||
var arrayBuff = Base64Binary.decodeArrayBuffer(dataURI);
|
var arrayBuff = Base64Binary.decodeArrayBuffer(dataURI);
|
||||||
myAudioContext.decodeAudioData(arrayBuff, function (audioData) {
|
myAudioContext.decodeAudioData(arrayBuff, function (audioData) {
|
||||||
myBuffer = audioData;
|
bufferArray[str] = audioData;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fsk.play = function () {
|
fsk.play = function (str) {
|
||||||
mySource = myAudioContext.createBufferSource();
|
mySource = myAudioContext.createBufferSource();
|
||||||
mySource.buffer = myBuffer;
|
if (typeof str !== 'undefined') {
|
||||||
|
mySource.buffer = bufferArray[str];
|
||||||
|
} else {
|
||||||
|
console.error('No AudioBuffer found for string "' + str + '"');
|
||||||
|
}
|
||||||
mySource.connect(myAudioContext.destination);
|
mySource.connect(myAudioContext.destination);
|
||||||
if ('AudioContext' in window) {
|
if ('AudioContext' in window) {
|
||||||
mySource.start(0);
|
mySource.start(0);
|
||||||
|
|
|
@ -9,17 +9,23 @@ ctrl.pos = 0;
|
||||||
ctrl.loop = false;
|
ctrl.loop = false;
|
||||||
|
|
||||||
ctrl.delay = {
|
ctrl.delay = {
|
||||||
f : 500,
|
f : 1100,
|
||||||
B : 700,
|
b : 1200,
|
||||||
x : 1000
|
x : 1000
|
||||||
};
|
};
|
||||||
|
|
||||||
ctrl.play = function (val) {
|
ctrl.play = function (val) {
|
||||||
fsk.generate(val);
|
fsk.play(val);
|
||||||
setTimeout(function () {
|
fsk.play(val);
|
||||||
fsk.play();
|
ctrl.posCmd(val);
|
||||||
ctrl.posCmd(val);
|
};
|
||||||
}, 10);
|
|
||||||
|
ctrl.generate = function () {
|
||||||
|
var cmds = Object.keys(ctrl.delay);
|
||||||
|
for (var i = 0; i < cmds.length; i++) {
|
||||||
|
console.log('Generating AudioBuffer for ' + cmds[i]);
|
||||||
|
fsk.generate(cmds[i]);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
ctrl.sendCmd = function (elem) {
|
ctrl.sendCmd = function (elem) {
|
||||||
|
@ -97,7 +103,7 @@ ctrl.highlight = function (i) {
|
||||||
if (i !== undefined && i !== false) {
|
if (i !== undefined && i !== false) {
|
||||||
//console.log(i);
|
//console.log(i);
|
||||||
$('.seq .row_f > div').eq(i).addClass('highlight');
|
$('.seq .row_f > div').eq(i).addClass('highlight');
|
||||||
$('.seq .row_B > div').eq(i).addClass('highlight');
|
$('.seq .row_b > div').eq(i).addClass('highlight');
|
||||||
$('.seq .row_x > div').eq(i).addClass('highlight');
|
$('.seq .row_x > div').eq(i).addClass('highlight');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -229,6 +235,10 @@ ctrl.onload = function () {
|
||||||
if (seq !== undefined && seq !== false) {
|
if (seq !== undefined && seq !== false) {
|
||||||
ctrl.seq = seq;
|
ctrl.seq = seq;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//pre-generate audiobuffers for more responsive buttons
|
||||||
|
ctrl.generate();
|
||||||
|
|
||||||
ctrl.layout();
|
ctrl.layout();
|
||||||
//FastClick.attach(document.body);
|
//FastClick.attach(document.body);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue