def remove_unsynchronization(data):
    """Remove ID3v2 unsynchronization scheme from data."""
    sync_index = data.find(b'\xff')
    if sync_index == -1:
        return data
    data = bytearray(data)
    d = bytearray()
    while sync_index != -1:
        d += data[:sync_index]
        if data[sync_index + 1:sync_index + 3] == b'\x00\x00':
            d += b'\xff\x00'
            data = data[sync_index + 3:]
        elif data[sync_index + 1:sync_index + 2] == b'\x00':
            d += b'\xff'
            data = data[sync_index + 2:]
        else:
            d += b'\xff'
            data = data[sync_index + 1:]
        sync_index = data.find(b'\xff')
    d += data
    return bytes(d)
