Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Michael Niedermayer <michael@niedermayer.cc>
To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Subject: [FFmpeg-devel] [PATCH 2/7] avradio/sdr: compensate for RTLSDR frequency limitations
Date: Mon, 17 Jul 2023 02:26:59 +0200
Message-ID: <20230717002704.3092192-2-michael@niedermayer.cc> (raw)
In-Reply-To: <20230717002704.3092192-1-michael@niedermayer.cc>

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(-)

diff --git a/libavradio/sdr.h b/libavradio/sdr.h
index ac6b7dffe0..dc20415457 100644
--- a/libavradio/sdr.h
+++ b/libavradio/sdr.h
@@ -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
diff --git a/libavradio/sdrdemux.c b/libavradio/sdrdemux.c
index a545e7cb4c..5a3af23a74 100644
--- a/libavradio/sdrdemux.c
+++ b/libavradio/sdrdemux.c
@@ -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
diff --git a/libavradio/sdrinradio.c b/libavradio/sdrinradio.c
index 0e7442fddf..f078d27e7b 100644
--- a/libavradio/sdrinradio.c
+++ b/libavradio/sdrinradio.c
@@ -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)
-- 
2.31.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

  reply	other threads:[~2023-07-17  0:27 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-17  0:26 [FFmpeg-devel] [PATCH 1/7] avradio/sdrdemux: icarrier just needs phase 2 block size Michael Niedermayer
2023-07-17  0:26 ` Michael Niedermayer [this message]
2023-07-17  0:27 ` [FFmpeg-devel] [PATCH 3/7] avradio/sdrinradio: Print all tunable elements Michael Niedermayer
2023-07-17  0:27 ` [FFmpeg-devel] [PATCH 4/7] avradio/sdrdemux: Use a local noise floor in FM Probing Michael Niedermayer
2023-07-17  0:27 ` [FFmpeg-devel] [PATCH 5/7] avradio/sdrdemux: adjust bandwidth to 200khz for FM probing Michael Niedermayer
2023-07-17  0:27 ` [FFmpeg-devel] [PATCH 6/7] avradio/sdr: Support setting gain value manually and automatic Michael Niedermayer
2023-07-17  0:27 ` [FFmpeg-devel] [PATCH 7/7] avradio/sdr: workaround inverted gain parameter on sdrplay Michael Niedermayer
2023-07-18 21:26 ` [FFmpeg-devel] [PATCH 1/7] avradio/sdrdemux: icarrier just needs phase 2 block size Michael Niedermayer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230717002704.3092192-2-michael@niedermayer.cc \
    --to=michael@niedermayer.cc \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git