這與數據的格式有關。 ArrayBuffer用於存儲原始字節。 這個問題是關於WAV format
的44個字節是頭看起來像這樣:
writeUTFBytes(view, 0, 'RIFF'); //Magic word identifying the stream (4 bytes)
view.setUint32(4, 44 + interleaved.length * 2, true); //Size of stream in bytes (4 bytes)
writeUTFBytes(view, 8, 'WAVE'); //Another magic word (4 bytes)
// FMT sub-chunk
writeUTFBytes(view, 12, 'fmt '); //format header (4bytes)
view.setUint32(16, 16, true); //4 bytes size of format (16 bytes)
view.setUint16(20, 1, true); //2 bytes audio format
// stereo (2 channels)
view.setUint16(22, 2, true); //2 bytes apparently number of channels
view.setUint32(24, 44100, true); //4 bytes sample rate
view.setUint32(28, 44100 * 4, true); //4 bytes byte rate
view.setUint16(32, 4, true); //2 bytes block align
view.setUint16(34, 16, true); //2 bytes bits per sample
// data sub-chunk
writeUTFBytes(view, 36, 'data'); //'data' == 4 bytes
view.setUint32(40, interleaved.length * 2, true);
然後我們來這是interleaved.length Int16的是每個項目2個字節的實際數據。
// write the PCM samples
var lng = interleaved.length;
var index = 44;
var volume = 1;
for (var i = 0; i < lng; i++){
view.setInt16(index, interleaved[i] * (0x7FFF * volume), true);
index += 2;
}
謝謝你有幫助(0x7FFF *音量)?這是什麼意思? – user3789242
您應該將問題標記爲WAV格式。 0x7FFFF是2^15-1。 這是交錯數據的位操作,可能會增加音量..我猜這是一個固定點的數學技巧,以避免使用浮點數學 – odedsh
我一直在試圖尋找一個網站,詳細描述的描述這個代碼,但我找不到,如果你可以幫助我的任何,例如什麼功能合併和交錯? – user3789242