From: Michael Niedermayer <michael@niedermayer.cc> To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org> Subject: [FFmpeg-devel] [PATCH 02/12] avradio/rds: Implement burst error decoder Date: Tue, 11 Jul 2023 23:19:00 +0200 Message-ID: <20230711211910.1257355-2-michael@niedermayer.cc> (raw) In-Reply-To: <20230711211910.1257355-1-michael@niedermayer.cc> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc> --- 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<<i) >> 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".
next prev parent reply other threads:[~2023-07-11 21:19 UTC|newest] Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-07-11 21:18 [FFmpeg-devel] [PATCH 01/12] avradio/sdrdemux: Fix use of uninitialized memory Michael Niedermayer 2023-07-11 21:19 ` Michael Niedermayer [this message] 2023-07-11 21:19 ` [FFmpeg-devel] [PATCH 03/12] avradio/rds: Keep track of program_id Michael Niedermayer 2023-07-11 21:19 ` [FFmpeg-devel] [PATCH 04/12] avradio/sdr: Move rds_ring to Station Michael Niedermayer 2023-07-11 21:19 ` [FFmpeg-devel] [PATCH 05/12] avradio/rds: move phase 2 window to main context Michael Niedermayer 2023-07-11 21:19 ` [FFmpeg-devel] [PATCH 06/12] avradio/sdr: Warnings cleanup Michael Niedermayer 2023-07-11 21:19 ` [FFmpeg-devel] [PATCH 07/12] avradio/rds: warnings cleanup Michael Niedermayer 2023-07-11 21:19 ` [FFmpeg-devel] [PATCH 08/12] avradio/sdr: Move IFFT and block size to main context Michael Niedermayer 2023-07-11 21:19 ` [FFmpeg-devel] [PATCH 09/12] avradio/sdr: Move per stream arraies " Michael Niedermayer 2023-07-11 21:19 ` [FFmpeg-devel] [PATCH 10/12] avradio/sdr: Move tx contexts out of stream so its not duplicated Michael Niedermayer 2023-07-11 21:19 ` [FFmpeg-devel] [PATCH 11/12] avradio/sdr: Pass AVStream instead of int to demodulate Michael Niedermayer 2023-07-11 21:19 ` [FFmpeg-devel] [PATCH 12/12] avradio/sdr: Process RDS of all stations not just the current one Michael Niedermayer 2023-07-12 23:26 ` [FFmpeg-devel] [PATCH 01/12] avradio/sdrdemux: Fix use of uninitialized memory Michael Niedermayer
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20230711211910.1257355-2-michael@niedermayer.cc \ --to=michael@niedermayer.cc \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git