added cmd line arument to list audiodev by number, test_tx.py and test_rx.py working OK with virtual audio card, updated README.md with latest examples

This commit is contained in:
drowe67 2021-12-14 12:35:19 +10:30 committed by David Rowe
parent af99e53ec7
commit 52841da285
3 changed files with 67 additions and 72 deletions

View file

@ -1,63 +1,36 @@
# 001_HIGHSNR_STDIO_AUDIO TEST SUITE
# FreeDV-JATE [Just Another TNC Experiment]
1. Install
```
sudo apt update
sudo apt upgrade
sudo apt install git cmake build-essential python3-pip portaudio19-dev python3-pyaudio
pip3 install crcengine
pip3 install threading
```
1. Install codec2, and set up the `libcodec2.so` shared library path, for example
```
export LD_LIBRARY_PATH=${HOME}/codec2/build_linux/src
```
## 001_HIGHSNR_STDIO_AUDIO TEST SUITE
## STDIO tests
Pipes are used to move audio samples from the Tx to Rx:
### INSTALL TEST SUITE
#### Install prerequierements
```
sudo apt update
sudo apt upgrade
sudo apt install git cmake build-essential python3-pip portaudio19-dev python3-pyaudio
pip3 install crcengine
pip3 install threading
python3 test_tx.py --mode datac1 --delay 500 --frames 2 --bursts 1 | python3 test_rx.py --mode datac1 --frames 2 --bursts 1
```
Change into a directory of your choice
Run the following commands --> They will download and compile the latest codec2 ( dr-packet ) files and LPCNet as well into the directory of your choice
```
wget https://raw.githubusercontent.com/DJ2LS/FreeDV-JATE/001_HIGHSNR_STDIO_AUDIO/install_test_suite.sh
chmod +x install_test_suite.sh
./install_test_suite.sh
```
### PARAMETERS
| parameter | description | side
|--|--|--|
| - -mode 12 | set the mode for FreeDV ( 10,11,12 ) | TX & RX
| - -delay 1 | set the delay between burst | TX
| - -frames 1 | set the number of frames per burst | TX & RX
| - -bursts 1 | set the number of bursts | TX & RX
| - -input "audio" | if set, program switches to audio instead of stdin | RX
| - -audioinput 2 | set the audio device | RX
| - -output "audio" | if set, program switches to audio instead of stdout | TX
| - -audiooutput 1 | set the audio device | TX
| - -debug | if used, print additional debugging output | RX
### STDIO TESTS FOR TERMINAL USAGE ONLY
python3 test_tx.py --mode 12 --delay 500 --frames 2 --bursts 1 | python3 test_rx.py --mode 12 --frames 2 --bursts 1
### AUDIO TESTS VIA VIRTUAL AUDIO DEVICE
#### Create audio sinkhole and subdevices
Note: This command needs to be run again after every reboot
```
sudo modprobe snd-aloop index=1,2 enable=1,1 pcm_substreams=1,1 id=CHAT1,CHAT2
```
check if devices have been created
## AUDIO test via virtual audio devices
1. Create virtual audio devices. Note: This command needs to be run again after every reboot
```
sudo modprobe snd-aloop index=1,2 enable=1,1 pcm_substreams=1,1 id=CHAT1,CHAT2
```
1. Check if devices have been created
```
aplay -l
Output should be like this:
Karte 0: Intel [HDA Intel], Gerät 0: Generic Analog [Generic Analog]
Sub-Geräte: 1/1
@ -74,17 +47,24 @@ Output should be like this:
Karte 2: CHAT2 [Loopback], Gerät 1: Loopback PCM [Loopback PCM]
Sub-Geräte: 1/1
Sub-Gerät #0: subdevice #0
```
1. Determine the audio device number you would like to use:
```
python3 test_rx.py --list
<snip>
audiodev: 0 HDA Intel PCH: ALC269VC Analog (hw:0,0)
audiodev: 1 HDA Intel PCH: HDMI 0 (hw:0,3)
audiodev: 2 HDA Intel PCH: HDMI 1 (hw:0,7)
audiodev: 3 HDA Intel PCH: HDMI 2 (hw:0,8)
audiodev: 4 Loopback: PCM (hw:1,0)
audiodev: 5 Loopback: PCM (hw:1,1)
audiodev: 6 Loopback: PCM (hw:2,0)
audiodev: 7 Loopback: PCM (hw:2,1)
```
In this case we choose audiodev 4 for the RX and 5 for the Tx.
#### Run tests:
Its important, to run TEST_RX at first to reduce the chance that we get some system side audio errors. Tests are showing, that its important to start with audio device "2" at first and then go to the lower virtual devices "1".
Audio device "0" is the default sound card.
##### RX side
python3 test_rx.py --mode 12 --frames 2 --bursts 1 --input "audio" --audioinput 2 --debug
##### TX side
python3 test_tx.py --mode 12 --delay 500 --frames 2 --bursts 1 --output "audio" --audiooutput 1
1. Start the Rx first, then Tx in separate consoles:
```
python3 test_rx.py --mode datac0 --frames 2 --bursts 1 --audiodev 4 --debug
python3 test_tx.py --mode datac0 --frames 2 --bursts 1 --audiodev 5

View file

@ -25,14 +25,21 @@ parser = argparse.ArgumentParser(description='Simons TEST TNC')
parser.add_argument('--bursts', dest="N_BURSTS", default=0, type=int)
parser.add_argument('--framesperburst', dest="N_FRAMES_PER_BURST", default=0, type=int)
parser.add_argument('--mode', dest="FREEDV_MODE", type=str, choices=['datac0', 'datac1', 'datac3'])
parser.add_argument('--audioinput', dest="AUDIO_INPUT", default=0, type=int)
parser.add_argument('--audiodev', dest="AUDIO_INPUT_DEVICE", default=0, type=int, help="audio device number to use")
parser.add_argument('--debug', dest="DEBUGGING_MODE", action="store_true")
parser.add_argument('--list', dest="LIST", action="store_true", help="list audio devices by number and exit")
args = parser.parse_args()
if args.LIST:
p = pyaudio.PyAudio()
for dev in range(0,p.get_device_count()):
print("audiodev: ", dev, p.get_device_info_by_index(dev)["name"])
quit()
N_BURSTS = args.N_BURSTS
N_FRAMES_PER_BURST = args.N_FRAMES_PER_BURST
AUDIO_INPUT_DEVICE = args.AUDIO_INPUT
AUDIO_INPUT_DEVICE = args.AUDIO_INPUT_DEVICE
MODE = codec2.FREEDV_MODE[args.FREEDV_MODE].value
DEBUGGING_MODE = args.DEBUGGING_MODE
@ -40,7 +47,8 @@ DEBUGGING_MODE = args.DEBUGGING_MODE
# AUDIO PARAMETERS
AUDIO_FRAMES_PER_BUFFER = 2048
MODEM_SAMPLE_RATE = codec2.api.FREEDV_FS_8000
AUDIO_SAMPLE_RATE_TX = 48000
AUDIO_SAMPLE_RATE_RX = 48000
assert (AUDIO_SAMPLE_RATE_RX % MODEM_SAMPLE_RATE) == 0
# check if we want to use an audio device then do an pyaudio init
if AUDIO_INPUT_DEVICE != 0:
@ -56,8 +64,7 @@ if AUDIO_INPUT_DEVICE != 0:
# ----------------------------------------------------------------
# DATA CHANNEL INITIALISATION
# DATA CHANNEL INITIALISATION
# open codec2 instance
freedv = cast(codec2.api.freedv_open(MODE), c_void_p)
@ -119,5 +126,5 @@ print(f"RECEIVED BURSTS: {rx_bursts} RECEIVED FRAMES: {rx_total_frames}", file=s
# and at last check if we had an openend pyaudio instance and close it
if AUDIO_INPUT_DEVICE != 0:
stream_tx.close()
stream_rx.close()
p.terminate()

View file

@ -21,14 +21,21 @@ parser.add_argument('--bursts', dest="N_BURSTS", default=0, type=int)
parser.add_argument('--framesperburst', dest="N_FRAMES_PER_BURST", default=0, type=int)
parser.add_argument('--delay', dest="DELAY_BETWEEN_BURSTS", default=0, type=int)
parser.add_argument('--mode', dest="FREEDV_MODE", type=str, choices=['datac0', 'datac1', 'datac3'])
parser.add_argument('--audiooutput', dest="AUDIO_OUTPUT", default=0, type=int)
parser.add_argument('--audiodev', dest="AUDIO_OUTPUT_DEVICE", default=0, type=int, help="audio output device number to use")
parser.add_argument('--list', dest="LIST", action="store_true", help="list audio devices by number and exit")
args = parser.parse_args()
if args.LIST:
p = pyaudio.PyAudio()
for dev in range(0,p.get_device_count()):
print("audiodev: ", dev, p.get_device_info_by_index(dev)["name"])
quit()
N_BURSTS = args.N_BURSTS
N_FRAMES_PER_BURST = args.N_FRAMES_PER_BURST
DELAY_BETWEEN_BURSTS = args.DELAY_BETWEEN_BURSTS/1000
AUDIO_OUTPUT_DEVICE = args.AUDIO_OUTPUT
AUDIO_OUTPUT_DEVICE = args.AUDIO_OUTPUT_DEVICE
MODE = codec2.FREEDV_MODE[args.FREEDV_MODE].value
@ -38,6 +45,7 @@ MODE = codec2.FREEDV_MODE[args.FREEDV_MODE].value
AUDIO_FRAMES_PER_BUFFER = 2048
MODEM_SAMPLE_RATE = codec2.api.FREEDV_FS_8000
AUDIO_SAMPLE_RATE_TX = 48000
assert (AUDIO_SAMPLE_RATE_TX % MODEM_SAMPLE_RATE) == 0
# check if we want to use an audio device then do an pyaudio init
if AUDIO_OUTPUT_DEVICE != 0: