(self, filename, mode)
Initialise WAV-file.
Initialise WAV-file.
Initialise WAV - file .
def __init__(self, filename, mode):
        """Initialise WAV-file."""
        TapeBitStream.__init__(self)
        self.filename = filename
        if not os.path.exists(filename):
            # create/overwrite file
            self.framerate = 22050
            self.sampwidth = 1
            self.nchannels = 1
            self.wav = io.open(self.filename, 'wb')
            self._write_wav_header()
            self.operating_mode = 'w'
        else:
            # open file for reading and find wave parameters
            try:
                self.wav = io.open(self.filename, 'r+b')
            except EnvironmentError:
                self.wav = io.open(self.filename, 'rb')
            if not self._read_wav_header():
                raise EndOfTape()
            self.operating_mode = 'r'
        self.wav_pos = 0
        self.buf_len = 1024
        # convert 8-bit and 16-bit values to ints
        if self.sampwidth == 1:
            self.sub_threshold = 0
            self.subtractor = 128*self.nchannels
        else:
            self.sub_threshold = 256*self.nchannels//2
            self.subtractor =  256*self.nchannels
        # volume above/below zero that is interpreted as zero
        self.zero_threshold = self.nchannels
        # 1000 us for 1, 500 us for 0; threshold for half-pulse (500 us, 250 us)
        self.halflength = [(250*self.framerate) // 1000000, (500*self.framerate) // 1000000]
        self.halflength_cut = (375 * self.framerate) // 1000000
        self.halflength_max = 2 * self.halflength_cut
        self.halflength_min = self.halflength_cut // 2
        self.length_cut = 2*self.halflength_cut
        # 2048 halves = 1024 pulses = 512 1-bits = 64 bytes of leader
        self.min_leader_halves = 2048
        # initialise generators
        self.filter = passthrough()
        self.filter.send(None)
        self.read_half = self._gen_read_halfpulse()
        # write fluff at start if this is a new file
        if self.operating_mode == 'w':
            self.write_intro()
        self.switch_mode(mode)
def __init__ ( self , filename , mode ) : TapeBitStream . __init__ ( self ) self . filename = filename if not os . path . exists ( filename ) : # create/overwrite file self . framerate = 22050 self . sampwidth = 1 self . nchannels = 1 self . wav = io . open ( self . filename , 'wb' ) self . _write_wav_header ( ) self . operating_mode = 'w' else : # open file for reading and find wave parameters try : self . wav = io . open ( self . filename , 'r+b' ) except EnvironmentError : self . wav = io . open ( self . filename , 'rb' ) if not self . _read_wav_header ( ) : raise EndOfTape ( ) self . operating_mode = 'r' self . wav_pos = 0 self . buf_len = 1024 # convert 8-bit and 16-bit values to ints if self . sampwidth == 1 : self . sub_threshold = 0 self . subtractor = 128 * self . nchannels else : self . sub_threshold = 256 * self . nchannels // 2 self . subtractor = 256 * self . nchannels # volume above/below zero that is interpreted as zero self . zero_threshold = self . nchannels # 1000 us for 1, 500 us for 0; threshold for half-pulse (500 us, 250 us) self . halflength = [ ( 250 * self . framerate ) // 1000000 , ( 500 * self . framerate ) // 1000000 ] self . halflength_cut = ( 375 * self . framerate ) // 1000000 self . halflength_max = 2 * self . halflength_cut self . halflength_min = self . halflength_cut // 2 self . length_cut = 2 * self . halflength_cut # 2048 halves = 1024 pulses = 512 1-bits = 64 bytes of leader self . min_leader_halves = 2048 # initialise generators self . filter = passthrough ( ) self . filter . send ( None ) self . read_half = self . _gen_read_halfpulse ( ) # write fluff at start if this is a new file if self . operating_mode == 'w' : self . write_intro ( ) self . switch_mode ( mode )