// Source code licensed under Apache License 2.0.
// Copyright © 2019 William Ngan. (https://github.com/williamngan/pts)
window.demoDescription = "Frequency domain demo in Sound guide.";
//// Demo code starts (anonymous function wrapper is optional) ---
(function() {
Pts.quickStart( "#pt", "#e2e6ef" );
var files = ["/assets/flute.mp3", "/assets/drum.mp3", "/assets/tambourine.mp3"];
var currFile = 0;
var bins = 32;
var sound;
// Note: use Sound.loadAsBuffer instead if you need support for Safari browser. (as of Apr 2019)
// See this example: https://github.com/williamngan/pts/blob/master/guide/js/examples/sound_frequency.js
function loadSound() {
Sound.load( files[currFile] ).then( s => {
sound = s.analyze(bins).start();
currFile = (currFile + 1) % files.length;
}).catch( e => console.error(e) );
}
function playButton() {
if (!sound || !sound.playing) {
form.fillOnly('rgba(0,0,0,.2)').circle( Circle.fromCenter( space.center, 30 ) );
form.fillOnly('#fff').polygon( Triangle.fromCenter( space.center, 15 ).rotate2D( Const.half_pi, space.center ) );
}
}
space.add({
animate: (time, ftime) => {