-
Notifications
You must be signed in to change notification settings - Fork 1
/
artist.html
245 lines (196 loc) · 7.45 KB
/
artist.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://unpkg.com/[email protected]/dist/boxicons.js"></script>
<link rel="stylesheet" href="./assets/css/style.css">
<script src="https://kit.fontawesome.com/860e7596f3.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.10.4/gsap.min.js"></script>
<title>Musichain</title>
</head>
<body>
<!-- <input type="file" id="file-input">
<button id="upload-button">Upload</button> -->
<div >
<link rel="stylesheet" href="artist.css">
<div class="center2">
<div class="title2" >
<h1 style="color: white;"><strong>Compare Music Album</strong></h1>
</div>
<!-- <div class="dropzone">
<input type="file" class="upload-input" id="file-input" name="audio" accept="audio/*">
</div> -->
<!-- <div class="title">
<h1>Drop file to upload</h1>
<button id="upload-button" class="btn2" name="uploadbutton" >Upload</button>
</div> -->
<!-- <div class="title">
<input type="file" id="file1">
</div>
<div class="title">
</div> -->
<input type="file" id="file1">
<input type="file" id="file2">
<script>
function compare() {
var file1 = document.getElementById("file1").files[0];
var file2 = document.getElementById("file2").files[0];
if (file1 && file2) {
var reader1 = new FileReader();
var reader2 = new FileReader();
reader1.onload = function(e) {
reader2.onload = function(e) {
var audioCtx = new (window.AudioContext || window.webkitAudioContext)();
audioCtx.decodeAudioData(reader1.result, function(buffer1) {
audioCtx.decodeAudioData(reader2.result, function(buffer2) {
calculateCorrelation(buffer1, buffer2);
});
});
}
reader2.readAsArrayBuffer(file2);
}
reader1.readAsArrayBuffer(file1);
}
}
function calculateCorrelation(buffer1, buffer2) {
var audioCtx = new (window.AudioContext || window.webkitAudioContext)();
var analyser = audioCtx.createAnalyser();
var source1 = audioCtx.createBufferSource();
var source2 = audioCtx.createBufferSource();
source1.buffer = buffer1;
source1.connect(analyser);
source1.start(0);
source2.buffer = buffer2;
source2.connect(analyser);
source2.start(0);
var numBins = analyser.frequencyBinCount;
var fftData1 = new Uint8Array(numBins);
var fftData2 = new Uint8Array(numBins);
var correlation = new Float32Array(numBins);
var maxCorr = -1;
var offset = 0;
var intervalId = setInterval(function() {
analyser.getByteFrequencyData(fftData1);
analyser.getByteFrequencyData(fftData2);
var corr = 0;
for (var j = 0; j < numBins; j++) {
corr += fftData1[j] * fftData2[j];
}
correlation[offset] = corr;
if (corr > maxCorr) {
maxCorr = corr;
}
offset++;
if (offset >= numBins) {
clearInterval(intervalId);
var similarity = maxCorr / (255 * numBins);
console.log("correlation"+correlation);
console.log("similarity"+similarity);
var resultDiv = document.getElementById("result");
resultDiv.innerHTML = "Similarity: " + similarity.toFixed(2);
}
}, 10);
}
</script>
<div class="title">
<h1>Compare Files</h1>
<button class="btn3" onclick="compare()">Compare</button>
</div>
<div class="result">
<!-- <h1 style="color: white;"></h1> -->
<!-- <div style="color: white;" id="result"></div> -->
<div style="border: 0.3px solid rgb(255, 255, 255); padding: 10px;" id="result"></div>
</div>
</div>
<div class="center">
<div>
<h1 style="color: white;"><strong>Upload music as Artist</strong></h1>
</div>
<!-- <div class="title">
<h1>Drop file to upload</h1>
</div> -->
<div class="dropzone">
<img src="http://100dayscss.com/codepen/upload.svg" class="upload-icon" />
<!-- <input type="file" class="upload-input" /> -->
<input type="file" class="upload-input" id="file-input" name="audio" accept="audio/*">
<!-- <button id="upload-button" class="btn" name="uploadbutton">Upload</button> -->
</div>
<div class="title">
<h1>Drop file to upload</h1>
<button id="upload-button" class="btn2" name="uploadbutton" >Upload</button>
</div>
<!-- <button class="btn" id="upload-button" name="uploadbutton"></button> -->
</div>
<div class="audio-container">
<h1>HackMusic</h1>
<div class="audio-img-wrapper">
<div class="audio-img">
<!-- <img id="myImage" src="https://images.unsplash.com/photo-1525362081669-2b476bb628c3?ixlib=rb-1.2.1&raw_url=true&q=80&fm=jpg" alt="" class="img"> -->
<img id="myImage" src="https://images.unsplash.com/photo-1525362081669-2b476bb628c3?ixlib=rb-1.2.1&raw_url=true&q=80&fm=jpg" alt="" class="img">
</div>
<h2 class="audio-title">Title of audio</h2>
<h6 class="audio-singer" id="singerName" >Singer name</h6>
</div>
<div class="audio-progress">
<div class="progress">
<div class="progress-bar"></div>
<div class="progress-head"></div>
</div>
<div class="current-time">00:00</div>
<div class="duration">00:00</div>
</div>
<div class="audio-btns">
<!-- <button class="btn shuffle">
<i class="fa-solid fa-shuffle"></i>
</button> -->
<button class="btn skip-back" onclick="updateSingerName()">
<i class="fa-solid fa-backward-step"></i>
</button>
<button class="btn play">
<span> <i class="fa-solid fa-play"></i> </span>
</button>
<button class="btn skip-forward" onclick="updateSingerName()">
<i class="fa-solid fa-forward-step"></i>
</button>
<!-- <button class="btn repeat">
<i class="fa-solid fa-repeat"></i>
</button> -->
</div>
</div>
</div>
<script src="./assets/js/main.js"></script>
<script type="module">
import { initializeApp } from "https://www.gstatic.com/firebasejs/9.17.1/firebase-app.js";
import { getDatabase, set,ref,get } from "https://www.gstatic.com/firebasejs/9.17.1/firebase-database.js";
import { getAnalytics } from "https://www.gstatic.com/firebasejs/9.17.1/firebase-analytics.js";
import { getAuth, createUserWithEmailAndPassword } from "https://www.gstatic.com/firebasejs/9.17.1/firebase-auth.js";
var firebaseConfig = {
apiKey: "AIzaSyB3ByfKpp3018i60eO1Zvjtcy5ibS6N_q0",
authDomain: "treehack-pro.firebaseapp.com",
projectId: "treehack-pro",
storageBucket: "treehack-pro.appspot.com",
messagingSenderId: "224737491755",
appId: "1:224737491755:web:faed54c98d6b4743b1e36e",
measurementId: "G-JWXCJFMN4X"
};
const app = initializeApp(firebaseConfig);
const database = getDatabase(app);
const auth = getAuth();
auth.onAuthStateChanged(function(user) {
if (user) {
// User is signed in.
var displayName = user.username;
var uid = user.uid;
const userRef = ref(database, 'users/' + uid);
get(userRef).then((snapshot) => {
const userData = snapshot.val();
document.getElementById("singerName").textContent = "Hello " +userData.username;
});
}});
</script>
<!-- original pen: https://codepen.io/roydigerhund/pen/ZQdbeN -->
<!-- NO JS ADDED YET -->
</body>
</html>