aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpiratfm <piratfm@gmail.com>2013-04-15 21:56:55 +0300
committerMatthias P. Braendli <matthias.braendli@mpb.li>2013-12-14 17:42:35 +0100
commit4cd6dde61ee3115a1d4b5bec50996c8e708370fa (patch)
tree6fb2bdcb9e801c12bab0a3b0460337f5f933dd0f
parentddb94b9025f6893a6d9543254fedf0a70c0549b8 (diff)
downloadfdk-aac-dabplus-4cd6dde61ee3115a1d4b5bec50996c8e708370fa.tar.gz
fdk-aac-dabplus-4cd6dde61ee3115a1d4b5bec50996c8e708370fa.tar.bz2
fdk-aac-dabplus-4cd6dde61ee3115a1d4b5bec50996c8e708370fa.zip
add reed-solomon encoding.
-rw-r--r--Makefile.am2
-rw-r--r--aac-enc-dabplus.c46
-rw-r--r--libAACenc/src/aacenc.cpp4
-rw-r--r--libAACenc/src/qc_main.cpp6
-rw-r--r--libFDK/src/FDK_crc.cpp4
-rw-r--r--libMpegTPEnc/src/tpenc_dab.cpp14
6 files changed, 56 insertions, 20 deletions
diff --git a/Makefile.am b/Makefile.am
index 395b5e2..316db15 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -39,7 +39,7 @@ bin_PROGRAMS = aac-enc$(EXEEXT) aac-enc-dabplus$(EXEEXT)
aac_enc_LDADD = libfdk-aac.la
aac_enc_SOURCES = aac-enc.c wavreader.c
-aac_enc_dabplus_LDADD = libfdk-aac.la
+aac_enc_dabplus_LDADD = libfdk-aac.la -lfec
aac_enc_dabplus_SOURCES = aac-enc-dabplus.c wavreader.c
diff --git a/aac-enc-dabplus.c b/aac-enc-dabplus.c
index 79a2379..b1152a5 100644
--- a/aac-enc-dabplus.c
+++ b/aac-enc-dabplus.c
@@ -25,6 +25,8 @@
#include "libAACenc/include/aacenc_lib.h"
#include "wavreader.h"
+#include <fec.h>
+
void usage(const char* name) {
fprintf(stderr, "%s [OPTION...]\n", name);
fprintf(stderr,
@@ -99,6 +101,8 @@ int main(int argc, char *argv[]) {
int wav_format, bits_per_sample, sample_rate=48000, channels=2;
uint8_t* input_buf;
int16_t* convert_buf;
+ uint8_t* rs_encoded_buf;
+ void *rs_handler = NULL;
int aot = AOT_DABPLUS_AAC_LC;
int afterburner = 0, raw_input=0;
HANDLE_AACENCODER handle;
@@ -274,11 +278,23 @@ int main(int argc, char *argv[]) {
int input_size = channels*2*info.frameLength;
input_buf = (uint8_t*) malloc(input_size);
convert_buf = (int16_t*) malloc(input_size);
+ rs_encoded_buf = (uint8_t*) malloc(120*subchannel_index);
+
+ /* symsize=8, gfpoly=0x11d, fcr=0, prim=1, nroots=10, pad=135 */
+ rs_handler = init_rs_char(8, 0x11d, 0, 1, 10, 135);
+ if (rs_handler == NULL) {
+ perror("init_rs_char failed");
+ return 0;
+ }
int loops = 0;
- int outbuf_size = subchannel_index*110;
+ int outbuf_size = subchannel_index*120;
uint8_t outbuf[20480];
+ if(outbuf_size % 5 != 0) {
+ fprintf(stderr, "(outbuf_size mod 5) = %d\n", outbuf_size % 5);
+ }
+
int frame=0;
while (1) {
AACENC_BufDesc in_buf = { 0 }, out_buf = { 0 };
@@ -339,7 +355,7 @@ int main(int argc, char *argv[]) {
}
if (out_args.numOutBytes == 0)
continue;
-
+#if 0
unsigned char au_start[6];
unsigned char* sfbuf = outbuf;
au_start[0] = 6;
@@ -348,12 +364,31 @@ int main(int argc, char *argv[]) {
fprintf (stderr, "au_start[0] = %d\n", au_start[0]);
fprintf (stderr, "au_start[1] = %d\n", au_start[1]);
fprintf (stderr, "au_start[2] = %d\n", au_start[2]);
+#endif
+
+ int row, col;
+ char buf_to_rs_enc[110];
+ char rs_enc[10];
+ for(row=0; row < subchannel_index; row++) {
+ for(col=0;col < 110; col++) {
+ buf_to_rs_enc[col] = outbuf[subchannel_index * col + row];
+ }
+
+ encode_rs_char(rs_handler, buf_to_rs_enc, rs_enc);
+
+ for(col=110; col<120; col++) {
+ outbuf[subchannel_index * col + row] = rs_enc[col-110];
+ assert(subchannel_index * col + row < outbuf_size);
+ }
+ }
fwrite(outbuf, 1, /*out_args.numOutBytes*/ outbuf_size, out_fh);
- fprintf(stderr, "Written %d/%d bytes!\n", out_args.numOutBytes, outbuf_size);
+ //fprintf(stderr, "Written %d/%d bytes!\n", out_args.numOutBytes + row*10, outbuf_size);
+ if(out_args.numOutBytes + row*10 == outbuf_size)
+ fprintf(stderr, ".");
- if(frame > 10)
- break;
+// if(frame > 10)
+// break;
frame++;
}
free(input_buf);
@@ -364,6 +399,7 @@ int main(int argc, char *argv[]) {
wav_read_close(wav);
}
fclose(out_fh);
+ free_rs_char(rs_handler);
aacEncClose(&handle);
diff --git a/libAACenc/src/aacenc.cpp b/libAACenc/src/aacenc.cpp
index 3585d80..1b1fd0d 100644
--- a/libAACenc/src/aacenc.cpp
+++ b/libAACenc/src/aacenc.cpp
@@ -914,13 +914,13 @@ AAC_ENCODER_ERROR FDKaacEnc_EncodeFrame( HANDLE_AAC_ENC hAacEnc,
/* adjust super frame bitrate */
avgTotalBits *= hAacEnc->config->nSubFrames;
- fprintf(stderr, "avgTotalBits=%d x %d\n", avgTotalBits, hAacEnc->config->nSubFrames);
+ //fprintf(stderr, "avgTotalBits=%d x %d\n", avgTotalBits, hAacEnc->config->nSubFrames);
}
/* Make first estimate of transport header overhead.
Take maximum possible frame size into account to prevent bitreservoir underrun. */
- fprintf(stderr, "avgTotalBits=%d, bitResTot=%d\n", avgTotalBits, hAacEnc->qcKernel->bitResTot);
+ //fprintf(stderr, "avgTotalBits=%d, bitResTot=%d\n", avgTotalBits, hAacEnc->qcKernel->bitResTot);
hAacEnc->qcKernel->globHdrBits = transportEnc_GetStaticBits(hTpEnc, avgTotalBits + hAacEnc->qcKernel->bitResTot);
diff --git a/libAACenc/src/qc_main.cpp b/libAACenc/src/qc_main.cpp
index d7799a5..e09769e 100644
--- a/libAACenc/src/qc_main.cpp
+++ b/libAACenc/src/qc_main.cpp
@@ -493,21 +493,21 @@ AAC_ENCODER_ERROR FDKaacEnc_AdjustBitrate(QC_STATE *RESTRICT hQC,
{
INT paddingOn=0;
INT frameLen;
- fprintf(stderr, "hQC->padding.paddingRest=%d bytes! (before)\n", hQC->padding.paddingRest);
+ //fprintf(stderr, "hQC->padding.paddingRest=%d bytes! (before)\n", hQC->padding.paddingRest);
/* Do we need an extra padding byte? */
paddingOn = FDKaacEnc_framePadding(bitRate,
sampleRate,
granuleLength,
&hQC->padding.paddingRest);
- fprintf(stderr, "hQC->padding.paddingRest=%d bytes! (after)\n", hQC->padding.paddingRest);
+ //fprintf(stderr, "hQC->padding.paddingRest=%d bytes! (after)\n", hQC->padding.paddingRest);
frameLen = paddingOn + FDKaacEnc_calcFrameLen(bitRate,
sampleRate,
granuleLength,
FRAME_LEN_BYTES_INT);
- fprintf(stderr, "frameLen=%d bytes!\n", frameLen);
+ //fprintf(stderr, "frameLen=%d bytes!\n", frameLen);
*avgTotalBits = frameLen<<3;
diff --git a/libFDK/src/FDK_crc.cpp b/libFDK/src/FDK_crc.cpp
index ccd9d19..a4c6900 100644
--- a/libFDK/src/FDK_crc.cpp
+++ b/libFDK/src/FDK_crc.cpp
@@ -467,7 +467,7 @@ static inline INT calcCrc_Bytes(
}
*pCrc = crc; /* update crc value */
- fprintf(stderr, "\n\n crc[%d]=%04x\n", i, crc);
+ //fprintf(stderr, "\n\n crc[%d]=%04x\n", i, crc);
return (i);
}
@@ -537,7 +537,7 @@ static void crcCalc(
}
}
- fprintf(stderr, "\n\n crc=%04x\n", crc);
+ //fprintf(stderr, "\n\n crc=%04x\n", crc);
hCrcInfo->crcValue = crc;
}
diff --git a/libMpegTPEnc/src/tpenc_dab.cpp b/libMpegTPEnc/src/tpenc_dab.cpp
index 0da1391..8f2603a 100644
--- a/libMpegTPEnc/src/tpenc_dab.cpp
+++ b/libMpegTPEnc/src/tpenc_dab.cpp
@@ -145,7 +145,7 @@ int dabWrite_GetHeaderBits( HANDLE_DAB hDab )
int dabWrite_CountTotalBitDemandHeader( HANDLE_DAB hDab, unsigned int streamDataLength )
{
- fprintf(stderr, "streamDataLength=%d (%d bytes)\n", streamDataLength, streamDataLength >> 3);
+ //fprintf(stderr, "streamDataLength=%d (%d bytes)\n", streamDataLength, streamDataLength >> 3);
return dabWrite_GetHeaderBits(hDab);
}
@@ -271,7 +271,7 @@ void dabWrite_EndRawDataBlock(HANDLE_DAB hDab,
INT crcIndex = 0;
USHORT crcData;
INT frameLen = (FDKgetValidBits(hBs) - hDab->subFrameStartBit) >> 3;
- fprintf(stderr, "frame=%d\n", frameLen);
+ //fprintf(stderr, "frame=%d\n", frameLen);
FDK_ASSERT(FDKgetValidBits(hBs) % 8 == 0); //only aligned au's
FDK_ASSERT(hDab->subchannels_num*110*8 > FDKgetValidBits(hBs)+2*8); //don't overlap superframe
@@ -282,7 +282,7 @@ void dabWrite_EndRawDataBlock(HANDLE_DAB hDab,
#if 1
if (hDab->currentBlock == hDab->num_raw_blocks) {
INT offset_size = hDab->subchannels_num*110*8 - 2*8 - FDKgetValidBits(hBs);
- fprintf(stderr, "offset_size=%d\n", offset_size >> 3);
+ //fprintf(stderr, "offset_size=%d\n", offset_size >> 3);
FDKpushFor(hBs, offset_size);
}
#endif
@@ -290,7 +290,7 @@ void dabWrite_EndRawDataBlock(HANDLE_DAB hDab,
FDKpushFor(&bsWriter, FDKgetValidBits(hBs) - hDab->subFrameStartBit);
FDKcrcEndReg(&hDab->crcInfo, &bsWriter, hDab->crcIndex);
crcData = FDKcrcGetCRC(&hDab->crcInfo);
- fprintf(stderr, "crcData = %04x\n", crcData);
+ //fprintf(stderr, "crcData = %04x\n", crcData);
/* Write inverted CRC of current raw data block */
FDKwriteBits(hBs, crcData ^ 0xffff, 16);
FDKsyncCache(hBs);
@@ -300,7 +300,7 @@ void dabWrite_EndRawDataBlock(HANDLE_DAB hDab,
if(hDab->currentBlock) {
FDKinitBitStream(&bsWriter, hBs->hBitBuf.Buffer, hBs->hBitBuf.bufSize, 0, BS_WRITER);
FDKpushFor(&bsWriter, 24 + (hDab->currentBlock-1)*12);
- fprintf(stderr, "FDKwriteBits() = %d\n", hDab->subFrameStartBit>>3);
+ //fprintf(stderr, "FDKwriteBits() = %d\n", hDab->subFrameStartBit>>3);
FDKwriteBits(&bsWriter, (hDab->subFrameStartBit>>3), 12);
FDKsyncCache(&bsWriter);
}
@@ -316,7 +316,7 @@ void dabWrite_EndRawDataBlock(HANDLE_DAB hDab,
FDKcrcEndReg(&hDab->crcFire, &bsWriter, crcIndex);
crcData = FDKcrcGetCRC(&hDab->crcFire);
- fprintf(stderr, "Firecode: %04x\n", crcData);
+ //fprintf(stderr, "Firecode: %04x\n", crcData);
FDKinitBitStream(&bsWriter, hBs->hBitBuf.Buffer, hBs->hBitBuf.bufSize, 0, BS_WRITER);
FDKwriteBits(&bsWriter, crcData, 16);
@@ -334,6 +334,6 @@ void dabWrite_EndRawDataBlock(HANDLE_DAB hDab,
/* Fixup CRC bits, since they come after each raw data block */
hDab->currentBlock++;
- fprintf(stderr, "dabWrite_EndRawDataBlock() *pBits=%d (%d)\n", *pBits, *pBits >> 3);
+ //fprintf(stderr, "dabWrite_EndRawDataBlock() *pBits=%d (%d)\n", *pBits, *pBits >> 3);
}