-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
95 lines (79 loc) · 2.1 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
var SoundSceneManager = require('./index.js');
var Looper = require('soundmodels/models/Looper');
window.AudioContext = window.AudioContext || window.webkitAudioContext;
var context = new AudioContext();
var toLoad = 0;
function loadManager(callback){
toLoad++;
var onload = function(){
toLoad--;
if (typeof callback === 'function'){
callback();
}
if (toLoad === 0){
if (typeof onLoadAll === 'function'){
onLoadAll();
}
}
};
return onload;
}
var oceanBgSound = new Looper(context, 'https://dl.dropboxusercontent.com/u/77191118/sounds/Ocean_Amb_V2.mp3', null, loadManager());
var diverSound = new Looper(context, 'https://dl.dropboxusercontent.com/u/77191118/sounds/Diver_V2.mp3', null, loadManager());
var kitchenSound = new Looper(context, 'https://dl.dropboxusercontent.com/u/77191118/sounds/restaurent.wav', null, loadManager());
var clubSound = new Audio('https://dl.dropboxusercontent.com/u/77191118/sounds/jazz.wav');
clubSound.loop = true;
var options ={
scenes:[{
name:"ocean",
sounds:[{
name:"background",
node: oceanBgSound,
},{
name:"diver",
node: diverSound,
}]
},{
name:"city",
sounds:[{
name:"club",
node: clubSound,
},{
name:"kitchen",
node: kitchenSound,
}]
}],
fadeDuration: 1,
startingScene: "ocean",
fadeInAtStart: true,
fadeInAtStartDuration: 5,
context: context
};
var nextButton ;
var prevButton ;
var muteButton ;
var sceneSpan;
window.addEventListener('load', function(){
nextButton = document.getElementById('next');
prevButton = document.getElementById('prev');
muteButton = document.getElementById('mute');
sceneSpan = document.getElementById('scene');
});
function onLoadAll(){
var ssm = new SoundSceneManager(options);
window.ssm = ssm;
console.log('starting SSM ', context.currentTime);
oceanBgSound.play();
diverSound.play();
// kitchenSound.play();
clubSound.play();
nextButton.addEventListener('click', function(){
ssm.transitionToNextScene();
});
prevButton.addEventListener('click', function(){
ssm.transitionToPrevScene();
});
muteButton.addEventListener('click', function(){
ssm.toggleMute();
});
}