Permalink
Browse files

tab fixing

  • Loading branch information...
1 parent ffca6ff commit ee4a320611ee811501ee5b90e97a8c31603047a5 @gasman committed Dec 8, 2011
Showing with 46 additions and 46 deletions.
  1. +45 −45 audio.js
  2. +1 −1 synth.js
View
@@ -6,9 +6,9 @@ function AudioPlayer(generator, opts) {
var checkInterval = latency * 100 /* in ms */
var audioElement = new Audio();
- var webkitAudio = window.AudioContext || window.webkitAudioContext;
- var requestStop = false;
-
+ var webkitAudio = window.AudioContext || window.webkitAudioContext;
+ var requestStop = false;
+
if (audioElement.mozSetup) {
audioElement.mozSetup(2, sampleRate); /* channels, sample rate */
@@ -31,53 +31,53 @@ function AudioPlayer(generator, opts) {
checkBuffer();
return {
- 'type': 'Firefox Audio',
- 'stop': function() {
- requestStop = true;
- }
+ 'type': 'Firefox Audio',
+ 'stop': function() {
+ requestStop = true;
+ }
}
} else if (webkitAudio) {
- // Uses Webkit Web Audio API if available
- var context = new webkitAudio();
- sampleRate = context.sampleRate;
-
- var channelCount = 2;
- var bufferSize = 4096*4; // Higher for less gitches, lower for less latency
-
- var node = context.createJavaScriptNode(bufferSize, 0, channelCount);
-
- node.onaudioprocess = function(e) { process(e) };
+ // Uses Webkit Web Audio API if available
+ var context = new webkitAudio();
+ sampleRate = context.sampleRate;
+
+ var channelCount = 2;
+ var bufferSize = 4096*4; // Higher for less gitches, lower for less latency
+
+ var node = context.createJavaScriptNode(bufferSize, 0, channelCount);
+
+ node.onaudioprocess = function(e) { process(e) };
- function process(e) {
- if (generator.finished) {
- node.disconnect();
- return;
- }
-
- var dataLeft = e.outputBuffer.getChannelData(0);
- var dataRight = e.outputBuffer.getChannelData(1);
+ function process(e) {
+ if (generator.finished) {
+ node.disconnect();
+ return;
+ }
+
+ var dataLeft = e.outputBuffer.getChannelData(0);
+ var dataRight = e.outputBuffer.getChannelData(1);
- var generate = generator.generate(bufferSize);
+ var generate = generator.generate(bufferSize);
- for (var i = 0; i < bufferSize; ++i) {
- dataLeft[i] = generate[i*2];
- dataRight[i] = generate[i*2+1];
- }
- }
-
- // start
- node.connect(context.destination);
-
- return {
- 'stop': function() {
- // pause
- node.disconnect();
- requestStop = true;
+ for (var i = 0; i < bufferSize; ++i) {
+ dataLeft[i] = generate[i*2];
+ dataRight[i] = generate[i*2+1];
+ }
+ }
+
+ // start
+ node.connect(context.destination);
+
+ return {
+ 'stop': function() {
+ // pause
+ node.disconnect();
+ requestStop = true;
},
- 'type': 'Webkit Audio'
- }
+ 'type': 'Webkit Audio'
+ }
- } else {
+ } else {
// Fall back to creating flash player
var c = document.createElement('div');
c.innerHTML = '<embed type="application/x-shockwave-flash" id="da-swf" src="da.swf" width="8" height="8" allowScriptAccess="always" style="position: fixed; left:-10px;" />';
@@ -114,12 +114,12 @@ function AudioPlayer(generator, opts) {
return {
'stop': function() {
swf.stop();
- requestStop = true;
+ requestStop = true;
},
'bufferedDuration': function() {
return swf.bufferedDuration();
},
- 'type': 'Flash Audio'
+ 'type': 'Flash Audio'
}
}
}
View
@@ -109,7 +109,7 @@ function ADSRGenerator(child, attackAmplitude, sustainAmplitude, attackTimeS, de
}
function midiToFrequency(note) {
- return 440 * Math.pow(2, (note-69)/12);
+ return 440 * Math.pow(2, (note-69)/12);
}
PianoProgram = {

0 comments on commit ee4a320

Please sign in to comment.