From 015427d9e74f34dc7d0f7fbad4ad1eaad6537cce Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Wed, 18 Sep 2019 11:49:11 +0200 Subject: EDI in: add audio levels metadata and source version --- lib/edi/STIDecoder.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'lib/edi/STIDecoder.cpp') diff --git a/lib/edi/STIDecoder.cpp b/lib/edi/STIDecoder.cpp index aab93e0..1f5d45e 100644 --- a/lib/edi/STIDecoder.cpp +++ b/lib/edi/STIDecoder.cpp @@ -44,6 +44,10 @@ STIDecoder::STIDecoder(STIDataCollector& data_collector, bool verbose) : std::bind(&STIDecoder::decode_ssn, this, _1, _2)); m_dispatcher.register_tag("*dmy", std::bind(&STIDecoder::decode_stardmy, this, _1, _2)); + m_dispatcher.register_tag("ODRa", + std::bind(&STIDecoder::decode_odraudiolevel, this, _1, _2)); + m_dispatcher.register_tag("ODRv", + std::bind(&STIDecoder::decode_odrversion, this, _1, _2)); } void STIDecoder::push_bytes(const vector &buf) @@ -183,6 +187,37 @@ bool STIDecoder::decode_stardmy(const vector& /*value*/, uint16_t) return true; } +bool STIDecoder::decode_odraudiolevel(const vector& value, uint16_t) +{ + constexpr size_t expected_length = 2 * sizeof(int16_t); + + audio_level_data audio_level; + + if (value.size() == expected_length) { + audio_level.left = read_16b(value.begin()); + audio_level.right = read_16b(value.begin() + 2); + } + else { + audio_level.left = 0; + audio_level.right = 0; + etiLog.level(warn) << "EDI: ODR AudioLevel TAG has wrong length!"; + } + + m_data_collector.update_audio_levels(audio_level); + + // Not being able to decode the audio level is a soft-failure, it should + // not disrupt decoding the actual audio data. + return true; +} + +bool STIDecoder::decode_odrversion(const vector& value, uint16_t) +{ + const auto vd = parse_odr_version_data(value); + m_data_collector.update_odr_version(vd); + + return true; +} + void STIDecoder::packet_completed() { m_data_collector.assemble(); -- cgit v1.2.3