rtlsdr in async mode is returning buffers full with data from previous calls.
I noticed that sometimes the first async callbacks would return TOO
QUICKLY so that it would be impossible to have sampled that data. This
might be because lib-usb have previous transfers submitted and not
cleared?
I compiled rtl_test with a small modification that will print the
sampling time if it is much lower than expected.
BUF_LENGTH is (16 * 16384)=256K, and SAMPLE_RATE is 2048000, so a full
buffer should take about 64ms.
You can see that in this example the async callback is returned after
7.79ms (and the following one 1.47ms later). So the data must be old.
The ns printf
nuno@ubuntu:~/Desktop/rtl-sdr/build/src$ ./rtl_test -p
Found 1 device(s):
0: ezcap USB 2.0 DVB-T/DAB/FM dongle
Using device 0: ezcap USB 2.0 DVB-T/DAB/FM dongle
Found Rafael Micro R820T tuner
Supported gain values (29): 0.0 0.9 1.4 2.7 3.7 7.7 8.7 12.5 14.4 15.7
16.6 19.7 20.7 22.9 25.4 28.0 29.7 32.8 33.8 36.4 37.2 38.6 40.2 42.1
43.4 43.9 44.5 48.0 49.6
Reporting PPM error measurement every 10 seconds...
Press ^C after a few minutes.
Reading samples in async mode...
ERROR ns: 7791886
ERROR ns: 9259301
lost at least 185 bytes
real sample rate: 2073369
real sample rate: 2048190
^CSignal caught, exiting!
User cancel, exiting...
Cumulative PPM error: -289
The modifications to demonstrate the issue:
nuno@ubuntu:~/Desktop/rtl-sdr/src$ git diff
diff --git a/src/rtl_test.c b/src/rtl_test.c
index f5a56b8..1935bfb 100644
--- a/src/rtl_test.c
+++ b/src/rtl_test.c
@@ -138,9 +138,11 @@ static void rtlsdr_callback(unsigned char *buf, uint32_t le
ppm_now.tv_sec = tv.tv_sec;
ppm_now.tv_nsec = tv.tv_usec*1000;
#endif
- if (ppm_now.tv_sec - ppm_recent.tv_sec > PPM_DURATION) {
- ns = 1000000000L * (int64_t)(ppm_now.tv_sec - ppm_recent.tv_sec)
- ns += (int64_t)(ppm_now.tv_nsec - ppm_recent.tv_nsec);
+ ns = 1000000000L * (int64_t)(ppm_now.tv_sec - ppm_recent.tv_sec);
+ ns += (int64_t)(ppm_now.tv_nsec - ppm_recent.tv_nsec);
+ if(ns<60000000)
+ printf("ERROR ns: %9lld\n",ns);
+ if (ppm_now.tv_sec - ppm_recent.tv_sec > PPM_DURATION) {
printf("real sample rate: %i\n",
(int)((1000000000L * ppm_count / 2L) / ns));
#ifndef __APPLE__
Nuno
Show replies by date