[FFmpeg-cvslog] [ffmpeg-radio] branch master updated. d438006e10 avradio/sdrdemux: Print log_debug level message on metadata changes

ffmpeg-git at ffmpeg.org ffmpeg-git at ffmpeg.org
Thu Jul 13 23:15:10 EEST 2023


The branch, master has been updated
       via  d438006e10903a044d3429df5c24d5a3cd165fe8 (commit)
       via  037260b13f2bba5a1e454964f771317173e99954 (commit)
       via  1392a35da8a29898ebcf1c19dc22fec952df7539 (commit)
       via  5c8413e55f0b60f8743b80efa989e31262e39719 (commit)
       via  724415438055d3d621bdc57b820c66b5541a36d1 (commit)
       via  874bc3cc19590a3768dffc0bd8b4a0b386598462 (commit)
       via  3bec4d194af940185502b23be1af5e4aaa32ac2d (commit)
       via  cb2059eb468f00a3423491b8f39c3b00eaaa3cef (commit)
       via  5d922961f42e96210c8a61f92469b95a3f5acd35 (commit)
       via  dec413caa64c72acd9ba47f65a19e4ad9f01f033 (commit)
       via  841670e4b95ebfecd02fdc33e978d9dc0dfa00e0 (commit)
       via  40a73bf3003b347c94ec9b3e0d63fb4f929e7e03 (commit)
      from  63ac31eb9fcfb43a81ae5dc538ad6a694ec05bb9 (commit)


- Log -----------------------------------------------------------------
commit d438006e10903a044d3429df5c24d5a3cd165fe8
Author:     Michael Niedermayer <michael at niedermayer.cc>
AuthorDate: Thu Jul 13 01:01:32 2023 +0200
Commit:     Michael Niedermayer <michael at niedermayer.cc>
CommitDate: Thu Jul 13 01:36:33 2023 +0200

    avradio/sdrdemux: Print log_debug level message on metadata changes
    
    Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>

diff --git a/libavradio/sdrdemux.c b/libavradio/sdrdemux.c
index b69b13d075..d40b92dd24 100644
--- a/libavradio/sdrdemux.c
+++ b/libavradio/sdrdemux.c
@@ -1716,6 +1716,7 @@ process_next_block:
                         if (t)
                             value = t->value;
                         if (strcmp(value, metadata_values[i])) {
+                            av_log(s, AV_LOG_DEBUG, "METADATA %s update %s -> %s\n", metadata_keys[i], value, metadata_values[i]);
                             av_dict_set(&st->metadata, metadata_keys[i], metadata_values[i], 0);
                             s->event_flags |= AVFMT_EVENT_FLAG_METADATA_UPDATED;
                         }

commit 037260b13f2bba5a1e454964f771317173e99954
Author:     Michael Niedermayer <michael at niedermayer.cc>
AuthorDate: Thu Jul 13 00:57:03 2023 +0200
Commit:     Michael Niedermayer <michael at niedermayer.cc>
CommitDate: Thu Jul 13 01:36:33 2023 +0200

    avradio/sdrdemux: deemphasis filter fixes
    
    Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>

diff --git a/libavradio/sdrdemux.c b/libavradio/sdrdemux.c
index 54d7622809..b69b13d075 100644
--- a/libavradio/sdrdemux.c
+++ b/libavradio/sdrdemux.c
@@ -67,7 +67,7 @@
 #define AM_MAX4  0.02
 
 //Least squares fit at 1khz points of frequency response shown by Frank McClatchie, FM SYSTEMS, INC. 800-235-6960
-static double emphasis75us(int f)
+static double emphasis75us(double f)
 {
     return ((((((((- 4.79546E-9 * f + 5.32101E-7) * f - 0.0000254577) * f + 0.000687225) * f
                    - 0.0114925) * f + 0.122781  ) * f - 0.827885    ) * f + 3.25025    ) * f - 4.6049) * f + 2.06937;
@@ -76,15 +76,16 @@ static double emphasis75us(int f)
 /**
  * Apply emphasis filter in frequency domain
  */
-static void apply_deemphasis(SDRContext *sdr, AVComplexFloat *data, int len, int sample_rate, int dir)
+static void apply_deemphasis(SDRContext *sdr, AVComplexFloat *data, int len, int block_size, int sample_rate, int dir)
 {
+    double factor = sample_rate / (2000.0*block_size);
     if (sdr->emphasis_mode == EMPHASIS_NONE)
         return;
 
-    len = FFMIN(len, len * 19000 / sample_rate);
+    len = FFMIN(len, len * 2 * 19000 / sample_rate);
 
     for (int i = 1; i < len; i++) {
-        double index = 1.0 + i / 1000;
+        double index = 1.0 + i * factor;
         double scale;
 
         if (sdr->emphasis_mode == EMPHASIS_50us)
@@ -1051,8 +1052,8 @@ static int demodulate_fm(SDRContext *sdr, Station *station, AVStream *st, AVPack
         if (st) {
             memcpy(sdr->fm_block + i, sdr->fm_block + 2*carrier19_i, sizeof(AVComplexFloat)*len17_i);
             memcpy(sdr->fm_block + i + 2*sdr->fm_block_size_p2 - len17_i, sdr->fm_block + 2*carrier19_i - len17_i, sizeof(AVComplexFloat)*len17_i);
-            apply_deemphasis(sdr, sdr->fm_block + i, sdr->fm_block_size_p2, sample_rate_p2, + 1);
-            apply_deemphasis(sdr, sdr->fm_block + i + 2*sdr->fm_block_size_p2, sdr->fm_block_size_p2, sample_rate_p2, - 1);
+            apply_deemphasis(sdr, sdr->fm_block + i, sdr->fm_block_size_p2, sdr->fm_block_size_p2, sample_rate_p2, + 1);
+            apply_deemphasis(sdr, sdr->fm_block + i + 2*sdr->fm_block_size_p2, sdr->fm_block_size_p2, sdr->fm_block_size_p2, sample_rate_p2, - 1);
             sdr->fm_ifft_p2(sdr->fm_ifft_p2_ctx, sdr->fm_iside   , sdr->fm_block + i, sizeof(AVComplexFloat));
             synchronous_am_demodulationN(sdr->fm_iside, sdr->fm_icarrier, sdr->fm_window_p2, 2*sdr->fm_block_size_p2, 2);
         }
@@ -1061,7 +1062,7 @@ static int demodulate_fm(SDRContext *sdr, Station *station, AVStream *st, AVPack
         return 0;
 
     memset(sdr->fm_block + len17_i, 0, (2*sdr->fm_block_size_p2 - len17_i) * sizeof(AVComplexFloat));
-    apply_deemphasis(sdr, sdr->fm_block, 2*sdr->fm_block_size_p2, sample_rate_p2, + 1);
+    apply_deemphasis(sdr, sdr->fm_block, sdr->fm_block_size_p2, sdr->fm_block_size_p2, sample_rate_p2, + 1);
     sdr->fm_ifft_p2(sdr->fm_ifft_p2_ctx, sdr->fm_iblock  , sdr->fm_block, sizeof(AVComplexFloat));
     memset(sdr->fm_iblock + 2*sdr->fm_block_size_p2, 0 ,(2*sdr->fm_block_size -2*sdr->fm_block_size_p2) * sizeof(AVComplexFloat));
 

commit 1392a35da8a29898ebcf1c19dc22fec952df7539
Author:     Michael Niedermayer <michael at niedermayer.cc>
AuthorDate: Thu Jul 13 00:32:03 2023 +0200
Commit:     Michael Niedermayer <michael at niedermayer.cc>
CommitDate: Thu Jul 13 01:36:33 2023 +0200

    avradio/sdrdemux: Reduce FM audio bandwidth down toward reality
    
    This avoids useless computations
    
    Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>

diff --git a/libavradio/sdrdemux.c b/libavradio/sdrdemux.c
index c0ca420c84..54d7622809 100644
--- a/libavradio/sdrdemux.c
+++ b/libavradio/sdrdemux.c
@@ -1519,9 +1519,9 @@ int ff_sdr_common_init(AVFormatContext *s)
     av_log(s, AV_LOG_INFO, "Block size %d\n", sdr->block_size);
 
     sdr->block_time = sdr->block_size / (double)sdr->sdr_sample_rate;
-    sdr->am_bandwidth    =   6 * 1000;
-    sdr->fm_bandwidth    = 180 * 1000;
-    sdr->fm_bandwidth_p2 =  18 * 1000;
+    sdr->am_bandwidth    =   6   * 1000;
+    sdr->fm_bandwidth    = 180   * 1000;
+    sdr->fm_bandwidth_p2 =  16.5 * 1000; // Officially Stereo Broadcast FM has 15khz audio bandwidth
 
     sdr->am_block_size    = find_block_size(sdr, sdr->am_bandwidth);
     sdr->fm_block_size    = find_block_size(sdr, sdr->fm_bandwidth);

commit 5c8413e55f0b60f8743b80efa989e31262e39719
Author:     Michael Niedermayer <michael at niedermayer.cc>
AuthorDate: Wed Jul 12 22:57:30 2023 +0200
Commit:     Michael Niedermayer <michael at niedermayer.cc>
CommitDate: Thu Jul 13 01:36:33 2023 +0200

    avradio/sdrdemux: Basic prefilter for RDS
    
    25% lower error rate
    
    Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>

diff --git a/libavradio/sdrdemux.c b/libavradio/sdrdemux.c
index bbd756f1d6..c0ca420c84 100644
--- a/libavradio/sdrdemux.c
+++ b/libavradio/sdrdemux.c
@@ -1031,6 +1031,19 @@ static int demodulate_fm(SDRContext *sdr, Station *station, AVStream *st, AVPack
 
         memcpy(sdr->fm_block + i, sdr->fm_block + 3*carrier19_i, sizeof(AVComplexFloat)*len2_4_i);
         memcpy(sdr->fm_block + i + 2*sdr->fm_block_size_p2 - len2_4_i, sdr->fm_block + 3*carrier19_i - len2_4_i, sizeof(AVComplexFloat)*len2_4_i);
+
+        //This improves the decoder performace from an error rate per packet of 0.539578 to 0.410425
+        for (int j= 0; j<len2_4_i; j++) {
+            float J = j / (float)len2_4_i;
+            float W = 1 - J*J;
+            sdr->fm_block[i+j].re *= W;
+            sdr->fm_block[i+j].im *= W;
+            if (j) {
+                sdr->fm_block[i + 2*sdr->fm_block_size_p2 - j].re *= W;
+                sdr->fm_block[i + 2*sdr->fm_block_size_p2 - j].im *= W;
+            }
+        }
+
         sdr->fm_ifft_p2(sdr->fm_ifft_p2_ctx, sdr->fm_iside   , sdr->fm_block + i, sizeof(AVComplexFloat));
         synchronous_am_demodulationN(sdr->fm_iside, sdr->fm_icarrier, sdr->fm_window_p2, 2*sdr->fm_block_size_p2, 3);
         ff_sdr_decode_rds(sdr, station, sdr->fm_iside);

commit 724415438055d3d621bdc57b820c66b5541a36d1
Author:     Michael Niedermayer <michael at niedermayer.cc>
AuthorDate: Wed Jul 12 19:47:36 2023 +0200
Commit:     Michael Niedermayer <michael at niedermayer.cc>
CommitDate: Thu Jul 13 01:36:33 2023 +0200

    avradio/sdrdemux: Export RT+ metadata updates
    
    Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>

diff --git a/libavradio/sdrdemux.c b/libavradio/sdrdemux.c
index e45d00724b..bbd756f1d6 100644
--- a/libavradio/sdrdemux.c
+++ b/libavradio/sdrdemux.c
@@ -1677,6 +1677,7 @@ process_next_block:
     for (int stream_index = 0; stream_index < s->nb_streams; stream_index++) {
         AVStream *st = s->streams[stream_index];
         SDRStream *sst = st->priv_data;
+        Station *station = sst->station;
 
         if (sst->processing_index) {
             int skip = 1;
@@ -1686,11 +1687,25 @@ process_next_block:
                     return skip;
             } else if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
                 if (sst->station) {
+                    const char *metadata_keys[] = {"artist", "title"};
+                    const char *metadata_values[] = {station->artist, station->title};
+                    AVDictionaryEntry *t = NULL;
+
                     skip = 0;
                     ret = ff_sdr_modulation_descs[ sst->station->modulation ].demodulate(sdr, sst->station, st, pkt);
                     if (ret < 0) {
                         av_log(s, AV_LOG_ERROR, "demodulation failed ret = %d\n", ret);
                     }
+                    for(int i = 0; i < FF_ARRAY_ELEMS(metadata_keys); i++) {
+                        const char *value = "";
+                        t = av_dict_get(st->metadata, metadata_keys[i], NULL, 0);
+                        if (t)
+                            value = t->value;
+                        if (strcmp(value, metadata_values[i])) {
+                            av_dict_set(&st->metadata, metadata_keys[i], metadata_values[i], 0);
+                            s->event_flags |= AVFMT_EVENT_FLAG_METADATA_UPDATED;
+                        }
+                    }
                 }
             } else
                 av_assert0(0);

commit 874bc3cc19590a3768dffc0bd8b4a0b386598462
Author:     Michael Niedermayer <michael at niedermayer.cc>
AuthorDate: Wed Jul 12 19:46:51 2023 +0200
Commit:     Michael Niedermayer <michael at niedermayer.cc>
CommitDate: Thu Jul 13 01:36:33 2023 +0200

    remove stray av_log()
    
    Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>

diff --git a/libavradio/rds.c b/libavradio/rds.c
index 4b16521e4c..1f2979d068 100644
--- a/libavradio/rds.c
+++ b/libavradio/rds.c
@@ -179,7 +179,6 @@ static int decode_rds_group(SDRContext *sdr, Station *station, uint16_t group[4]
                 v <<= 6;
             }
             tag[1][2] >>= 1;
-            av_log(0,0, "\n");
             for(int i = 0; i<2; i++) {
                 char *target= NULL;
                 switch(tag[i][0]) {

commit 3bec4d194af940185502b23be1af5e4aaa32ac2d
Author:     Michael Niedermayer <michael at niedermayer.cc>
AuthorDate: Wed Jul 12 17:00:27 2023 +0200
Commit:     Michael Niedermayer <michael at niedermayer.cc>
CommitDate: Thu Jul 13 01:36:32 2023 +0200

    avradio/rds: Better file title
    
    Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>

diff --git a/libavradio/rds.c b/libavradio/rds.c
index 30e4209ae8..4b16521e4c 100644
--- a/libavradio/rds.c
+++ b/libavradio/rds.c
@@ -1,5 +1,5 @@
 /*
- * RDS
+ * Radio Data System
  * Copyright (c) 2023 Michael Niedermayer
  *
  * This file is part of FFmpeg.

commit cb2059eb468f00a3423491b8f39c3b00eaaa3cef
Author:     Michael Niedermayer <michael at niedermayer.cc>
AuthorDate: Wed Jul 12 16:11:53 2023 +0200
Commit:     Michael Niedermayer <michael at niedermayer.cc>
CommitDate: Thu Jul 13 01:36:32 2023 +0200

    avradio/rds: Implement RadioText Plus
    
    Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>

diff --git a/libavradio/rds.c b/libavradio/rds.c
index e121c9db8e..30e4209ae8 100644
--- a/libavradio/rds.c
+++ b/libavradio/rds.c
@@ -143,6 +143,17 @@ static int decode_rds_group(SDRContext *sdr, Station *station, uint16_t group[4]
             AV_WB16(station->radiotext + 4*(group[1]&15) + 2, group[3]);
         }
     break;}
+    case 3:
+        if (!b) {
+            int application_id = group[3];
+            switch (application_id) {
+            case 0x4BD7:
+                //RadioText Plus / RT+ for group 2A RT - IEC 62106-6:2023
+                station->rtp_appgroup = group[1] & 31;
+                break;
+            }
+        }
+    break;
     case 10:
         if (b==0) {
             AV_WB16(station->programm_type_name + 4*(group[1]&1)    , group[2]);
@@ -152,7 +163,38 @@ static int decode_rds_group(SDRContext *sdr, Station *station, uint16_t group[4]
 //     case 14:
 //     break;
     default:
-        av_log(sdr->avfmt, AV_LOG_DEBUG, "RDS: PI %X, A %X B %X PTY %X\n", pi,a,b,pty);
+        if (2*a + b == station->rtp_appgroup) {
+            int toggle_bit  = group[1]&16;
+            int running_bit = group[1]&8;
+            uint64_t v = ((group[1]&7LL)<<32) + ((uint64_t)group[2]<<16) + group[3];
+            int tag[2][3];
+            if (toggle_bit != station->rtp_toggle_bit) {
+                station->artist[0] =
+                station->title[0] =
+                station->album[0] = 0;
+            }
+            station->rtp_toggle_bit = toggle_bit;
+            for(int i = 0; i<6; i++) {
+                tag[i/3][i%3] = (v>>29) & 63;
+                v <<= 6;
+            }
+            tag[1][2] >>= 1;
+            av_log(0,0, "\n");
+            for(int i = 0; i<2; i++) {
+                char *target= NULL;
+                switch(tag[i][0]) {
+                case 1: target = station->title; break;
+                case 2: target = station->album; break;
+                case 4: target = station->artist; break;
+                default:
+                    av_log(sdr->avfmt, AV_LOG_DEBUG, "Unhandled RT+ code %d\n", tag[i][0]);
+                }
+                if (target) {
+                    memcpy(target, station->radiotext + tag[i][1], 1 + tag[i][2]);
+                    target[1+tag[i][2]] = 0;
+                }
+            }
+        }
     }
 
     return 0;
diff --git a/libavradio/sdr.h b/libavradio/sdr.h
index 4b3e14da02..ac6b7dffe0 100644
--- a/libavradio/sdr.h
+++ b/libavradio/sdr.h
@@ -72,10 +72,17 @@ typedef enum Modulation {
 
 typedef struct Station {
     char name[9];
+
     char radiotext[65];
+    char artist[65];
+    char title[65];
+    char album[65];
     char programm_type_name[9];
     int program_id[2];
     uint8_t rt_ab_flag;
+    uint8_t rtp_toggle_bit;
+    uint8_t rtp_running_bit;
+    uint16_t rtp_appgroup;
 
     enum Modulation modulation;
     double frequency;
diff --git a/libavradio/vissualize.c b/libavradio/vissualize.c
index d87ca167de..a3dcf5801b 100644
--- a/libavradio/vissualize.c
+++ b/libavradio/vissualize.c
@@ -221,6 +221,11 @@ int ff_sdr_vissualization(SDRContext *sdr, AVStream *st, AVPacket *pkt)
             if (s->radiotext[0]) {
                 draw_string(pkt->data, 4*w, s->radiotext, xmid + 8*yd, 320*h2 + 24*yd, xd, yd, color, color, color, w, h);
             }
+            if (s->title[0] || s->artist[0]) {
+                int len = strlen(s->title) + 1;
+                draw_string(pkt->data, 4*w, s->title , xmid + 8*yd, 320*h2 + 2*24*yd, xd, yd, color, color*1.5, color, w, h);
+                draw_string(pkt->data, 4*w, s->artist, xmid + 8*yd + 9*xd*len, 320*h2 + 2*24*yd + 9*yd*len, xd, yd, color, color*2, color, w, h);
+            }
         }
     }
 

commit 5d922961f42e96210c8a61f92469b95a3f5acd35
Author:     Michael Niedermayer <michael at niedermayer.cc>
AuthorDate: Wed Jul 12 16:10:23 2023 +0200
Commit:     Michael Niedermayer <michael at niedermayer.cc>
CommitDate: Wed Jul 12 16:10:23 2023 +0200

    avradio/rds: Implement clearing radio text
    
    Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>

diff --git a/libavradio/rds.c b/libavradio/rds.c
index 55b24a0d9e..e121c9db8e 100644
--- a/libavradio/rds.c
+++ b/libavradio/rds.c
@@ -130,14 +130,19 @@ static int decode_rds_group(SDRContext *sdr, Station *station, uint16_t group[4]
     case 0:
         AV_WB16(station->name + 2*(group[1]&3), group[3]);
     break;
-    case 2:
+    case 2:{
+        int new_ab_flag = group[1] & 16;
+        if (new_ab_flag != station->rt_ab_flag) {
+            memset(station->radiotext, 0, sizeof(station->radiotext));
+            station->rt_ab_flag = new_ab_flag;
+        }
         if (b) {
             AV_WB16(station->radiotext + 2*(group[1]&15)    , group[3]);
         } else {
             AV_WB16(station->radiotext + 4*(group[1]&15)    , group[2]);
             AV_WB16(station->radiotext + 4*(group[1]&15) + 2, group[3]);
         }
-    break;
+    break;}
     case 10:
         if (b==0) {
             AV_WB16(station->programm_type_name + 4*(group[1]&1)    , group[2]);
diff --git a/libavradio/sdr.h b/libavradio/sdr.h
index 29ac4a2963..4b3e14da02 100644
--- a/libavradio/sdr.h
+++ b/libavradio/sdr.h
@@ -75,6 +75,8 @@ typedef struct Station {
     char radiotext[65];
     char programm_type_name[9];
     int program_id[2];
+    uint8_t rt_ab_flag;
+
     enum Modulation modulation;
     double frequency;
     int nb_frequency;       ///< number of detections which are used to compute the frequency

commit dec413caa64c72acd9ba47f65a19e4ad9f01f033
Author:     Michael Niedermayer <michael at niedermayer.cc>
AuthorDate: Wed Jul 12 01:44:08 2023 +0200
Commit:     Michael Niedermayer <michael at niedermayer.cc>
CommitDate: Wed Jul 12 01:44:08 2023 +0200

    avradio/sdrdemux: basic warning cleanup
    
    Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>

diff --git a/libavradio/sdrdemux.c b/libavradio/sdrdemux.c
index fd3f5dd52d..e45d00724b 100644
--- a/libavradio/sdrdemux.c
+++ b/libavradio/sdrdemux.c
@@ -1148,7 +1148,6 @@ static int setup_stream(SDRContext *sdr, int stream_index, Station *station)
     AVFormatContext *s = sdr->avfmt;
     AVStream *st = s->streams[stream_index];
     SDRStream *sst = st->priv_data;
-    int ret;
 
     //For now we expect each station to be only demodulated once, nothing should break though if its done more often
     av_assert0(station->stream == NULL || station->stream == sst);
@@ -1163,9 +1162,9 @@ static int setup_stream(SDRContext *sdr, int stream_index, Station *station)
     station->stream = sst;
 
     if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
+        int block_size;
         free_stream(sdr, stream_index);
 
-        int block_size;
         if (sst->station->modulation == FM) {
             block_size = sdr->fm_block_size;
         } else

commit 841670e4b95ebfecd02fdc33e978d9dc0dfa00e0
Author:     Michael Niedermayer <michael at niedermayer.cc>
AuthorDate: Wed Jul 12 01:43:29 2023 +0200
Commit:     Michael Niedermayer <michael at niedermayer.cc>
CommitDate: Wed Jul 12 01:43:29 2023 +0200

    avradio/sdrdemux: Compute FM station frequency more exactly
    
    Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>

diff --git a/libavradio/sdrdemux.c b/libavradio/sdrdemux.c
index fea4202709..fd3f5dd52d 100644
--- a/libavradio/sdrdemux.c
+++ b/libavradio/sdrdemux.c
@@ -383,6 +383,7 @@ static int create_candidate_station(SDRContext *sdr, enum Modulation modulation,
     Station *station_list[1000];
     double snapdistance = modulation == AM ? AM_FREQ_TOLERANCE : FM_FREQ_TOLERANCE;
     int nb_stations = ff_sdr_find_stations(sdr, freq, snapdistance, station_list, FF_ARRAY_ELEMS(station_list));
+    int update_freq = 1;
 
     if (nb_stations) {
         for(int i = 1; i<nb_stations; i++)
@@ -409,12 +410,18 @@ static int create_candidate_station(SDRContext *sdr, enum Modulation modulation,
             goto fail;
     } else {
         station = station_list[0];
+
+        //demodulated FM stations have their frequency computed exactly, so dont mess them up
+        update_freq = station->modulation != FM || !station->in_station_list || !sdr->demodulate_all_fm;
+
         // We will update the frequency so we need to reinsert
         tree_remove(&sdr->station_root, station, station_cmp, &next);
-        station->frequency = station->nb_frequency * station->frequency + freq;
+        if (update_freq)
+            station->frequency = station->nb_frequency * station->frequency + freq;
         station->timeout   = 0;
     }
-    station->frequency /= ++station->nb_frequency;
+    if(update_freq)
+        station->frequency /= ++station->nb_frequency;
 
     station->detection_per_mix_frequency[histogram_index(sdr, freq)] ++;
     station->modulation   = modulation;
@@ -934,6 +941,22 @@ static int probe_fm(SDRContext *sdr)
     return 0;
 }
 
+static void station_update_freq(SDRContext *sdr, Station *station, double freq)
+{
+    struct AVTreeNode *next = NULL;
+    void *tmp;
+
+    //We must reinsert the station if we change the key (frequency)
+    tree_remove(&sdr->station_root, station, station_cmp, &next);
+
+    station->frequency = station->nb_frequency * station->frequency + freq;
+    station->frequency /= ++station->nb_frequency;
+
+    tmp = tree_insert(&sdr->station_root, station, station_cmp, &next);
+    av_assert0(!tmp || tmp == station);
+    av_freep(&next);
+}
+
 static int demodulate_fm(SDRContext *sdr, Station *station, AVStream *st, AVPacket *pkt)
 {
     SDRStream *sst = st ? st->priv_data : NULL;
@@ -953,11 +976,12 @@ static int demodulate_fm(SDRContext *sdr, Station *station, AVStream *st, AVPack
     int len2_4_i    = 2L*sdr->fm_block_size* 2400 / sample_rate;
     double carrier19_i_exact;
     int W= 5;
+    double dc = 0, dcw = 0;
+    int len2 = FFMIN(index, 2*sdr->block_size - index);
 
     av_assert0(!st || (sst == station->stream && sst->station == station));
 
     //If only some of the bandwidth is available, just try with less
-    int len2 = FFMIN(index, 2*sdr->block_size - index);
     if (len2 < len && len2 > len/2)
         len = len2;
 
@@ -979,9 +1003,14 @@ static int demodulate_fm(SDRContext *sdr, Station *station, AVStream *st, AVPack
         sdr->fm_iblock[i].re = atan2(x.im * y.re - x.re * y.im,
                                      x.re * y.re + x.im * y.im) * sdr->fm_window[i];
         sdr->fm_iblock[i].im = 0;
+        dc += sdr->fm_iblock[i].re;
+        dcw+= sdr->fm_window[i] * sdr->fm_window[i];
     }
     sdr->fm_iblock[i].re = 0;
     sdr->fm_iblock[i].im = 0;
+    dc *= M_PI/2 * sqrt((2*sdr->fm_block_size - 1) / dcw);
+
+    station_update_freq(sdr, station, freq-dc);
 
     av_assert0(sdr->fm_block_size_p2 * 2 < sdr->fm_block_size);
     //FIXME this only needs to be a RDFT

commit 40a73bf3003b347c94ec9b3e0d63fb4f929e7e03
Author:     Michael Niedermayer <michael at niedermayer.cc>
AuthorDate: Wed Jul 12 01:42:12 2023 +0200
Commit:     Michael Niedermayer <michael at niedermayer.cc>
CommitDate: Wed Jul 12 01:42:12 2023 +0200

    avradio/sdrdemux: require better timeout for replacing station
    
    Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>

diff --git a/libavradio/sdrdemux.c b/libavradio/sdrdemux.c
index 2103feaca8..fea4202709 100644
--- a/libavradio/sdrdemux.c
+++ b/libavradio/sdrdemux.c
@@ -216,7 +216,8 @@ static int create_station(SDRContext *sdr, Station *candidate_station) {
         }
     }
     if (best_station) {
-        if (score > best_station->score && conflict == INT_MAX) {
+        if (score > best_station->score && conflict == INT_MAX &&
+            candidate_station->timeout < best_station->timeout) {
             int log_level = fabs(best_station->frequency - freq) < 3.0 ? AV_LOG_DEBUG : AV_LOG_WARNING;
             av_log(sdr->avfmt, log_level, "Update station score:%f -> %f freq: %f %f -> %f\n",
                     best_station->score, score,

-----------------------------------------------------------------------

Summary of changes:
 libavradio/rds.c        | 52 ++++++++++++++++++++++++++--
 libavradio/sdr.h        |  9 +++++
 libavradio/sdrdemux.c   | 91 ++++++++++++++++++++++++++++++++++++++++---------
 libavradio/vissualize.c |  5 +++
 4 files changed, 138 insertions(+), 19 deletions(-)


hooks/post-receive
-- 



More information about the ffmpeg-cvslog mailing list