mirror of
https://github.com/romanz/amodem.git
synced 2026-02-24 16:18:12 +08:00
call recv.py and send.py with filename as an argument
This commit is contained in:
3
recv.py
3
recv.py
@@ -186,7 +186,8 @@ def main(fname):
|
||||
f.write(data)
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
logging.basicConfig(level=logging.INFO, format='%(asctime)s %(levelname)-12s %(message)s')
|
||||
main('rx.int16')
|
||||
main(fname=sys.argv[1])
|
||||
if pylab:
|
||||
pylab.show()
|
||||
|
||||
9
send.py
9
send.py
@@ -42,11 +42,11 @@ def modulate(sig, bits):
|
||||
if all(symbols == 0):
|
||||
break
|
||||
|
||||
def main():
|
||||
def main(fname):
|
||||
import ecc
|
||||
log.info('Running MODEM @ {:.1f} kbps'.format(sigproc.modem_bps / 1e3))
|
||||
|
||||
with open('tx.int16', 'wb') as fd:
|
||||
with open(fname, 'wb') as fd:
|
||||
start(fd, sym.carrier[carrier_index])
|
||||
for c in sym.carrier:
|
||||
training(fd, c)
|
||||
@@ -55,5 +55,6 @@ def main():
|
||||
modulate(fd, bits)
|
||||
|
||||
if __name__ == '__main__':
|
||||
logging.basicConfig(level=logging.DEBUG, format='%(message)s')
|
||||
main()
|
||||
import sys
|
||||
logging.basicConfig(level=logging.INFO, format='%(asctime)s %(levelname)-12s %(message)s')
|
||||
main(fname=sys.argv[1])
|
||||
|
||||
13
test.sh
13
test.sh
@@ -3,17 +3,18 @@ set -u
|
||||
set -e
|
||||
|
||||
dd if=/dev/urandom of=data.send bs=1024 count=1
|
||||
./send.py
|
||||
./send.py tx.int16
|
||||
|
||||
killall arecord aplay || true
|
||||
|
||||
./wave.py record rx.int16 &
|
||||
PID=$!
|
||||
|
||||
./wave.py play tx.int16
|
||||
sleep 1
|
||||
kill -INT $PID
|
||||
|
||||
./recv.py
|
||||
killall arecord aplay || true
|
||||
|
||||
./recv.py rx.int16
|
||||
./errors.py data.*
|
||||
if [ -z $? ]; then
|
||||
./show.py tx.int16 rx.int16
|
||||
fi
|
||||
fi
|
||||
|
||||
17
wave.py
17
wave.py
@@ -7,13 +7,15 @@ import logging
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
from common import Fs
|
||||
Fs = int(Fs)
|
||||
Fs = int(Fs) # sampling rate
|
||||
bits_per_sample = 16
|
||||
audio_format = 'S{}_LE'.format(bits_per_sample) # PCM signed little endian
|
||||
|
||||
def play(fname, **kwargs):
|
||||
return launch('aplay', fname, '-q', '-f', 'S16_LE', '-c', '1', '-r', Fs, **kwargs)
|
||||
return launch('aplay', fname, '-q', '-f', audio_format, '-c', '1', '-r', Fs, **kwargs)
|
||||
|
||||
def record(fname, **kwargs):
|
||||
return launch('arecord', fname, '-q', '-f', 'S16_LE', '-c', '1', '-r', Fs, **kwargs)
|
||||
return launch('arecord', fname, '-q', '-f', audio_format, '-c', '1', '-r', Fs, **kwargs)
|
||||
|
||||
def launch(*args, **kwargs):
|
||||
args = map(str, args)
|
||||
@@ -41,4 +43,11 @@ if __name__ == '__main__':
|
||||
p = args.func(args.filename)
|
||||
|
||||
import sys
|
||||
sys.exit(p.wait())
|
||||
exitcode = 0
|
||||
try:
|
||||
exitcode = p.wait()
|
||||
except KeyboardInterrupt:
|
||||
p.kill()
|
||||
exitcode = p.wait()
|
||||
|
||||
sys.exit(exitcode)
|
||||
|
||||
Reference in New Issue
Block a user