-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.html
136 lines (106 loc) · 3.45 KB
/
test.html
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<!-- For testing/creating new nodes interface separately -->
<!DOCTYPE html><html><head>
<title>Test</title>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/scarletsframe.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/lodash.min.js"></script>
<script src="/dist/engine.min.js?1590401976888"></script>
<script type="text/javascript">
$ = sf.dom;
</script>
<script type="text/javascript" src='https://cdn.jsdelivr.net/npm/sfmediastream@latest'></script>
<link href="/dist/blackprint.min.css?1590384721993">
<script src="/dist/blackprint.html.js?1590383005665"></script>
<script src="/dist/blackprint.min.js?1590401847902"></script>
</head><body style="background-color:#232323">
<!-- Component that will be handled on script -->
<comp-test>
{{henlo}}
</comp-test>
<audio src="http://localhost/kizuna-ai/perfecthuh.m4a?1" controls crossorigin></audio>
<canvas id="canvas"></canvas>
<!-- Declare your script here -->
<script type="text/javascript">
sf.component('comp-test', function(self){
self.henlo = 'henlo';
});
</script>
<script type="text/javascript">
var audioCtx = ScarletsMedia.audioContext;
var el = document.querySelector('audio');
var source = audioCtx.createMediaElementSource(el);
const dpr = window.devicePixelRatio || 1;
var WIDTH = canvas.width = canvas.offsetWidth =
1024 * dpr;
var HEIGHT = canvas.height = canvas.offsetHeight =
200 * dpr;
var options = {audio:{channelCount:1, echoCancellation:false}};
navigator.mediaDevices.getUserMedia(options).then(function(mediaStream){
var mic = audioCtx.createMediaStreamSource(mediaStream);
mic.connect(pitchShift.input);
});
const ctx = canvas.getContext("2d");
ctx.scale(dpr, dpr);
// ctx.translate(0, HEIGHT);
ctx.lineWidth = 1;
function drawLineSegment(x, y, flip){
ctx.beginPath();
if(flip){
ctx.moveTo(x+2, HEIGHT);
ctx.lineTo(x+2, HEIGHT-y);
}
else{
ctx.moveTo(x+2, 0);
ctx.lineTo(x+2, y);
}
ctx.stroke();
};
el.playbackRate = 0.07;
document.addEventListener('click', function(){
el.currentTime = 0.602616;
// el.play();
});
var analyser = audioCtx.createAnalyser();
var analyser2 = audioCtx.createAnalyser();
analyser2.minDecibels = analyser.minDecibels = -90;
analyser2.maxDecibels = analyser.maxDecibels = -0;
source.connect(analyser);
source.connect(audioCtx.destination);
var pitchShift = ScarletsMediaEffect.pitchShift();
// pitchShift.shift(3);
//source.connect(pitchShift.input);
pitchShift.output.connect(audioCtx.destination);
pitchShift.output.connect(analyser2);
analyser.fftSize = analyser2.fftSize = 2048;
var bufferLength = analyser.frequencyBinCount;
var dataArray = new Uint8Array(bufferLength);
var dataArray2 = new Uint8Array(bufferLength);
el.onplay = function(){
//requestAnimationFrame(draw);
}
requestAnimationFrame(draw);
function draw() {
if(!el.paused)
analyser.getByteFrequencyData(dataArray);
ctx.clearRect(0, 0, WIDTH, HEIGHT);
// Pure (Blue)
ctx.strokeStyle = "#0000ffa6";
for(var i = 0; i < bufferLength; i++) {
var v = dataArray[i] / 128.0;
var y = v * HEIGHT/2;
drawLineSegment(i, y);
}
analyser2.getByteFrequencyData(dataArray2);
// Modified (Red)
ctx.strokeStyle = "#ff0b0ba6";
for(var i = 0; i < bufferLength; i++) {
var v = dataArray2[i] / 128.0;
var y = v * HEIGHT/2;
drawLineSegment(i, y, true);
}
requestAnimationFrame(draw);
}
</script>
<!-- Component that will be handled on script -->
<style type="text/scss">
</style>
</body></html>