Move the calculation which involves the samplerate as well as user
provided options out of the meta packet reception and to the top of the
decode() method. Especially only use the samplerate after it was tested
for availability.
def metadata(self, key, value):
if key == srd.SRD_CONF_SAMPLERATE:
self.samplerate = value
def metadata(self, key, value):
if key == srd.SRD_CONF_SAMPLERATE:
self.samplerate = value
- self.bit_width = float(self.samplerate) / float(self.options['bitrate'])
- self.half_bit_width = self.bit_width / 2.0
- self.break_threshold = self.bit_width * 1.2 # Break if the line is low for longer than this
def handle_bit(self, bit):
self.bits.append(bit)
def handle_bit(self, bit):
self.bits.append(bit)
def decode(self):
if not self.samplerate:
raise SamplerateError('Cannot decode without samplerate.')
def decode(self):
if not self.samplerate:
raise SamplerateError('Cannot decode without samplerate.')
+ self.bit_width = float(self.samplerate) / float(self.options['bitrate'])
+ self.half_bit_width = self.bit_width / 2.0
+ # BREAK if the line is low for longer than this.
+ self.break_threshold = self.bit_width * 1.2
while True:
if self.state == 'INIT':
while True:
if self.state == 'INIT':