aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile.am2
-rw-r--r--src/etianalyse.cpp2
-rw-r--r--src/fig0_1.cpp14
-rw-r--r--src/figs.hpp2
-rw-r--r--src/watermarkdecoder.cpp114
-rw-r--r--src/watermarkdecoder.hpp63
6 files changed, 133 insertions, 64 deletions
diff --git a/Makefile.am b/Makefile.am
index e10b8e8..38b9cf5 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -51,7 +51,7 @@ etisnoop_SOURCES = src/dabplussnoop.cpp src/dabplussnoop.hpp \
src/rsdecoder.cpp src/rsdecoder.hpp \
src/tables.cpp src/tables.hpp \
src/utils.cpp src/utils.hpp \
- src/watermarkdecoder.hpp \
+ src/watermarkdecoder.hpp src/watermarkdecoder.cpp \
src/wavfile.c src/wavfile.h \
src/fec/char.h \
src/fec/decode_rs_char.c src/fec/decode_rs.h \
diff --git a/src/etianalyse.cpp b/src/etianalyse.cpp
index 6e14343..dbd9adc 100644
--- a/src/etianalyse.cpp
+++ b/src/etianalyse.cpp
@@ -644,7 +644,7 @@ void ETI_Analyser::eti_analyse()
if (config.decode_watermark) {
std::string watermark(wm_decoder.calculate_watermark());
- printf("Watermark:\n %s\n", watermark.c_str());
+ printf("Watermark: %s\n", watermark.c_str());
}
if (config.analyse_fig_rates) {
diff --git a/src/fig0_1.cpp b/src/fig0_1.cpp
index c812b46..db2250c 100644
--- a/src/fig0_1.cpp
+++ b/src/fig0_1.cpp
@@ -26,19 +26,21 @@
#include "figs.hpp"
#include <cstdio>
-#include <unordered_set>
+#include <vector>
+#include <algorithm>
-static std::unordered_set<int> subchannels_seen;
+static std::vector<int> subchannels_seen;
-bool fig0_1_is_complete(int subch_id)
+bool fig0_1_is_complete(fig0_common_t& fig0, int subch_id)
{
- bool complete = subchannels_seen.count(subch_id);
+ bool complete = std::count(subchannels_seen.begin(), subchannels_seen.end(), subch_id) > 0;
if (complete) {
+ fig0.wm_decoder.push_fig0_1_bit(subchannels_seen.front() < subchannels_seen.back());
subchannels_seen.clear();
}
else {
- subchannels_seen.insert(subch_id);
+ subchannels_seen.push_back(subch_id);
}
return complete;
@@ -55,7 +57,7 @@ fig_result_t fig0_1(fig0_common_t& fig0, const display_settings_t &disp)
while (i <= fig0.figlen-3) {
// iterate over subchannels
int subch_id = f[i] >> 2;
- r.complete |= fig0_1_is_complete(subch_id);
+ r.complete |= fig0_1_is_complete(fig0, subch_id);
int start_addr = ((f[i] & 0x03) << 8) |
(f[i+1]);
diff --git a/src/figs.hpp b/src/figs.hpp
index 570c535..d7ea494 100644
--- a/src/figs.hpp
+++ b/src/figs.hpp
@@ -65,7 +65,7 @@ struct fig0_common_t {
figlen(fig_len),
ensemble(ens),
fibcrccorrect(true),
- wm_decoder(wm_dec) { }
+ wm_decoder(wm_dec) {}
uint8_t* f;
uint16_t figlen;
diff --git a/src/watermarkdecoder.cpp b/src/watermarkdecoder.cpp
new file mode 100644
index 0000000..33eb960
--- /dev/null
+++ b/src/watermarkdecoder.cpp
@@ -0,0 +1,114 @@
+/*
+ Copyright (C) 2014 CSP Innovazione nelle ICT s.c.a r.l. (http://www.csp.it/)
+ Copyright (C) 2020 Matthias P. Braendli (http://www.opendigitalradio.org)
+ Copyright (C) 2015 Data Path
+
+ 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
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+ Authors:
+ Sergio Sagliocco <sergio.sagliocco@csp.it>
+ Matthias P. Braendli <matthias@mpb.li>
+ / | |- ')|) |-|_ _ (|,_ .| _ ,_ \
+ Data Path \(|(||_(|/_| (||_||(a)_||||(|||.(_()|||/
+
+*/
+
+#include <vector>
+#include <sstream>
+#include "watermarkdecoder.hpp"
+
+static std::string calc_watermark(const std::vector<bool>& bits)
+{
+ // First try to find the 0x55 0x55 sync in the waternark data
+ size_t bit_ix;
+ int alternance_count = 0;
+ bool last_bit = 1;
+ for (bit_ix = 0; bit_ix < bits.size(); bit_ix++) {
+ if (alternance_count == 16) {
+ break;
+ }
+ else {
+ if (last_bit != bits[bit_ix]) {
+ last_bit = bits[bit_ix];
+ alternance_count++;
+ }
+ else {
+ alternance_count = 0;
+ last_bit = 1;
+ }
+ }
+ }
+
+ if (bit_ix < bits.size()) {
+ fprintf(stderr, "Found SYNC at offset %zu out of %zu\n",
+ bit_ix - alternance_count, bits.size());
+
+ std::stringstream watermark_ss;
+
+ uint8_t b = 0;
+ size_t i = 0;
+ while (bit_ix < bits.size()) {
+
+ b |= bits[bit_ix] << (7 - i);
+
+ if (i == 7) {
+ watermark_ss << (char)b;
+
+ b = 0;
+ i = 0;
+ }
+ else {
+ i++;
+ }
+
+ bit_ix += 2;
+ }
+
+ return watermark_ss.str();
+ }
+ else {
+ return "";
+ }
+}
+
+WatermarkDecoder::WatermarkDecoder() {}
+
+void WatermarkDecoder::push_fig0_1_bit(bool bit)
+{
+ // The order of FIG0_1 subchannels represents the bits
+ m_fig0_1_bits.push_back(bit);
+}
+
+void WatermarkDecoder::push_confind_bit(bool confind)
+{
+ // The ConfInd of FIG 0/10 contains the CRC-DABMUX and ODR-DabMux watermark
+ m_confind_bits.push_back(confind);
+}
+
+std::string WatermarkDecoder::calculate_watermark()
+{
+ std::string w_old = calc_watermark(m_confind_bits);
+ std::string w_new = calc_watermark(m_fig0_1_bits);
+ if (not w_new.empty()) {
+ return w_new;
+ }
+ else if (not w_old.empty()) {
+ return w_old + " (old watermark)";
+ }
+ else {
+ return "(NOT FOUND)";
+ }
+}
+
+
diff --git a/src/watermarkdecoder.hpp b/src/watermarkdecoder.hpp
index 171d1ae..522443c 100644
--- a/src/watermarkdecoder.hpp
+++ b/src/watermarkdecoder.hpp
@@ -1,6 +1,6 @@
/*
Copyright (C) 2014 CSP Innovazione nelle ICT s.c.a r.l. (http://www.csp.it/)
- Copyright (C) 2016 Matthias P. Braendli (http://www.opendigitalradio.org)
+ Copyright (C) 2022 Matthias P. Braendli (http://www.opendigitalradio.org)
Copyright (C) 2015 Data Path
This program is free software: you can redistribute it and/or modify
@@ -32,68 +32,21 @@
class WatermarkDecoder
{
public:
- WatermarkDecoder() {}
+ WatermarkDecoder();
- void push_confind_bit(bool confind)
- {
- // The ConfInd of FIG 0/10 contains the CRC-DABMUX and ODR-DabMux watermark
- m_confind_bits.push_back(confind);
- }
+ // The order of FIG0_1 subchannels represents the bits
+ void push_fig0_1_bit(bool bit);
- std::string calculate_watermark()
- {
- // First try to find the 0x55 0x55 sync in the waternark data
- size_t bit_ix;
- int alternance_count = 0;
- bool last_bit = 1;
- for (bit_ix = 0; bit_ix < m_confind_bits.size(); bit_ix++) {
- if (alternance_count == 16) {
- break;
- }
- else {
- if (last_bit != m_confind_bits[bit_ix]) {
- last_bit = m_confind_bits[bit_ix];
- alternance_count++;
- }
- else {
- alternance_count = 0;
- last_bit = 1;
- }
- }
+ // The ConfInd of FIG 0/10 contains the CRC-DABMUX and ODR-DabMux watermark
+ void push_confind_bit(bool confind);
- }
-
- fprintf(stderr, "Found SYNC at offset %zu out of %zu\n",
- bit_ix - alternance_count, m_confind_bits.size());
-
- std::stringstream watermark_ss;
-
- uint8_t b = 0;
- size_t i = 0;
- while (bit_ix < m_confind_bits.size()) {
-
- b |= m_confind_bits[bit_ix] << (7 - i);
-
- if (i == 7) {
- watermark_ss << (char)b;
-
- b = 0;
- i = 0;
- }
- else {
- i++;
- }
-
- bit_ix += 2;
- }
-
- return watermark_ss.str();
- }
+ std::string calculate_watermark();
private:
const WatermarkDecoder& operator=(const WatermarkDecoder&) = delete;
WatermarkDecoder(const WatermarkDecoder&) = delete;
std::vector<bool> m_confind_bits;
+ std::vector<bool> m_fig0_1_bits;
};