Skip to content

Commit

Permalink
Compute AccurateRip v2 checksum instead of v1
Browse files Browse the repository at this point in the history
Import hcs64/morituri@498d2ba.

Issue thomasvs/morituri#119.

Test branch in which AccurateRip v1 support is dropped in favor of
AccurateRip v2.
  • Loading branch information
JoeLametta committed Apr 13, 2015
1 parent e10f37d commit e63b877
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions morituri/common/checksum.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,9 @@ def do_checksum_buffer(self, buf, checksum):
# ... on 5th frame, only use last value
elif self._discFrameCounter == 5:
values = struct.unpack("<I", buf[-4:])
checksum += common.SAMPLES_PER_FRAME * 5 * values[0]
mvalue = common.SAMPLES_PER_FRAME * 5 * values[0]
(hi, lo) = divmod(mvalue, 2 ** 32)
checksum += lo + hi
checksum &= 0xFFFFFFFF
return checksum

Expand All @@ -311,18 +313,18 @@ def do_checksum_buffer(self, buf, checksum):
self.debug('skipping frame %d', self._discFrameCounter)
return checksum

# self._bytes is updated after do_checksum_buffer
factor = self._bytes / 4 + 1
values = struct.unpack("<%dI" % (len(buf) / 4), buf)
for value in values:
checksum += factor * value
factor += 1
for i, value in enumerate(values):
# self._bytes is updated after do_checksum_buffer
mvalue = (self._bytes / 4 + i + 1) * value
(hi, lo) = divmod(mvalue, 2 ** 32)
checksum += lo + hi
checksum &= 0xFFFFFFFF
# offset = self._bytes / 4 + i + 1
# if offset % common.SAMPLES_PER_FRAME == 0:
# print 'frame %d, ends before %d, last value %08x, CRC %08x' % (
# offset / common.SAMPLES_PER_FRAME, offset, value, sum)

checksum &= 0xFFFFFFFF
return checksum


Expand Down

0 comments on commit e63b877

Please sign in to comment.