Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH 01/18] avradio/sdrdemux: Fix uninitialized access
@ 2023-07-08 21:25 Michael Niedermayer
  2023-07-08 21:25 ` [FFmpeg-devel] [PATCH 02/18] avradio/sdrdemux: factor frequency tolerance constants out Michael Niedermayer
                   ` (17 more replies)
  0 siblings, 18 replies; 19+ messages in thread
From: Michael Niedermayer @ 2023-07-08 21:25 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavradio/sdrdemux.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/libavradio/sdrdemux.c b/libavradio/sdrdemux.c
index bed74ebd26..3bb5a69cf1 100644
--- a/libavradio/sdrdemux.c
+++ b/libavradio/sdrdemux.c
@@ -1500,9 +1500,11 @@ int avpriv_sdr_common_init(AVFormatContext *s)
         SDRStream *sst = st->priv_data;
         av_assert0(st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO);
         sst->frame_size   = sdr->width * sdr->height * 4;
-        sst->frame_buffer = av_malloc(sst->frame_size * 2);
+        sst->frame_buffer = av_mallocz(sst->frame_size * 2);
         if (!sst->frame_buffer)
             return AVERROR(ENOMEM);
+        for(int i = 3; i<sst->frame_size * 2; i+=4)
+            sst->frame_buffer[i] = 255;
     }
 
     sdr->pts = 0;
-- 
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".

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [FFmpeg-devel] [PATCH 02/18] avradio/sdrdemux: factor frequency tolerance constants out
  2023-07-08 21:25 [FFmpeg-devel] [PATCH 01/18] avradio/sdrdemux: Fix uninitialized access Michael Niedermayer
@ 2023-07-08 21:25 ` Michael Niedermayer
  2023-07-08 21:25 ` [FFmpeg-devel] [PATCH 03/18] avradio/sdr: Add fm multiple parameter Michael Niedermayer
                   ` (16 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: Michael Niedermayer @ 2023-07-08 21:25 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavradio/sdrdemux.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/libavradio/sdrdemux.c b/libavradio/sdrdemux.c
index 3bb5a69cf1..1f2d778978 100644
--- a/libavradio/sdrdemux.c
+++ b/libavradio/sdrdemux.c
@@ -61,6 +61,9 @@
 #define FREQ_BITS 22
 #define TIMEBASE ((48000ll / 128) << FREQ_BITS)
 
+#define AM_FREQ_TOLERANCE 5
+#define FM_FREQ_TOLERANCE 500
+
 #define STATION_TIMEOUT 100 ///< The number of frames after which a station is removed if it was not detected
 #define CANDIDATE_STATION_TIMEOUT 4
 
@@ -248,7 +251,7 @@ static int create_station(SDRContext *sdr, Station *candidate_station) {
 
     nb_candidate_match += candidate_station->nb_frequency - 1;
     for (i=0; i<nb_stations; i++) {
-        int freq_precission = modulation == AM ? 5 : 500;
+        int freq_precission = modulation == AM ? AM_FREQ_TOLERANCE : FM_FREQ_TOLERANCE;
         Station *s = station_list[i];
         double delta = fabs(s->frequency - freq);
 
@@ -383,7 +386,7 @@ static int create_candidate_station(SDRContext *sdr, enum Modulation modulation,
     void *tmp;
     struct AVTreeNode *next = NULL;
     Station *station_list[1000];
-    double snapdistance = modulation == AM ? 5 : 500;
+    double snapdistance = modulation == AM ? AM_FREQ_TOLERANCE : FM_FREQ_TOLERANCE;
     int nb_stations = find_stations(sdr, freq, snapdistance, station_list, FF_ARRAY_ELEMS(station_list));
 
     if (nb_stations) {
-- 
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".

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [FFmpeg-devel] [PATCH 03/18] avradio/sdr: Add fm multiple parameter
  2023-07-08 21:25 [FFmpeg-devel] [PATCH 01/18] avradio/sdrdemux: Fix uninitialized access Michael Niedermayer
  2023-07-08 21:25 ` [FFmpeg-devel] [PATCH 02/18] avradio/sdrdemux: factor frequency tolerance constants out Michael Niedermayer
@ 2023-07-08 21:25 ` Michael Niedermayer
  2023-07-08 21:25 ` [FFmpeg-devel] [PATCH 04/18] avradio/sdrinradio: Dont automatically select 2.56Mhz on the rtlsdr Michael Niedermayer
                   ` (15 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: Michael Niedermayer @ 2023-07-08 21:25 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 doc/demuxers.texi     | 7 +++++++
 libavradio/sdr.h      | 1 +
 libavradio/sdrdemux.c | 9 +++++++++
 3 files changed, 17 insertions(+)

diff --git a/doc/demuxers.texi b/doc/demuxers.texi
index 81c46ce08f..86f031b9ed 100644
--- a/doc/demuxers.texi
+++ b/doc/demuxers.texi
@@ -965,6 +965,13 @@ it can also result in the detection of SDR artifacts such as reflections of stro
 as weak stations. Future versions may be better able to separate weak stations from artifacts
 looking like weak stations.
 
+@item fm_multiple
+Multiple of frequency in hz at which to search for stations.
+you can set this to 100000 to probe stations at 0.1MHz increments
+Most SDR artifacts are not at exact multiplies, this is thus an effective
+way to eliminate these artifacts.
+disabled by default.
+
 @item am_mode
 AM Demodulation method. Several different methods are supported.
 @table @samp
diff --git a/libavradio/sdr.h b/libavradio/sdr.h
index 1053e45efe..ff4bfcaa1f 100644
--- a/libavradio/sdr.h
+++ b/libavradio/sdr.h
@@ -159,6 +159,7 @@ typedef struct SDRContext {
 
     float am_threshold;
     float fm_threshold;
+    float fm_multiple;
 
     pthread_t hw_thread;
     int thread_started;
diff --git a/libavradio/sdrdemux.c b/libavradio/sdrdemux.c
index 1f2d778978..13cec10505 100644
--- a/libavradio/sdrdemux.c
+++ b/libavradio/sdrdemux.c
@@ -915,6 +915,14 @@ static int probe_fm(SDRContext *sdr)
 
                     if (fabs(f2 - f) > 1000)
                         continue;
+
+                    if (sdr->fm_multiple) {
+                        double f3 = lrint(f2 / sdr->fm_multiple) * sdr->fm_multiple;
+                        if (fabs(f2 - f3) > FM_FREQ_TOLERANCE)
+                            continue;
+                        f2 = f3;
+                    }
+
                     create_candidate_station(sdr, FM, f2, bandwidth_f, bandwidth_p2, score);
                 }
             }
@@ -2169,6 +2177,7 @@ const AVOption avpriv_sdr_options[] = {
 
     { "am_threshold"     , "AM detection threshold", OFFSET(am_threshold), AV_OPT_TYPE_FLOAT, {.dbl = 20}, 0, FLT_MAX, DEC},
     { "fm_threshold"     , "FM detection threshold", OFFSET(fm_threshold), AV_OPT_TYPE_FLOAT, {.dbl = 50}, 0, FLT_MAX, DEC},
+    { "fm_multiple"      , "FM frequency mutiple",   OFFSET(fm_multiple ), AV_OPT_TYPE_FLOAT, {.dbl =  0}, 0, FLT_MAX, DEC},
 
     { NULL },
 };
-- 
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".

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [FFmpeg-devel] [PATCH 04/18] avradio/sdrinradio: Dont automatically select 2.56Mhz on the rtlsdr
  2023-07-08 21:25 [FFmpeg-devel] [PATCH 01/18] avradio/sdrdemux: Fix uninitialized access Michael Niedermayer
  2023-07-08 21:25 ` [FFmpeg-devel] [PATCH 02/18] avradio/sdrdemux: factor frequency tolerance constants out Michael Niedermayer
  2023-07-08 21:25 ` [FFmpeg-devel] [PATCH 03/18] avradio/sdr: Add fm multiple parameter Michael Niedermayer
@ 2023-07-08 21:25 ` Michael Niedermayer
  2023-07-08 21:25 ` [FFmpeg-devel] [PATCH 05/18] avradio/sdrdemux: Do not timeout negative stations Michael Niedermayer
                   ` (14 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: Michael Niedermayer @ 2023-07-08 21:25 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

2.56Mhz produces more artifacts than lower sample rates at least
in the FM broadcast band

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavradio/sdrinradio.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavradio/sdrinradio.c b/libavradio/sdrinradio.c
index c6f5742436..052e2298da 100644
--- a/libavradio/sdrinradio.c
+++ b/libavradio/sdrinradio.c
@@ -235,8 +235,8 @@ static int sdrindev_initial_hw_setup(AVFormatContext *s)
             (sdr->sdr_sample_rate < ranges[i].minimum || sdr->sdr_sample_rate > ranges[i].maximum))
             continue;
         if (sdr->rtlsdr_fixes)
-            // 2.88 and 3.2 Mhz do not work reliable here so lets not automatically choose them, the user can override this
-            if (ranges[i].maximum > (2560000 + 2880000)/2)
+            // 2.56, 2.88 and 3.2 Mhz do not work reliable here so lets not automatically choose them, the user can override this
+            if (ranges[i].maximum > (2560000 + 2160000)/2)
                 continue;
         max_sample_rate = FFMAX(max_sample_rate, ranges[i].maximum);
     }
-- 
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".

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [FFmpeg-devel] [PATCH 05/18] avradio/sdrdemux: Do not timeout negative stations
  2023-07-08 21:25 [FFmpeg-devel] [PATCH 01/18] avradio/sdrdemux: Fix uninitialized access Michael Niedermayer
                   ` (2 preceding siblings ...)
  2023-07-08 21:25 ` [FFmpeg-devel] [PATCH 04/18] avradio/sdrinradio: Dont automatically select 2.56Mhz on the rtlsdr Michael Niedermayer
@ 2023-07-08 21:25 ` Michael Niedermayer
  2023-07-08 21:25 ` [FFmpeg-devel] [PATCH 06/18] avradio/sdrinradio: Factor print_and_free_list() out Michael Niedermayer
                   ` (13 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: Michael Niedermayer @ 2023-07-08 21:25 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

If we identified that a station is an artifact of the SDR, we dont
want to timeout that to avoid it being redetected as station

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavradio/sdrdemux.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/libavradio/sdrdemux.c b/libavradio/sdrdemux.c
index 13cec10505..39eaa0c094 100644
--- a/libavradio/sdrdemux.c
+++ b/libavradio/sdrdemux.c
@@ -347,6 +347,7 @@ static void decay_stations(SDRContext *sdr)
 
     for (int i=0; i<nb_stations; i++) {
         Station *station = station_list[i];
+        int hs;
 
         if (station->frequency - station->bandwidth/2 < sdr->block_center_freq - sdr->bandwidth/2 ||
             station->frequency + station->bandwidth/2 > sdr->block_center_freq + sdr->bandwidth/2)
@@ -355,9 +356,10 @@ static void decay_stations(SDRContext *sdr)
         if (station->timeout)
             station->non_detection_per_mix_frequency[histogram_index(sdr, station->frequency)] ++;
 
+        hs = histogram_score(station);
+
         if (station->in_station_list) {
             int station_timeout = STATION_TIMEOUT;
-            int hs = histogram_score(station);
 
             if (hs == 0) {
                 station_timeout = 5; //give the station a moment to be properly detected and then discard it
@@ -370,7 +372,13 @@ static void decay_stations(SDRContext *sdr)
                     station->in_station_list = 0;
             }
         } else {
-            if (station->timeout++ > CANDIDATE_STATION_TIMEOUT) {
+            int station_timeout = CANDIDATE_STATION_TIMEOUT;
+
+            //We do not want to drop "negative" stations to avoid them being redetected
+            if (hs <= 0)
+                station_timeout = INT_MAX;
+
+            if (station->timeout++ > station_timeout) {
                 struct AVTreeNode *next = NULL;
                 tree_remove(&sdr->station_root, station, station_cmp, &next);
                 av_freep(&next);
-- 
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".

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [FFmpeg-devel] [PATCH 06/18] avradio/sdrinradio: Factor print_and_free_list() out
  2023-07-08 21:25 [FFmpeg-devel] [PATCH 01/18] avradio/sdrdemux: Fix uninitialized access Michael Niedermayer
                   ` (3 preceding siblings ...)
  2023-07-08 21:25 ` [FFmpeg-devel] [PATCH 05/18] avradio/sdrdemux: Do not timeout negative stations Michael Niedermayer
@ 2023-07-08 21:25 ` Michael Niedermayer
  2023-07-08 21:25 ` [FFmpeg-devel] [PATCH 07/18] avradio/sdrinradio: Print list of Time Sources Michael Niedermayer
                   ` (12 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: Michael Niedermayer @ 2023-07-08 21:25 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavradio/sdrinradio.c | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/libavradio/sdrinradio.c b/libavradio/sdrinradio.c
index 052e2298da..e4f17f4bc9 100644
--- a/libavradio/sdrinradio.c
+++ b/libavradio/sdrinradio.c
@@ -93,6 +93,17 @@ static int sdrindev_set_frequency_callback(SDRContext *sdr, int64_t freq)
     return 0;
 }
 
+static void print_and_free_list(AVFormatContext *s, char** names, size_t length, const char *title)
+{
+    if (length) {
+        av_log(s, AV_LOG_INFO, "%s:", title);
+        for (int i = 0; i < length; i++)
+            av_log(s, AV_LOG_INFO, "%c%s", ", "[!i], names[i]);
+        av_log(s, AV_LOG_INFO, "\n");
+    }
+    SoapySDRStrings_clear(&names, length);
+}
+
 /**
  * Initial setup of SDR HW through soapy.
  * This will go over available settings and match them up with what the user requested
@@ -162,19 +173,11 @@ static int sdrindev_initial_hw_setup(AVFormatContext *s)
 
     //Go over all Antennas and print them
     names = SoapySDRDevice_listAntennas(soapy, SOAPY_SDR_RX, 0, &length);
-    av_log(s, AV_LOG_INFO, "Antennas: ");
-    for (i = 0; i < length; i++)
-        av_log(s, AV_LOG_INFO, "%s, ", names[i]);
-    av_log(s, AV_LOG_INFO, "\n");
-    SoapySDRStrings_clear(&names, length);
+    print_and_free_list(s, names, length, "Antennas");
 
     //Go over all Gain Elements and print them
     names = SoapySDRDevice_listGains(soapy, SOAPY_SDR_RX, 0, &length);
-    av_log(s, AV_LOG_INFO, "Rx Gain Elements: ");
-    for (i = 0; i < length; i++)
-        av_log(s, AV_LOG_INFO, "%s, ", names[i]);
-    av_log(s, AV_LOG_INFO, "\n");
-    SoapySDRStrings_clear(&names, length);
+    print_and_free_list(s, names, length, "Rx Gain Elements");
 
     //Inform the user if AGC is supported and setup AGC as requested by the user
     has_agc = SoapySDRDevice_hasGainMode(soapy, SOAPY_SDR_RX, 0);
-- 
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".

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [FFmpeg-devel] [PATCH 07/18] avradio/sdrinradio: Print list of Time Sources
  2023-07-08 21:25 [FFmpeg-devel] [PATCH 01/18] avradio/sdrdemux: Fix uninitialized access Michael Niedermayer
                   ` (4 preceding siblings ...)
  2023-07-08 21:25 ` [FFmpeg-devel] [PATCH 06/18] avradio/sdrinradio: Factor print_and_free_list() out Michael Niedermayer
@ 2023-07-08 21:25 ` Michael Niedermayer
  2023-07-08 21:25 ` [FFmpeg-devel] [PATCH 08/18] avradio: split out vissualization code Michael Niedermayer
                   ` (11 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: Michael Niedermayer @ 2023-07-08 21:25 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavradio/sdrinradio.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/libavradio/sdrinradio.c b/libavradio/sdrinradio.c
index e4f17f4bc9..af87b49495 100644
--- a/libavradio/sdrinradio.c
+++ b/libavradio/sdrinradio.c
@@ -171,6 +171,9 @@ static int sdrindev_initial_hw_setup(AVFormatContext *s)
         return AVERROR_EXTERNAL;
     }
 
+    names = SoapySDRDevice_listTimeSources(soapy, &length);
+    print_and_free_list(s, names, length, "Clocks");
+
     //Go over all Antennas and print them
     names = SoapySDRDevice_listAntennas(soapy, SOAPY_SDR_RX, 0, &length);
     print_and_free_list(s, names, length, "Antennas");
-- 
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".

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [FFmpeg-devel] [PATCH 08/18] avradio: split out vissualization code
  2023-07-08 21:25 [FFmpeg-devel] [PATCH 01/18] avradio/sdrdemux: Fix uninitialized access Michael Niedermayer
                   ` (5 preceding siblings ...)
  2023-07-08 21:25 ` [FFmpeg-devel] [PATCH 07/18] avradio/sdrinradio: Print list of Time Sources Michael Niedermayer
@ 2023-07-08 21:25 ` Michael Niedermayer
  2023-07-08 21:25 ` [FFmpeg-devel] [PATCH 09/18] avradio/sdrdemux: The RTLSDR DC artifact is not consistent Michael Niedermayer
                   ` (10 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: Michael Niedermayer @ 2023-07-08 21:25 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavradio/Makefile     |   4 +-
 libavradio/sdr.h        |  21 ++++
 libavradio/sdrdemux.c   | 207 +++-------------------------------------
 libavradio/vissualize.c | 200 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 238 insertions(+), 194 deletions(-)
 create mode 100644 libavradio/vissualize.c

diff --git a/libavradio/Makefile b/libavradio/Makefile
index 23c173bc58..40b38f798e 100644
--- a/libavradio/Makefile
+++ b/libavradio/Makefile
@@ -11,5 +11,5 @@ OBJS    = allradios.o                                                   \
 
 
 # input/output radios
-OBJS-$(CONFIG_SDR_INRADIO)            		+= sdrinradio.o
-OBJS-$(CONFIG_SDRFILE_INRADIO)                  += sdrdemux.o
+OBJS-$(CONFIG_SDR_INRADIO)            		+= sdrinradio.o vissualize.o
+OBJS-$(CONFIG_SDRFILE_INRADIO)                  += sdrdemux.o vissualize.o
diff --git a/libavradio/sdr.h b/libavradio/sdr.h
index ff4bfcaa1f..95ff903293 100644
--- a/libavradio/sdr.h
+++ b/libavradio/sdr.h
@@ -34,6 +34,8 @@
 #include "libavutil/tx.h"
 #include "libavformat/avformat.h"
 
+#define FREQ_BITS 22
+#define TIMEBASE ((48000ll / 128) << FREQ_BITS)
 
 #define INDEX2F(INDEX) (((INDEX) - sdr->block_size  + 0.5) * 0.5 * sdr->sdr_sample_rate / sdr->block_size      + sdr->block_center_freq)
 #define F2INDEX(F)     (((    F) - sdr->block_center_freq) * 2   * sdr->block_size      / sdr->sdr_sample_rate + sdr->block_size  - 0.5)
@@ -229,6 +231,8 @@ typedef struct BandDescriptor {
 
 extern const AVOption avpriv_sdr_options[];
 
+extern ModulationDescriptor ff_sdr_modulation_descs[];
+
 /**
  * Set the center frequency of the hardware
  * this will check the argument and call set_frequency_callback()
@@ -250,4 +254,21 @@ void avpriv_sdr_stop_threading(AVFormatContext *s);
 
 int avpriv_sdr_read_close(AVFormatContext *s);
 
+int ff_sdr_vissualization(SDRContext *sdr, AVStream *st, AVPacket *pkt);
+
+/**
+ * Find stations within the given parameters.
+ * @param[out] station_list array to return stations in
+ * @param nb_stations size of station array
+ * @returns number of stations found
+ */
+int ff_sdr_find_stations(SDRContext *sdr, double freq, double range, Station **station_list, int station_list_size);
+
+int ff_sdr_histogram_score(Station *s);
+
+static inline float len2(AVComplexFloat c)
+{
+    return c.re*c.re + c.im*c.im;
+}
+
 #endif /* AVRADIO_SDR_H */
diff --git a/libavradio/sdrdemux.c b/libavradio/sdrdemux.c
index 39eaa0c094..392fece4e9 100644
--- a/libavradio/sdrdemux.c
+++ b/libavradio/sdrdemux.c
@@ -48,7 +48,6 @@
 #include "libavutil/thread.h"
 #include "libavutil/tree.h"
 #include "libavutil/tx.h"
-#include "libavutil/xga_font_data.h"
 #include "libavcodec/kbdwin.h"
 #include "libavformat/avformat.h"
 #include "libavformat/demux.h"
@@ -58,9 +57,6 @@
 #include "libavutil/lfg.h"
 #endif
 
-#define FREQ_BITS 22
-#define TIMEBASE ((48000ll / 128) << FREQ_BITS)
-
 #define AM_FREQ_TOLERANCE 5
 #define FM_FREQ_TOLERANCE 500
 
@@ -101,11 +97,6 @@ static void apply_deemphasis(SDRContext *sdr, AVComplexFloat *data, int len, int
     }
 }
 
-static float len2(AVComplexFloat c)
-{
-    return c.re*c.re + c.im*c.im;
-}
-
 static void free_station(Station *station)
 {
     av_freep(&station->name);
@@ -120,7 +111,7 @@ static inline int histogram_index(SDRContext *sdr, double f)
     return av_clip((int)f, 0, HISTOGRAMM_SIZE-1);
 }
 
-static int histogram_score(Station *s)
+int ff_sdr_histogram_score(Station *s)
 {
     int score = 0;
     for(int i = 0; i<HISTOGRAMM_SIZE; i++) {
@@ -168,13 +159,7 @@ static int free_station_enu(void *opaque, void *elem)
     return 0;
 }
 
-/**
- * Find stations within the given parameters.
- * @param[out] station_list array to return stations in
- * @param nb_stations size of station array
- * @returns number of stations found
- */
-static int find_stations(SDRContext *sdr, double freq, double range, Station **station_list, int station_list_size)
+int ff_sdr_find_stations(SDRContext *sdr, double freq, double range, Station **station_list, int station_list_size)
 {
     FindStationContext find_station_context;
     find_station_context.freq = freq;
@@ -205,11 +190,11 @@ static int create_station(SDRContext *sdr, Station *candidate_station) {
         return 0;
 
     // suspect looking histogram
-    if (histogram_score(candidate_station) <= 0)
+    if (ff_sdr_histogram_score(candidate_station) <= 0)
         return 0;
 
     Station *station_list[1000];
-    int nb_stations = find_stations(sdr, sdr->block_center_freq, sdr->sdr_sample_rate*0.5, station_list, FF_ARRAY_ELEMS(station_list));
+    int nb_stations = ff_sdr_find_stations(sdr, sdr->block_center_freq, sdr->sdr_sample_rate*0.5, station_list, FF_ARRAY_ELEMS(station_list));
     for (i=0; i<nb_stations; i++) {
         Station *s = station_list[i];
         double delta = fabs(s->frequency - freq);
@@ -305,7 +290,7 @@ static void create_stations(SDRContext *sdr)
     if (!sdr->block_center_freq)
         return;
 
-    int nb_stations = find_stations(sdr, sdr->block_center_freq, sdr->sdr_sample_rate*0.5, station_list, FF_ARRAY_ELEMS(station_list));
+    int nb_stations = ff_sdr_find_stations(sdr, sdr->block_center_freq, sdr->sdr_sample_rate*0.5, station_list, FF_ARRAY_ELEMS(station_list));
 
     for(int i = 0; i<nb_stations; i++) {
         create_station(sdr, station_list[i]);
@@ -343,7 +328,7 @@ static void *tree_remove(struct AVTreeNode **rootp, void *key,
 static void decay_stations(SDRContext *sdr)
 {
     Station *station_list[1000];
-    int nb_stations = find_stations(sdr, sdr->block_center_freq, sdr->bandwidth*0.5, station_list, FF_ARRAY_ELEMS(station_list));
+    int nb_stations = ff_sdr_find_stations(sdr, sdr->block_center_freq, sdr->bandwidth*0.5, station_list, FF_ARRAY_ELEMS(station_list));
 
     for (int i=0; i<nb_stations; i++) {
         Station *station = station_list[i];
@@ -356,7 +341,7 @@ static void decay_stations(SDRContext *sdr)
         if (station->timeout)
             station->non_detection_per_mix_frequency[histogram_index(sdr, station->frequency)] ++;
 
-        hs = histogram_score(station);
+        hs = ff_sdr_histogram_score(station);
 
         if (station->in_station_list) {
             int station_timeout = STATION_TIMEOUT;
@@ -395,7 +380,7 @@ static int create_candidate_station(SDRContext *sdr, enum Modulation modulation,
     struct AVTreeNode *next = NULL;
     Station *station_list[1000];
     double snapdistance = modulation == AM ? AM_FREQ_TOLERANCE : FM_FREQ_TOLERANCE;
-    int nb_stations = find_stations(sdr, freq, snapdistance, station_list, FF_ARRAY_ELEMS(station_list));
+    int nb_stations = ff_sdr_find_stations(sdr, freq, snapdistance, station_list, FF_ARRAY_ELEMS(station_list));
 
     if (nb_stations) {
         for(int i = 1; i<nb_stations; i++)
@@ -1066,7 +1051,7 @@ BandDescriptor band_descs[] = {
     {"FM broadcast band", "FM", 88000000, 108000000},
 };
 
-ModulationDescriptor modulation_descs[] = {
+ModulationDescriptor ff_sdr_modulation_descs[] = {
     {"Amplitude Modulation", "AM", AM, AVMEDIA_TYPE_AUDIO, probe_am, demodulate_am},
     {"Frequency Modulation", "FM", FM, AVMEDIA_TYPE_AUDIO, probe_fm, demodulate_fm},
 };
@@ -1260,7 +1245,7 @@ static int snap2station(SDRContext *sdr, int *seek_direction) {
     double best_distance = INT64_MAX;
     Station *best_station = NULL;
     Station *station_list[1000];
-    int nb_stations = find_stations(sdr, sdr->block_center_freq, sdr->sdr_sample_rate*0.5, station_list, FF_ARRAY_ELEMS(station_list));
+    int nb_stations = ff_sdr_find_stations(sdr, sdr->block_center_freq, sdr->sdr_sample_rate*0.5, station_list, FF_ARRAY_ELEMS(station_list));
 
     if (sst->station) {
         current_freq = sst->station->frequency;
@@ -1612,168 +1597,6 @@ static int sdrfile_initial_setup(AVFormatContext *s)
     return avpriv_sdr_common_init(s);
 }
 
-static inline void draw_point_component(uint8_t *frame_buffer, ptrdiff_t stride, int x, int y, int r, int g, int b, int w, int h)
-{
-    uint8_t *p;
-
-    if (x<0 || y<0 || x>=w || y>=h)
-        return;
-    p = frame_buffer + 4*x + stride*y;
-
-    p[0] = av_clip_uint8(p[0] + (b>>16));
-    p[1] = av_clip_uint8(p[1] + (g>>16));
-    p[2] = av_clip_uint8(p[2] + (r>>16));
-}
-
-// Draw a point with subpixel precission, (it looked bad otherwise)
-static void draw_point(uint8_t *frame_buffer, ptrdiff_t stride, int x, int y, int r, int g, int b, int w, int h)
-{
-    int px = x>>8;
-    int py = y>>8;
-    int sx = x&255;
-    int sy = y&255;
-    int s;
-
-    s = (256 - sx) * (256 - sy);
-    draw_point_component(frame_buffer, stride, px  , py  , r*s, g*s, b*s, w, h);
-    s = sx * (256 - sy);
-    draw_point_component(frame_buffer, stride, px+1, py  , r*s, g*s, b*s, w, h);
-    s = (256 - sx) * sy;
-    draw_point_component(frame_buffer, stride, px  , py+1, r*s, g*s, b*s, w, h);
-    s = sx * sy;
-    draw_point_component(frame_buffer, stride, px+1, py+1, r*s, g*s, b*s, w, h);
-}
-
-static void draw_char(uint8_t *frame_buffer, ptrdiff_t stride, char ch, int x0, int y0, int xd, int yd, int r, int g, int b, int w, int h)
-{
-    for(int y = 0; y < 16; y++) {
-        int mask = avpriv_vga16_font[16*ch + y];
-        for(int x = 0; x < 8; x++) {
-            if (mask&0x80)
-                draw_point(frame_buffer, stride, x0 + xd*x - yd*y, y0 + yd*x + xd*y, r, g, b, w, h);
-            mask<<=1;
-        }
-    }
-}
-
-static void draw_string(uint8_t *frame_buffer, ptrdiff_t stride, char *str, int x0, int y0, int xd, int yd, int r, int g, int b, int w, int h)
-{
-    while(*str) {
-        draw_char(frame_buffer, stride, *str++, x0, y0, xd, yd, r, g, b, w, h);
-        x0 += xd*9;
-        y0 += yd*9;
-    }
-}
-
-static int vissualization(SDRContext *sdr, AVStream *st, AVPacket *pkt)
-{
-    SDRStream *sst = st->priv_data;
-    int w = st->codecpar->width;
-    int h = st->codecpar->height;
-    int h2 = FFMIN(64, h / 4);
-    int frame_index = av_rescale(sdr->pts,        sdr->fps.num, sdr->fps.den * TIMEBASE);
-    int  last_index = av_rescale(sdr->last_pts,   sdr->fps.num, sdr->fps.den * TIMEBASE);
-    int skip = frame_index == last_index || sdr->missing_streams;
-    av_assert0(sdr->missing_streams >= 0);
-
-    for(int x= 0; x<w; x++) {
-        int color;
-        int idx = 4*(x + sst->frame_buffer_line*w);
-        int bindex  =  x    * 2ll * sdr->block_size / w;
-        int bindex2 = (x+1) * 2ll * sdr->block_size / w;
-        float a = 0;
-        av_assert0(bindex2 <= 2 * sdr->block_size);
-        for (int i = bindex; i < bindex2; i++) {
-            AVComplexFloat sample = sdr->block[i];
-            a += len2(sample);
-        }
-        color = lrintf(log(a)*8 + 32);
-
-        sst->frame_buffer[idx + 0] = color;
-        sst->frame_buffer[idx + 1] = color;
-        sst->frame_buffer[idx + 2] = color;
-        sst->frame_buffer[idx + 3] = 255;
-    }
-
-    // Display locations of all vissible stations
-//     for(int station_index = 0; station_index<sdr->nb_stations; station_index++) {
-//         Station *s = sdr->station[station_index];
-//         double f = s->frequency;
-// //                     int bw = s->bandwidth;
-// //                     int xleft = 256*((f-bw) - sdr->block_center_freq + sdr->sdr_sample_rate/2) * w / sdr->sdr_sample_rate;
-// //                     int xright= 256*((f+bw) - sdr->block_center_freq + sdr->sdr_sample_rate/2) * w / sdr->sdr_sample_rate;
-//         int xmid  = 256*( f     - sdr->block_center_freq + sdr->sdr_sample_rate/2) * w / sdr->sdr_sample_rate;
-//         int g = s->modulation == AM ? 50 : 0;
-//         int b = s->modulation == AM ? 0 : 70;
-//         int r = s->stream ? 50 : 0;
-//
-//         draw_point(sst->frame_buffer, 4*w, xmid, 256*(sst->frame_buffer_line+1), r, g, b, w, h);
-//     }
-
-    if (!skip) {
-        int ret = av_new_packet(pkt, sst->frame_size);
-        if (ret < 0)
-            return ret;
-
-        for(int y= 0; y<h2; y++) {
-            for(int x= 0; x<w; x++) {
-                int color;
-                int idx = x + y*w;
-                int idx_t = (idx / h2) + (idx % h2)*w;
-                int bindex  =  idx    * 2ll * sdr->block_size / (w * h2);
-                int bindex2 = (idx+1) * 2ll * sdr->block_size / (w * h2);
-                float a = 0;
-                av_assert0(bindex2 <= 2 * sdr->block_size);
-                for (int i = bindex; i < bindex2; i++) {
-                    AVComplexFloat sample = sdr->block[i];
-                    a += len2(sample);
-                }
-                color = lrintf(log(a)*9 + 64);
-
-                idx_t *= 4;
-
-                pkt->data[idx_t+0] = color;
-                pkt->data[idx_t+1] = color;
-                pkt->data[idx_t+2] = color;
-                pkt->data[idx_t+3] = 255;
-            }
-        }
-
-        for (int y= h2; y<h; y++)
-            memcpy(pkt->data + 4*y*w, sst->frame_buffer + 4*(y + sst->frame_buffer_line - h2)*w, 4*w);
-
-        Station *station_list[1000];
-        int nb_stations = find_stations(sdr, sdr->block_center_freq, sdr->sdr_sample_rate*0.6, station_list, FF_ARRAY_ELEMS(station_list));
-        for(int station_index = 0; station_index<nb_stations; station_index++) {
-            Station *s = station_list[station_index];
-            double f = s->frequency;
-            int xmid  = 256*( f     - sdr->block_center_freq + sdr->sdr_sample_rate/2) * w / sdr->sdr_sample_rate;
-            char text[20];
-            int color = s->stream ? 64 : 32;
-            int size = s->stream ? 181 : 128;
-            int xd = size, yd = size;
-
-            if (!s->in_station_list)
-                continue;
-
-            snprintf(text, sizeof(text), "%s %f Mhz",
-                     modulation_descs[s->modulation].shortname,
-                     f/1000000);
-            draw_string(pkt->data, 4*w, text, xmid + 8*yd, 320*h2, xd, yd, color, color, color, w, h);
-        }
-    }
-
-    if (!sst->frame_buffer_line) {
-        memcpy(sst->frame_buffer + sst->frame_size, sst->frame_buffer, sst->frame_size);
-        sst->frame_buffer_line = h-1;
-    } else
-        sst->frame_buffer_line--;
-
-//TODO
-//                 draw RDS*
-    return skip;
-}
-
 int avpriv_sdr_read_packet(AVFormatContext *s, AVPacket *pkt)
 {
     SDRContext *sdr = s->priv_data;
@@ -1789,13 +1612,13 @@ process_next_block:
         if (sst->processing_index) {
             int skip = 1;
             if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
-                skip = vissualization(sdr, st, pkt);
+                skip = ff_sdr_vissualization(sdr, st, pkt);
                 if (skip < 0)
                     return skip;
             } else if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
                 if (sst->station) {
                     skip = 0;
-                    ret = modulation_descs[ sst->station->modulation ].demodulate(sdr, stream_index, pkt);
+                    ret = ff_sdr_modulation_descs[ sst->station->modulation ].demodulate(sdr, stream_index, pkt);
                     if (ret < 0) {
                         av_log(s, AV_LOG_ERROR, "demodulation failed ret = %d\n", ret);
                     }
@@ -1970,8 +1793,8 @@ process_next_block:
             sdr->skip_probe = 5;
             probe_common(sdr);
 
-            for(int i = 0; i < FF_ARRAY_ELEMS(modulation_descs); i++) {
-                ModulationDescriptor *md = &modulation_descs[i];
+            for(int i = 0; i < FF_ARRAY_ELEMS(ff_sdr_modulation_descs); i++) {
+                ModulationDescriptor *md = &ff_sdr_modulation_descs[i];
                 md->probe(sdr);
                 av_assert0(i == md->modulation);
             }
@@ -1992,7 +1815,7 @@ process_next_block:
         } else {
             av_assert0(sdr->mode == AllStationMode);
             Station *station_list[1000];
-            int nb_stations = find_stations(sdr, sdr->block_center_freq, sdr->sdr_sample_rate*0.5, station_list, FF_ARRAY_ELEMS(station_list));
+            int nb_stations = ff_sdr_find_stations(sdr, sdr->block_center_freq, sdr->sdr_sample_rate*0.5, station_list, FF_ARRAY_ELEMS(station_list));
             for(int i = 0; i<nb_stations; i++) {
                 Station *station = station_list[i];
                 if (!station->stream) {
diff --git a/libavradio/vissualize.c b/libavradio/vissualize.c
new file mode 100644
index 0000000000..c165e0fb63
--- /dev/null
+++ b/libavradio/vissualize.c
@@ -0,0 +1,200 @@
+/*
+ * SDR Demuxer / Demodulator Vissualization
+ * Copyright (c) 2023 Michael Niedermayer
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ *
+ *
+ */
+
+
+#include "sdr.h"
+
+#include <float.h>
+#include "libavutil/avassert.h"
+#include "libavutil/ffmath.h"
+#include "libavutil/intreadwrite.h"
+#include "libavutil/opt.h"
+#include "libavutil/avstring.h"
+#include "libavutil/xga_font_data.h"
+#include "libavformat/avformat.h"
+
+static inline void draw_point_component(uint8_t *frame_buffer, ptrdiff_t stride, int x, int y, int r, int g, int b, int w, int h)
+{
+    uint8_t *p;
+
+    if (x<0 || y<0 || x>=w || y>=h)
+        return;
+    p = frame_buffer + 4*x + stride*y;
+
+    p[0] = av_clip_uint8(p[0] + (b>>16));
+    p[1] = av_clip_uint8(p[1] + (g>>16));
+    p[2] = av_clip_uint8(p[2] + (r>>16));
+}
+
+// Draw a point with subpixel precission, (it looked bad otherwise)
+static void draw_point(uint8_t *frame_buffer, ptrdiff_t stride, int x, int y, int r, int g, int b, int w, int h)
+{
+    int px = x>>8;
+    int py = y>>8;
+    int sx = x&255;
+    int sy = y&255;
+    int s;
+
+    s = (256 - sx) * (256 - sy);
+    draw_point_component(frame_buffer, stride, px  , py  , r*s, g*s, b*s, w, h);
+    s = sx * (256 - sy);
+    draw_point_component(frame_buffer, stride, px+1, py  , r*s, g*s, b*s, w, h);
+    s = (256 - sx) * sy;
+    draw_point_component(frame_buffer, stride, px  , py+1, r*s, g*s, b*s, w, h);
+    s = sx * sy;
+    draw_point_component(frame_buffer, stride, px+1, py+1, r*s, g*s, b*s, w, h);
+}
+
+static void draw_char(uint8_t *frame_buffer, ptrdiff_t stride, char ch, int x0, int y0, int xd, int yd, int r, int g, int b, int w, int h)
+{
+    for(int y = 0; y < 16; y++) {
+        int mask = avpriv_vga16_font[16*ch + y];
+        for(int x = 0; x < 8; x++) {
+            if (mask&0x80)
+                draw_point(frame_buffer, stride, x0 + xd*x - yd*y, y0 + yd*x + xd*y, r, g, b, w, h);
+            mask<<=1;
+        }
+    }
+}
+
+static void draw_string(uint8_t *frame_buffer, ptrdiff_t stride, char *str, int x0, int y0, int xd, int yd, int r, int g, int b, int w, int h)
+{
+    while(*str) {
+        draw_char(frame_buffer, stride, *str++, x0, y0, xd, yd, r, g, b, w, h);
+        x0 += xd*9;
+        y0 += yd*9;
+    }
+}
+
+int ff_sdr_vissualization(SDRContext *sdr, AVStream *st, AVPacket *pkt)
+{
+    SDRStream *sst = st->priv_data;
+    int w = st->codecpar->width;
+    int h = st->codecpar->height;
+    int h2 = FFMIN(64, h / 4);
+    int frame_index = av_rescale(sdr->pts,        sdr->fps.num, sdr->fps.den * TIMEBASE);
+    int  last_index = av_rescale(sdr->last_pts,   sdr->fps.num, sdr->fps.den * TIMEBASE);
+    int skip = frame_index == last_index || sdr->missing_streams;
+    av_assert0(sdr->missing_streams >= 0);
+
+    for(int x= 0; x<w; x++) {
+        int color;
+        int idx = 4*(x + sst->frame_buffer_line*w);
+        int bindex  =  x    * 2ll * sdr->block_size / w;
+        int bindex2 = (x+1) * 2ll * sdr->block_size / w;
+        float a = 0;
+        av_assert0(bindex2 <= 2 * sdr->block_size);
+        for (int i = bindex; i < bindex2; i++) {
+            AVComplexFloat sample = sdr->block[i];
+            a += len2(sample);
+        }
+        color = lrintf(log(a)*8 + 32);
+
+        sst->frame_buffer[idx + 0] = color;
+        sst->frame_buffer[idx + 1] = color;
+        sst->frame_buffer[idx + 2] = color;
+        sst->frame_buffer[idx + 3] = 255;
+    }
+
+    // Display locations of all vissible stations
+//     for(int station_index = 0; station_index<sdr->nb_stations; station_index++) {
+//         Station *s = sdr->station[station_index];
+//         double f = s->frequency;
+// //                     int bw = s->bandwidth;
+// //                     int xleft = 256*((f-bw) - sdr->block_center_freq + sdr->sdr_sample_rate/2) * w / sdr->sdr_sample_rate;
+// //                     int xright= 256*((f+bw) - sdr->block_center_freq + sdr->sdr_sample_rate/2) * w / sdr->sdr_sample_rate;
+//         int xmid  = 256*( f     - sdr->block_center_freq + sdr->sdr_sample_rate/2) * w / sdr->sdr_sample_rate;
+//         int g = s->modulation == AM ? 50 : 0;
+//         int b = s->modulation == AM ? 0 : 70;
+//         int r = s->stream ? 50 : 0;
+//
+//         draw_point(sst->frame_buffer, 4*w, xmid, 256*(sst->frame_buffer_line+1), r, g, b, w, h);
+//     }
+
+    if (!skip) {
+        int ret = av_new_packet(pkt, sst->frame_size);
+        if (ret < 0)
+            return ret;
+
+        for(int y= 0; y<h2; y++) {
+            for(int x= 0; x<w; x++) {
+                int color;
+                int idx = x + y*w;
+                int idx_t = (idx / h2) + (idx % h2)*w;
+                int bindex  =  idx    * 2ll * sdr->block_size / (w * h2);
+                int bindex2 = (idx+1) * 2ll * sdr->block_size / (w * h2);
+                float a = 0;
+                av_assert0(bindex2 <= 2 * sdr->block_size);
+                for (int i = bindex; i < bindex2; i++) {
+                    AVComplexFloat sample = sdr->block[i];
+                    a += len2(sample);
+                }
+                color = lrintf(log(a)*9 + 64);
+
+                idx_t *= 4;
+
+                pkt->data[idx_t+0] = color;
+                pkt->data[idx_t+1] = color;
+                pkt->data[idx_t+2] = color;
+                pkt->data[idx_t+3] = 255;
+            }
+        }
+
+        for (int y= h2; y<h; y++)
+            memcpy(pkt->data + 4*y*w, sst->frame_buffer + 4*(y + sst->frame_buffer_line - h2)*w, 4*w);
+
+        Station *station_list[1000];
+        int nb_stations = ff_sdr_find_stations(sdr, sdr->block_center_freq, sdr->sdr_sample_rate*0.6, station_list, FF_ARRAY_ELEMS(station_list));
+        for(int station_index = 0; station_index<nb_stations; station_index++) {
+            Station *s = station_list[station_index];
+            double f = s->frequency;
+            int xmid  = 256*( f     - sdr->block_center_freq + sdr->sdr_sample_rate/2) * w / sdr->sdr_sample_rate;
+            char text[80];
+            int color = s->stream ? 64 : 32;
+            int size = s->stream ? 181 : 128;
+            int xd = size, yd = size;
+
+            if (!s->in_station_list)
+                continue;
+
+            snprintf(text, sizeof(text), "%s %f Mhz %d %d %d",
+                     ff_sdr_modulation_descs[s->modulation].shortname,
+                     f/1000000, (int)s->score, ff_sdr_histogram_score(s), s->timeout);
+            draw_string(pkt->data, 4*w, text, xmid + 8*yd, 320*h2, xd, yd, color, color, color, w, h);
+        }
+    }
+
+    if (!sst->frame_buffer_line) {
+        memcpy(sst->frame_buffer + sst->frame_size, sst->frame_buffer, sst->frame_size);
+        sst->frame_buffer_line = h-1;
+    } else
+        sst->frame_buffer_line--;
+
+//TODO
+//                 draw RDS*
+    return skip;
+}
-- 
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".

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [FFmpeg-devel] [PATCH 09/18] avradio/sdrdemux: The RTLSDR DC artifact is not consistent
  2023-07-08 21:25 [FFmpeg-devel] [PATCH 01/18] avradio/sdrdemux: Fix uninitialized access Michael Niedermayer
                   ` (6 preceding siblings ...)
  2023-07-08 21:25 ` [FFmpeg-devel] [PATCH 08/18] avradio: split out vissualization code Michael Niedermayer
@ 2023-07-08 21:25 ` Michael Niedermayer
  2023-07-08 21:25 ` [FFmpeg-devel] [PATCH 10/18] avradio/sdr: eliminate avpriv_* Michael Niedermayer
                   ` (9 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: Michael Niedermayer @ 2023-07-08 21:25 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

so we need to check every block, we cannot just check a few and
then subtract the same value

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavradio/sdr.h      |  1 -
 libavradio/sdrdemux.c | 23 +++++++++++------------
 2 files changed, 11 insertions(+), 13 deletions(-)

diff --git a/libavradio/sdr.h b/libavradio/sdr.h
index 95ff903293..13237707b3 100644
--- a/libavradio/sdr.h
+++ b/libavradio/sdr.h
@@ -202,7 +202,6 @@ typedef struct SDRContext {
     int missing_streams;
 
     int rtlsdr_fixes;
-    float rtlsdr_dc_offset;
 } SDRContext;
 
 typedef struct ModulationDescriptor {
diff --git a/libavradio/sdrdemux.c b/libavradio/sdrdemux.c
index 392fece4e9..6682768461 100644
--- a/libavradio/sdrdemux.c
+++ b/libavradio/sdrdemux.c
@@ -1705,21 +1705,20 @@ process_next_block:
         const int8_t *halfblock0 = fifo_element[0].halfblock;
         const int8_t *halfblock1 = fifo_element[1].halfblock;
         if (sdr->rtlsdr_fixes>0) {
-            if (!sdr->rtlsdr_dc_offset || !sdr->block_center_freq) {
-                int sum = 0;
-                for (i = 0; i<2*sdr->block_size; i++)
-                    sum += halfblock0[i]
-                        +  halfblock1[i];
-                sdr->rtlsdr_dc_offset = -sum / (4.0*sdr->block_size);
-                av_log(s, AV_LOG_DEBUG, "Compensating DC offset %f (this should be around -0.6)\n", sdr->rtlsdr_dc_offset);
-            }
+            int sum = 0;
+            float offset;
+            for (i = 0; i<2*sdr->block_size; i++)
+                sum += halfblock0[i]
+                    +  halfblock1[i];
+            offset = -sum / (4.0*sdr->block_size);
+            av_log(s, AV_LOG_DEBUG, "Compensating DC offset %f (this should be around -0.6)\n", offset);
             for (i = 0; i<sdr->block_size; i++) {
-                sdr->windowed_block[i].re = (halfblock0[2*i+0] + sdr->rtlsdr_dc_offset) * sdr->window[i];
-                sdr->windowed_block[i].im = (halfblock0[2*i+1] + sdr->rtlsdr_dc_offset) * sdr->window[i];
+                sdr->windowed_block[i].re = (halfblock0[2*i+0] + offset) * sdr->window[i];
+                sdr->windowed_block[i].im = (halfblock0[2*i+1] + offset) * sdr->window[i];
             }
             for (i = sdr->block_size; i<2*sdr->block_size; i++) {
-                sdr->windowed_block[i].re = (halfblock1[2*(i - sdr->block_size)+0] + sdr->rtlsdr_dc_offset) * sdr->window[i];
-                sdr->windowed_block[i].im = (halfblock1[2*(i - sdr->block_size)+1] + sdr->rtlsdr_dc_offset) * sdr->window[i];
+                sdr->windowed_block[i].re = (halfblock1[2*(i - sdr->block_size)+0] + offset) * sdr->window[i];
+                sdr->windowed_block[i].im = (halfblock1[2*(i - sdr->block_size)+1] + offset) * sdr->window[i];
             }
         } else {
             for (i = 0; i<sdr->block_size; i++) {
-- 
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".

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [FFmpeg-devel] [PATCH 10/18] avradio/sdr: eliminate avpriv_*
  2023-07-08 21:25 [FFmpeg-devel] [PATCH 01/18] avradio/sdrdemux: Fix uninitialized access Michael Niedermayer
                   ` (7 preceding siblings ...)
  2023-07-08 21:25 ` [FFmpeg-devel] [PATCH 09/18] avradio/sdrdemux: The RTLSDR DC artifact is not consistent Michael Niedermayer
@ 2023-07-08 21:25 ` Michael Niedermayer
  2023-07-08 21:25 ` [FFmpeg-devel] [PATCH 11/18] avradio/vissualize: rotate waterfall Michael Niedermayer
                   ` (8 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: Michael Niedermayer @ 2023-07-08 21:25 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavradio/sdr.h        | 14 +++++++-------
 libavradio/sdrdemux.c   | 32 ++++++++++++++++----------------
 libavradio/sdrinradio.c | 14 +++++++-------
 3 files changed, 30 insertions(+), 30 deletions(-)

diff --git a/libavradio/sdr.h b/libavradio/sdr.h
index 13237707b3..2940ffa389 100644
--- a/libavradio/sdr.h
+++ b/libavradio/sdr.h
@@ -228,7 +228,7 @@ typedef struct BandDescriptor {
     int64_t freq_max;
 } BandDescriptor ;
 
-extern const AVOption avpriv_sdr_options[];
+extern const AVOption ff_sdr_options[];
 
 extern ModulationDescriptor ff_sdr_modulation_descs[];
 
@@ -237,21 +237,21 @@ extern ModulationDescriptor ff_sdr_modulation_descs[];
  * this will check the argument and call set_frequency_callback()
  * It can be called before the thread is started or from within the thread,
  */
-int avpriv_sdr_set_freq(SDRContext *sdr, int64_t freq);
+int ff_sdr_set_freq(SDRContext *sdr, int64_t freq);
 
-int avpriv_sdr_common_init(AVFormatContext *s);
+int ff_sdr_common_init(AVFormatContext *s);
 
-int avpriv_sdr_read_packet(AVFormatContext *s, AVPacket *pkt);
+int ff_sdr_read_packet(AVFormatContext *s, AVPacket *pkt);
 
-int avpriv_sdr_read_seek(AVFormatContext *s, int stream_index, int64_t target, int flags);
+int ff_sdr_read_seek(AVFormatContext *s, int stream_index, int64_t target, int flags);
 
 /**
  * shuts down threads, destroys mutex
  * Safe to call if no thread was started or after it was shutdown
  */
-void avpriv_sdr_stop_threading(AVFormatContext *s);
+void ff_sdr_stop_threading(AVFormatContext *s);
 
-int avpriv_sdr_read_close(AVFormatContext *s);
+int ff_sdr_read_close(AVFormatContext *s);
 
 int ff_sdr_vissualization(SDRContext *sdr, AVStream *st, AVPacket *pkt);
 
diff --git a/libavradio/sdrdemux.c b/libavradio/sdrdemux.c
index 6682768461..2bce1045f4 100644
--- a/libavradio/sdrdemux.c
+++ b/libavradio/sdrdemux.c
@@ -1056,7 +1056,7 @@ ModulationDescriptor ff_sdr_modulation_descs[] = {
     {"Frequency Modulation", "FM", FM, AVMEDIA_TYPE_AUDIO, probe_fm, demodulate_fm},
 };
 
-int avpriv_sdr_set_freq(SDRContext *sdr, int64_t freq)
+int ff_sdr_set_freq(SDRContext *sdr, int64_t freq)
 {
     freq = av_clip64(freq, sdr->min_center_freq, sdr->max_center_freq);
 
@@ -1390,9 +1390,9 @@ static void *soapy_needs_bigger_buffers_worker(SDRContext *sdr)
         }
         if (sdr->wanted_freq != sdr->freq) {
             //We could use a seperate MUTEX for the FIFO and for soapy
-            avpriv_sdr_set_freq(sdr, sdr->wanted_freq);
+            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
-            //And theres not much else we can do, an error message was already printed by avpriv_sdr_set_freq() in that case
+            //And theres not much else we can do, an error message was already printed by ff_sdr_set_freq() in that case
             block_counter = 0; // we just changed the frequency, do not trust the next blocks content
         }
         pthread_mutex_unlock(&sdr->mutex);
@@ -1416,7 +1416,7 @@ static void *soapy_needs_bigger_buffers_worker(SDRContext *sdr)
     return NULL;
 }
 
-int avpriv_sdr_common_init(AVFormatContext *s)
+int ff_sdr_common_init(AVFormatContext *s)
 {
     SDRContext *sdr = s->priv_data;
     AVStream *st;
@@ -1588,16 +1588,16 @@ static int sdrfile_initial_setup(AVFormatContext *s)
     //After reading the first packet header we return to the begin so the packet can be read whole
     avio_seek(s->pb, 0, SEEK_SET);
 
-    ret = avpriv_sdr_set_freq(sdr, sdr->wanted_freq);
+    ret = ff_sdr_set_freq(sdr, sdr->wanted_freq);
     if (ret < 0)
         return ret;
 
     sdr->read_callback = sdrfile_read_callback;
 
-    return avpriv_sdr_common_init(s);
+    return ff_sdr_common_init(s);
 }
 
-int avpriv_sdr_read_packet(AVFormatContext *s, AVPacket *pkt)
+int ff_sdr_read_packet(AVFormatContext *s, AVPacket *pkt)
 {
     SDRContext *sdr = s->priv_data;
     int ret, i, full_blocks, seek_direction;
@@ -1860,7 +1860,7 @@ process_next_block:
     return AVERROR(EAGAIN);
 }
 
-int avpriv_sdr_read_seek(AVFormatContext *s, int stream_index,
+int ff_sdr_read_seek(AVFormatContext *s, int stream_index,
                          int64_t target, int flags)
 {
     SDRContext *sdr = s->priv_data;
@@ -1900,7 +1900,7 @@ int avpriv_sdr_read_seek(AVFormatContext *s, int stream_index,
     return 0;
 }
 
-void avpriv_sdr_stop_threading(AVFormatContext *s)
+void ff_sdr_stop_threading(AVFormatContext *s)
 {
     SDRContext *sdr = s->priv_data;
 
@@ -1919,12 +1919,12 @@ void avpriv_sdr_stop_threading(AVFormatContext *s)
     sdr->thread_started = 0;
 }
 
-int avpriv_sdr_read_close(AVFormatContext *s)
+int ff_sdr_read_close(AVFormatContext *s)
 {
     SDRContext *sdr = s->priv_data;
     int i;
 
-    avpriv_sdr_stop_threading(s);
+    ff_sdr_stop_threading(s);
 
     av_fifo_freep2(&sdr->empty_block_fifo);
     av_fifo_freep2(&sdr->full_block_fifo);
@@ -1969,7 +1969,7 @@ static int sdrfile_probe(const AVProbeData *p)
 #define OFFSET(x) offsetof(SDRContext, x)
 #define DEC AV_OPT_FLAG_DECODING_PARAM
 
-const AVOption avpriv_sdr_options[] = {
+const AVOption ff_sdr_options[] = {
     { "video_size", "set frame size", OFFSET(width), AV_OPT_TYPE_IMAGE_SIZE, {.str = "0x0"}, 0, 0, DEC },
     { "framerate" , "set frame rate", OFFSET(fps), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, INT_MAX,DEC },
     { "block_size", "FFT block size", OFFSET(block_size), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, DEC},
@@ -2015,7 +2015,7 @@ const AVOption avpriv_sdr_options[] = {
 static const AVClass sdrfile_demuxer_class = {
     .class_name = "sdrfile",
     .item_name  = av_default_item_name,
-    .option     = avpriv_sdr_options,
+    .option     = ff_sdr_options,
     .version    = LIBAVUTIL_VERSION_INT,
     .category   = AV_CLASS_CATEGORY_DEMUXER,
 };
@@ -2026,9 +2026,9 @@ const AVInputFormat ff_sdrfile_demuxer = {
     .priv_data_size = sizeof(SDRContext),
     .read_probe     = sdrfile_probe,
     .read_header    = sdrfile_initial_setup,
-    .read_packet    = avpriv_sdr_read_packet,
-    .read_close     = avpriv_sdr_read_close,
-    .read_seek      = avpriv_sdr_read_seek,
+    .read_packet    = ff_sdr_read_packet,
+    .read_close     = ff_sdr_read_close,
+    .read_seek      = ff_sdr_read_seek,
     .flags_internal = FF_FMT_INIT_CLEANUP,
     .priv_class = &sdrfile_demuxer_class,
 };
diff --git a/libavradio/sdrinradio.c b/libavradio/sdrinradio.c
index af87b49495..0e7442fddf 100644
--- a/libavradio/sdrinradio.c
+++ b/libavradio/sdrinradio.c
@@ -272,7 +272,7 @@ static int sdrindev_initial_hw_setup(AVFormatContext *s)
         av_log(s, AV_LOG_ERROR, "setSampleRate fail: %s\n", SoapySDRDevice_lastError());
         return AVERROR_EXTERNAL;
     }
-    ret = avpriv_sdr_set_freq(sdr, sdr->wanted_freq);
+    ret = ff_sdr_set_freq(sdr, sdr->wanted_freq);
     if (ret < 0)
         return ret;
 
@@ -331,7 +331,7 @@ static int sdrindev_initial_hw_setup(AVFormatContext *s)
 
     SoapySDRDevice_activateStream(soapy, soapyRxStream, 0, 0, 0);
 
-    return avpriv_sdr_common_init(s);
+    return ff_sdr_common_init(s);
 }
 
 static int sdrindev_read_close(AVFormatContext *s)
@@ -339,7 +339,7 @@ static int sdrindev_read_close(AVFormatContext *s)
     SDRContext *sdr = s->priv_data;
     SoapySDRDevice *soapy = sdr->soapy;
 
-    avpriv_sdr_stop_threading(s);
+    ff_sdr_stop_threading(s);
 
     if (soapy) {
         if (sdr->soapyRxStream) {
@@ -352,7 +352,7 @@ static int sdrindev_read_close(AVFormatContext *s)
         sdr->soapy = NULL;
     }
 
-    return avpriv_sdr_read_close(s);
+    return ff_sdr_read_close(s);
 }
 
 static int sdr_get_device_list(AVFormatContext *ctx, AVDeviceInfoList *device_list)
@@ -402,7 +402,7 @@ static int sdr_get_device_list(AVFormatContext *ctx, AVDeviceInfoList *device_li
 static const AVClass sdr_demuxer_class = {
     .class_name = "sdr",
     .item_name  = av_default_item_name,
-    .option     = avpriv_sdr_options,
+    .option     = ff_sdr_options,
     .version    = LIBAVUTIL_VERSION_INT,
     .category   = AV_CLASS_CATEGORY_RADIO_INPUT,
 };
@@ -412,9 +412,9 @@ const AVInputFormat ff_sdr_demuxer = {
     .long_name      = NULL_IF_CONFIG_SMALL("Software Defined Radio Demodulator"),
     .priv_data_size = sizeof(SDRContext),
     .read_header    = sdrindev_initial_hw_setup,
-    .read_packet    = avpriv_sdr_read_packet,
+    .read_packet    = ff_sdr_read_packet,
     .read_close     = sdrindev_read_close,
-    .read_seek      = avpriv_sdr_read_seek,
+    .read_seek      = ff_sdr_read_seek,
     .get_device_list= sdr_get_device_list,
     .flags          = AVFMT_NOFILE,
     .flags_internal = FF_FMT_INIT_CLEANUP,
-- 
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".

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [FFmpeg-devel] [PATCH 11/18] avradio/vissualize: rotate waterfall
  2023-07-08 21:25 [FFmpeg-devel] [PATCH 01/18] avradio/sdrdemux: Fix uninitialized access Michael Niedermayer
                   ` (8 preceding siblings ...)
  2023-07-08 21:25 ` [FFmpeg-devel] [PATCH 10/18] avradio/sdr: eliminate avpriv_* Michael Niedermayer
@ 2023-07-08 21:25 ` Michael Niedermayer
  2023-07-08 21:25 ` [FFmpeg-devel] [PATCH 12/18] avradio/sdrdemux: Set AVFMTCTX_NOHEADER Michael Niedermayer
                   ` (7 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: Michael Niedermayer @ 2023-07-08 21:25 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavradio/sdr.h        |  1 +
 libavradio/vissualize.c | 35 ++++++++++++++++++++++++++++++-----
 2 files changed, 31 insertions(+), 5 deletions(-)

diff --git a/libavradio/sdr.h b/libavradio/sdr.h
index 2940ffa389..8a2ab1c78a 100644
--- a/libavradio/sdr.h
+++ b/libavradio/sdr.h
@@ -116,6 +116,7 @@ typedef struct SDRStream {
     int frame_size;
     int frame_buffer_line;
     uint8_t *frame_buffer;
+    int64_t last_block_center_freq;
 } SDRStream;
 
 typedef struct SDRContext {
diff --git a/libavradio/vissualize.c b/libavradio/vissualize.c
index c165e0fb63..b27f78f171 100644
--- a/libavradio/vissualize.c
+++ b/libavradio/vissualize.c
@@ -90,6 +90,14 @@ static void draw_string(uint8_t *frame_buffer, ptrdiff_t stride, char *str, int
     }
 }
 
+static void advance_waterfall(SDRStream *sst, int h) {
+    if (!sst->frame_buffer_line) {
+        memcpy(sst->frame_buffer + sst->frame_size, sst->frame_buffer, sst->frame_size);
+        sst->frame_buffer_line = h-1;
+    } else
+        sst->frame_buffer_line--;
+}
+
 int ff_sdr_vissualization(SDRContext *sdr, AVStream *st, AVPacket *pkt)
 {
     SDRStream *sst = st->priv_data;
@@ -101,6 +109,27 @@ int ff_sdr_vissualization(SDRContext *sdr, AVStream *st, AVPacket *pkt)
     int skip = frame_index == last_index || sdr->missing_streams;
     av_assert0(sdr->missing_streams >= 0);
 
+    if (sdr->block_center_freq) {
+        if (sst->last_block_center_freq) {
+            int last_center = lrint((F2INDEX(sst->last_block_center_freq) - sdr->block_size) * w / (2*sdr->block_size));
+
+            last_center %= w;
+            if (last_center < 0)
+                last_center += w;
+            av_assert0(last_center >= 0 && last_center < w);
+
+            for(int y= 0; y<h - 1; y++) {
+                uint8_t *dst = sst->frame_buffer + 4*w*(sst->frame_buffer_line + y);
+                uint8_t *src = dst + 4*w;
+
+                memcpy(dst + 4*last_center, src,                       4*(w - last_center));
+                memcpy(dst                , src + 4*(w - last_center), 4*     last_center );
+            }
+            advance_waterfall(sst, h);
+        }
+        sst->last_block_center_freq = sdr->block_center_freq;
+    }
+
     for(int x= 0; x<w; x++) {
         int color;
         int idx = 4*(x + sst->frame_buffer_line*w);
@@ -188,11 +217,7 @@ int ff_sdr_vissualization(SDRContext *sdr, AVStream *st, AVPacket *pkt)
         }
     }
 
-    if (!sst->frame_buffer_line) {
-        memcpy(sst->frame_buffer + sst->frame_size, sst->frame_buffer, sst->frame_size);
-        sst->frame_buffer_line = h-1;
-    } else
-        sst->frame_buffer_line--;
+    advance_waterfall(sst, h);
 
 //TODO
 //                 draw RDS*
-- 
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".

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [FFmpeg-devel] [PATCH 12/18] avradio/sdrdemux: Set AVFMTCTX_NOHEADER
  2023-07-08 21:25 [FFmpeg-devel] [PATCH 01/18] avradio/sdrdemux: Fix uninitialized access Michael Niedermayer
                   ` (9 preceding siblings ...)
  2023-07-08 21:25 ` [FFmpeg-devel] [PATCH 11/18] avradio/vissualize: rotate waterfall Michael Niedermayer
@ 2023-07-08 21:25 ` Michael Niedermayer
  2023-07-08 21:25 ` [FFmpeg-devel] [PATCH 13/18] avradio/sdrdemux: fix bug adding candidate stations and then crashing Michael Niedermayer
                   ` (6 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: Michael Niedermayer @ 2023-07-08 21:25 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

This is needed as stations may not be detected immedeately

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavradio/sdrdemux.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libavradio/sdrdemux.c b/libavradio/sdrdemux.c
index 2bce1045f4..1c77583fd4 100644
--- a/libavradio/sdrdemux.c
+++ b/libavradio/sdrdemux.c
@@ -1425,6 +1425,7 @@ int ff_sdr_common_init(AVFormatContext *s)
     float scale = 1.0 / sdr->sample_scale;
 
     sdr->avfmt = s;
+    s->ctx_flags |= AVFMTCTX_NOHEADER;
 
     if (sdr->width>1 && sdr->height>1) {
         /* video stream */
-- 
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".

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [FFmpeg-devel] [PATCH 13/18] avradio/sdrdemux: fix bug adding candidate stations and then crashing
  2023-07-08 21:25 [FFmpeg-devel] [PATCH 01/18] avradio/sdrdemux: Fix uninitialized access Michael Niedermayer
                   ` (10 preceding siblings ...)
  2023-07-08 21:25 ` [FFmpeg-devel] [PATCH 12/18] avradio/sdrdemux: Set AVFMTCTX_NOHEADER Michael Niedermayer
@ 2023-07-08 21:25 ` Michael Niedermayer
  2023-07-08 21:25 ` [FFmpeg-devel] [PATCH 14/18] avradio/sdrdemux: fm_probe: dont allow bandwidh=sample rate Michael Niedermayer
                   ` (5 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: Michael Niedermayer @ 2023-07-08 21:25 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavradio/sdrdemux.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavradio/sdrdemux.c b/libavradio/sdrdemux.c
index 1c77583fd4..5300311c3a 100644
--- a/libavradio/sdrdemux.c
+++ b/libavradio/sdrdemux.c
@@ -1818,7 +1818,7 @@ process_next_block:
             int nb_stations = ff_sdr_find_stations(sdr, sdr->block_center_freq, sdr->sdr_sample_rate*0.5, station_list, FF_ARRAY_ELEMS(station_list));
             for(int i = 0; i<nb_stations; i++) {
                 Station *station = station_list[i];
-                if (!station->stream) {
+                if (!station->stream && station->in_station_list) {
                     /* audio stream */
                     AVStream *st = avformat_new_stream(s, NULL);
                     SDRStream *sst;
-- 
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".

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [FFmpeg-devel] [PATCH 14/18] avradio/sdrdemux: fm_probe: dont allow bandwidh=sample rate
  2023-07-08 21:25 [FFmpeg-devel] [PATCH 01/18] avradio/sdrdemux: Fix uninitialized access Michael Niedermayer
                   ` (11 preceding siblings ...)
  2023-07-08 21:25 ` [FFmpeg-devel] [PATCH 13/18] avradio/sdrdemux: fix bug adding candidate stations and then crashing Michael Niedermayer
@ 2023-07-08 21:25 ` Michael Niedermayer
  2023-07-08 21:25 ` [FFmpeg-devel] [PATCH 15/18] doc: add sdr examples Michael Niedermayer
                   ` (4 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: Michael Niedermayer @ 2023-07-08 21:25 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

if bandwidth is set incorrectly the noise floor can be very wrong, which
causes issues as the threshold is based on the noise floor

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavradio/sdrdemux.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavradio/sdrdemux.c b/libavradio/sdrdemux.c
index 5300311c3a..b51fa4296a 100644
--- a/libavradio/sdrdemux.c
+++ b/libavradio/sdrdemux.c
@@ -843,7 +843,7 @@ static int probe_fm(SDRContext *sdr)
     int bandwidth_p2 =  38*1000; //phase 2 bandwidth
     int half_bw_i = bandwidth_f * (int64_t)sdr->block_size / sdr->sdr_sample_rate;
     float last_score[3] = {FLT_MAX, FLT_MAX, FLT_MAX};
-    int border_i = (sdr->sdr_sample_rate - sdr->bandwidth) * sdr->block_size / sdr->sdr_sample_rate;
+    int border_i = (sdr->sdr_sample_rate - FFMIN(sdr->bandwidth, sdr->sdr_sample_rate*7/8)) * sdr->block_size / sdr->sdr_sample_rate;
     double noise_floor = FLT_MAX;
 
     if (2*half_bw_i > 2*sdr->block_size)
-- 
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".

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [FFmpeg-devel] [PATCH 15/18] doc: add sdr examples
  2023-07-08 21:25 [FFmpeg-devel] [PATCH 01/18] avradio/sdrdemux: Fix uninitialized access Michael Niedermayer
                   ` (12 preceding siblings ...)
  2023-07-08 21:25 ` [FFmpeg-devel] [PATCH 14/18] avradio/sdrdemux: fm_probe: dont allow bandwidh=sample rate Michael Niedermayer
@ 2023-07-08 21:25 ` Michael Niedermayer
  2023-07-08 21:25 ` [FFmpeg-devel] [PATCH 16/18] avradio/sdr: rename fft_p2 Michael Niedermayer
                   ` (3 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: Michael Niedermayer @ 2023-07-08 21:25 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 doc/demuxers.texi | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/doc/demuxers.texi b/doc/demuxers.texi
index 86f031b9ed..75ec55170a 100644
--- a/doc/demuxers.texi
+++ b/doc/demuxers.texi
@@ -1003,6 +1003,16 @@ No emphasis used
 
 @end table
 
+Example: Use ffplay to listen to radio, arrow keys allow switching stations
+@example
+ffplay -sdr_freq 88M -f sdr a -video_size 1600x600
+@end example
+
+Example: Record all radio stations between about 101Mhz and 107Mhz
+@example
+ffmpeg -sdr_freq 104M -sdr_sr 7M -mode all_mode -f sdr -i a -map 0 -y fm.nut
+@end example
+
 @end table
 
 @section tedcaptions
-- 
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".

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [FFmpeg-devel] [PATCH 16/18] avradio/sdr: rename fft_p2
  2023-07-08 21:25 [FFmpeg-devel] [PATCH 01/18] avradio/sdrdemux: Fix uninitialized access Michael Niedermayer
                   ` (13 preceding siblings ...)
  2023-07-08 21:25 ` [FFmpeg-devel] [PATCH 15/18] doc: add sdr examples Michael Niedermayer
@ 2023-07-08 21:25 ` Michael Niedermayer
  2023-07-08 21:25 ` [FFmpeg-devel] [PATCH 17/18] avradio/sdrdemux: more correct phase 2 bandwidth of FM demodulation Michael Niedermayer
                   ` (2 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: Michael Niedermayer @ 2023-07-08 21:25 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

The FFT really is from the point of view of the stream Phase 1 not
Phase 2 of the demodulation.

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavradio/sdr.h      | 4 ++--
 libavradio/sdrdemux.c | 8 ++++----
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/libavradio/sdr.h b/libavradio/sdr.h
index 8a2ab1c78a..1582f70d86 100644
--- a/libavradio/sdr.h
+++ b/libavradio/sdr.h
@@ -95,10 +95,10 @@ typedef struct FIFOElement {
 
 typedef struct SDRStream {
     AVTXContext *ifft_ctx;
-    AVTXContext *fft_p2_ctx;
+    AVTXContext *fft_ctx;
     AVTXContext *ifft_p2_ctx;
     av_tx_fn ifft;
-    av_tx_fn fft_p2;
+    av_tx_fn fft;
     av_tx_fn ifft_p2;
     int block_size;
     int block_size_p2;
diff --git a/libavradio/sdrdemux.c b/libavradio/sdrdemux.c
index b51fa4296a..1ded01e957 100644
--- a/libavradio/sdrdemux.c
+++ b/libavradio/sdrdemux.c
@@ -979,7 +979,7 @@ static int demodulate_fm(SDRContext *sdr, int stream_index, AVPacket *pkt)
     //FIXME this only needs to be a RDFT
     //CONSIDER, this and in fact alot can be done with bandpass and lowpass filters instead of FFTs, find out which is better
     //CONSIDER synthesizing the carrier instead of IFFT, we have all parameters for that
-    sst->fft_p2(sst->fft_p2_ctx, sst->block, sst->iblock, sizeof(AVComplexFloat));
+    sst->fft(sst->fft_ctx, sst->block, sst->iblock, sizeof(AVComplexFloat));
     // Only the low N/2+1 are used the upper is just a reflection
 
     carrier19_i_exact = find_am_carrier(sdr, sst->block, 2*sst->block_size, (void*)(sst->block + 1 + sst->block_size), carrier19_i, 10, 10);
@@ -1078,10 +1078,10 @@ static void free_stream(SDRContext *sdr, int stream_index)
     SDRStream *sst = st->priv_data;
 
     av_tx_uninit(&sst->ifft_ctx);
-    av_tx_uninit(&sst->fft_p2_ctx);
+    av_tx_uninit(&sst->fft_ctx);
     av_tx_uninit(&sst->ifft_p2_ctx);
     sst->ifft = NULL;
-    sst->fft_p2 = NULL;
+    sst->fft  = NULL;
     sst->ifft_p2 = NULL;
     sst->block_size = 0;
 
@@ -1127,7 +1127,7 @@ static int setup_stream(SDRContext *sdr, int stream_index, Station *station)
 
         if (sst->station->bandwidth_p2) {
             //Allocate 2nd stage demodulation fields if needed
-            ret = av_tx_init(&sst-> fft_p2_ctx, &sst-> fft_p2, AV_TX_FLOAT_FFT, 0, 2*sst->block_size   , NULL, 0);
+            ret = av_tx_init(&sst-> fft_ctx, &sst-> fft, AV_TX_FLOAT_FFT, 0, 2*sst->block_size   , NULL, 0);
             if (ret < 0)
                 return ret;
 
-- 
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".

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [FFmpeg-devel] [PATCH 17/18] avradio/sdrdemux: more correct phase 2 bandwidth of FM demodulation
  2023-07-08 21:25 [FFmpeg-devel] [PATCH 01/18] avradio/sdrdemux: Fix uninitialized access Michael Niedermayer
                   ` (14 preceding siblings ...)
  2023-07-08 21:25 ` [FFmpeg-devel] [PATCH 16/18] avradio/sdr: rename fft_p2 Michael Niedermayer
@ 2023-07-08 21:25 ` Michael Niedermayer
  2023-07-08 21:25 ` [FFmpeg-devel] [PATCH 18/18] avradio/sdrdemux: Fix DC offset issue in AM demodulation Michael Niedermayer
  2023-07-09 23:43 ` [FFmpeg-devel] [PATCH 01/18] avradio/sdrdemux: Fix uninitialized access Michael Niedermayer
  17 siblings, 0 replies; 19+ messages in thread
From: Michael Niedermayer @ 2023-07-08 21:25 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavradio/sdrdemux.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavradio/sdrdemux.c b/libavradio/sdrdemux.c
index 1ded01e957..d73cbc0a06 100644
--- a/libavradio/sdrdemux.c
+++ b/libavradio/sdrdemux.c
@@ -840,7 +840,7 @@ static int probe_fm(SDRContext *sdr)
 {
     int i;
     int bandwidth_f  = 180*1000;
-    int bandwidth_p2 =  38*1000; //phase 2 bandwidth
+    int bandwidth_p2 =  18*1000; //phase 2 bandwidth
     int half_bw_i = bandwidth_f * (int64_t)sdr->block_size / sdr->sdr_sample_rate;
     float last_score[3] = {FLT_MAX, FLT_MAX, FLT_MAX};
     int border_i = (sdr->sdr_sample_rate - FFMIN(sdr->bandwidth, sdr->sdr_sample_rate*7/8)) * sdr->block_size / sdr->sdr_sample_rate;
-- 
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".

^ permalink raw reply	[flat|nested] 19+ messages in thread

* [FFmpeg-devel] [PATCH 18/18] avradio/sdrdemux: Fix DC offset issue in AM demodulation
  2023-07-08 21:25 [FFmpeg-devel] [PATCH 01/18] avradio/sdrdemux: Fix uninitialized access Michael Niedermayer
                   ` (15 preceding siblings ...)
  2023-07-08 21:25 ` [FFmpeg-devel] [PATCH 17/18] avradio/sdrdemux: more correct phase 2 bandwidth of FM demodulation Michael Niedermayer
@ 2023-07-08 21:25 ` Michael Niedermayer
  2023-07-09 23:43 ` [FFmpeg-devel] [PATCH 01/18] avradio/sdrdemux: Fix uninitialized access Michael Niedermayer
  17 siblings, 0 replies; 19+ messages in thread
From: Michael Niedermayer @ 2023-07-08 21:25 UTC (permalink / raw)
  To: FFmpeg development discussions and patches

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavradio/sdrdemux.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/libavradio/sdrdemux.c b/libavradio/sdrdemux.c
index d73cbc0a06..7cc71b2cfb 100644
--- a/libavradio/sdrdemux.c
+++ b/libavradio/sdrdemux.c
@@ -740,7 +740,8 @@ static int demodulate_am(SDRContext *sdr, int stream_index, AVPacket *pkt)
         AVComplexFloat mm;
         double s2 = 0;
         double dcw = 0;
-        float amp, amp2;
+        float amp, stamp, wamp;
+
         for(i = 0; i<2*sst->block_size; i++) {
             double tmp;
             AVComplexFloat v = sst->iblock[i];
@@ -755,17 +756,17 @@ static int demodulate_am(SDRContext *sdr, int stream_index, AVPacket *pkt)
             dcw    += sst->window[i] * sst->window[i];
         }
 
-        amp = dcw / (dc1.re*dc1.re + dc1.im*dc1.im);
-        amp2= dcw / s2;
-        amp = FFMIN(amp, amp2 * 0.1);
+        stamp = dcw / (dc1.re*dc1.re + dc1.im*dc1.im);
+        amp = FFMIN(stamp, dcw / s2 * 0.1);
         if (sst->am_amplitude)
             amp = 0.9*sst->am_amplitude + 0.1*amp;
         sst->am_amplitude = amp;
+        wamp = amp/stamp;
 
         mm = (AVComplexFloat){dc1.re * amp, -dc1.im * amp};
         for(i = 0; i<2*sst->block_size; i++) {
             AVComplexFloat v = sst->iblock[i];
-            sst->iblock[i].re = v.re*mm.re - v.im*mm.im - sst->window[i];
+            sst->iblock[i].re = v.re*mm.re - v.im*mm.im - sst->window[i] * wamp;
             sst->iblock[i].im = v.re*mm.im + v.im*mm.re;
         }
 
-- 
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".

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [FFmpeg-devel] [PATCH 01/18] avradio/sdrdemux: Fix uninitialized access
  2023-07-08 21:25 [FFmpeg-devel] [PATCH 01/18] avradio/sdrdemux: Fix uninitialized access Michael Niedermayer
                   ` (16 preceding siblings ...)
  2023-07-08 21:25 ` [FFmpeg-devel] [PATCH 18/18] avradio/sdrdemux: Fix DC offset issue in AM demodulation Michael Niedermayer
@ 2023-07-09 23:43 ` Michael Niedermayer
  17 siblings, 0 replies; 19+ messages in thread
From: Michael Niedermayer @ 2023-07-09 23:43 UTC (permalink / raw)
  To: FFmpeg development discussions and patches


[-- Attachment #1.1: Type: text/plain, Size: 457 bytes --]

On Sat, Jul 08, 2023 at 11:25:13PM +0200, Michael Niedermayer wrote:
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>  libavradio/sdrdemux.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)

will apply patchset

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

I know you won't believe me, but the highest form of Human Excellence is
to question oneself and others. -- Socrates

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

[-- Attachment #2: Type: text/plain, Size: 251 bytes --]

_______________________________________________
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".

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2023-07-09 23:43 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-08 21:25 [FFmpeg-devel] [PATCH 01/18] avradio/sdrdemux: Fix uninitialized access Michael Niedermayer
2023-07-08 21:25 ` [FFmpeg-devel] [PATCH 02/18] avradio/sdrdemux: factor frequency tolerance constants out Michael Niedermayer
2023-07-08 21:25 ` [FFmpeg-devel] [PATCH 03/18] avradio/sdr: Add fm multiple parameter Michael Niedermayer
2023-07-08 21:25 ` [FFmpeg-devel] [PATCH 04/18] avradio/sdrinradio: Dont automatically select 2.56Mhz on the rtlsdr Michael Niedermayer
2023-07-08 21:25 ` [FFmpeg-devel] [PATCH 05/18] avradio/sdrdemux: Do not timeout negative stations Michael Niedermayer
2023-07-08 21:25 ` [FFmpeg-devel] [PATCH 06/18] avradio/sdrinradio: Factor print_and_free_list() out Michael Niedermayer
2023-07-08 21:25 ` [FFmpeg-devel] [PATCH 07/18] avradio/sdrinradio: Print list of Time Sources Michael Niedermayer
2023-07-08 21:25 ` [FFmpeg-devel] [PATCH 08/18] avradio: split out vissualization code Michael Niedermayer
2023-07-08 21:25 ` [FFmpeg-devel] [PATCH 09/18] avradio/sdrdemux: The RTLSDR DC artifact is not consistent Michael Niedermayer
2023-07-08 21:25 ` [FFmpeg-devel] [PATCH 10/18] avradio/sdr: eliminate avpriv_* Michael Niedermayer
2023-07-08 21:25 ` [FFmpeg-devel] [PATCH 11/18] avradio/vissualize: rotate waterfall Michael Niedermayer
2023-07-08 21:25 ` [FFmpeg-devel] [PATCH 12/18] avradio/sdrdemux: Set AVFMTCTX_NOHEADER Michael Niedermayer
2023-07-08 21:25 ` [FFmpeg-devel] [PATCH 13/18] avradio/sdrdemux: fix bug adding candidate stations and then crashing Michael Niedermayer
2023-07-08 21:25 ` [FFmpeg-devel] [PATCH 14/18] avradio/sdrdemux: fm_probe: dont allow bandwidh=sample rate Michael Niedermayer
2023-07-08 21:25 ` [FFmpeg-devel] [PATCH 15/18] doc: add sdr examples Michael Niedermayer
2023-07-08 21:25 ` [FFmpeg-devel] [PATCH 16/18] avradio/sdr: rename fft_p2 Michael Niedermayer
2023-07-08 21:25 ` [FFmpeg-devel] [PATCH 17/18] avradio/sdrdemux: more correct phase 2 bandwidth of FM demodulation Michael Niedermayer
2023-07-08 21:25 ` [FFmpeg-devel] [PATCH 18/18] avradio/sdrdemux: Fix DC offset issue in AM demodulation Michael Niedermayer
2023-07-09 23:43 ` [FFmpeg-devel] [PATCH 01/18] avradio/sdrdemux: Fix uninitialized access Michael Niedermayer

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