Permalink
Browse files

Fixed test1, now outputs sound!

  • Loading branch information...
1 parent cfb1d8b commit 9089b60415f9b4acca27b463286adc08bbe4ad46 @flyx committed Jul 22, 2012
Showing with 26 additions and 21 deletions.
  1. +1 −0 .gitignore
  2. +25 −21 tests/test1.html
View
@@ -0,0 +1 @@
+.DS_Store
View
@@ -2,7 +2,7 @@
<html>
<head>
-
+ <link type="text/css" href="css/ui-lightness/jquery-ui-1.8.21.custom.css" rel="Stylesheet" />
</head>
<body>
<header>
@@ -13,7 +13,9 @@
<table>
<tr>
<td>Frequency:</td>
- <td id="slider"></td>
+ <td style="min-width: 200px">
+ <div id="slider"></div>
+ </td>
</tr>
</table>
</article>
@@ -22,33 +24,35 @@
<script src="js/jquery-ui.js"></script>
<script>
SineWave = function(context) {
- var that = this;
- this.x = 0; // Initial sample number
- this.context = context;
- this.sample_rate = 44100;
- this.frequency = 440;
- this.node = context.createJavaScriptNode(1024, 1, 1);
- this.node.onaudioprocess = function(e) { that.process(e) };
+ var that = this;
+ this.x = 0; // Initial sample number
+ this.context = context;
+ this.sample_rate = 44100;
+ this.frequency = 440;
+ this.next_frequency = 440;
+ this.node = context.createJavaScriptNode(1024, 1, 1);
+ this.node.onaudioprocess = function(e) { that.process(e) };
}
SineWave.prototype.process = function(e) {
- var data = e.outputBuffer.getChannelData(0);
- for (var i = 0; i < data.length; ++i) {
- //data[i] = Math.sin(this.x++);
- data[i] = Math.sin(this.x++ / (this.sample_rate / 2 * Math.PI * this.frequency));
- }
+ this.frequency = this.next_frequency;
+ var data = e.outputBuffer.getChannelData(0);
+ for (var i = 0; i < data.length; ++i) {
+ //data[i] = Math.sin(this.x++);
+ data[i] = Math.sin(this.x++ / (this.sample_rate / (2 * Math.PI * this.frequency)));
+ }
}
SineWave.prototype.play = function() {
- this.node.connect(this.context.destination);
+ this.node.connect(this.context.destination);
}
SineWave.prototype.pause = function() {
- this.node.disconnect();
+ this.node.disconnect();
}
SineWave.prototype.setFrequency = function(freq) {
- this.next_frequency = freq;
+ this.next_frequency = freq;
}
</script>
<script>
@@ -61,10 +65,10 @@
sinewave.play();
$("#slider").slider({
- value: 440,
- min: 1,
- max: 2048,
- slide: function(event, ui) { sinewave.setFrequency(ui.value); }
+ value: 440,
+ min: 1,
+ max: 2048,
+ slide: function(event, ui) { sinewave.setFrequency(ui.value); }
});
});
</script>

0 comments on commit 9089b60

Please sign in to comment.