How to use the amodem.common.dumps function in amodem

To help you get started, we’ve selected a few amodem examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github romanz / amodem / tests / test_sampling.py View on Github external
def test_resample():
    x = np.sin(2*np.pi * 10 * np.linspace(0, 1, 1001))
    src = BytesIO(common.dumps(x))
    dst = BytesIO()
    sampling.resample(src=src, dst=dst, df=0.0)
    y = common.loads(dst.getvalue())
    err = x[:len(y)] - y
    assert np.max(np.abs(err)) < 1e-4

    dst = BytesIO()
    sampling.resample(src=BytesIO(b'\x00\x00'), dst=dst, df=0.0)
    assert dst.tell() == 0
github romanz / amodem / tests / test_calib.py View on Github external
def test_drift(freq_err):
    freq = config.Fc * (1 + freq_err / 1e6)
    t = np.arange(int(1.0 * config.Fs)) * config.Ts
    frame_length = 100
    rms = 0.5
    signal = rms * np.cos(2 * np.pi * freq * t)
    src = BytesIO(common.dumps(signal))
    iters = 0
    for r in calib.detector(config, src, frame_length=frame_length):
        assert r.success is True
        assert abs(r.rms - rms) < 1e-3
        assert abs(r.total - rms) < 1e-3
        iters += 1

    assert iters > 0
    assert iters == config.baud / frame_length
github romanz / amodem / tests / test_calib.py View on Github external
def test_too_noisy():
    r = random.Random(0)  # generate random binary signal
    signal = np.array([r.choice([-1, 1]) for i in range(int(config.Fs))])
    src = BytesIO(common.dumps(signal * 0.5))
    for r in calib.detector(config, src=src):
        assert not r.success
        assert r.msg == 'too noisy signal'
github romanz / amodem / amodem / send.py View on Github external
def write(self, sym):
        sym = np.array(sym) * self.gain
        data = common.dumps(sym)
        self.fd.write(data)
        self.offset += len(sym)
github romanz / amodem / amodem / calib.py View on Github external
def send(config, dst, volume_cmd=None, gain=1.0, limit=None):
    volume_ctl = volume_controller(volume_cmd)
    volume_ctl(1.0)  # full scale output volume

    calibration_symbols = int(1.0 * config.Fs)
    t = np.arange(0, calibration_symbols) * config.Ts
    signals = [gain * np.sin(2 * np.pi * f * t) for f in config.frequencies]
    signals = [common.dumps(s) for s in signals]

    for signal in itertools.islice(itertools.cycle(signals), limit):
        dst.write(signal)
github romanz / amodem / amodem / sampling.py View on Github external
def resample(src, dst, df=0.0):
    x = common.load(src)
    sampler = Sampler(x, Interpolator())
    sampler.freq += df
    y = sampler.take(len(x))
    dst.write(common.dumps(y))