beetbox / pyacoustid

Python bindings for Chromaprint acoustic fingerprinting and the Acoustid Web service
MIT License
330 stars 66 forks source link

decode_fingerprint returns signed integers #72

Closed fvhockney closed 2 years ago

fvhockney commented 2 years ago

When decoding a generated fingerprint with chromaprint.decode_fingerprint(data) the result contains signed integers when chromaprint.h specifies unsigned integers. Running the same song through fpcalc -raw <file> also returns only unsigned integers.

I believe the issue is in chromaprint.py

--SNIP--
_libchromaprint.chromaprint_decode_fingerprint.argtypes = \
    (ctypes.POINTER(ctypes.c_char), ctypes.c_int,
     ctypes.POINTER(ctypes.POINTER(ctypes.c_int32)),
--SNIP--

--SNIP--
def decode_fingerprint(data, base64=True):
    result_ptr = ctypes.POINTER(ctypes.c_int32)()
--SNIP--

they should be

--SNIP--
_libchromaprint.chromaprint_decode_fingerprint.argtypes = \
    (ctypes.POINTER(ctypes.c_char), ctypes.c_int,
     ctypes.POINTER(ctypes.POINTER(ctypes.c_uint32)),
--SNIP--

--SNIP--
def decode_fingerprint(data, base64=True):
    result_ptr = ctypes.POINTER(ctypes.c_uint32)()
--SNIP--

making these changes result in decode_fingerprint and fpcalc returning the same values

Before change:

(621.0, ([908999590, 384710310, 380449462, 397357718, 363147918, 77935242, 77918859, 77642440, 81832728, 74558268, 74558260, 70298404, 70298400, 70292225, 339116739, 339657346, 339362450, 1416254114, 1420448418, 1453947298, 1453881507, 1454926003, 1446520961, 1446783120, 1193027712,1142305216, 1154875968, 1167196704, -980221408, -946854368, ...

After change:

(621.0, ([908999590, 384710310, 380449462, 397357718, 363147918, 77935242, 77918859, 77642440, 81832728, 74558268, 74558260, 70298404, 70298400, 70292225, 339116739, 339657346, 339362450, 1416254114, 1420448418, 1453947298, 1453881507, 1454926003, 1446520961, 1446783120, 1193027712,1142305216, 1154875968, 1167196704, 3314745888, 3348112928,

Output of fpcalc -raw

DURATION=621
FINGERPRINT=908999590,384710310,380449462,397357718,363147918,77935242,77918859,77642440,81832728,74558268,74558260,70298404,70298400,70292225,339116739,339657346,339362450,1416254114,1420448418,1453947298,1453881507,1454926003,1446520961,1446783120,1193027712,1142305216,1154875968,1167196704,3314745888,3348112928, ...
sampsyo commented 2 years ago

Yep; this looks wrong! Thanks for pointing this out! Any chance you could turn your proposed change into a small pull request?

fvhockney commented 2 years ago

Pull request made :-)

sampsyo commented 2 years ago

Fixed in #73.