• Stars
    star
    840
  • Rank 51,999 (Top 2 %)
  • Language
    JavaScript
  • License
    Apache License 2.0
  • Created almost 8 years ago
  • Updated about 1 month ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Spatial Audio Rendering on the web.

Omnitone: Spatial Audio Rendering on the Web

Travis npm GitHub license

Omnitone is a robust implementation of ambisonic decoding and binaural rendering written in Web Audio API. Its rendering process is powered by the fast native features from Web Audio API (GainNode and Convolver), ensuring the optimum performance.

The implementation of Omnitone is based on the Google spatial media specification and SADIE's binaural filters. It also powers Resonance Audio SDK for web.

If you are looking for interactive panning based on Omnitone's ambisonic rendering, be sure to check out Songbird project!

Feature Highlights

Omnitone offers ambisonic decoding and binaural rendering of:

  • First-order-ambisonic stream
  • High-order-ambisonic stream (2nd and 3rd order)

Omnitone in action:

How it works

The input audio stream can be either an HTMLMediaElement (<video> or <audio> tag) or a multichannel AudioBufferSourceNode. The rotation of the sound field also can be easily linked to the mobile phone's sensor or the on-screen user interaction.

Omnitone Diagram

Usage

The first step is to include the library file in an HTML document. Omnitone is available on Google's CDN.

<script src="https://www.gstatic.com/external_hosted/omnitone/build/omnitone.min.js"></script>
<script>
  // `Omnitone` object is loaded and ready.
  var audioContext = new AudioContext();
  var foaRenderer = Omnitone.createFOARenderer(audioContext);
</script>

Alternatively, you can install Omnitone as a part of your local development via NPM.

npm install omnitone

As of version 1.3.0, Omnitone library includes an ES6 module. This is convenient when you integrate Omnitone into your project.

import Omnitone from './omnitone/build/omnitone.min.esm.js';

const audioContext = new AudioContext();
const foaRenderer = Omnitone.createFOARenderer(audioContext);

You can also git clone the repository and use the library file as usual.

git clone https://github.com/GoogleChrome/omnitone.git

FOARenderer

FOARenderer is for the first-order-ambisonic stream, which consists of 4 channels.

// Set up an audio element to feed the ambisonic source audio feed.
const audioElement = document.createElement('audio');
audioElement.src = 'audio-file-foa-acn.wav';

// Create AudioContext, MediaElementSourceNode and FOARenderer.
const audioContext = new AudioContext();
const audioElementSource = audioContext.createMediaElementSource(audioElement);
const foaRenderer = Omnitone.createFOARenderer(audioContext);

// Make connection and start play. Hook up the user input for the playback.
foaRenderer.initialize().then(function() {
  audioElementSource.connect(foaRenderer.input);
  foaRenderer.output.connect(audioContext.destination);

  // This is necessary to activate audio playback out of autoplay block.
  someButton.onclick = () => {
    audioContext.resume();
    audioElement.play();
  };
});

HOARenderer

HOARenderer is for the higher-order-ambisonic stream. Currently Omnitone supports 2nd and 3rd order ambisonics, which consist of 9 channels and 16 channels respectively.

// Works exactly the same way with FOARenderer. See the usage above.
var hoaRenderer = Omnitone.createHOARenderer(audioContext);

Rotation and Rendering Mode

The rotation matrix in Omnitone renderer can be updated inside of the application's animation loop to rotate the entire sound field. Omnitone supports both 3x3 and 4x4 rotation matrices(column-major).

// Rotation with 3x3 or 4x4 matrix.
renderer.setRotationMatrix3(rotationMatrix3);
renderer.setRotationMatrix4(rotationMatrix4);

For example, if you want to hook up the Three.js perspective camera:

renderer.setRotationMatrix4(camera.matrixWorld.elements);

Use setRenderingMode method to change the operation of the decoder. This is useful when switching between spatial media (ambisonic) and non-spatial media (mono or stereo) or when you want to save the CPU power by disabling the decoder.

// Mono or regular multi-channel layouts.
renderer.setRenderingMode('bypass');

// Use ambisonic rendering.
renderer.setRenderingMode('ambisonic');

// Disable encoding completely. (audio processing disabled)
renderer.setRenderingMode('off');

Development

Building Omnitone Locally

For the development, get a copy of the repository first and run the following script to build the library. Omnitone uses WebPack to compile the sources.

npm run build       # build omnitone library files.
npm run build-doc   # build JSDoc3 documentation.
npm run eslint      # Run ESLint against source files.

Test

Omnitone uses Travis and Karma test runner for the automated testing. To run the test suite locally, make sure to install dependencies before launch the local test runner. The test suite requires the promisifed version of OfflineAudioContext, so the Karma test runner will choose Chrome as a default test runner.

npm test

Local Testing on Linux

Since the test suite requires Chromium-based browser, the following set up might be necessary for Karma to run properly on Linux distros without Chromium-based browser.

# Tested with Ubuntu 16.04
sudo apt install chromium-browser
export CHROME_BIN=chromium-browser

Audio Codec Compatibility

Omnitone is designed to run on any browser that supports Web Audio API, however, it does not address the incompatibility issue around various media codecs in the browser. At the time of writing, the decoding of compressed multichannel audio with more than 3 channels via <video> or <audio> elements is not fully supported by the majority of mobile browsers.

Related Resources

Acknowledgments

Special thanks to Boris Smus, Brandon Jones, Dillon Cower, Drew Allen, Julius Kammerl and Marcin Gorzel for their help on this project. We are also grateful to Tim Fain and Jaunt VR for their permission to use beautiful VR contents in the demo.

Support

If you have found an error in this library, please file an issue at: https://github.com/GoogleChrome/omnitone/issues.

Patches are encouraged, and may be submitted by forking this project and submitting a pull request through GitHub. See CONTRIBUTING for more detail.

License

Copyright 2016 Google Inc. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

More Repositories

1

lighthouse

Automated auditing, performance metrics, and best practices for the web.
JavaScript
27,804
star
2

chrome-extensions-samples

Chrome Extensions Samples
JavaScript
13,907
star
3

workbox

📦 Workbox: JavaScript libraries for Progressive Web Apps
JavaScript
12,091
star
4

web-vitals

Essential metrics for a healthy site.
JavaScript
7,111
star
5

lighthouse-ci

Automate running Lighthouse for every commit, viewing the changes, and preventing regressions
JavaScript
6,210
star
6

rendertron

A Headless Chrome rendering solution
TypeScript
5,926
star
7

samples

A repo containing samples tied to new functionality in each release of Google Chrome.
HTML
5,709
star
8

web.dev

The frontend, backend, and content source code for web.dev
Nunjucks
3,544
star
9

dialog-polyfill

Polyfill for the HTML dialog element
JavaScript
2,425
star
10

web-vitals-extension

A Chrome extension to measure essential metrics for a healthy site
CSS
2,318
star
11

accessibility-developer-tools

This is a library of accessibility-related testing and utility code.
JavaScript
2,274
star
12

developer.chrome.com

The frontend, backend, and content source code for developer.chrome.com
HTML
1,660
star
13

custom-tabs-client

Chrome custom tabs examples
Java
1,399
star
14

chrome-launcher

Launch Google Chrome with ease from node.
TypeScript
1,166
star
15

proxy-polyfill

Proxy object polyfill
JavaScript
1,127
star
16

devtools-docs

The legacy documentation for Chrome DevTools.
HTML
686
star
17

android-browser-helper

The Android Browser Helper library helps developers use Custom Tabs and Trusted Web Activities on top of the AndroidX browser support library.
Java
655
star
18

chromium-dashboard

Chrome Status Dashboard
Python
624
star
19

OriginTrials

Enabling safe experimentation with web APIs
Bikeshed
520
star
20

audion

Audion is a Chrome extension that adds a Web Audio panel to Developer Tools. This panel visualizes the web audio graph in real-time.
TypeScript
357
star
21

related-website-sets

Python
282
star
22

chrome-app-codelab

The goal of this tutorial is to get you building Chrome apps fast. Once you've completed the tutorial, you will have a simple Todo app. We've done our best to capture some of the trickier parts to the development process keeping the sample simple and straightforward.
JavaScript
214
star
23

lighthouse-stack-packs

Lighthouse Stack Packs
JavaScript
207
star
24

CrUX

The place to share queries, ideas, or issues related to the Chrome UX Report
Jupyter Notebook
201
star
25

inert-polyfill

Polyfill for the HTML inert attribute
JavaScript
188
star
26

chrome-types

Code to parse Chrome's internal extension type definitions—published on NPM as chrome-types
JavaScript
157
star
27

devtools-samples

Samples for demonstrating DevTools features.
HTML
149
star
28

ip-protection

147
star
29

CertificateTransparency

HTML
139
star
30

browser-bug-search

Search across all major browser vendor issue trackers
JavaScript
113
star
31

multi-device

Chrome multi-device (mobile) docs
HTML
102
star
32

kino

A sample offline streaming video PWA built for web.dev/media
JavaScript
92
star
33

jank-busters

Resources for jank busting on the web.
JavaScript
64
star
34

webstore-docs

Developer docs for Chrome Web Store:
HTML
64
star
35

budget.json

37
star
36

private-tokens

37
star
37

webdev-infra

JavaScript
36
star
38

.github

10
star
39

.allstar

7
star
40

CertificateTransparency-todelete

HTML
7
star
41

lighthouse-plugin-example

JavaScript
1
star