Update index.html
Browse files- index.html +60 -5
index.html
CHANGED
@@ -1279,17 +1279,72 @@ document.getElementById('sw-register-btn').addEventListener('click', registerSer
|
|
1279 |
combinedAudioSource.stop();
|
1280 |
}
|
1281 |
|
1282 |
-
|
1283 |
-
|
1284 |
-
|
1285 |
-
|
1286 |
-
|
|
|
|
|
|
|
1287 |
|
1288 |
// γΊγ¬θ¨ι²γγͺγ»γγ
|
1289 |
syncDriftLog = [];
|
1290 |
lastSyncTime = performance.now();
|
1291 |
}
|
1292 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1293 |
// ι³ε£°γγ‘γ€γ«γγγΌγ
|
1294 |
function loadAudioFiles() {
|
1295 |
audioFiles.forEach(file => {
|
|
|
1279 |
combinedAudioSource.stop();
|
1280 |
}
|
1281 |
|
1282 |
+
// ζ°γγ audio θ¦η΄ γδ½ζ
|
1283 |
+
const combinedAudioElement = document.createElement('audio');
|
1284 |
+
combinedAudioElement.src = URL.createObjectURL(bufferToWave(combinedAudioBuffer));
|
1285 |
+
combinedAudioElement.preservesPitch = true; // γγγγηΆζ
|
1286 |
+
combinedAudioElement.playbackRate = currentPlaybackRate;
|
1287 |
+
combinedAudioElement.currentTime = currentTime;
|
1288 |
+
combinedAudioElement.play();
|
1289 |
+
|
1290 |
|
1291 |
// γΊγ¬θ¨ι²γγͺγ»γγ
|
1292 |
syncDriftLog = [];
|
1293 |
lastSyncTime = performance.now();
|
1294 |
}
|
1295 |
|
1296 |
+
function bufferToWave(abuffer) {
|
1297 |
+
const numOfChan = abuffer.numberOfChannels,
|
1298 |
+
length = abuffer.length * numOfChan * 2 + 44,
|
1299 |
+
buffer = new ArrayBuffer(length),
|
1300 |
+
view = new DataView(buffer),
|
1301 |
+
channels = [],
|
1302 |
+
sampleRate = abuffer.sampleRate,
|
1303 |
+
offset = 0,
|
1304 |
+
pos = 0;
|
1305 |
+
|
1306 |
+
// write WAV header
|
1307 |
+
setUint32(0x46464952); // "RIFF"
|
1308 |
+
setUint32(length - 8); // file length - 8
|
1309 |
+
setUint32(0x45564157); // "WAVE"
|
1310 |
+
|
1311 |
+
setUint32(0x20746d66); // "fmt " chunk
|
1312 |
+
setUint32(16); // length = 16
|
1313 |
+
setUint16(1); // PCM (uncompressed)
|
1314 |
+
setUint16(numOfChan);
|
1315 |
+
setUint32(sampleRate);
|
1316 |
+
setUint32(sampleRate * 2 * numOfChan);
|
1317 |
+
setUint16(numOfChan * 2);
|
1318 |
+
setUint16(16);
|
1319 |
+
|
1320 |
+
setUint32(0x61746164); // "data" - chunk
|
1321 |
+
setUint32(length - pos - 4);
|
1322 |
+
|
1323 |
+
// write interleaved data
|
1324 |
+
for (let i = 0; i < abuffer.length; i++) {
|
1325 |
+
for (let channel = 0; channel < numOfChan; channel++) {
|
1326 |
+
let sample = abuffer.getChannelData(channel)[i] * 0x7fff;
|
1327 |
+
if (sample < -32768) sample = -32768;
|
1328 |
+
if (sample > 32767) sample = 32767;
|
1329 |
+
view.setInt16(pos, sample, true);
|
1330 |
+
pos += 2;
|
1331 |
+
}
|
1332 |
+
}
|
1333 |
+
|
1334 |
+
function setUint16(data) {
|
1335 |
+
view.setUint16(pos, data, true);
|
1336 |
+
pos += 2;
|
1337 |
+
}
|
1338 |
+
|
1339 |
+
function setUint32(data) {
|
1340 |
+
view.setUint32(pos, data, true);
|
1341 |
+
pos += 4;
|
1342 |
+
}
|
1343 |
+
|
1344 |
+
return new Blob([buffer], { type: 'audio/wav' });
|
1345 |
+
}
|
1346 |
+
|
1347 |
+
|
1348 |
// ι³ε£°γγ‘γ€γ«γγγΌγ
|
1349 |
function loadAudioFiles() {
|
1350 |
audioFiles.forEach(file => {
|