Skip to content
Browse files

giving up on panning for now. it's adding a muddy sound for no appare…

…nt reason
  • Loading branch information...
1 parent 870e075 commit f8435464b565ac53823ed85705e8dd9bbc836939 @richtaur committed
Showing with 25 additions and 13 deletions.
  1. +1 −1 audia-min.js
  2. +13 −9 audia.js
  3. +11 −3 examples/index.html
View
2 audia-min.js
@@ -1,7 +1,7 @@
var Audia=function(){var g=!0;if(typeof AudioContext=="function")var d=new AudioContext;else typeof webkitAudioContext=="function"?d=new webkitAudioContext:g=!1;var i=function(b,a,d){if(b<a)return a;else if(b>d)return d;return b},h={},c={},j=0,a=function(b){this._id=++j;this._duration=this._currentTime=0;this._onendedTimeout=this._gain=null;this._playing=this._muted=!1;this._startTime=this._source=null;this._volume=1;if(typeof b=="string")this.src=b;else if(typeof b=="object")for(var a in b)this[a]=
b[a];c[this._id]=this};a.__defineGetter__("version",function(){return 0.1});a.__defineGetter__("supported",function(){return g});if(!g)return a;a.muteAll=function(){for(var b in c)c[b].mute()};a.unmuteAll=function(){for(var b in c)c[b].unmute()};a.prototype.__defineGetter__("currentTime",function(){if(this._playing){var b=d.currentTime-this._startTime+this._currentTime;return b>this._duration?this._duration:b}else return this._currentTime});a.prototype.__defineSetter__("currentTime",function(b){b=
i(b,0,this._duration);if(this.currentTime!=b){var a=this._playing;this._stop();this._currentTime=b;a&&this.play()}});a.prototype.__defineGetter__("duration",function(){return this._duration});a.prototype.__defineGetter__("muted",function(){return this._muted});a.prototype.__defineSetter__("muted",function(b){b?this.mute():this.unmute()});a.prototype.__defineGetter__("playing",function(){return this._playing});a.prototype.__defineGetter__("src",function(){return this._src});a.prototype.__defineSetter__("src",
-function(b){this._src=b;var a=this,c=d.createGainNode();c.connect(d.destination);c.gain.value=this._muted?0:this._volume;var f=d.createBufferSource();f.connect(c);this._gain=c;this._source=f;if(b in h)f.buffer=h[b];else{var e=new XMLHttpRequest;e.open("GET",b,!0);e.responseType="arraybuffer";e.onload=function(){var c=d.createBuffer(e.response,!1);f.buffer=c;h[b]=c;a._duration=c.duration;a.onload()};e.send()}});a.prototype.__defineGetter__("volume",function(){return this._volume});a.prototype.__defineSetter__("volume",
+function(b){this._src=b;var a=this,c=d.createGainNode();c.gain.value=this._muted?0:this._volume;var f=d.createBufferSource();f.connect(c);c.connect(d.destination);this._gain=c;this._source=f;if(b in h)f.buffer=h[b];else{var e=new XMLHttpRequest;e.open("GET",b,!0);e.responseType="arraybuffer";e.onload=function(){var c=d.createBuffer(e.response,!1);f.buffer=c;h[b]=c;a._duration=c.duration;a.onload()};e.send()}});a.prototype.__defineGetter__("volume",function(){return this._volume});a.prototype.__defineSetter__("volume",
function(b){this._volume=b=i(b,0,10);if(!this._muted)this._gain.gain.value=b});a.prototype.onended=function(){};a.prototype.onload=function(){};a.prototype.play=function(b){if(b!==void 0)this.currentTime=b;if(!this._playing){this._regenerateBuffer();b=this._duration-this._currentTime-0.01;this._source.noteGrainOn(0,this._currentTime,b);this._playing=!0;this._startTime=d.currentTime;var a=this;this._onendedTimeout=setTimeout(function(){a.onended();a._stop();a.currentTime=0;a.loop&&a.play()},b*1E3)}};
a.prototype.pause=function(){this._stop()};a.prototype.stop=function(){this._stop();this._currentTime=0};a.prototype._stop=function(){if(this._playing){if(this._onendedTimeout)clearTimeout(this._onendedTimeout),this._onendedTimeout=null;this._source.noteOff(0);this._expireBuffer();this._currentTime+=d.currentTime-this._startTime;this._playing=!1}};a.prototype._expireBuffer=function(){this._source=null};a.prototype.mute=function(){this._muted=!0;if(this._gain)this._gain.gain.value=0};a.prototype.unmute=
function(){this._muted=!1;if(this._gain)this._gain.gain.value=this._volume};a.prototype._regenerateBuffer=function(){this.src=this._src};return a}();
View
22 audia.js
@@ -132,24 +132,28 @@ var Audia = (function () {
// Create the gain node and set the volume
var gain = audioContext.createGainNode();
- gain.connect(audioContext.destination);
gain.gain.value = this._muted ? 0 : this._volume;
- /*
+ // Note: panning code is commented out for now, because
+ // the mere presence of a panner is causing everything
+ // to sound muddy.
+ // http://code.google.com/p/chromium/issues/detail?id=108852
// Create the panner node and set the panning
- var panner = audioContext.createPanner();
- panner.connect(gain);
- panner.setPosition(0, 0, 0);
- panner.refDistance = 0;
- */
+ //var panner = audioContext.createPanner();
- // Create the buffer source and connect to the gain
+ // Create the buffer source and connect everything
var source = audioContext.createBufferSource();
- //source.connect(panner);
+ /*
+ source.connect(panner);
+ panner.connect(gain);
+ gain.connect(audioContext.destination);
+ */
source.connect(gain);
+ gain.connect(audioContext.destination);
// Retain!
this._gain = gain;
+ //this._panner = panner;
this._source = source;
if (url in buffers) {
View
14 examples/index.html
@@ -5,7 +5,7 @@
<title>Audia library example</title>
</head>
<body>
- <h1><a href="https://github.com/lostdecade/audia">Audia</a> library example</h1>
+ <h1><a href="https://github.com/richtaur/audia">Audia</a> library example</h1>
<p>
For a thorough explanation of these examples, see the <a href="http://www.lostdecadegames.com/audia-is-a-library-for-simplifying-the-web-audio-api">Lost Decade Games blog</a>.
</p>
@@ -19,9 +19,17 @@
<input id="loop-attack" type="checkbox"> Loop
</label>
</p>
+ <!--
+ <p>
+ <label>
+ <input id="loop-pan" min="-1" max="1" step="0.25" value="0" type="range">
+ Panning
+ </label>
+ </p>
+ -->
<p>
- <a href="https://github.com/richtaur/audia/blob/master/examples/example.js">View source</a>
+ <a href="https://github.com/richtaur/audia/blob/master/examples/example.js#L9">View source</a>
</p>
<hr>
@@ -49,7 +57,7 @@
</p>
<p>
- <a href="https://github.com/lostdecade/audia/blob/master/examples/example.js#L24">View source</a>
+ <a href="https://github.com/richtaur/audia/blob/master/examples/example.js#L24">View source</a>
</p>
<script src="../audia.js"></script>

0 comments on commit f843546

Please sign in to comment.
Something went wrong with that request. Please try again.