in reply to Re^11: pack/unpack binary editing
in thread pack/unpack binary editing

OK, that piece of code worked perfect. However, now when I look at the file the first frame is on synce but the rest are off by a few bits. I believe this to be because when we remove the bits prior to the sync and then pack it up the frame is no longer on a byte boundary. This is the problem I've been dealing with. If I remove a couple bits from the beginning then when I pack it up the files being padded to place it back on a byte boundary. I'm starting to think I'm going to have to just suck it up and either deal with the slowness or get a C programmer to do it. Any thoughts??

Replies are listed 'Best First'.
Re^13: pack/unpack binary editing
by BrowserUk (Patriarch) on Feb 10, 2005 at 18:05 UTC
    ... the rest are off by a few bits.

    The only way that can be true, is if

  • the sync mark itself is not meant to be on a byte boundary.

    Ie. If it is meant be a few bits into each frame?

    This is possible and easily dealt with.

  • Or the frames are themselves are "a few bits" longer than 960 bytes, which doesn't makes much sense.

    Could you unpack the first 3 or 4 frames of the (raw) file to binascii and post them on your scratchpad?


    Examine what is said, not who speaks.
    Silence betokens consent.
    Love the truth but pardon error.
      Sorry, the company would frown upon that. I think my problem is that I'm reading in the equivalent of 2 frames but have to discard so many bits to get to the sync. afterwhich I no longer have a frame left that's on a byte boundary. This is why I am currently writting the ascii-ized binary out to a file then reopening and going though the file to pack it back. I forgot I had changed that part of the code.

        If you are only discarding from the first (double) record, then if the original file is sync'd, the resultant file will be:

        Read |------------|------------|------------|------------|---| --------------------------------------------------------- ....|s 7680 bits |s 7680 bits |s 7680 bits |s 7680 bits | --------------------------------------------------------- write <<<<|s-------|----s-------|----s-------|----s-------|---| |s-------|----s-------|----s-------|----s-------|---| ----------------------------------------------------- |s 7680 bits |s 7680 bits |s 7680 bits |s 7680 bits | -----------------------------------------------------

        Anyway, good luck.


        Examine what is said, not who speaks.
        Silence betokens consent.
        Love the truth but pardon error.