soiz1 commited on
Commit
5cf1daf
·
1 Parent(s): c7e0a7f

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +46 -45
index.html CHANGED
@@ -1191,57 +1191,58 @@ video.webkitPreservesPitch = true; // 古いWebKit用
1191
  }
1192
  }
1193
 
1194
- function bufferToWave(abuffer) {
1195
- const numOfChan = abuffer.numberOfChannels,
1196
- length = abuffer.length * numOfChan * 2 + 44,
1197
- buffer = new ArrayBuffer(length),
1198
- view = new DataView(buffer),
1199
- channels = [],
1200
- sampleRate = abuffer.sampleRate,
1201
- offset = 0,
1202
- pos = 0;
1203
-
1204
- // write WAV header
1205
- setUint32(0x46464952); // "RIFF"
1206
- setUint32(length - 8); // file length - 8
1207
- setUint32(0x45564157); // "WAVE"
1208
-
1209
- setUint32(0x20746d66); // "fmt " chunk
1210
- setUint32(16); // length = 16
1211
- setUint16(1); // PCM (uncompressed)
1212
- setUint16(numOfChan);
1213
- setUint32(sampleRate);
1214
- setUint32(sampleRate * 2 * numOfChan);
1215
- setUint16(numOfChan * 2);
1216
- setUint16(16);
1217
-
1218
- setUint32(0x61746164); // "data" - chunk
1219
- setUint32(length - pos - 4);
1220
-
1221
- // write interleaved data
1222
- for (let i = 0; i < abuffer.length; i++) {
1223
- for (let channel = 0; channel < numOfChan; channel++) {
1224
- let sample = abuffer.getChannelData(channel)[i] * 0x7fff;
1225
- if (sample < -32768) sample = -32768;
1226
- if (sample > 32767) sample = 32767;
1227
- view.setInt16(pos, sample, true);
1228
- pos += 2;
1229
- }
1230
- }
1231
-
1232
- function setUint16(data) {
1233
- view.setUint16(pos, data, true);
1234
  pos += 2;
1235
  }
 
1236
 
1237
- function setUint32(data) {
1238
- view.setUint32(pos, data, true);
1239
- pos += 4;
1240
- }
1241
 
1242
- return new Blob([buffer], { type: 'audio/wav' });
 
 
1243
  }
1244
 
 
 
 
1245
  function applyVolume() {
1246
  if (!isAudioCombined) return;
1247
 
 
1191
  }
1192
  }
1193
 
1194
+ function bufferToWave(abuffer) {
1195
+ const numOfChan = abuffer.numberOfChannels,
1196
+ length = abuffer.length * numOfChan * 2 + 44,
1197
+ buffer = new ArrayBuffer(length),
1198
+ view = new DataView(buffer),
1199
+ channels = [],
1200
+ sampleRate = abuffer.sampleRate;
1201
+
1202
+ // posをletで宣言(constから変更)
1203
+ let pos = 0;
1204
+
1205
+ // write WAV header
1206
+ setUint32(0x46464952); // "RIFF"
1207
+ setUint32(length - 8); // file length - 8
1208
+ setUint32(0x45564157); // "WAVE"
1209
+
1210
+ setUint32(0x20746d66); // "fmt " chunk
1211
+ setUint32(16); // length = 16
1212
+ setUint16(1); // PCM (uncompressed)
1213
+ setUint16(numOfChan);
1214
+ setUint32(sampleRate);
1215
+ setUint32(sampleRate * 2 * numOfChan);
1216
+ setUint16(numOfChan * 2);
1217
+ setUint16(16);
1218
+
1219
+ setUint32(0x61746164); // "data" - chunk
1220
+ setUint32(length - pos - 4);
1221
+
1222
+ // write interleaved data
1223
+ for (let i = 0; i < abuffer.length; i++) {
1224
+ for (let channel = 0; channel < numOfChan; channel++) {
1225
+ let sample = abuffer.getChannelData(channel)[i] * 0x7fff;
1226
+ if (sample < -32768) sample = -32768;
1227
+ if (sample > 32767) sample = 32767;
1228
+ view.setInt16(pos, sample, true);
 
 
 
 
 
1229
  pos += 2;
1230
  }
1231
+ }
1232
 
1233
+ function setUint16(data) {
1234
+ view.setUint16(pos, data, true);
1235
+ pos += 2;
1236
+ }
1237
 
1238
+ function setUint32(data) {
1239
+ view.setUint32(pos, data, true);
1240
+ pos += 4;
1241
  }
1242
 
1243
+ return new Blob([buffer], { type: 'audio/wav' });
1244
+ }
1245
+
1246
  function applyVolume() {
1247
  if (!isAudioCombined) return;
1248