-
Notifications
You must be signed in to change notification settings - Fork 7
/
demo.js
97 lines (80 loc) · 3.31 KB
/
demo.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
93
94
95
96
97
var selected_level;
var selected_type;
var selected_processing;
var noise_level_id=-1;
var noise_type_id=-1;
var noise_processing_id=-1;
var music_pos = -1;
var noise_levels = ["0dB", "5dB", "10dB", "15dB", "20dB", "clean"];
var noise_types = ["babble_", "car_", "street_"];
var noise_processings = ["", "rnnoise_", "speexdsp_"];
function updateMusicClip() {
if (noise_level_id==5) document.getElementById("noise_type_selector").classList.add("inactive");
if (noise_level_id!=5) document.getElementById("noise_type_selector").classList.remove("inactive");
var audio = document.getElementById("music_player");
name = "samples/" + noise_processings[noise_processing_id];
if (noise_level_id != 5) name = name + noise_types[noise_type_id];
name = name + noise_levels[noise_level_id];
var extension = "opus";
if (!audio.canPlayType('audio/ogg; codecs="opus"')) extension = "mp3";
/*console.log("extension = " + extension);*/
name = name + "." + extension;
var playing = !(audio.paused);
var position = audio.currentTime;
if (music_pos >= 0)
position = music_pos;
audio.src = name;
audio.addEventListener("loadedmetadata",
function() {
// don't set if zero
if(position>0)
audio.currentTime = position;
if(playing)
audio.play();
this.removeEventListener("loadedmetadata",arguments.callee,true);
}, true);
audio.load();
/*console.log(audio.canPlayType('audio/ogg; codecs="opus"'));
console.log(audio.canPlayType("audio/mpeg;"));
console.log(audio.canPlayType('audio/wav; codecs="1"'));*/
}
function setLevel(level_id, item) {
if (noise_level_id == level_id) return;
noise_level_id = level_id;
if (selected_level) selected_level.classList.remove("selected");
item.classList.add("selected");
selected_level = item;
updateMusicClip();
}
function setType(type_id, item) {
if (noise_type_id == type_id) return;
noise_type_id = type_id;
if (selected_type) selected_type.classList.remove("selected");
item.classList.add("selected");
selected_type = item;
updateMusicClip();
}
function setProcessing(processing_id, item) {
if (noise_processing_id == processing_id) return;
noise_processing_id = processing_id;
if (selected_processing) selected_processing.classList.remove("selected");
item.classList.add("selected");
selected_processing = item;
updateMusicClip();
}
function music_norestart() {
music_pos = -1;
document.getElementById("music_restart_string").innerHTML = "Player will <b>continue</b> when changing sample.";
}
function music_setrestart() {
music_pos = document.getElementById("music_player").currentTime;
document.getElementById("music_restart_string").innerHTML = "Player will <b>restart at " + music_pos.toFixed(2) + " seconds</b> when changing sample.";
}
function init_demo() {
setLevel(3, document.getElementById("default_level"));
setType(0, document.getElementById("default_type"));
setProcessing(0, document.getElementById("default_processing"));
music_norestart();
liveNoise(0, document.getElementById("default_live_noise"));
liveNoiseSuppression(0, document.getElementById("default_live_noise_suppression"));
}