src/web-audio-backend.js
/**
   * Constructor for AudioFeeder's Web Audio API backend.
   * @class
   * @param {number} numChannels - requested count of output channels
   * @param {number} sampleRate - requested sample rate for output
   * @param {Object} options - pass URL path to directory containing 'dynamicaudio.swf' in 'base' parameter
   *
   * @classdesc Web Audio API output backend for AudioFeeder.
   * Maintains an internal {@link BufferQueue} of audio samples to be output on demand.
   */
Constructor for AudioFeeder's Web Audio API backend.
@class
@param {number} numChannels - requested count of output channels
@param {number} sampleRate - requested sample rate for output
@param {Object} options - pass URL path to directory containing 'dynamicaudio.swf' in 'base' parameter

@classdesc Web Audio API output backend for AudioFeeder.
Maintains an internal  BufferQueue of audio samples to be output on demand.
Constructor for AudioFeeder ' s Web Audio API backend . @class @param { number } numChannels - requested count of output channels @param { number } sampleRate - requested sample rate for output @param { Object } options - pass URL path to directory containing ' dynamicaudio . swf ' in ' base ' parameter @classdesc Web Audio API output backend for AudioFeeder . Maintains an internal BufferQueue of audio samples to be output on demand .
function WebAudioBackend(numChannels, sampleRate, options) {
    var context = options.audioContext || WebAudioBackend.initSharedAudioContext();
    this._context = context;
    this.output = options.output || context.destination
    this.rate = context.sampleRate;
    this.channels = 2; 
    if (options.bufferSize) {
        this.bufferSize = (options.bufferSize | 0);
    }
    this.bufferThreshold = 2 * this.bufferSize;
    this._bufferQueue = new BufferQueue(this.channels, this.bufferSize);
    this._playbackTimeAtBufferTail = context.currentTime;
    this._queuedTime = 0;
    this._delayedTime = 0;
    this._dropped = 0;
    this._liveBuffer = this._bufferQueue.createBuffer(this.bufferSize);
    if (context.createScriptProcessor) {
      this._node = context.createScriptProcessor(this.bufferSize, 0, this.channels);
    } else if (context.createJavaScriptNode) {
      this._node = context.createJavaScriptNode(this.bufferSize, 0, this.channels);
    } else {
      throw new Error("Bad version of web audio API?");
    }
  }
function WebAudioBackend ( numChannels , sampleRate , options ) { var context = options . audioContext || WebAudioBackend . initSharedAudioContext ( ) ; this . _context = context ; this . output = options . output || context . destination this . rate = context . sampleRate ; this . channels = 2 ; if ( options . bufferSize ) { this . bufferSize = ( options . bufferSize | 0 ) ; } this . bufferThreshold = 2 * this . bufferSize ; this . _bufferQueue = new BufferQueue ( this . channels , this . bufferSize ) ; this . _playbackTimeAtBufferTail = context . currentTime ; this . _queuedTime = 0 ; this . _delayedTime = 0 ; this . _dropped = 0 ; this . _liveBuffer = this . _bufferQueue . createBuffer ( this . bufferSize ) ; if ( context . createScriptProcessor ) { this . _node = context . createScriptProcessor ( this . bufferSize , 0 , this . channels ) ; } else if ( context . createJavaScriptNode ) { this . _node = context . createJavaScriptNode ( this . bufferSize , 0 , this . channels ) ; } else { throw new Error ( "Bad version of web audio API?" ) ; } }
Constructor for AudioFeeder's Web Audio API backend.
Constructor for AudioFeeder ' s Web Audio API backend .
/*
     * Optional audio node can be provided to connect the feeder to
     * @type {AudioNode}
     */ /**
     * Actual sample rate supported for output, in Hz
     * @type {number}
     * @readonly
     */ /**
     * Actual count of channels supported for output
     * @type {number}
     * @readonly
     *
     * Note currently this is forced to 2. More channels (5.1, etc)
     * aren't well specified and need to be tested. Fewer channels
     * (mono) ends up too loud unless we reduce amplitude in the
     * resampling operation.
     */ //this.channels = Math.min(numChannels, 2); // @fixme remove this limit // @fixme remove this limit // @todo support new audio worker mode too // In older Safari versions