[PATCH 1/1] add -S (synchronous) mode to rtl_fm

Alan Corey alancorey at yahoo.com
Tue Apr 23 19:46:47 UTC 2013


Did you also fix the pthread_mutex_unlock when it was already unlocked?  The cmake patch should get included too.

For me this dumps core with an abort, so it sounds like the thread thing:

Using device 0: ezcap USB 2.0 DVB-T/DAB/FM dongle
Found Rafael Micro R820T tuner
Oversampling input by: 2x.
Oversampling output by: 4x.
Buffer size: 6.02ms
Tuned to 88856000 Hz.
Sampling at 1360000 Hz.
Output at 32000 Hz.
Exact sample rate is: 1360000.050439 Hz
Tuner gain set to automatic.
Reading samples in sync mode...
In:0.00% 00:00:00.00 [00:00:00.00] Out:0     [      |      ]        Clip:0
Done.
Abort (core dumped)

This is OpenBSD 5.2 with the libusbs from ports:

d530# pkg_info | grep libusb
libusb-compat-0.1.4 libusb-0.1 compatibility layer for libusb1
libusb1-1.0.9p3     library for USB device access from userspace

  Alan

-----

Radio Astronomy - the ultimate DX

--- On Tue, 4/23/13, Stuart Henderson <stu at spacehopper.org> wrote:

From: Stuart Henderson <stu at spacehopper.org>
Subject: [PATCH 1/1] add -S (synchronous) mode to rtl_fm
To: osmocom-sdr at lists.osmocom.org
Date: Tuesday, April 23, 2013, 10:47 AM

The enclosed diff adds a synchronous mode to rtl_fm. This helps
OpenBSD (where libusb async isn't yet working).

Signed-off-by: Stuart Henderson <stu at spacehopper.org>
---
 src/rtl_fm.c | 29 +++++++++++++++++++++++++----
 1 file changed, 25 insertions(+), 4 deletions(-)

diff --git a/src/rtl_fm.c b/src/rtl_fm.c
index e8ebb77..a71e287 100644
--- a/src/rtl_fm.c
+++ b/src/rtl_fm.c
@@ -128,6 +128,7 @@ void usage(void)
         "\t[-E sets lower edge tuning (default: center)]\n"
         "\t[-N enables NBFM mode (default: on)]\n"
         "\t[-W enables WBFM mode (default: off)]\n"
+        "\t[-S force sync output (default: async)]\n"
         "\t (-N -s 170k -o 4 -A fast -r 32k -l 0 -D)\n"
         "\tfilename (a '-' dumps samples to stdout)\n"
         "\t (omitting the filename also uses stdout)\n\n"
@@ -723,12 +724,14 @@ int main(int argc, char **argv)
     uint32_t dev_index = 0;
     int device_count;
     int ppm_error = 0;
+    int sync_mode = 0;
     char vendor[256], product[256], serial[256];
+
     fm_init(&fm);
     pthread_mutex_init(&data_ready, NULL);
     pthread_mutex_init(&data_write, NULL);
 
-    while ((opt = getopt(argc, argv, "d:f:g:s:b:l:o:t:r:p:EFA:NWMULRDC")) != -1) {
+    while ((opt = getopt(argc, argv, "d:f:g:s:b:l:o:t:r:p:EFA:NWMULRDSC")) != -1) {
         switch (opt) {
         case 'd':
             dev_index = atoi(optarg);
@@ -815,6 +818,9 @@ int main(int argc, char **argv)
         case 'R':
             fm.mode_demod = &raw_demod;
             break;
+        case 'S':
+            sync_mode = 1;
+            break;
         default:
             usage();
             break;
@@ -921,9 +927,24 @@ int main(int argc, char **argv)
         fprintf(stderr, "WARNING: Failed to reset buffers.\n");}
 
     pthread_create(&demod_thread, NULL, demod_thread_fn, (void *)(&fm));
-    rtlsdr_read_async(dev, rtlsdr_callback, (void *)(&fm),
-                  DEFAULT_ASYNC_BUF_NUMBER,
-                  lcm_post[fm.post_downsample] * DEFAULT_BUF_LENGTH);
+    if (sync_mode) {
+        fprintf(stderr, "Reading samples in sync mode...\n");
+        while (!do_exit) {
+            r = rtlsdr_read_sync(dev, &fm.buf,
+                         lcm_post[fm.post_downsample] * DEFAULT_BUF_LENGTH,
+                         &fm.buf_len);
+            if (r < 0) {
+                fprintf(stderr, "WARNING: sync read failed.\n");
+                break;
+            }
+            full_demod(&fm);
+        }
+    } else {
+        fprintf(stderr, "Reading samples in async mode...\n");
+        rtlsdr_read_async(dev, rtlsdr_callback, (void *)(&fm),
+                  DEFAULT_ASYNC_BUF_NUMBER,
+                  lcm_post[fm.post_downsample] * DEFAULT_BUF_LENGTH);
+    }
 
     if (do_exit) {
         fprintf(stderr, "\nUser cancel, exiting...\n");}
-- 
1.8.1.3



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/osmocom-sdr/attachments/20130423/d9638e6a/attachment.html>


More information about the osmocom-sdr mailing list