我正在Squeak的一個小型項目中工作,並遇到了一個問題:無法正確解碼WAV文件。在吱吱聲中對WAV文件進行解碼Smalltalk
這裏有兩種方法,我使用它的那一刻解碼:
convert4bitUnsignedTo16Bit: anArray
"Convert the given array of samples--assumed to be 4-bit unsigned, linear data--into 16-bit signed samples. Return an array containing the resulting samples. I only thinking it is unsigned. I don't really know."
| n samples s |
n _ anArray size.
samples _ SoundBuffer newStereoSampleCount: (n * 2).
1 to: n do: [:i |
s _ anArray at: i.
samples at: (i * 2) put: (self imaDecode: s).
samples at: ((i * 2) - 1) put: (self imaDecode: s)].
^ samples
。
imaDecode: number
| n |
n _ number.
n >= 128 ifTrue: [n _ n - 256].
^ (n) * 16
它給了我一個正確的聲音,如果我仔細聽,我可以聽到原始聲音。但它非常穩定。
我想知道是否有人可以發現我的代碼有什麼問題,並幫助我找出爲什麼聲音如此穩定。 (順便說一下:我會調用採樣方法中的readFrom:
方法的convert4bitUnsignedFrom16Bit:
方法,data
變量作爲參數)。