-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add support for Spatial audio rendering via Omnitone (#181)
- Loading branch information
1 parent
ebe0727
commit 2af9aa3
Showing
7 changed files
with
2,811 additions
and
2,180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>videojs-vr Demo</title> | ||
<link href="../node_modules/video.js/dist/video-js.css" rel="stylesheet"> | ||
<link href="../dist/videojs-vr.css" rel="stylesheet"> | ||
</head> | ||
<body> | ||
<video width="640" height="300" id="videojs-vr-player" class="video-js vjs-default-skin" crossorigin="anonymous" controls playsinline> | ||
<source src="https://storage.googleapis.com/omnitone-demo.google.com.a.appspot.com/fuerza-imprevista-1080p-h264-aac.mp4" type="video/mp4"> | ||
</video> | ||
<ul> | ||
<li><a href="../">return to main example</a></li> | ||
</ul> | ||
<script src="../node_modules/video.js/dist/video.js"></script> | ||
<script src="../node_modules/omnitone/build/omnitone.js"></script> | ||
<script src="../dist/videojs-vr.js"></script> | ||
<script> | ||
(function(window, videojs) { | ||
var player = window.player = videojs('videojs-vr-player'); | ||
player.mediainfo = player.mediainfo || {}; | ||
player.mediainfo.projection = '360'; | ||
|
||
// AUTO is the default and looks at mediainfo | ||
var vr = window.vr = player.vr({projection: 'AUTO', debug: true, forceCardboard: false, omnitone: Omnitone, omnitoneOptions: {}}); | ||
}(window, window.videojs)); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import videojs from 'video.js'; | ||
|
||
/** | ||
* This class manages ambisonic decoding and binaural rendering via Omnitone library. | ||
*/ | ||
class OmnitoneController extends videojs.EventTarget { | ||
/** | ||
* Omnitone controller class. | ||
* | ||
* @class | ||
* @param {AudioContext} audioContext - associated AudioContext. | ||
* @param {Omnitone library} omnitone - Omnitone library element. | ||
* @param {HTMLVideoElement} video - vidoe tag element. | ||
* @param {Object} options - omnitone options. | ||
*/ | ||
constructor(audioContext, omnitone, video, options) { | ||
super(); | ||
|
||
const settings = videojs.mergeOptions({ | ||
// Safari uses the different AAC decoder than FFMPEG. The channel order is | ||
// The default 4ch AAC channel layout for FFMPEG AAC channel ordering. | ||
channelMap: videojs.browser.IS_SAFARI ? [2, 0, 1, 3] : [0, 1, 2, 3], | ||
ambisonicOrder: 1 | ||
}, options); | ||
|
||
this.videoElementSource = audioContext.createMediaElementSource(video); | ||
this.foaRenderer = omnitone.createFOARenderer(audioContext, settings); | ||
|
||
this.foaRenderer.initialize().then(() => { | ||
if (audioContext.state === 'suspended') { | ||
this.trigger({type: 'audiocontext-suspended'}); | ||
} | ||
this.videoElementSource.connect(this.foaRenderer.input); | ||
this.foaRenderer.output.connect(audioContext.destination); | ||
this.initialized = true; | ||
this.trigger({type: 'omnitone-ready'}); | ||
}, (error) => { | ||
videojs.log.warn(`videojs-vr: Omnitone initializes failed with the following error: ${error})`); | ||
}); | ||
} | ||
|
||
/** | ||
* Updates the rotation of the Omnitone decoder based on three.js camera matrix. | ||
* | ||
* @param {Camera} camera Three.js camera object | ||
*/ | ||
update(camera) { | ||
if (!this.initialized) { | ||
return; | ||
} | ||
this.foaRenderer.setRotationMatrixFromCamera(camera.matrix); | ||
} | ||
|
||
/** | ||
* Destroys the controller and does any necessary cleanup. | ||
*/ | ||
dispose() { | ||
this.initialized = false; | ||
this.foaRenderer.setRenderingMode('bypass'); | ||
this.foaRenderer = null; | ||
} | ||
} | ||
|
||
export default OmnitoneController; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters