This commit is contained in:
Ryan Oldenburg 2022-05-25 22:22:42 -05:00
parent 583c797b40
commit 8caaca13c0

View file

@ -540,8 +540,8 @@ proc getBits(state: var DecoderState, n: int): int =
if state.bitsBuffered < n: if state.bitsBuffered < n:
state.fillBitBuffer() state.fillBitBuffer()
let k = lrot(state.bitBuffer, n) let k = lrot(state.bitBuffer, n)
state.bitBuffer = k and (not bitMasks[n])
result = (k and bitMasks[n]).int result = (k and bitMasks[n]).int
state.bitBuffer = k and (not bitMasks[n])
state.bitsBuffered -= n state.bitsBuffered -= n
proc getBitsAsSignedInt(state: var DecoderState, n: int): int = proc getBitsAsSignedInt(state: var DecoderState, n: int): int =
@ -551,12 +551,12 @@ proc getBitsAsSignedInt(state: var DecoderState, n: int): int =
failInvalid() failInvalid()
if state.bitsBuffered < n: if state.bitsBuffered < n:
state.fillBitBuffer() state.fillBitBuffer()
let sign = cast[int32](state.bitBuffer) shr 31 let
var k = lrot(state.bitBuffer, n) sign = cast[int32](state.bitBuffer) shr 31 # Sign is always in MSB
k = lrot(state.bitBuffer, n)
result = (k and bitMasks[n]).int + (biases[n] and (not sign))
state.bitBuffer = k and (not bitMasks[n]) state.bitBuffer = k and (not bitMasks[n])
k = k and bitMasks[n]
state.bitsBuffered -= n state.bitsBuffered -= n
result = k.int + (biases[n] and (not sign))
proc decodeRegularBlock( proc decodeRegularBlock(
state: var DecoderState, component: int, data: var array[64, int16] state: var DecoderState, component: int, data: var array[64, int16]