aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/dabplussnoop.cpp53
-rw-r--r--src/dabplussnoop.hpp40
-rw-r--r--src/etisnoop.cpp16
-rw-r--r--src/rsdecoder.cpp7
4 files changed, 82 insertions, 34 deletions
diff --git a/src/dabplussnoop.cpp b/src/dabplussnoop.cpp
index cd91d49..ae5a218 100644
--- a/src/dabplussnoop.cpp
+++ b/src/dabplussnoop.cpp
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2014, 2015 Matthias P. Braendli (http://www.opendigitalradio.org)
+ Copyright (C) 2016 Matthias P. Braendli (http://www.opendigitalradio.org)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -57,21 +57,6 @@ void DabPlusSnoop::push(uint8_t* streamdata, size_t streamsize)
// m_data now points to a valid header
if (decode()) {
-
- // First dump to subchannel file (superframe+parity word)
- if (m_raw_data_stream_fd == NULL) {
- stringstream dump_filename;
- dump_filename << "stream-" << m_index << ".msc";
-
- m_raw_data_stream_fd = fopen(dump_filename.str().c_str(), "w");
-
- if (m_raw_data_stream_fd == NULL) {
- perror("File open failed");
- }
- }
-
- fwrite(&m_data[0], m_subchannel_index, 120, m_raw_data_stream_fd);
-
// We have been able to decode the AUs, now flush vector
m_data.clear();
}
@@ -138,8 +123,14 @@ bool DabPlusSnoop::decode()
int rs_errors = rs_dec.DecodeSuperframe(b, m_subchannel_index);
if (rs_errors == -1) {
+ // Uncorrectable errors, flush our buffer
+ m_data.clear();
return false;
}
+ else if (rs_errors > 0) {
+ printf("RS Decoder for stream %d: %d uncorrected errors\n",
+ m_index, rs_errors);
+ }
// -- Parse he_aac_super_frame
// ---- Parse he_aac_super_frame_header
@@ -257,7 +248,7 @@ bool DabPlusSnoop::extract_au(vector<int> au_start)
{
#if DPS_DEBUG
printf(DPS_PREFIX DPS_INDENT
- "Copy au %zu of size %zu\n",
+ "Copy au %zu of size %d\n",
au,
au_start[au+1] - au_start[au]-2 );
#endif
@@ -317,8 +308,36 @@ bool DabPlusSnoop::analyse_au(vector<vector<uint8_t> >& aus)
void DabPlusSnoop::close()
{
m_faad_decoder.close();
+}
+void StreamSnoop::close()
+{
if (m_raw_data_stream_fd) {
fclose(m_raw_data_stream_fd);
}
+
+ dps.close();
+}
+
+void StreamSnoop::push(uint8_t* streamdata, size_t streamsize)
+{
+ if (m_index == -1) {
+ throw std::runtime_error("StreamSnoop not properly initialised");
+ }
+
+ // First dump to subchannel file (superframe+parity word)
+ if (m_raw_data_stream_fd == NULL) {
+ stringstream dump_filename;
+ dump_filename << "stream-" << m_index << ".msc";
+
+ m_raw_data_stream_fd = fopen(dump_filename.str().c_str(), "w");
+
+ if (m_raw_data_stream_fd == NULL) {
+ perror("File open failed");
+ }
+ }
+
+ fwrite(streamdata, streamsize, 1, m_raw_data_stream_fd);
+
+ dps.push(streamdata, streamsize);
}
diff --git a/src/dabplussnoop.hpp b/src/dabplussnoop.hpp
index 865a35e..8efc481 100644
--- a/src/dabplussnoop.hpp
+++ b/src/dabplussnoop.hpp
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2014 Matthias P. Braendli (http://www.opendigitalradio.org)
+ Copyright (C) 2016 Matthias P. Braendli (http://www.opendigitalradio.org)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
dabplussnoop.cpp
- Parse DAB+ frames from a ETI file
+ Extract MSC data and parse DAB+ frames from a ETI file
Authors:
Matthias P. Braendli <matthias@mpb.li>
@@ -81,15 +81,14 @@ he_aac_super_frame(subchannel_index)
#ifndef __DABPLUSSNOOP_H_
#define __DABPLUSSNOOP_H_
-
+// DabPlusSnoop is responsible for decoding DAB+ audio
class DabPlusSnoop
{
public:
DabPlusSnoop() :
m_index(0),
m_subchannel_index(0),
- m_data(0),
- m_raw_data_stream_fd(NULL) {}
+ m_data(0) {}
void set_subchannel_index(unsigned subchannel_index)
{
@@ -125,9 +124,40 @@ class DabPlusSnoop
unsigned m_subchannel_index;
std::vector<uint8_t> m_data;
+};
+
+// StreamSnoop is responsible for saving msc data into files,
+// and calling DabPlusSnoop's decode routine if it's a DAB+ subchannel
+class StreamSnoop
+{
+ public:
+ StreamSnoop() :
+ dps(),
+ m_index(-1),
+ m_raw_data_stream_fd(NULL) {}
+
+ void set_subchannel_index(unsigned subchannel_index)
+ {
+ dps.set_subchannel_index(subchannel_index);
+ }
+
+ void set_index(int index)
+ {
+ m_index = index;
+ dps.set_index(index);
+ }
+
+ void push(uint8_t* streamdata, size_t streamsize);
+
+ void close(void);
+
+ private:
+ DabPlusSnoop dps;
+ int m_index;
FILE* m_raw_data_stream_fd;
};
+
#endif
diff --git a/src/etisnoop.cpp b/src/etisnoop.cpp
index 92f54fd..600f503 100644
--- a/src/etisnoop.cpp
+++ b/src/etisnoop.cpp
@@ -166,7 +166,7 @@ struct eti_analyse_config_t {
FILE* etifd;
bool ignore_error;
- std::map<int, DabPlusSnoop> streams_to_decode;
+ std::map<int, StreamSnoop> streams_to_decode;
bool analyse_fic_carousel;
bool analyse_fig_rates;
bool analyse_fig_rates_per_second;
@@ -210,7 +210,7 @@ void usage(void)
"Usage: etisnoop [-v] [-f] [-w] [-i filename] [-d stream_index]\n"
"\n"
" -v increase verbosity (can be given more than once)\n"
- " -d N decode subchannel N into .msc and .wav files\n"
+ " -d N decode subchannel N into .msc file and if DAB+, decode to .wav file\n"
" -f analyse FIC carousel\n"
" -r analyse FIG rates in FIGs per second\n"
" -R analyse FIG rates in frames per FIG\n"
@@ -237,8 +237,8 @@ int main(int argc, char *argv[])
case 'd':
{
int subchix = atoi(optarg);
- DabPlusSnoop dps;
- config.streams_to_decode[subchix] = dps;
+ StreamSnoop snoop;
+ config.streams_to_decode[subchix] = snoop;
}
break;
case 'e':
@@ -691,12 +691,8 @@ int eti_analyse(eti_analyse_config_t& config)
}
}
-
- std::map<int, DabPlusSnoop>::iterator it;
- for (it = config.streams_to_decode.begin();
- it != config.streams_to_decode.end();
- ++it) {
- it->second.close();
+ for (auto& snoop : config.streams_to_decode) {
+ snoop.second.close();
}
if (config.decode_watermark) {
diff --git a/src/rsdecoder.cpp b/src/rsdecoder.cpp
index 98ccd39..5d01dcf 100644
--- a/src/rsdecoder.cpp
+++ b/src/rsdecoder.cpp
@@ -1,7 +1,6 @@
/*
Copyright (C) 2015 Stefan Pöschel
-
- Copyright (C) 2015 Matthias P. Braendli (http://www.opendigitalradio.org)
+ Copyright (C) 2016 Matthias P. Braendli (http://www.opendigitalradio.org)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -20,6 +19,8 @@
#include <stdexcept>
#include "rsdecoder.hpp"
+#define RSDEC_DEBUG 0
+
RSDecoder::RSDecoder()
{
rs_handle = init_rs_char(8, 0x11D, 0, 1, 10, 135);
@@ -67,6 +68,7 @@ int RSDecoder::DecodeSuperframe(std::vector<uint8_t> &sf, int subch_index)
}
}
+#if RSDEC_DEBUG
// output statistics
if (total_corr_count || uncorr_errors) {
printf("RS uncorrected errors:\n");
@@ -76,6 +78,7 @@ int RSDecoder::DecodeSuperframe(std::vector<uint8_t> &sf, int subch_index)
}
printf("\n");
}
+#endif
return uncorr_errors ? -1 : total_corr_count;
}