diff --git a/amodem/audio.py b/amodem/audio.py index 63a734a..e5ebb71 100644 --- a/amodem/audio.py +++ b/amodem/audio.py @@ -4,6 +4,7 @@ import functools log = logging.getLogger(__name__) + class ALSA(object): def __init__(self, tool, Fs): self.Fs = int(Fs) # sampling rate diff --git a/amodem/calib.py b/amodem/calib.py index 484f88b..b58e4ab 100644 --- a/amodem/calib.py +++ b/amodem/calib.py @@ -82,6 +82,7 @@ def run_recorder(config, recorder): fmt = '{freq:6.0f} Hz: {message:s}{extra:s}' fields = ['peak', 'total', 'rms', 'coherency'] + def recv(config, audio_record=audio.record, verbose=False): extra = '' if verbose: diff --git a/amodem/config.py b/amodem/config.py index 02a4b32..8213269 100644 --- a/amodem/config.py +++ b/amodem/config.py @@ -32,7 +32,8 @@ class Configuration(object): # QAM constellation Nx = 2 ** int(np.ceil(bits_per_symbol / 2)) Ny = self.Npoints // Nx - symbols = np.array([complex(x, y) for x in range(Nx) for y in range(Ny)]) + symbols = [complex(x, y) for x in range(Nx) for y in range(Ny)] + symbols = np.array(symbols) symbols = symbols - symbols[-1]/2 self.symbols = symbols / np.max(np.abs(symbols)) diff --git a/amodem/dsp.py b/amodem/dsp.py index e2f5fb9..a8c963f 100644 --- a/amodem/dsp.py +++ b/amodem/dsp.py @@ -130,7 +130,7 @@ class MODEM(object): self.symbols = symbols self.bits_per_symbol = bits_per_symbol - bits_map = dict((symbol, bits) for bits, symbol in self.encode_map.items()) + bits_map = dict(item[::-1] for item in self.encode_map.items()) self.decode_list = [(s, bits_map[s]) for s in self.symbols] def encode(self, bits): diff --git a/amodem/equalizer.py b/amodem/equalizer.py index c1b4930..da85920 100644 --- a/amodem/equalizer.py +++ b/amodem/equalizer.py @@ -9,6 +9,7 @@ import random _constellation = [1, 1j, -1, -1j] + class Equalizer(object): def __init__(self, config): @@ -22,7 +23,6 @@ class Equalizer(object): choose = lambda: [r.choice(_constellation) for j in range(self.Nfreq)] return np.array([choose() for i in range(length)]) - def modulator(self, symbols): gain = 1.0 / len(self.carriers) result = [] @@ -65,7 +65,8 @@ class Equalizer(object): return h def equalize_signal(self, signal, expected, order, lookahead=0): - signal = np.concatenate([np.zeros(order-1), signal, np.zeros(lookahead)]) + signal = [np.zeros(order-1), signal, np.zeros(lookahead)] + signal = np.concatenate(signal) length = len(expected) A = [] diff --git a/amodem/recv.py b/amodem/recv.py index 8d5ee6c..ccb2181 100644 --- a/amodem/recv.py +++ b/amodem/recv.py @@ -154,7 +154,7 @@ class Receiver(object): def start(self, signal, gain=1.0): sampler = sampling.Sampler(signal, sampling.Interpolator()) - symbols = dsp.Demux(sampler=sampler, omegas=self.omegas, Nsym=self.Nsym) + symbols = dsp.Demux(sampler, omegas=self.omegas, Nsym=self.Nsym) freq_err = self._prefix(symbols, gain=gain) sampler.freq -= freq_err diff --git a/amodem/send.py b/amodem/send.py index ef6b8ba..865236d 100644 --- a/amodem/send.py +++ b/amodem/send.py @@ -12,6 +12,7 @@ from . import framing from . import equalizer from . import dsp + class Sender(object): def __init__(self, fd, config): self.offset = 0 @@ -50,6 +51,7 @@ class Sender(object): total_bits = i * Nfreq * self.modem.bits_per_symbol log.debug('Sent %8.1f kB', total_bits / 8e3) + def main(args): sender = Sender(args.output, config=args.config) Fs = args.config.Fs @@ -70,7 +72,7 @@ def main(args): data_duration = sender.offset - training_duration log.info('Sent %.3f kB @ %.3f seconds', - reader.total / 1e3, data_duration / Fs) + reader.total / 1e3, data_duration / Fs) # post-padding audio with silence sender.write(np.zeros(int(Fs * args.silence_stop)))