Spec Differences

From Audio WG Wiki
Jump to: navigation, search

This page is to describe the qualitative and quantitative differences between the Web Audio API and the MediaStream Processing API, in particular with regard to the Use Cases and Requirements established by the Audio WG.

As much as possible, this document is intended to be precise and impartial, e.g. instead of saying that one specification is more closely integrated with the WebRTC API, it should describe what the integration is, and how it works.

Differences At a Glance

This table is based on the Level 1 outlines of each spec.

API FeatureMediaStreamWeb Audio
Faster than real-time processingNoYes
Native EffectsNoYes
Audio primarily manipulated through <Audio> tagsYesNo
Audio primarily manipulated through an Audio-ContextNoYes
Can load sounds faster than playbackNoYes
Streams/nodes can contain video & audio dataYesNo


Differences By Example

This section lists differences between the Web Audio spec and the Media Streams Spec with side-by-side examples.

Reading Data from a Media Element

This example demonstrates how to get audio data, using an <audio> or <video> media element as a source.

Web Audio

  function init(){

    var context         = new webkitAudioContext()
      , mediaElement    = document.getElementById( 'audio-element' )
      , sourceNode      = context.createMediaElementSource( mediaElement )
      , javaScriptNode  = context.createJavaScriptNode(2048)
      , audioData       = document.getElementById( 'audio-data' )
      ;

    var processAudio = function(e){
      var channels = e.inputBuffer.numberOfChannels
        , buffer = e.inputBuffer
        ;

      for(var i=0; i< channels; i++){
        audioData.innerHTML += e.inputBuffer.getChannelData(i)[0] +', ';
      }
    };

    javaScriptNode.onaudioprocess = processAudio;

    sourceNode.connect( javaScriptNode );
    javaScriptNode.connect( context.destination );
  };

MediaStream Processing API

Specification: MediaStream Processing API

Editor: Robert O'Callahan (Mozilla)

Browser Support: Firefox nightlies

Features and Design Decisions

  • Native code is deliberately minimal, relies upon JavaScript libraries to provide higher-level functionality


Web Audio API

Specification: Web Audio API

Editor: Chris Rogers (Google)

Browser Support: WebKit trunk, Chrome, Safari nightlies?

Features and Design Decisions

  • Native code tries to meet needs of common functionality of platform-level audio APIs