From e9fe05c4ea058aed9725eb59250833f3157e4c88 Mon Sep 17 00:00:00 2001 From: Divye Kapoor Date: Sat, 21 Nov 2015 07:57:47 +0000 Subject: [PATCH 1/2] Be accurate in disallowing sampling rates in SoftFM. The rtl-sdr driver code disallows most of the sampling rates below 900 kS/s. However, it allows a small window of sampling rates between [250001, 300000]. The update to the conditional is along the lines of the conditions imposed by the RTL SDR driver here: http://cgit.osmocom.org/rtl-sdr/tree/src/librtlsdr.c The default sampling rate of 1 MS/s causes severe buffer underruns on a Raspberry Pi 2. However choosing a sampling rate of 250 kS/s and lower values for PCM sampling causes successful FM demodulation of strong FM stations on the device. --- main.cc | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/main.cc b/main.cc index 0af964e..ca34327 100644 --- a/main.cc +++ b/main.cc @@ -144,7 +144,7 @@ void adjust_gain(SampleVector& samples, double gain) * This code runs in a separate thread. * The RTL-SDR library is not capable of buffering large amounts of data. * Running this in a background thread ensures that the time between calls - * to RtlSdrSource::get_samples() is very short. + * to RtlSdrSource::get_samples() is very short. */ void read_source_data(RtlSdrSource *rtlsdr, DataBuffer *buf) { @@ -219,7 +219,7 @@ void usage() " -d devidx RTL-SDR device index, 'list' to show device list (default 0)\n" " -g gain Set LNA gain in dB, or 'auto' (default auto)\n" " -a Enable RTL AGC mode (default disabled)\n" - " -s ifrate IF sample rate in Hz (default 1000000, min 900001)\n" + " -s ifrate IF sample rate in Hz (default 1000000, valid range: [225001, 300000] U [900000, 3200000])\n" " -r pcmrate Audio sample rate in Hz (default 48000 Hz)\n" " -M Disable stereo decoding\n" " -R filename Write audio data as raw S16_LE samples\n" @@ -355,8 +355,11 @@ int main(int argc, char **argv) } break; case 's': - // NOTE: RTL does not suppor sample rate 900 kS/s or lower - if (!parse_dbl(optarg, ifrate) || ifrate <= 900000) { + // NOTE: RTL does not support some sample rates below 900 kS/s + // Also, max sampling rate is 3.2 MS/s + if (!parse_dbl(optarg, ifrate) || + (ifrate <= 225000) || (ifrate > 3200000) || + ((ifrate > 300000) && (ifrate <= 900000))) { badarg("-s"); } break; From d5dd2d96035a2fa98d0d8484195ef9c308aae0b4 Mon Sep 17 00:00:00 2001 From: Joris van Rantwijk Date: Sun, 22 Nov 2015 16:04:25 +0100 Subject: [PATCH 2/2] Fix minor issues in checking of IF sample rate option. --- main.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/main.cc b/main.cc index ca34327..5bcf286 100644 --- a/main.cc +++ b/main.cc @@ -219,7 +219,8 @@ void usage() " -d devidx RTL-SDR device index, 'list' to show device list (default 0)\n" " -g gain Set LNA gain in dB, or 'auto' (default auto)\n" " -a Enable RTL AGC mode (default disabled)\n" - " -s ifrate IF sample rate in Hz (default 1000000, valid range: [225001, 300000] U [900000, 3200000])\n" + " -s ifrate IF sample rate in Hz (default 1000000)\n" + " (valid ranges: [225001, 300000], [900001, 3200000]))\n" " -r pcmrate Audio sample rate in Hz (default 48000 Hz)\n" " -M Disable stereo decoding\n" " -R filename Write audio data as raw S16_LE samples\n" @@ -358,8 +359,8 @@ int main(int argc, char **argv) // NOTE: RTL does not support some sample rates below 900 kS/s // Also, max sampling rate is 3.2 MS/s if (!parse_dbl(optarg, ifrate) || - (ifrate <= 225000) || (ifrate > 3200000) || - ((ifrate > 300000) && (ifrate <= 900000))) { + (ifrate < 225001) || (ifrate > 3200000) || + ((ifrate > 300000) && (ifrate < 900001))) { badarg("-s"); } break;