jsbasic/bell.js
2017-02-19 21:17:01 -08:00

64 lines
10 KiB
JavaScript

//
// Bell - play an audio file for the CHR$(7) "BEL" beep
//
var Bell;
if (typeof Bell !== 'function') {
Bell = function(base) {
// Prefer Web Audio
if ('AudioContext' in window) {
this.play = function() {
if (!this.ctx) {
this.ctx = new AudioContext();
this.gain = this.ctx.createGain();
this.gain.gain.value = 0.75;
this.gain.connect(this.ctx.destination);
}
if (this.osc)
this.osc.disconnect();
this.osc = this.ctx.createOscillator();
this.osc.type = 'square';
this.osc.frequency.value = 935;
this.osc.connect(this.gain);
this.osc.start(this.ctx.currentTime);
this.osc.stop(this.ctx.currentTime + 0.1);
};
this.stop = function() {};
return;
}
var DATA_MP3 = "data:audio/mp3;base64,//tQxAAACKhXabQTABGrmzE3KVACUZAAJACBEnA2wABBGMYxuAF3d33u4iIgghlkCBAAECCByJwfl4nB8P/B8HwfxOD4PrP8Hz/ggCAIA+fKAg7/+IAxlDmIOBwOBwOBwOBwOBgAAAAvsPfh+QCdNGoDlrCk09ENDCfgEgcONDUH+Bg80gbDCIBANAwwBWK2cNMQQC9wNjQYRAKDP/gGA4ZUUqKXC+Yj5vv8LLgsaAzgLgMCgQMgCwk1m/5p5fJ9S3PKI46qbzQCZASIFv6LvP/7UsQFAAupY3W89oARPSludJapcmndwY1sa2ew6Yta/COmtiB/qdMDuEhHiXUNfk5v+sWItkv//9RkF7Rb/1N61Lvd67JIcxJUFILyVf//sp6W691nbOozm3f00mPKFeZqYAC5BEMl25UAwQEyBZsBRtaDKwmBWpxRAT7sZUPnBK/+tEGwGtqFu8mGrHG/wZDv///qAZ/+PTG9UfI0f/uCbf//7onfzWW2eSw21qxBNPwNvYI70upORAMFBMg27hCQ55uY0DYA8ANOsP/9BJNf//tSxAyACjmHdaQ0VdFuMm41BQ+bVdUFuDgSW/o5PPer4ukf///zgRLf/nkG1roKOTX/oJgqTe3//9907V00j0+tgQzLWrU3msKrzlowStENECIgObmyJSNnOomSK5FQ2g85q6XacHT/1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2rYx3L5uLL9wHMtr68ox675RtnV8X3gKw/N0dV15Zl3H9nV040c4fsoAAIABBwCAABPKQKEhKwKAOAEAjySJomRZoihZliiKpui6omi6rqRppqlpnmlammeapmmqsimarixpmmlanmaamqeZpmiarmuapqyKpinLpmrKsmmasuy6sm27rmzbomnKsmmasmyapiy7sqvbruzquqRZpql5nmlqnmeapmrKsmmarqt5nmp6nmiqniiqqmqqqq2qqixbnmeamuippieKqmqqpq2aqirLpqrasmmqtmyqqm27quz6sm3rummqsm2qpi2bqmrbruzqsizbui9pmmlqnmeamueZpmmasmyaqitbnqeaniiqquaJpmqqqiybpqrKlueZqieKquqJnmuaqirLpmraqmmatmyqqi2bpirLrm37vuvKsm6qqmybqmrrpmrKsmzLvu/Kqu6KpinLpqrasmmqsi3bsu/Lsqz7omnKsmmqsm2qqi7Lsm0bs2z7umiasm2qpi2bqirbsi37uizbuu/Krm+rqqzrsi37uu76rnDrujC8smz7qqz6uivbum/rMtv2fUTTlGVTNW3bVFVZdmXZ9mXb9n3RNG1bVVVbNk3VtmVZ9n1Ztm1hNE3ZNlVV1k3VtG1Zlm1htmXhdmXZt2Vb9nXXlXVf133j12Xd5rqy7cuyrfuqq/q27vvCcOuu8AoAABhwAAAIMKEMFBqyEgCIAgAAjGGMMQiNUs45B6FRyjnnIGTOQQghlcw5CCGUkjkHoZSUMucglJJSCKGUlFoLIZSUUmsFAAAUOAAABNigKbE4QKEhKwGAVAAAg+NYlueZomrasmNJnieKqqmqtu1IlueJommqqm1bnieKpqmqruvrmueJommqquvqumiapqmqruu6ui6aoqmqquu6sq6bpqqqriu7suzrpqqqquvKriz7wqq6rivLsm3rwrCqruvKsmzbtm/cuq7rvu/7wpGt67ou/MIxDEcBAOAJDgBABTasjnBSNBZYaMhKACADAIAwBiGDEEIGIYSQUkohpZQSAAAw4AAAEGBCGSg0ZEUAECcAABhDKaSUUkoppZRSSimllFJKKaWUUkoppZRSSimllFJIKaWUUkoppZRSSimllFJKKaWUUkoppZRSSimllFJKKaWUUkoppZRSSimllFJKqaSUUkoppZRSSimllFJKKaWUUkoppZRSSimllFJKKaWUUkoppZRSSimllFJKKaWUUkoppZRSSimllFJKKaWUUkoppZRSSimllFJKKaWUUkoppZRSSimllFJKKaWUUkoppZRSSimllFJKKaWUUkoppZRSSimllFJKKaWUUkoppZRSSimllFJKKaWUUkoppZRSSimllFJKKaWUUkoppZRSSimllFJKKaWUUkoppZRSSimllFJKKaWUUkoppZRSSimllFJKKaWUUkoppZRSSimllFJKKaWUUkoppZRSSimllFJKKZVSSimllFJKKaWUUkoppZRSSimllFJKKaWUUkoppZRSSimllFJKKaWUUkoppZRSSimllFJKKaWUUkoppZRSSimllFJKKaWUUkoppZRSSimllFJKKaWUUgoAkIpwAJB6MKEMFBqyEgBIBQAAjFFKKcacgxAx5hhj0EkoKWLMOcYclJJS5RyEEFJpLbfKOQghpNRSbZlzUlqLMeYYM+ekpBRbzTmHUlKLseaaa+6ktFZrrjXnWlqrNdecc825tBZrrjnXnHPLMdecc8455xhzzjnnnHPOBQDgNDgAgB7YsDrCSdFYYKEhKwGAVAAAAhmlGHPOOegQUow55xyEECKFGHPOOQghVIw55xx0EEKoGHPMOQghhJA55xyEEEIIIXMOOugghBBCBx2EEEIIoZTOQQghhBBKKCGEEEIIIYQQOgghhBBCCCGEEEIIIYRSSgghhBBCCaGUUAAAYIEDAECADasjnBSNBRYashIAAAIAgByWoFLOhEGOQY8NQcpRMw1CTDnRmWJOajMVU5A5EJ10EhlqQdleMgsAAIAgACDABBAYICj4QgiIMQAAQYjMEAmFVbDAoAwaHOYBwANEhEQAkJigSLu4gC4DXNDFXQdCCEIQglgcQAEJODjhhife8IQbnKBTVOogAAAAAAAMAOABAOCgACIimquwuMDI0Njg6PAIAAAAAAAWAPgAADg+gIiI5iosLjAyNDY4OjwCAAAAAAAAAACAgIAAAAAAAEAAAACAgE9nZ1MABL0gAAAAAAAAamQAAAIAAABD4CsyCyQgg36CgoiFioaONOd3TEz5E9c/BxTQ5C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L4YRkG0CsjwBM0lgTNM/FxjNQlhuWNDqfgI/+gB+fF4/Lv5BhlGfEaI85/WgPXtnOni5WWdg83qBnEgA22FWgixrGKH92/y+KeNNq8RsjAEAAIuG9SLg5vSXDAcxAEC9Ypo+d9jcYHXSolRUDPv3rGV8czRkMJlOxRE0KvHBkzmxHVidJRzBKXQCLuwO4vJwkGDzC49hu3ox7BZa76K3uvQ1GmowIABey63n4Qms0PAXtmjcH5/1z4QXfSDpDbBGA9hWbRSJrPsfppFz++yb+pv2iuJLL1qCK81qAf0OPXOq795whAXASrmiBeymGITsof2pmTp4NbRJLmH334dCVo8BF5EFhQElZ4TcWmrv75W280BypK6BjoKRHbTGdWtmKc4ehgfbRRY+q8jUAX66vdwPP0CSEu+IQdgrxfYMT54eY4wxUo80xhipAeATBACwUQzliMyorVGpvXWc3zd8VbX9jDEq0EsAAAB4UpbiLk5hUK3g19bXd97rG0DSZxeLUwDUHu+8LevrWHv5zpzCB/C8eQAsurauHo41auvFnDfvCA74BingzWO9GGAUj7AoxUAXv0qABndYmwA=";
var tag;
// Fallback to HTML5 audio
tag = document.createElement('audio');
if (typeof tag.canPlayType === 'function') {
tag.setAttribute('preload', 'true');
if (tag.canPlayType('audio/mp3') || tag.canPlayType('audio/mpeg')) {
tag.setAttribute('src', DATA_MP3);
} else if (tag.canPlayType('audio/ogg')) {
tag.setAttribute('src', DATA_OGG);
}
this.play = function() { tag.play(); };
this.stop = function() { tag.pause(); tag.currentTime = 0; };
return;
}
// Fallback for IE<9
tag = document.createElement('bgsound');
if ('loop' in tag) {
tag.src = base + 'res/bell.wav';
tag.loop = 1;
this.play = function() { document.body.appendChild(tag); };
this.stop = function() { document.body.removeChild(tag); };
return;
}
this.play = function() { };
this.stop = function() { };
};
}