Esempio n. 1
0
    def sync_bitstream(self, bitstream):
        log.debug("start sync bitstream at wave pos: %s" % bitstream.pformat_pos())
        bitstream.sync(32) # Sync bitstream to wave sinus cycle

#         test_bitstream = list(itertools.islice(bitstream, 258 * 8))
#         print_bitlist(test_bitstream)

        log.debug("Searching for lead-in byte at wave pos: %s" % bitstream.pformat_pos())

        # Searching for lead-in byte
        lead_in_pattern = list(codepoints2bitstream(self.cfg.LEAD_BYTE_CODEPOINT))
        max_pos = self.cfg.LEAD_BYTE_LEN * 8
        try:
            leader_pos = find_iter_window(bitstream, lead_in_pattern, max_pos)
        except MaxPosArraived, err:
            log.error("Error: Leader-Byte '%s' (%s) not found in the first %i Bytes! (%s)" % (
                list2str(lead_in_pattern), hex(self.cfg.LEAD_BYTE_CODEPOINT),
                self.cfg.LEAD_BYTE_LEN, err
            ))
Esempio n. 2
0
    def write_codepoint(self, codepoints):
        written_codepoints = []
        bits = []
        for bit in codepoints2bitstream(codepoints):
            bits.append(bit)
            if len(bits) == 8:
                written_codepoints.append(bits2codepoint(bits))
                bits = []
                
            if bit == 0:
#                 wavefile.writeframes(self.bit_nul_samples)
                self.wavefile.writeframes(self.bit_nul_samples)
            elif bit == 1:
#                 wavefile.writeframes(self.bit_one_samples)
                self.wavefile.writeframes(self.bit_one_samples)
            else:
                raise TypeError
        log.debug("Written at %s: %s" % (
            self.pformat_pos(), ",".join([hex(x) for x in written_codepoints])
        ))
Esempio n. 3
0
    def sync_bitstream(self, bitstream):
        log.debug("start sync bitstream at wave pos: %s" %
                  bitstream.pformat_pos())
        bitstream.sync(32)  # Sync bitstream to wave sinus cycle

        #         test_bitstream = list(itertools.islice(bitstream, 258 * 8))
        #         print_bitlist(test_bitstream)

        log.debug("Searching for lead-in byte at wave pos: %s" %
                  bitstream.pformat_pos())

        # Searching for lead-in byte
        lead_in_pattern = list(
            codepoints2bitstream(self.cfg.LEAD_BYTE_CODEPOINT))
        max_pos = self.cfg.LEAD_BYTE_LEN * 8
        try:
            leader_pos = find_iter_window(bitstream, lead_in_pattern, max_pos)
        except MaxPosArraived, err:
            log.error(
                "Error: Leader-Byte '%s' (%s) not found in the first %i Bytes! (%s)"
                %
                (list2str(lead_in_pattern), hex(self.cfg.LEAD_BYTE_CODEPOINT),
                 self.cfg.LEAD_BYTE_LEN, err))
Esempio n. 4
0
                self.cfg.LEAD_BYTE_LEN, err
            ))
        except PatternNotFound, err:
            log.error("Error: Leader-Byte '%s' (%s) doesn't exist in bitstream! (%s)" % (
                list2str(lead_in_pattern), hex(self.cfg.LEAD_BYTE_CODEPOINT), err
            ))
        else:
            log.info("Leader-Byte '%s' (%s) found at %i Bytes (wave pos: %s)" % (
                list2str(lead_in_pattern), hex(self.cfg.LEAD_BYTE_CODEPOINT),
                leader_pos, bitstream.pformat_pos()
            ))

        log.debug("Search for sync-byte at wave pos: %s" % bitstream.pformat_pos())

        # Search for sync-byte
        sync_pattern = list(codepoints2bitstream(self.cfg.SYNC_BYTE_CODEPOINT))
        max_search_bits = self.cfg.MAX_SYNC_BYTE_SEARCH * 8
        try:
            sync_pos = find_iter_window(bitstream, sync_pattern, max_search_bits)
        except MaxPosArraived, err:
            raise SyncByteNotFoundError(
                "Error: Sync-Byte '%s' (%s) not found in the first %i Bytes! (%s)" % (
                    list2str(sync_pattern), hex(self.cfg.SYNC_BYTE_CODEPOINT),
                    self.cfg.MAX_SYNC_BYTE_SEARCH, err
                )
            )
        except PatternNotFound, err:
            raise SyncByteNotFoundError(
                "Error: Sync-Byte '%s' (%s) doesn't exist in bitstream! (%s)" % (
                    list2str(sync_pattern), hex(self.cfg.SYNC_BYTE_CODEPOINT),
                    err
Esempio n. 5
0
        except PatternNotFound, err:
            log.error(
                "Error: Leader-Byte '%s' (%s) doesn't exist in bitstream! (%s)"
                % (list2str(lead_in_pattern), hex(
                    self.cfg.LEAD_BYTE_CODEPOINT), err))
        else:
            log.info(
                "Leader-Byte '%s' (%s) found at %i Bytes (wave pos: %s)" %
                (list2str(lead_in_pattern), hex(self.cfg.LEAD_BYTE_CODEPOINT),
                 leader_pos, bitstream.pformat_pos()))

        log.debug("Search for sync-byte at wave pos: %s" %
                  bitstream.pformat_pos())

        # Search for sync-byte
        sync_pattern = list(codepoints2bitstream(self.cfg.SYNC_BYTE_CODEPOINT))
        max_search_bits = self.cfg.MAX_SYNC_BYTE_SEARCH * 8
        try:
            sync_pos = find_iter_window(bitstream, sync_pattern,
                                        max_search_bits)
        except MaxPosArraived, err:
            raise SyncByteNotFoundError(
                "Error: Sync-Byte '%s' (%s) not found in the first %i Bytes! (%s)"
                % (list2str(sync_pattern), hex(self.cfg.SYNC_BYTE_CODEPOINT),
                   self.cfg.MAX_SYNC_BYTE_SEARCH, err))
        except PatternNotFound, err:
            raise SyncByteNotFoundError(
                "Error: Sync-Byte '%s' (%s) doesn't exist in bitstream! (%s)" %
                (list2str(sync_pattern), hex(
                    self.cfg.SYNC_BYTE_CODEPOINT), err))
        else: