Created
December 1, 2012 12:14
-
-
Save tatat/4181927 to your computer and use it in GitHub Desktop.
Uint16で扱ってるサウンドデータをFloat32に変換
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var convert_uint16_to_float32 = function(data_view, little_endian) { | |
var byte_length = data_view.byteLength | |
, result = new DataView(new ArrayBuffer(byte_length * 2)) | |
, converter = new DataView(new ArrayBuffer(2)); | |
little_endian = !! little_endian; | |
for (var i = 0, uint16, int16; i < byte_length; i += 2) { | |
uint16 = data_view.getUint16(i, little_endian); | |
converter.setInt16(0, (uint16 + 0x8000) * 0xFFFF); | |
int16 = converter.getInt16(0); | |
result.setFloat32(i * 2, (int16 + 0.5) / (0x7FFF + 0.5)); | |
} | |
return result; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment