From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id B99F546DAF for ; Tue, 11 Jul 2023 21:19:30 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4D62068C5F7; Wed, 12 Jul 2023 00:19:21 +0300 (EEST) Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5AF9E68C311 for ; Wed, 12 Jul 2023 00:19:14 +0300 (EEST) Received: by mail.gandi.net (Postfix) with ESMTPSA id 81CDE20004 for ; Tue, 11 Jul 2023 21:19:13 +0000 (UTC) From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Tue, 11 Jul 2023 23:19:00 +0200 Message-Id: <20230711211910.1257355-2-michael@niedermayer.cc> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230711211910.1257355-1-michael@niedermayer.cc> References: <20230711211910.1257355-1-michael@niedermayer.cc> MIME-Version: 1.0 X-GND-Sasl: michael@niedermayer.cc Subject: [FFmpeg-devel] [PATCH 02/12] avradio/rds: Implement burst error decoder X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: Signed-off-by: Michael Niedermayer --- libavradio/rds.c | 55 ++++++++++++++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 21 deletions(-) diff --git a/libavradio/rds.c b/libavradio/rds.c index dd9a934c3c..2cb7942bbd 100644 --- a/libavradio/rds.c +++ b/libavradio/rds.c @@ -35,29 +35,42 @@ #include "libavformat/avformat.h" #include "libavformat/demux.h" +#define MAX_BURST 5 // Tradeoff between undetected errors and correction capacity values from 2 to 5 are reasonable + +static int burst_len(unsigned u) +{ + if (!u) + return 0; + + while(!(u&1)) + u>>=1; + return 1+av_log2(u); +} + /** * Check and correct RDS block * @param[out] group the data bits are returned here * @param block block nu,ber (0 to 3) * @return 1 if correctable single bit error, 0 if no error, >99 if non correctable errors */ -static int check_rds_block(uint16_t group[4], const float diff[104], int block) +static int check_rds_block(Station *station, uint16_t group[4], const float diff[104], const int block) { #define RDS_G 0x5B9 //101 1011 1001 static const uint16_t offset[4] = {0x0FC, 0x198, 0x168, 0x1B4}; unsigned codeword = 0; - unsigned syndrom = 0; - //we carry floats through to here so we can do a soft decission decoder - //ATM lets just do hard decission decoding that should be more than good enough + unsigned syndrom = 0; + const float *blockdiff = diff + block*26; //FIXME we could do this more efficiently but does it matter? for(int i=0; i<26; i++) { - int bit = (diff[i + block*26]<0); + int bit = blockdiff[i] < 0; + codeword += codeword + bit; syndrom += syndrom + bit; if (syndrom & (1<<10)) syndrom ^= RDS_G; } + if (block==2 && (group[1]&0x800)) { syndrom ^= 0x350; }else @@ -66,25 +79,24 @@ static int check_rds_block(uint16_t group[4], const float diff[104], int block) group[block] = codeword >> 10; - // try correcting some basic errors - if (syndrom) { - for (unsigned e = 1; e <= 2; e ++) { - unsigned mask = 255 >> (8-e); - unsigned syndrom1 = mask; - for(int i=0; i<27-e; i++) { - if (syndrom == syndrom1) { - group[block] ^= (mask<> 10; - return e; + // try correcting the most common error patterns + for (int i=0; i<27-MAX_BURST; i++) { + if (!(syndrom>>MAX_BURST)) { + int ret = burst_len(syndrom); + group[block] ^= (syndrom << i) >> 10; + + return ret; } - syndrom1 += syndrom1; - if (syndrom1 & (1<<10)) - syndrom1 ^= RDS_G; } + + return ret; } - return 100; // this is a good place do a 2nd pass with a soft decssion multi bit decoder + if (syndrom&1) + syndrom ^= RDS_G; + syndrom >>= 1; } - return 0; + return 20; } static int decode_rds_group(SDRContext *sdr, SDRStream *sst, uint16_t group[4]) @@ -131,6 +143,7 @@ int ff_sdr_decode_rds(SDRContext *sdr, SDRStream *sst, AVComplexFloat *signal) uint16_t group[4]; int64_t num_step_in_p2 = sdr->sdr_sample_rate * (int64_t)sst->block_size_p2; int64_t den_step_on_p2 = sdr->block_size * 2375LL; + Station *station = sst->station; #define IDX(I) ((I)*num_step_in_p2/den_step_on_p2) av_assert0(sst->rds_ring_pos <= sst->rds_ring_size - 2*sst->block_size_p2); @@ -171,7 +184,7 @@ int ff_sdr_decode_rds(SDRContext *sdr, SDRStream *sst, AVComplexFloat *signal) for (phase = 0; phase < 104; phase++) { int error = 0; for (int block = 0; block < 4; block++) { - error += check_rds_block(group, diff + phase, block); + error += check_rds_block(station, group, diff + phase, block); } if (error < best_errors) { best_errors = error; @@ -184,7 +197,7 @@ int ff_sdr_decode_rds(SDRContext *sdr, SDRStream *sst, AVComplexFloat *signal) if (best_errors < 10) { int error = 0; for (int block = 0; block < 4; block++) { - error += check_rds_block(group, diff + best_phase, block); + error += check_rds_block(station, group, diff + best_phase, block); } //have to recheck because of floats if (error < 10) { -- 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".