From 55d65a22abd83ea841cc2b22d10790897e145c9a Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Sat, 30 Apr 2016 17:42:52 +0200 Subject: Fix DAB insertion of SCF-CRC --- libtoolame-dab/bitstream.c | 5 +++++ libtoolame-dab/bitstream.h | 1 + libtoolame-dab/toolame.c | 18 ++++++++++++++---- 3 files changed, 20 insertions(+), 4 deletions(-) (limited to 'libtoolame-dab') diff --git a/libtoolame-dab/bitstream.c b/libtoolame-dab/bitstream.c index b426a4b..28e6408 100644 --- a/libtoolame-dab/bitstream.c +++ b/libtoolame-dab/bitstream.c @@ -37,6 +37,11 @@ /* see toollame.c */ int minimum = MINIMUM; +void bs_set_minimum(int min) +{ + minimum = min; +} + /* empty the buffer to the output device when the buffer becomes full */ void empty_buffer (Bit_stream_struc * bs, int minimum) { diff --git a/libtoolame-dab/bitstream.h b/libtoolame-dab/bitstream.h index 017a12d..3f990da 100644 --- a/libtoolame-dab/bitstream.h +++ b/libtoolame-dab/bitstream.h @@ -19,3 +19,4 @@ unsigned int hget1bit (void); /* MI */ unsigned long hgetbits (int); unsigned long hsstell (void); void hputbuf (unsigned int, int); +void bs_set_minimum(int minimum); diff --git a/libtoolame-dab/toolame.c b/libtoolame-dab/toolame.c index 7dc5aa5..961561f 100644 --- a/libtoolame-dab/toolame.c +++ b/libtoolame-dab/toolame.c @@ -278,12 +278,13 @@ int toolame_encode_frame( unsigned char *output_buffer, size_t output_buffer_size) { - extern int minimum; if (encode_first_call) { hdr_to_frps(&frame); encode_first_call = 0; } + frameNum++; + const int nch = frame.nch; const int error_protection = header.error_protection; @@ -301,8 +302,9 @@ int toolame_encode_frame( /* You must have one frame in memory if you are in DAB mode */ /* in conformity of the norme ETS 300 401 http://www.etsi.org */ /* see bitstream.c */ - if (frameNum == 1) - minimum = lg_frame + MINIMUM; + if (frameNum == 1) { + bs_set_minimum(lg_frame + MINIMUM); + } adb -= header.dab_extension * 8 + (xpad_len ? xpad_len : FPAD_LENGTH) * 8; } @@ -532,8 +534,16 @@ int toolame_encode_frame( for (int i = header.dab_extension - 1; i >= 0; i--) { CRC_calcDAB (&frame, bit_alloc, scfsi, scalar, &crc, i); /* this crc is for the previous frame in DAB mode */ - if (bs.buf_byte_idx + lg_frame < bs.buf_size) + if (bs.buf_byte_idx + lg_frame < bs.buf_size) { bs.buf[bs.buf_byte_idx + lg_frame] = crc; + } + else { + if (frameNum > 1) { + // frameNum 1 will always fail, because there is no previous frame + fprintf(stderr, "Error: Failed to insert SCF-CRC in frame %d, %d < %d\n", + frameNum, bs.buf_byte_idx + lg_frame, bs.buf_size); + } + } /* reserved 2 bytes for F-PAD in DAB mode */ putbits (&bs, crc, 8); } -- cgit v1.2.3