aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2014-03-22 21:55:26 +0100
committerMatthias P. Braendli <matthias.braendli@mpb.li>2014-03-22 21:55:26 +0100
commita96ff49819b5016e61197256cd8b53dc17386b29 (patch)
tree7852ae7f94ad46782962e19a3e90ad8482ed9784
parent2394a74289fabb7592cf42a9311b990aa940e8fc (diff)
downloadtoolame-dab-a96ff49819b5016e61197256cd8b53dc17386b29.tar.gz
toolame-dab-a96ff49819b5016e61197256cd8b53dc17386b29.tar.bz2
toolame-dab-a96ff49819b5016e61197256cd8b53dc17386b29.zip
integration with mot-encoder
-rw-r--r--Makefile3
-rw-r--r--toolame.c42
-rw-r--r--xpad.c51
-rw-r--r--xpad.h19
4 files changed, 103 insertions, 12 deletions
diff --git a/Makefile b/Makefile
index 665387f..6d80dba 100644
--- a/Makefile
+++ b/Makefile
@@ -23,7 +23,8 @@ c_sources = \
availbits.c \
ath.c \
encode_new.c \
- zmqoutput.c
+ zmqoutput.c \
+ xpad.c
OBJ = $(c_sources:.c=.o)
diff --git a/toolame.c b/toolame.c
index 27899d4..93d769d 100644
--- a/toolame.c
+++ b/toolame.c
@@ -20,13 +20,14 @@
#include "subband.h"
#include "encode_new.h"
#include "toolame.h"
+#include "xpad.h"
#include <assert.h>
FILE *musicin;
Bit_stream_struc bs;
char *programName;
-char toolameversion[10] = "0.2l";
+char toolameversion[10] = "0.2l-pad";
void global_init (void)
{
@@ -391,9 +392,24 @@ int main (int argc, char **argv)
/* If not all the bits were used, write out a stack of zeros */
for (i = 0; i < adb; i++)
put1bit (&bs, 0);
+
if (header.dab_extension) {
- /* Reserve some bytes for X-PAD in DAB mode */
- putbits (&bs, 0, header.dab_length * 8);
+ if (xpad_len()) {
+ /* Reserve some bytes for X-PAD in DAB mode */
+
+ /* always fill it entirely
+ for (i=header.dab_length-xpad_len(); i>0; i--) {
+ putbits(&bs, 0, 8);
+ }
+ */
+
+ for (i = 0; i < header.dab_length; i++) {
+ putbits (&bs, xpad_byte(), 8);
+ }
+ }
+ else {
+ fprintf(stderr, "error getting xpad!\n");
+ }
for (i = header.dab_extension - 1; i >= 0; i--) {
CRC_calcDAB (&frame, bit_alloc, scfsi, scalar, &crc, i);
@@ -403,7 +419,10 @@ int main (int argc, char **argv)
/* reserved 2 bytes for F-PAD in DAB mode */
putbits (&bs, crc, 8);
}
- putbits (&bs, 0, 16);
+ putbits (&bs, xpad_fpad(), 16); // CI
+
+ //header.dab_length = xpad_len(); // set xpad-length for next frame
+
}
frameBits = sstell (&bs) - sentBits;
@@ -521,8 +540,8 @@ void usage (void)
{ /* print syntax & exit */
/* FIXME: maybe have an option to display better definitions of help codes, and
long equivalents of the flags */
- fprintf (stdout, "\ntooLAME version %s with ZMQ support for ODR-DabMux\n"
- " (http://www.opendigitalradio.org)\n", toolameversion);
+ fprintf (stdout, "\ntooLAME version %s (http://toolame.sourceforge.net)\n",
+ toolameversion);
fprintf (stdout, "MPEG Audio Layer II encoder\n\n");
fprintf (stdout, "usage: \n");
fprintf (stdout, "\t%s [options] <input> <output>\n\n", programName);
@@ -554,14 +573,13 @@ void usage (void)
fprintf (stdout, "\t-o mark as original\n");
fprintf (stdout, "\t-e add error protection\n");
fprintf (stdout, "\t-r force padding bit/frame off\n");
- fprintf (stdout, "\t-D len add DAB extensions of length [len]\n");
+ fprintf (stdout, "\t-D portnum activate DAB-mode. Listen for pad data on port portnum\n");
fprintf (stdout, "\t-t talkativity 0=no messages (dflt 2)");
fprintf (stdout, "Files\n");
fprintf (stdout,
"\tinput input sound file. (WAV,AIFF,PCM or use '/dev/stdin')\n");
- fprintf (stdout, "\toutput output file name for encoded bitstream\n");
- fprintf (stdout, "\t -or- output URI for ZeroMQ output,\n");
- fprintf (stdout, "\t format: tcp://<hostname>:<port>\n");
+ fprintf (stdout, "\toutput output bit stream of encoded audio\n");
+ fprintf (stdout, "\t prefix with tcp:// to use a ZMQ output\n");
fprintf (stdout,
"\n\tAllowable bitrates for 16, 22.05 and 24kHz sample input\n");
fprintf (stdout,
@@ -775,9 +793,11 @@ void parse_args (int argc, char **argv, frame_info * frame, int *psy,
break;
case 'D':
argUsed = 1;
- header->dab_length = atoi (arg);
+ header->dab_length = atoi(arg);
+ //header->dab_length = xpad_len();
header->error_protection = TRUE;
header->dab_extension = 2;
+ header->padding = 0;
glopts.dab = TRUE;
break;
case 'c':
diff --git a/xpad.c b/xpad.c
new file mode 100644
index 0000000..231bdd9
--- /dev/null
+++ b/xpad.c
@@ -0,0 +1,51 @@
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <assert.h>
+
+#include "xpad.h"
+
+static int xpad_fd = 0;
+
+uint16_t xpad_fpad() {
+ uint16_t fpad = 0x2; // CI flag
+
+ if (xpad_len()) {
+ fpad |= 1<<13; // variable length X-PAD
+ }
+
+ return fpad;
+}
+
+int xpad_len() {
+ if (xpad_fd == 0) {
+ xpad_fd = open("/home/bram/dab/mot-slideshow.file", O_RDONLY);
+ if (xpad_fd < 0) {
+ perror("Failed to open xpad file");
+ exit(1);
+ }
+ }
+ return 1;
+}
+
+uint8_t xpad_byte(void) {
+ uint8_t dat;
+
+ assert(xpad_fd != 0);
+ ssize_t num_read = read(xpad_fd, &dat, 1);
+
+ if (num_read == 0) {
+ fprintf(stderr, "xpad rewind\n");
+ lseek(xpad_fd, 0, SEEK_SET);
+ num_read = read(xpad_fd, &dat, 1);
+
+ assert(num_read == 1);
+ }
+
+ return dat;
+}
+
diff --git a/xpad.h b/xpad.h
new file mode 100644
index 0000000..2a06399
--- /dev/null
+++ b/xpad.h
@@ -0,0 +1,19 @@
+#ifndef _XPAD_H_
+#define _XPAD_H_
+
+#include <stdint.h>
+
+/* Return the number of bytes of x-pad data
+ * we have ready
+ */
+int xpad_len(void);
+
+/* Get one x-pad byte
+ */
+uint8_t xpad_byte(void);
+
+/* Calculate the two F-PAD bytes */
+uint16_t xpad_fpad(void);
+
+#endif
+