aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libtoolame-dab/toolame.c9
-rw-r--r--libtoolame-dab/toolame.h2
-rw-r--r--src/dabplus-enc.cpp19
3 files changed, 22 insertions, 8 deletions
diff --git a/libtoolame-dab/toolame.c b/libtoolame-dab/toolame.c
index 02cedf6..7dc5aa5 100644
--- a/libtoolame-dab/toolame.c
+++ b/libtoolame-dab/toolame.c
@@ -88,7 +88,6 @@ void global_init (void)
static frame_info frame;
static frame_header header;
static int frameNum;
-static int xpad_len;
static int psycount;
static int model;
static unsigned int crc;
@@ -257,12 +256,15 @@ int toolame_set_samplerate(long sample_rate)
int toolame_set_pad(int pad_len)
{
- header.dab_length = pad_len;
- if (header.dab_length <= 0) {
+ if (pad_len < 0) {
fprintf(stderr, "Invalid XPAD length specified\n");
return 1;
}
+ if (pad_len) {
+ header.dab_length = pad_len;
+ }
+
return 0;
}
@@ -272,6 +274,7 @@ static int encode_first_call = 1;
int toolame_encode_frame(
short buffer[2][1152],
unsigned char *xpad_data,
+ size_t xpad_len,
unsigned char *output_buffer,
size_t output_buffer_size)
{
diff --git a/libtoolame-dab/toolame.h b/libtoolame-dab/toolame.h
index 1c29e24..5450ca0 100644
--- a/libtoolame-dab/toolame.h
+++ b/libtoolame-dab/toolame.h
@@ -1,5 +1,6 @@
#ifndef __TOOLAME_H_
#define __TOOLAME_H_
+#include <stdlib.h>
/* All exported functions shown here return zero
* on success */
@@ -38,6 +39,7 @@ int toolame_set_pad(int pad_len);
int toolame_encode_frame(
short buffer[2][1152],
unsigned char *xpad_data,
+ size_t xpad_len,
unsigned char *output_buffer,
size_t output_buffer_size);
diff --git a/src/dabplus-enc.cpp b/src/dabplus-enc.cpp
index 3813041..1b351aa 100644
--- a/src/dabplus-enc.cpp
+++ b/src/dabplus-enc.cpp
@@ -673,13 +673,15 @@ int main(int argc, char *argv[])
err = toolame_set_channel_mode(dab_channel_mode);
}
+ if (err == 0) {
+ err = toolame_set_pad(padlen);
+ }
+
if (err) {
fprintf(stderr, "libtoolame-dab init failed: %d\n", err);
return err;
}
- // TODO int toolame_set_pad(int pad_len);
-
input_buf.resize(2 * 1152 * BYTES_PER_SAMPLE);
}
@@ -1050,8 +1052,15 @@ int main(int argc, char *argv[])
numOutBytes = out_args.numOutBytes;
}
else if (selected_encoder == encoder_selection_t::toolame_dab) {
- const int calculated_padlen = ret > 0 ? pad_buf[padlen] : 0;
- uint8_t *xpad_data = pad_buf + (padlen - calculated_padlen); // offset due to unused PAD bytes
+ int calculated_padlen = 0;
+ if (ret == padlen + 1) {
+ calculated_padlen = pad_buf[padlen];
+ if (calculated_padlen <= 2) {
+ stringstream ss;
+ ss << "Invalid XPAD Length " << calculated_padlen;
+ throw runtime_error(ss.str());
+ }
+ }
short input_buffers[2][1152];
@@ -1072,7 +1081,7 @@ int main(int argc, char *argv[])
}
if (read_bytes) {
- numOutBytes = toolame_encode_frame(input_buffers, xpad_data, &outbuf[0], outbuf.size());
+ numOutBytes = toolame_encode_frame(input_buffers, pad_buf, calculated_padlen, &outbuf[0], outbuf.size());
}
else {
numOutBytes = toolame_finish(&outbuf[0], outbuf.size());