diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2016-12-25 21:34:03 +0100 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2016-12-25 21:34:03 +0100 |
commit | 2bba7d602744ccd6dab26940661f0fdfbf231af8 (patch) | |
tree | 590a5808497da3b621e29239cd56db6c89c2d6a9 /src/PuncturingEncoder.cpp | |
parent | b5fd4a6ab6ac92af2141233f802e71c861cd89f4 (diff) | |
download | dabmod-2bba7d602744ccd6dab26940661f0fdfbf231af8.tar.gz dabmod-2bba7d602744ccd6dab26940661f0fdfbf231af8.tar.bz2 dabmod-2bba7d602744ccd6dab26940661f0fdfbf231af8.zip |
Refactor flowgraph and puncturing rules
Diffstat (limited to 'src/PuncturingEncoder.cpp')
-rw-r--r-- | src/PuncturingEncoder.cpp | 56 |
1 files changed, 22 insertions, 34 deletions
diff --git a/src/PuncturingEncoder.cpp b/src/PuncturingEncoder.cpp index 66fd0e0..a212a93 100644 --- a/src/PuncturingEncoder.cpp +++ b/src/PuncturingEncoder.cpp @@ -1,6 +1,11 @@ /* Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011 Her Majesty the Queen in Right of Canada (Communications Research Center Canada) + + Copyright (C) 2016 + Matthias P. Braendli, matthias.braendli@mpb.li + + http://opendigitalradio.org */ /* This file is part of ODR-DabMod. @@ -32,47 +37,29 @@ PuncturingEncoder::PuncturingEncoder() : ModCodec(), d_in_block_size(0), d_out_block_size(0), - d_tail_rule(NULL) + d_tail_rule() { PDEBUG("PuncturingEncoder() @ %p\n", this); } - -PuncturingEncoder::~PuncturingEncoder() -{ - PDEBUG("PuncturingEncoder::~PuncturingEncoder() @ %p\n", this); - for (unsigned i = 0; i < d_rules.size(); ++i) { - PDEBUG(" Deleting rules @ %p\n", d_rules[i]); - delete d_rules[i]; - } - if (d_tail_rule != NULL) { - PDEBUG(" Deleting rules @ %p\n", d_tail_rule); - delete d_tail_rule; - } -} - void PuncturingEncoder::adjust_item_size() { PDEBUG("PuncturingEncoder::adjust_item_size()\n"); int in_size = 0; int out_size = 0; int length = 0; - std::vector<PuncturingRule*>::iterator ptr; - - for (ptr = d_rules.begin(); ptr != d_rules.end(); ++ptr) { - for (length = (*ptr)->length(); length > 0; length -= 4) { - out_size += (*ptr)->bit_size(); + + for (const auto& rule : d_rules) { + for (length = rule.length(); length > 0; length -= 4) { + out_size += rule.bit_size(); in_size += 4; -// PDEBUG("- in: %i, out: %i\n", in_size, out_size); } -// PDEBUG("- in: %i, out: %i\n", in_size, (out_size + 7) / 8); } - if (d_tail_rule != NULL) { -// PDEBUG("- computing tail rule\n"); + + if (d_tail_rule) { in_size += d_tail_rule->length(); out_size += d_tail_rule->bit_size(); -// PDEBUG("- in: %i, out: %i\n", in_size, out_size); } d_in_block_size = in_size; @@ -86,7 +73,7 @@ void PuncturingEncoder::adjust_item_size() void PuncturingEncoder::append_rule(const PuncturingRule& rule) { PDEBUG("append_rule(rule(%zu, 0x%x))\n", rule.length(), rule.pattern()); - d_rules.push_back(new PuncturingRule(rule)); + d_rules.push_back(rule); adjust_item_size(); } @@ -95,7 +82,7 @@ void PuncturingEncoder::append_rule(const PuncturingRule& rule) void PuncturingEncoder::append_tail_rule(const PuncturingRule& rule) { PDEBUG("append_tail_rule(rule(%zu, 0x%x))\n", rule.length(), rule.pattern()); - d_tail_rule = new PuncturingRule(rule); + d_tail_rule = rule; adjust_item_size(); } @@ -113,14 +100,14 @@ int PuncturingEncoder::process(Buffer* const dataIn, Buffer* dataOut) unsigned char data; uint32_t mask; uint32_t pattern; - std::vector<PuncturingRule*>::iterator ptr = d_rules.begin(); + auto rule_it = d_rules.begin(); PDEBUG(" in block size: %zu\n", d_in_block_size); PDEBUG(" out block size: %zu\n", d_out_block_size); dataOut->setLength(d_out_block_size); const unsigned char* in = reinterpret_cast<const unsigned char*>(dataIn->getData()); unsigned char* out = reinterpret_cast<unsigned char*>(dataOut->getData()); - + if (dataIn->getLength() != d_in_block_size) { throw std::runtime_error("PuncturingEncoder::process wrong input size"); } @@ -129,9 +116,9 @@ int PuncturingEncoder::process(Buffer* const dataIn, Buffer* dataOut) d_in_block_size -= d_tail_rule->length(); } while (in_count < d_in_block_size) { - for (length = (*ptr)->length(); length > 0; length -= 4) { + for (length = rule_it->length(); length > 0; length -= 4) { mask = 0x80000000; - pattern = (*ptr)->pattern(); + pattern = rule_it->pattern(); for (int i = 0; i < 4; ++i) { data = in[in_count++]; for (int j = 0; j < 8; ++j) { @@ -148,8 +135,8 @@ int PuncturingEncoder::process(Buffer* const dataIn, Buffer* dataOut) } } } - if (++ptr == d_rules.end()) { - ptr = d_rules.begin(); + if (++rule_it == d_rules.end()) { + rule_it = d_rules.begin(); } } if (d_tail_rule) { @@ -183,11 +170,12 @@ int PuncturingEncoder::process(Buffer* const dataIn, Buffer* dataOut) for (size_t i = d_out_block_size; i < dataOut->getLength(); ++i) { out[out_count++] = 0; } + assert(out_count == dataOut->getLength()); if (out_count != dataOut->getLength()) { throw std::runtime_error("PuncturingEncoder::process output size " "does not correspond!"); } - + return d_out_block_size; } |