--- vtrtlsdr.c.orig 2015-12-27 19:44:51.974350707 +0100 +++ vtrtlsdr.c 2015-12-27 23:08:04.130494884 +0100 @@ -22,6 +22,10 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // +// Changelog: +// 20151227: added direct sampling option +// changed minimum sample rate to 226k +// -- Jacek Lipkowski #include "config.h" #include "vtport.h" @@ -40,7 +44,7 @@ static double srcal = 1.0; // Sample rate calibration coefficient static unsigned int sample_rate = 0; // Nominal sample rate -static double frequency = 0; // Tuner frequency +static double frequency = -1; // Tuner frequency static int gain = 0; // Tuner gain, units of 0.1dB, 0 = use AGC static timestamp timebase = timestamp_ZERO; // Base of our timestamp @@ -52,6 +56,10 @@ static int UFLAG = FALSE; // Set TRUE with -u option static int QFLAG = FALSE; // -q option: invert Q signal + +// -D option: direct sampling: 0 (off), 1 (I input), 2 (Q input) +static int direct_sampling = 0; + /////////////////////////////////////////////////////////////////////////////// // Timestamping // /////////////////////////////////////////////////////////////////////////////// @@ -254,6 +262,9 @@ open_device(); + if( rtlsdr_set_direct_sampling(dev, direct_sampling) != 0) + VT_bailout( "RTL set direct sampling failed"); + if( rtlsdr_set_sample_rate(dev, sample_rate) < 0) VT_bailout( "cannot set RTL sample rate"); @@ -266,7 +277,7 @@ VT_report( 1, "frequency %.0f Hz", frequency); uint32_t actual_freq = rtlsdr_get_center_freq( dev); - if( !actual_freq) VT_bailout( "error setting frequency"); + if ((!direct_sampling)&&( !actual_freq)) VT_bailout( "error setting frequency"); VT_report( 1, "actual freq %d Hz", actual_freq); VT_report( 1, "frequency correction: %d ppm", @@ -486,7 +497,7 @@ " -L name Specify log file\n" " -d device Device number (default 0)\n" " -d ? List available devices\n" - " -r rate Sample rate 1000000 to 3200000\n" + " -r rate Sample rate 226000 to 3200000\n" "\n" " -F hertz Tuner frequency, Hertz\n" " -g gain Tuner gain (dB, default 0 = auto)\n" @@ -494,6 +505,7 @@ " -q Invert the Q signal\n" "\n" " -u No sample rate tracking\n" + " -D type Turn on direct sampling mode (0-off, 1-I input, 2-Q input)\n" " -T stamp Start time when using -u\n" " (default is to use system clock)\n" "\n" @@ -509,12 +521,36 @@ while( 1) { - int c = getopt( argc, argv, "vBd:r:g:F:T:L:uq?"); + int c = getopt( argc, argv, "vBd:r:g:F:T:L:uqiD:?"); if( c == 'v') VT_up_loglevel(); else - if( c == 'B') background = 1; - else + if( c == 'B') background = 1; + else + if( c == 'D') { + switch (*optarg) { + case '1': + case 'I': + case 'i': + direct_sampling=1; + break; + + case '2': + case 'Q': + case 'q': + direct_sampling=2; + break; + case '0': + direct_sampling=0; + break; + + default: + fprintf(stderr,"Unknown direct sampling option: [%s]\n",optarg); + exit(1); + } + + } + else if( c == 'L') VT_set_logfile( "%s", optarg); else if( c == 'd') @@ -564,10 +600,13 @@ if( sample_rate <= 0) VT_bailout( "invalid or missing sample rate, needs -r"); if( sample_rate > 3200000) VT_bailout( "max sample rate 3200000"); - if( sample_rate < 1000000) VT_bailout( "min sample rate 1000000"); + if( sample_rate < 226000) VT_bailout( "min sample rate 226000"); + + if (frequency < 0) + VT_bailout( "invalid frequency"); - if( frequency <= 0) - VT_bailout( "invalid or missing frequency, needs -F"); + if ((!direct_sampling)&&(frequency == 0)) + VT_bailout( "missing frequency, needs -F"); if( background) {