我可以成功創建一個16位的wav文件,但是當創建一個24位文件時,我聽到的只是白噪聲。我正在設置24位有符號整數數據塊。我是否必須在wav文件頭的字節20中設置一些特殊的音頻格式?我目前使用的格式1.有什麼特別的我可以創建一個24位WAV文件?
編輯#1
的wBitsPerSample
字段設置爲24。wAvgBytesPerSec
(字節速率)字段設置爲
// 44100 * (2 * 3)
sampleRate * blockAlign
和wBlockAlign
設置到
// 2 * 3
numChannels * bytesPerSampe
假設你人準備好了,數據本身需要是24位對接(需要位移和掩碼,除非數據已經來自24位字節源)。或換句話說:每個樣本需要3個字節。和16位字節順序一樣重要。
雖然我不知道我是否有這部分權利。
我的數據來自Float32,從-1到1(AudioBuffer.getChannelData()
)。我然後將其轉換爲INT24:
function floatTo24BitPCM(output, offset, input) {
for (var i = 0; i < input.length; i++, offset += 3) {
var s = Math.floor(input[i] * 8388608 + 0.5)
output.setInt24(offset, s, true)
}
}
和
DataView.prototype.setInt24 = function(pos, val, littleEndian) {
this.setInt16(pos, val >> 8, littleEndian);
this.setInt8(pos+2, val & ~4294967040, littleEndian); // this "magic number" masks off the first 16 bits
}
,這個流程是否尊重規範(它好像我DOIT位移位和setInt24
屏蔽)?
編輯#2
修改
DataView.prototype.setInt24 = function(pos, val, littleEndian) {
this.setInt16(pos, val >> 8, littleEndian);
this.setInt8(pos+2, val & ~4294967040, littleEndian); // this "magic number" masks off the first 16 bits
}
到
DataView.prototype.setUint24 = function(pos, val, littleEndian) {
this.setUint8(pos, val & ~4294967040, littleEndian); // this "magic number" masks off the first 16 bits
this.setUint16(pos + 1, val >> 8, littleEndian);
}
的伎倆。我假設字節順序不正確?我很困惑,爲什麼把最後一個字節放在前兩個字節之前是正確的順序。
我還建議這個問題重新開放,因爲它已經足夠窄而不再被視爲「廣泛」。
你可以發佈一些代碼來幫助我們找出你錯誤的地方嗎? – bejado
請看我編輯的相關代碼。 – maximedupre