Skip to content

Commit 22551e7

Browse files
committed
sync mode is not default, lowered number of buffers for librtlsdr
1 parent e3e6ee2 commit 22551e7

File tree

2 files changed

+46
-8
lines changed

2 files changed

+46
-8
lines changed

src/librtlsdr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ static rtlsdr_dongle_t known_devices[] = {
354354
{ 0x1f4d, 0xd803, "PROlectrix DV107669" },
355355
};
356356

357-
#define DEFAULT_BUF_NUMBER 15
357+
#define DEFAULT_BUF_NUMBER 1
358358
#define DEFAULT_BUF_LENGTH (16 * 32 * 512)
359359

360360
#define DEF_RTL_XTAL_FREQ 28800000

src/rtl_fm.c

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ static int *atan_lut = NULL;
9292
static int atan_lut_size = 131072; /* 512 KB */
9393
static int atan_lut_coef = 8;
9494

95+
static uint8_t *buffer = NULL;
96+
static int use_sync = 0;
97+
9598
struct dongle_state
9699
{
97100
int exit_flag;
@@ -215,6 +218,7 @@ void usage(void)
215218
"\t enables low-leakage downsample filter\n"
216219
"\t size can be 0 or 9. 0 has bad roll off\n"
217220
"\t[-A std/fast/lut choose atan math (default: std)]\n"
221+
"\t[-S force sync output (defatuls: async)]\n"
218222
//"\t[-C clip_path (default: off)\n"
219223
//"\t (create time stamped raw clips, requires squelch)\n"
220224
//"\t (path must have '\%s' and will expand to date_time_freq)\n"
@@ -236,7 +240,8 @@ sighandler(int signum)
236240
if (CTRL_C_EVENT == signum) {
237241
fprintf(stderr, "Signal caught, exiting!\n");
238242
do_exit = 1;
239-
rtlsdr_cancel_async(dongle.dev);
243+
if (!use_sync)
244+
rtlsdr_cancel_async(dongle.dev);
240245
return TRUE;
241246
}
242247
return FALSE;
@@ -246,7 +251,8 @@ static void sighandler(int signum)
246251
{
247252
fprintf(stderr, "Signal caught, exiting!\n");
248253
do_exit = 1;
249-
rtlsdr_cancel_async(dongle.dev);
254+
if (!use_sync)
255+
rtlsdr_cancel_async(dongle.dev);
250256
}
251257
#endif
252258

@@ -1034,6 +1040,20 @@ void sanity_checks(void)
10341040

10351041
}
10361042

1043+
void dongle_read_sync(struct dongle_state *s)
1044+
{
1045+
int r;
1046+
int n_read;
1047+
1048+
r = rtlsdr_read_sync(s->dev, buffer, ACTUAL_BUF_LENGTH, &n_read);
1049+
if (r < 0) {
1050+
fprintf(stderr, "WARNING: sync read failed.\n");
1051+
return;
1052+
}
1053+
1054+
rtlsdr_callback(buffer, n_read, s);
1055+
}
1056+
10371057
int main(int argc, char **argv)
10381058
{
10391059
#ifndef _WIN32
@@ -1047,7 +1067,7 @@ int main(int argc, char **argv)
10471067
output_init(&output);
10481068
controller_init(&controller);
10491069

1050-
while ((opt = getopt(argc, argv, "d:f:g:s:b:l:o:t:r:p:E:F:A:M:h")) != -1) {
1070+
while ((opt = getopt(argc, argv, "d:f:g:s:b:l:o:t:r:p:E:F:A:M:h:S")) != -1) {
10511071
switch (opt) {
10521072
case 'd':
10531073
dongle.dev_index = verbose_device_search(optarg);
@@ -1142,6 +1162,9 @@ int main(int argc, char **argv)
11421162
demod.deemph = 1;
11431163
demod.squelch_level = 0;}
11441164
break;
1165+
case 'S':
1166+
use_sync = 1;
1167+
break;
11451168
case 'h':
11461169
default:
11471170
usage();
@@ -1229,18 +1252,33 @@ int main(int argc, char **argv)
12291252
usleep(100000);
12301253
pthread_create(&output.thread, NULL, output_thread_fn, (void *)(&output));
12311254
pthread_create(&demod.thread, NULL, demod_thread_fn, (void *)(&demod));
1232-
pthread_create(&dongle.thread, NULL, dongle_thread_fn, (void *)(&dongle));
12331255

1234-
while (!do_exit) {
1235-
usleep(100000);
1256+
if (!use_sync) {
1257+
pthread_create(&dongle.thread, NULL, dongle_thread_fn, (void *)(&dongle));
1258+
while(!do_exit) {
1259+
usleep(100000);
1260+
}
1261+
}
1262+
else {
1263+
1264+
buffer = malloc(ACTUAL_BUF_LENGTH * sizeof(uint8_t));
1265+
1266+
while (!do_exit) {
1267+
dongle_read_sync(&dongle);
1268+
usleep(100);
1269+
}
1270+
1271+
free (buffer);
12361272
}
1273+
12371274

12381275
if (do_exit) {
12391276
fprintf(stderr, "\nUser cancel, exiting...\n");}
12401277
else {
12411278
fprintf(stderr, "\nLibrary error %d, exiting...\n", r);}
12421279

1243-
rtlsdr_cancel_async(dongle.dev);
1280+
if (!use_sync)
1281+
rtlsdr_cancel_async(dongle.dev);
12441282
pthread_join(dongle.thread, NULL);
12451283
safe_cond_signal(&demod.ready, &demod.ready_m);
12461284
pthread_join(demod.thread, NULL);

0 commit comments

Comments
 (0)