mirror of
https://github.com/romanz/amodem.git
synced 2026-02-24 16:18:12 +08:00
PEP8 fixes
This commit is contained in:
@@ -4,6 +4,7 @@ import functools
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ALSA(object):
|
||||
def __init__(self, tool, Fs):
|
||||
self.Fs = int(Fs) # sampling rate
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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))
|
||||
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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 = []
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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)))
|
||||
|
||||
Reference in New Issue
Block a user