Permalink
Browse files

split web audio api enhancements into separate module

  • Loading branch information...
1 parent 3e45c78 commit defec14a41ab256453fe7283546beb3e94077c84 @also also committed May 13, 2011
Showing with 59 additions and 63 deletions.
  1. +0 −63 audio.js
  2. +59 −0 waa-enhancements.js
View
63 audio.js
@@ -2,69 +2,6 @@ window.AudioContext = webkitAudioContext;
window.AudioBuffer = new AudioContext().createBuffer(0, 0, 0).constructor;
-var TWO_CHANNELS = 2;
-var SAMPLE_RATE = 2;
-
-var BufferMethods = {
- slice: function (begin, end) {
- var channelData = [];
- var i;
- var end = end || this.length;
- for (i = 0; i < this.numberOfChannels; i++) {
- channelData.push(this.getChannelData(i).subarray(begin, end));
- }
- return new FakeAudioBuffer(this.sampleRate, channelData);
- },
-
- extract: function (target, length, startPosition) {
- var slice = this.slice(startPosition, startPosition + length);
- target.set(slice);
- return slice.length;
- },
-
- set: function (buffer, offset) {
- for (var i = 0; i < this.numberOfChannels; i++) {
- this.getChannelData(i).set(buffer.getChannelData(i), offset);
- }
- }
-};
-
-_.extend(AudioBuffer.prototype, BufferMethods);
-
-function FakeAudioBuffer(sampleRate, channelData) {
- this._sampleRate = sampleRate;
- this._channelData = channelData;
-}
-
-FakeAudioBuffer.createEmpty = function(numberOfChannels, length, sampleRate) {
- var channelData = [];
- var i;
- for (i = 0; i < numberOfChannels; i++) {
- channelData.push(new Float32Array(length));
- }
- return new FakeAudioBuffer(sampleRate, channelData);
-}
-
-FakeAudioBuffer.prototype = {
- get length() {
- return this._channelData[0].length;
- },
-
- get numberOfChannels() {
- return this._channelData.length;
- },
-
- get sampleRate() {
- return this._sampleRate;
- },
-
- getChannelData: function (channel) {
- return this._channelData[channel];
- }
-};
-
-_.extend(FakeAudioBuffer.prototype, BufferMethods);
-
function AudioBufferSampleSource(audioBuffer) {
this._audioBuffer = audioBuffer;
}
View
59 waa-enhancements.js
@@ -0,0 +1,59 @@
+var BufferMethods = {
+ slice: function (begin, end) {
+ var channelData = [];
+ var i;
+ var end = end || this.length;
+ for (i = 0; i < this.numberOfChannels; i++) {
+ channelData.push(this.getChannelData(i).subarray(begin, end));
+ }
+ return new FakeAudioBuffer(this.sampleRate, channelData);
+ },
+
+ extract: function (target, length, startPosition) {
+ var slice = this.slice(startPosition, startPosition + length);
+ target.set(slice);
+ return slice.length;
+ },
+
+ set: function (buffer, offset) {
+ for (var i = 0; i < this.numberOfChannels; i++) {
+ this.getChannelData(i).set(buffer.getChannelData(i), offset);
+ }
+ }
+};
+
+_.extend(AudioBuffer.prototype, BufferMethods);
+
+function FakeAudioBuffer(sampleRate, channelData) {
+ this._sampleRate = sampleRate;
+ this._channelData = channelData;
+}
+
+FakeAudioBuffer.createEmpty = function(numberOfChannels, length, sampleRate) {
+ var channelData = [];
+ var i;
+ for (i = 0; i < numberOfChannels; i++) {
+ channelData.push(new Float32Array(length));
+ }
+ return new FakeAudioBuffer(sampleRate, channelData);
+}
+
+FakeAudioBuffer.prototype = {
+ get length() {
+ return this._channelData[0].length;
+ },
+
+ get numberOfChannels() {
+ return this._channelData.length;
+ },
+
+ get sampleRate() {
+ return this._sampleRate;
+ },
+
+ getChannelData: function (channel) {
+ return this._channelData[channel];
+ }
+};
+
+_.extend(FakeAudioBuffer.prototype, BufferMethods);

0 comments on commit defec14

Please sign in to comment.