@@ -210,7 +210,7 @@ typedef struct SDRContext {
/**
* Setup the hardware for the requested frequency
*/
- int (*set_frequency_callback)(struct SDRContext *sdr, int64_t frequency);
+ int64_t (*set_frequency_callback)(struct SDRContext *sdr, int64_t frequency);
/**
* Read from the hardware, block if nothing available with a reasonable timeout
@@ -1129,11 +1129,10 @@ ModulationDescriptor ff_sdr_modulation_descs[] = {
int ff_sdr_set_freq(SDRContext *sdr, int64_t freq)
{
freq = av_clip64(freq, sdr->min_center_freq, sdr->max_center_freq);
-
if (sdr->set_frequency_callback) {
- int ret = sdr->set_frequency_callback(sdr, freq);
- if (ret < 0)
- return ret;
+ freq = sdr->set_frequency_callback(sdr, freq);
+ if (freq < 0)
+ return freq;
}
sdr->freq = freq;
@@ -1421,7 +1420,7 @@ static void *soapy_needs_bigger_buffers_worker(SDRContext *sdr)
if (sdr->seek_direction && block_counter > 5) {
sdr->wanted_freq = snap2band(sdr, sdr->wanted_freq, sdr->seek_direction*sdr->bandwidth*0.5);
}
- if (sdr->wanted_freq != sdr->freq) {
+ if (fabs(sdr->wanted_freq - sdr->freq) > 1500) {
//We could use a seperate MUTEX for the FIFO and for soapy
ff_sdr_set_freq(sdr, sdr->wanted_freq);
//This shouldnt really cause any problem if we just continue on error except that we continue returning data with the previous target frequency range
@@ -68,7 +68,7 @@ static int sdrindev_read_callback(SDRContext *sdr, FIFOElement *fifo_element, in
return ret;
}
-static int sdrindev_set_frequency_callback(SDRContext *sdr, int64_t freq)
+static int64_t sdrindev_set_frequency_callback(SDRContext *sdr, int64_t freq)
{
AVFormatContext *avfmt = sdr->avfmt;
SoapySDRDevice *soapy = sdr->soapy;
@@ -83,6 +83,12 @@ static int sdrindev_set_frequency_callback(SDRContext *sdr, int64_t freq)
} else
sdr->current_direct_samp = value;
}
+ //The R820T has a 16 bit fractional PLL which can do only multiplies of 439.45
+ //Its more complex but this approximation works
+ //It has to be noted that SOAPY does not tell us about this, instead saopy
+ //pretends whatever we ask for we get exactly, but we dont
+ //For more details see: michelebavaro.blogspot.com/2014/05/gnss-carrier-phase-rtlsdr-and.html
+ freq = lrint(freq / 439.45) * 439.45;
}
if (SoapySDRDevice_setFrequency(soapy, SOAPY_SDR_RX, 0, freq, NULL) != 0) {
@@ -90,7 +96,7 @@ static int sdrindev_set_frequency_callback(SDRContext *sdr, int64_t freq)
return AVERROR_EXTERNAL;
}
}
- return 0;
+ return freq;
}
static void print_and_free_list(AVFormatContext *s, char** names, size_t length, const char *title)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc> --- libavradio/sdr.h | 2 +- libavradio/sdrdemux.c | 9 ++++----- libavradio/sdrinradio.c | 10 ++++++++-- 3 files changed, 13 insertions(+), 8 deletions(-)