aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2016-04-30 17:42:52 +0200
committerMatthias P. Braendli <matthias.braendli@mpb.li>2016-04-30 17:42:52 +0200
commit55d65a22abd83ea841cc2b22d10790897e145c9a (patch)
tree4aa1b69fc72c8cd675a327351b4d9e35039de5f2
parentc1599cb19601443c48c45c5ad8d1b0d40a6238bc (diff)
downloadfdk-aac-dabplus-55d65a22abd83ea841cc2b22d10790897e145c9a.tar.gz
fdk-aac-dabplus-55d65a22abd83ea841cc2b22d10790897e145c9a.tar.bz2
fdk-aac-dabplus-55d65a22abd83ea841cc2b22d10790897e145c9a.zip
Fix DAB insertion of SCF-CRC
-rw-r--r--libtoolame-dab/bitstream.c5
-rw-r--r--libtoolame-dab/bitstream.h1
-rw-r--r--libtoolame-dab/toolame.c18
3 files changed, 20 insertions, 4 deletions
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);
}