ThomasHabets / rustradio

Like GNURadio, but in Rust
14 stars 5 forks source link

fixed the AU reader and added APRS test data #3

Closed Frank-Buss closed 8 months ago

Frank-Buss commented 8 months ago

This PR fixes the AU reader. Some AU files have only 32 bytes header size. This resulted in this bug:

target/debug/examples/ax25-1200-rx -v 2 -a -r testdata/aprs.au --sample_rate 44100
Running…
2024-03-30T02:04:07+01:00 - WARN EOF on testdata/aprs.au. Repeat: false
thread 'main' panicked at src/au.rs:203:17:
assertion `left == right` failed
  left: 32
 right: 44
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

The au file was created from a wav file with this command:

ffmpeg -i aprs.wav -acodec pcm_s16be aprs.au

Both files are now also in the testdata directory. With the fix it can read the AU file:

target/debug/examples/ax25-1200-rx -v 2 -a -r testdata/aprs.au --sample_rate 44100
Running…
2024-03-30T02:12:51+01:00 - WARN EOF on testdata/aprs.au. Repeat: false
2024-03-30T02:12:51+01:00 - WARN EOF on testdata/aprs.au. Repeat: false
2024-03-30T02:12:51+01:00 - WARN EOF on testdata/aprs.au. Repeat: false
2024-03-30T02:12:51+01:00 - WARN EOF on testdata/aprs.au. Repeat: false
2024-03-30T02:12:51+01:00 - WARN EOF on testdata/aprs.au. Repeat: false
2024-03-30T02:12:51+01:00 - WARN EOF on testdata/aprs.au. Repeat: false
2024-03-30T02:12:51+01:00 - INFO Block name         Seconds  Percent
2024-03-30T02:12:51+01:00 - INFO -----------------------------------
2024-03-30T02:12:51+01:00 - INFO FileSource           0.031   10.29%
2024-03-30T02:12:51+01:00 - INFO AuDecode             0.017    5.62%
2024-03-30T02:12:51+01:00 - INFO Hilbert              0.187   61.26%
2024-03-30T02:12:51+01:00 - INFO QuadratureDemod      0.009    2.82%
2024-03-30T02:12:51+01:00 - INFO FftFilterFloat       0.057   18.72%
2024-03-30T02:12:51+01:00 - INFO add_const            0.002    0.63%
2024-03-30T02:12:51+01:00 - INFO SymbolSync           0.002    0.52%
2024-03-30T02:12:51+01:00 - INFO BinarySlicer         0.000    0.03%
2024-03-30T02:12:51+01:00 - INFO NrziDecode           0.000    0.03%
2024-03-30T02:12:51+01:00 - INFO HDLC Deframer        0.000    0.07%
2024-03-30T02:12:51+01:00 - INFO DebugSinkNoCopy      0.000    0.00%
2024-03-30T02:12:51+01:00 - INFO -----------------------------------
2024-03-30T02:12:51+01:00 - INFO All blocks           0.305   99.99%
2024-03-30T02:12:51+01:00 - INFO Non-block time       0.000    0.01%
2024-03-30T02:12:51+01:00 - INFO Elapsed seconds      0.305  100.00%
Block name         Seconds  Percent
-----------------------------------
FileSource           0.031   10.29%
AuDecode             0.017    5.62%
Hilbert              0.187   61.26%
QuadratureDemod      0.009    2.82%
FftFilterFloat       0.057   18.72%
add_const            0.002    0.63%
SymbolSync           0.002    0.52%
BinarySlicer         0.000    0.03%
NrziDecode           0.000    0.03%
HDLC Deframer        0.000    0.07%
DebugSinkNoCopy      0.000    0.00%
-----------------------------------
All blocks           0.305   99.92%
Non-block time       0.000    0.08%
Elapsed seconds      0.305  100.00%

2024-03-30T02:12:51+01:00 - INFO HDLC Deframer: Decoded 0 (incl 0 bitfixes), CRC error 0

Note that the program couldn't decode the test file, there is one record in it. direwolf-1.7.0-9807304 can do it:

atest aprs.wav
44100 samples per second.  16 bits per sample.  1 audio channels.
265278 audio bytes in file.  Duration = 3.0 seconds.
Fix Bits level = 0
Channel 0: 1200 baud, AFSK 1200 & 2200 Hz, A, 44100 sample rate.

DECODED[1] 0:02.162 DB0KOE-1 audio level = 88(21/23)
[0] DB0KOE-1>APNL51:}KOESTW-15>APLG01,TCPIP,DB0KOE-1*:=5055.77NL00654.39E&LoRa APRS RX-iGate, 433.775MHz, Koeln Stadtwald

1 from aprs.wav
1 packets decoded in 0.090 seconds.  33.3 x realtime

Not sure if maybe the AU reader has still a problem, but this is a new issue after this is merged.

ThomasHabets commented 8 months ago

Thanks for your fix. Looks like I left something ugly from debugging.

Since the code doesn't support wav files, there's nothing lost from dropping the .wav test file, right? (especially since it's the same?)

I'm not too eager to add .wav file support, since it's it's not a format you can stream. I'd accept a well written PR, but seems to me better to stay with streamable formats, and convert any .wav files before/after.

I'm not ashamed to say that Direwolf is currently a better decoder. This is for 9600bps, but this code is lagging behind in 1200bps too. This doc says direwolf decodes 1011 packets from track 1 of the wb2osz test CD (IIRC track 2 is actually incorrectly distorted, and not suitable for comparison), while my example ax25-1200-rx can only do 909 decodes (confirmed both before and after your patch).

But its decoding performance is not due to the .au file reader, but due to the clock recovery. Rustradio needs a better clock recovery block. Possibly by tuning the existing clock recovery, we can make the testdata decode. So it's good to have it in there.

I can't compare how well the WPCR would do, since it requires raw I/Q, and unfortunately the WB2OSZ data is post FM-demodulation audio. And merely converting to I/Q now won't help, since it needs the signal strength that was lost in the demod.

Just checking if you had plans in PRs or otherwise for the wav file. If it's not needed you can remove it from the PR, or if you prefer, I'm happy to do it.

Thanks again!

Frank-Buss commented 8 months ago

You are right, the wav file is not needed, was the same, I removed it. I created an amended commit to avoid cluttering the history.

ThomasHabets commented 8 months ago

Thanks!