code: def sync(self, length):
          
  
          # go in wave stream to the first bit
          try:
              self.next()
          except StopIteration:
              print "Error: no bits identified!"
              sys.exit(-1)
  
          log.info("First bit is at: %s" % self.pformat_pos())
          log.debug("enable half sinus scan")
          self.half_sinus = True
  
          # Toggle sync test by consuming one half sinus sample
  #         self.iter_trigger_generator.next() # Test sync
  
          # get "half sinus cycle" test data
          test_durations = itertools.islice(self.iter_duration_generator, length)
          # It's a tuple like: [(frame_no, duration)...]
  
          test_durations = list(test_durations)
  
          diff1, diff2 = diff_info(test_durations)
          log.debug("sync diff info: %i vs. %i" % (diff1, diff2))
  
          if diff1 > diff2:
              log.info("\nbit-sync one step.")
              self.iter_trigger_generator.next()
              log.debug("Synced.")
          else:
              log.info("\nNo bit-sync needed.")
  
          self.half_sinus = False
          log.debug("disable half sinus scan")
docs: synchronized weave sync trigger