Created
October 15, 2017 21:23
-
-
Save tfogo/b80a3e4ea184c0c653f0ee1b1349a4dc to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<!DOCTYPE html> | |
<head> | |
</head> | |
<body> | |
<div id="song1"> | |
<button onclick="playSong1()">play</button> | |
<button onclick="mySource.setPosition(-0.9, 8.9, 0)">right 1</button> | |
<button onclick="mySource.setPosition(-2, 8.9, -1)">right 2</button> | |
<button onclick="mySource.setPosition(-1, 8.9, -2)">right 3</button> | |
<button onclick="mySource.setPosition(0, 8.9, -3)">right 4</button> | |
<button onclick="mySource.setPosition(1, 8.9, -2)">right 5</button> | |
<button onclick="mySource.setPosition(2, 8.9, -1)">right 6</button> | |
<button onclick="mySource.setPosition(0.9, 8.9, 0)">right 7</button> | |
<button onclick="mySource.setPosition(0, 8.9, 0)">right 8</button> | |
</div> | |
<div id="song2"> | |
<button onclick="playSong2()">play</button> | |
<button onclick="mySource2.setPosition(-0.9, 8.9, 0)">right 1</button> | |
<button onclick="mySource2.setPosition(-2, 8.9, -1)">right 2</button> | |
<button onclick="mySource2.setPosition(-1, 8.9, -2)">right 3</button> | |
<button onclick="mySource2.setPosition(0, 8.9, -3)">right 4</button> | |
<button onclick="mySource2.setPosition(1, 8.9, -2)">right 5</button> | |
<button onclick="mySource2.setPosition(2, 8.9, -1)">right 6</button> | |
<button onclick="mySource2.setPosition(0.9, 8.9, 0)">right 7</button> | |
<button onclick="mySource2.setPosition(0, 8.9, 0)">right 8</button> | |
</div> | |
<script type="text/javascript" src="http://rawgit.com/google/songbird/master/build/songbird.js"></script> | |
<script> | |
let mySource, mySource2; | |
function play(audioSource) { | |
let audioContext = new AudioContext(); | |
// Create a (1st-order Ambisonic) Songbird scene. | |
let songbird = new Songbird(audioContext); | |
// Send songbird's binaural output to stereo out. | |
songbird.output.connect(audioContext.destination); | |
// Set room acoustics properties. | |
let dimensions = { | |
width : 4, | |
height : 2.5, | |
depth : 3 | |
}; | |
let materials = { | |
left : 'plaster-rough', | |
right : 'plaster-rough', | |
front : 'plaster-rough', | |
back : 'plaster-rough', | |
down : 'plywood-panel', | |
up : 'plaster-rough' | |
}; | |
songbird.setRoomProperties(dimensions, materials); | |
// Create an audio element. Feed into audio graph. | |
let audioElement = document.createElement('audio'); | |
audioElement.src = audioSource; | |
let audioElementSource = | |
audioContext.createMediaElementSource(audioElement); | |
// Create a Source, connect desired audio input to it. | |
let source = songbird.createSource(); | |
audioElementSource.connect(source.input); | |
// The source position is relative to the origin | |
// (center of the room). | |
source.setPosition(0.0, 8.9, 0); | |
// Playback the audio. | |
audioElement.play(); | |
audioElement.loop = true; | |
return source; | |
} | |
function playSong1() { | |
mySource = play('http://localhost:9000/song1.mp3') | |
} | |
function playSong2() { | |
mySource2 = play('http://localhost:9000/song2.mp3') | |
} | |
</script> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment