diff --git a/amodem/__main__.py b/amodem/__main__.py index 9bbd8de..2243c4b 100644 --- a/amodem/__main__.py +++ b/amodem/__main__.py @@ -88,11 +88,11 @@ def FileType(mode, interface_factory=None): def get_volume_cmd(args): - volume_controllers = [ - dict(test='pactl --version', - send='pactl set-sink-volume @DEFAULT_SINK@', - recv='pactl set-source-volume @DEFAULT_SOURCE@') - ] + volume_controllers = [{ + 'test': 'pactl --version', + 'send': 'pactl set-sink-volume @DEFAULT_SINK@', + 'recv': 'pactl set-source-volume @DEFAULT_SOURCE@' + }] if args.calibrate == 'auto': for c in volume_controllers: if os.system(c['test']) == 0: diff --git a/amodem/audio.py b/amodem/audio.py index 3b70ff8..811b5fc 100644 --- a/amodem/audio.py +++ b/amodem/audio.py @@ -7,6 +7,10 @@ import time log = logging.getLogger(__name__) +class AudioError(Exception): + pass + + class Interface: def __init__(self, config, debug=False): self.debug = bool(debug) @@ -35,7 +39,7 @@ class Interface: def _error_check(self, res): if res != 0: - raise Exception(res, self._error_string(res)) + raise AudioError(res, self._error_string(res)) def __enter__(self): self.call('Initialize') diff --git a/amodem/calib.py b/amodem/calib.py index 59f7f45..be9fee7 100644 --- a/amodem/calib.py +++ b/amodem/calib.py @@ -75,10 +75,10 @@ def detector(config, src, frame_length=200): else: msg = f'too {errors[flags.index(False)]} signal' - yield dict( - freq=freq, rms=rms, peak=peak, coherency=coherency, - total=total, success=success, msg=msg - ) + yield { + 'freq': freq, 'rms': rms, 'peak': peak, 'coherency': coherency, + 'total': total, 'success': success, 'msg': msg + } def volume_calibration(result_iterator, volume_ctl): diff --git a/amodem/dsp.py b/amodem/dsp.py index c0afd45..68f77b2 100644 --- a/amodem/dsp.py +++ b/amodem/dsp.py @@ -79,7 +79,7 @@ class MODEM: symbols = np.array(list(symbols)) bits_per_symbol = np.log2(len(symbols)) bits_per_symbol = np.round(bits_per_symbol) - N = (2 ** bits_per_symbol) + N = 2 ** bits_per_symbol assert N == len(symbols) bits_per_symbol = int(bits_per_symbol) diff --git a/amodem/recv.py b/amodem/recv.py index 0ccc272..ff8a3e6 100644 --- a/amodem/recv.py +++ b/amodem/recv.py @@ -43,7 +43,7 @@ class Receiver: self.plt.subplot(1, 2, 2) self.plt.plot(np.abs(S)) self.plt.plot(equalizer.prefix) - errors = (bits != equalizer.prefix) + errors = bits != equalizer.prefix if any(errors): msg = f'Incorrect prefix: {sum(errors)} errors' raise ValueError(msg) diff --git a/amodem/stream.py b/amodem/stream.py index e542dbe..8b4a60f 100644 --- a/amodem/stream.py +++ b/amodem/stream.py @@ -5,7 +5,7 @@ class Reader: wait = 0.2 timeout = 2.0 - bufsize = (8 << 10) + bufsize = 8 << 10 def __init__(self, fd, data_type=None, eof=False): self.fd = fd