UNPKG

web-audio-api

Version:
105 lines (89 loc) 4.19 kB
var EventEmitter = require('events').EventEmitter , async = require('async') , utils = require('./utils') , readOnlyAttr = utils.readOnlyAttr , DspObject = require('./DspObject') , AudioInput = require('./audioports').AudioInput , AudioOutput = require('./audioports').AudioOutput var ChannelCountMode = ['max', 'clamped-max', 'explicit'], ChannelInterpretation = ['speakers', 'discrete'] var AudioNode = (function(super$0){"use strict";var PRS$0 = (function(o,t){o["__proto__"]={"a":t};return o["a"]===t})({},{});var DP$0 = Object.defineProperty;var GOPD$0 = Object.getOwnPropertyDescriptor;var MIXIN$0 = function(t,s){for(var p in s){if(s.hasOwnProperty(p)){DP$0(t,p,GOPD$0(s,p));}}return t};var SP$0 = Object.setPrototypeOf||function(o,p){if(PRS$0){o["__proto__"]=p;}else {DP$0(o,"__proto__",{"value":p,"configurable":true,"enumerable":false,"writable":true});}return o};var OC$0 = Object.create;if(!PRS$0)MIXIN$0(AudioNode, super$0);var proto$0={}; function AudioNode(context, numberOfInputs, numberOfOutputs, channelCount, channelCountMode, channelInterpretation) { super$0.call(this, context) readOnlyAttr(this, 'context', context) readOnlyAttr(this, 'numberOfInputs', numberOfInputs) readOnlyAttr(this, 'numberOfOutputs', numberOfOutputs) channelCount = channelCount || 2 Object.defineProperty(this, 'channelCount', { get: function() { return channelCount }, set: function(val) { if (val < 1) throw new Error('Invalid number of channels') channelCount = val }, configurable: true }) var channelCountMode = channelCountMode Object.defineProperty(this, 'channelCountMode', { get: function() { return channelCountMode }, set: function(val) { if (ChannelCountMode.indexOf(val) === -1) throw new Error('Unvalid value for channelCountMode : ' + val) channelCountMode = val }, configurable: true }) var channelInterpretation = channelInterpretation Object.defineProperty(this, 'channelInterpretation', { get: function() { return channelInterpretation }, set: function(val) { if (ChannelInterpretation.indexOf(val) === -1) throw new Error('Unvalid value for channelInterpretation : ' + val) channelInterpretation = val }, configurable: true }) // Initialize audio ports var i this._inputs = [] this._outputs = [] for (i = 0; i < this.numberOfInputs; i++) this._inputs.push(new AudioInput(context, this, i)) for (i = 0; i < this.numberOfOutputs; i++) this._outputs.push(new AudioOutput(context, this, i)) }if(super$0!==null)SP$0(AudioNode,super$0);AudioNode.prototype = OC$0(super$0!==null?super$0.prototype:null,{"constructor":{"value":AudioNode,"configurable":true,"writable":true}});DP$0(AudioNode,"prototype",{"configurable":false,"enumerable":false,"writable":false}); proto$0.connect = function(destination) {var output = arguments[1];if(output === void 0)output = 0;var input = arguments[2];if(input === void 0)input = 0; if (output >= this.numberOfOutputs) throw new Error('output out of bounds ' + output) if (input >= destination.numberOfInputs) throw new Error('input out of bounds ' + input) this._outputs[output].connect(destination._inputs[input]) }; proto$0.disconnect = function() {var output = arguments[0];if(output === void 0)output = 0; if (output >= this.numberOfOutputs) throw new Error('output out of bounds ' + output) var audioOut = this._outputs[output] audioOut.sinks.slice(0).forEach(function(sink) { audioOut.disconnect(sink) }) }; // Disconnects all ports and remove all events listeners proto$0._kill = function() { this._inputs.forEach(function(input) { input._kill() }) this._outputs.forEach(function(output) { output._kill() }) this.removeAllListeners() this._tick = function() { throw new Error('this node has been killed') } }; MIXIN$0(AudioNode.prototype,proto$0);proto$0=void 0;return AudioNode;})(DspObject); module.exports = AudioNode