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="for" title="f" onclick="ctrl.set(this);">0</div>
|
||||
</div>
|
||||
<div class="row_B">
|
||||
<div class="row_b">
|
||||
<div class="back" title="b" onclick="ctrl.set(this);">0</div>
|
||||
</div>
|
||||
<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) {
|
||||
myAudioContext = new AudioContext();
|
||||
|
@ -51,6 +51,7 @@ var fsk = {};
|
|||
|
||||
fsk.generate = function (str) {
|
||||
if (str.length === 0) return;
|
||||
//console.time('generate');
|
||||
var utf8 = toUTF8(str);
|
||||
//console.log(utf8);
|
||||
|
||||
|
@ -87,13 +88,17 @@ fsk.generate = function (str) {
|
|||
|
||||
var arrayBuff = Base64Binary.decodeArrayBuffer(dataURI);
|
||||
myAudioContext.decodeAudioData(arrayBuff, function (audioData) {
|
||||
myBuffer = audioData;
|
||||
bufferArray[str] = audioData;
|
||||
});
|
||||
}
|
||||
|
||||
fsk.play = function () {
|
||||
fsk.play = function (str) {
|
||||
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);
|
||||
if ('AudioContext' in window) {
|
||||
mySource.start(0);
|
||||
|
|
|
@ -9,17 +9,23 @@ ctrl.pos = 0;
|
|||
ctrl.loop = false;
|
||||
|
||||
ctrl.delay = {
|
||||
f : 500,
|
||||
B : 700,
|
||||
f : 1100,
|
||||
b : 1200,
|
||||
x : 1000
|
||||
};
|
||||
|
||||
ctrl.play = function (val) {
|
||||
fsk.generate(val);
|
||||
setTimeout(function () {
|
||||
fsk.play();
|
||||
ctrl.posCmd(val);
|
||||
}, 10);
|
||||
fsk.play(val);
|
||||
fsk.play(val);
|
||||
ctrl.posCmd(val);
|
||||
};
|
||||
|
||||
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) {
|
||||
|
@ -97,7 +103,7 @@ ctrl.highlight = function (i) {
|
|||
if (i !== undefined && i !== false) {
|
||||
//console.log(i);
|
||||
$('.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');
|
||||
}
|
||||
};
|
||||
|
@ -229,6 +235,10 @@ ctrl.onload = function () {
|
|||
if (seq !== undefined && seq !== false) {
|
||||
ctrl.seq = seq;
|
||||
}
|
||||
|
||||
//pre-generate audiobuffers for more responsive buttons
|
||||
ctrl.generate();
|
||||
|
||||
ctrl.layout();
|
||||
//FastClick.attach(document.body);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue