JSFiddle - React, Tailwind, and code Playground
Seismic web audio from the IRIS API, mixing both horizontal and vertical channels into a stereo composite
by nathansnider
HTML
<script src="http://www.html5rocks.com/en/tutorials/webaudio/intro/js/buffer-loader.js"></script>
<input type="button" id="playButton" value="">
JavaScript
//web audio BufferLoader for seismic stereo, including vertical component
var network = 'II',
station = 'XPFO',
location = '20',
channel = 'BH',
chL = '1',
chR = '2',
chC = 'Z',
starttime = '2015-09-16T22:50:00',
endtime = '2015-09-17T06:50:00',
centerGain = 0.3; //mix proportion of center-panned vertical component
var context= new AudioContext();
var bufferLoader;
window.onload = init();
window.AudioContext = window.AudioContext || window.webkitAudioContext;
var playButton = document.getElementById("playButton");
function init() {
// Fix up prefixing
bufferLoader = new BufferLoader(
context, [
'http://service.iris.edu/irisws/timeseries/1/query?net=' + network + '&sta=' + station + '&loc=' + location + '&cha=' + channel + chL + '&starttime=' + starttime + '&endtime=' + endtime + '&output=audio&audiosamplerate=44100',
'http://service.iris.edu/irisws/timeseries/1/query?net=' + network + '&sta=' + station + '&loc=' + location + '&cha=' + channel + chR + '&starttime=' + starttime + '&endtime=' + endtime + '&output=audio&audiosamplerate=44100',
'http://service.iris.edu/irisws/timeseries/1/query?net=' + network + '&sta=' + station + '&loc=' + location + '&cha=' + channel + chC + '&starttime=' + starttime + '&endtime=' + endtime + '&output=audio&audiosamplerate=44100'
],
playStereoBuffer
);
bufferLoader.load();
}
function playStereoBuffer(bufferList) {
// create a buffer source for each channel
var sourceL = context.createBufferSource();
var sourceR = context.createBufferSource();
var sourceC = context.createBufferSource();
sourceL.buffer = bufferList[0];
sourceR.buffer = bufferList[1];
sourceC.buffer = bufferList[2];
//merge left and right channels into stereo for playback
var merger = context.createChannelMerger(2);
sourceL.connect(merger, 0, 0);
sourceR.connect(merger, 0, 1);
var gainC = context.createGain();
sourceC.connect(gainC);
var gainLR = context.createGain();
...