[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] [gnuradio] 03/06: fec: TPC encoder whitespace cleanup
From: |
git |
Subject: |
[Commit-gnuradio] [gnuradio] 03/06: fec: TPC encoder whitespace cleanup |
Date: |
Tue, 14 Apr 2015 15:02:54 +0000 (UTC) |
This is an automated email from the git hooks/post-receive script.
jcorgan pushed a commit to branch maint
in repository gnuradio.
commit 8c0c878e59594e59649cce408a4aaeeb26ff12f5
Author: Sean Nowlan <address@hidden>
Date: Mon Apr 13 12:12:16 2015 -0400
fec: TPC encoder whitespace cleanup
---
gr-fec/lib/tpc_encoder.cc | 140 +++++++++++++++++++++++-----------------------
1 file changed, 69 insertions(+), 71 deletions(-)
diff --git a/gr-fec/lib/tpc_encoder.cc b/gr-fec/lib/tpc_encoder.cc
index 44c065f..63ef44a 100755
--- a/gr-fec/lib/tpc_encoder.cc
+++ b/gr-fec/lib/tpc_encoder.cc
@@ -35,7 +35,7 @@
#include <string.h> // for memcpy
namespace gr {
-namespace fec {
+namespace fec {
generic_encoder::sptr
tpc_encoder::make(std::vector<int> row_polys, std::vector<int> col_polys, int
krow, int kcol, int bval, int qval)
{
@@ -49,7 +49,7 @@ tpc_encoder::tpc_encoder (std::vector<int> row_polys,
std::vector<int> col_polys
// first we operate on data chunks of get_input_size()
// TODO: should we verify this and throw an error if it doesn't match? YES
// hwo do we do that?
-
+
// calculate the input and output sizes
inputSize = (d_krow*d_kcol - (d_bval+d_qval));
rowEncoder_K = ceil(log(d_rowpolys[0])/log(2)); // rowEncoder_K is the
constraint length of the row encoder polynomial
@@ -58,12 +58,12 @@ tpc_encoder::tpc_encoder (std::vector<int> row_polys,
std::vector<int> col_polys
colEncoder_K = ceil(log(d_colpolys[0])/log(2)); // colEncoder_K is the
constraint length of the col encoder polynomial
colEncoder_n = d_colpolys.size();
colEncoder_m = colEncoder_K - 1;
-
+
outputSize =
((d_krow+rowEncoder_m)*rowEncoder_n)*((d_kcol+colEncoder_m)*colEncoder_n) -
d_bval;
-
+
//DEBUG_PRINT("inputSize=%d outputSize=%d\n", inputSize, outputSize);
//fp = fopen("c_encoder_output.txt", "w");
-
+
// resize internal matrices
rowNumStates = 1 << (rowEncoder_K-1); // 2^(row_mm)
colNumStates = 1 << (colEncoder_K-1); // 2^(col_mm)
@@ -71,32 +71,32 @@ tpc_encoder::tpc_encoder (std::vector<int> row_polys,
std::vector<int> col_polys
rowNextStates.resize(2, std::vector<int>(rowNumStates,0));
colOutputs.resize(2, std::vector<int>(colNumStates,0));
colNextStates.resize(2, std::vector<int>(colNumStates,0));;
-
+
rowTail.resize(rowNumStates, 0);
colTail.resize(colNumStates, 0);
-
+
// precalculate the state transition matrix for the row polynomial
tpc_common::precomputeStateTransitionMatrix_RSCPoly(rowNumStates,
d_rowpolys, rowEncoder_K, rowEncoder_n,
rowOutputs,
rowNextStates);
-
+
// calculate the tail for the row
tpc_common::rsc_tail(rowTail, d_rowpolys, rowNumStates, rowEncoder_m);
-
+
// precalculate the state transition matrix for the column polynomial
tpc_common::precomputeStateTransitionMatrix_RSCPoly(colNumStates,
d_colpolys, colEncoder_K, colEncoder_n,
colOutputs,
colNextStates);
// calculate the tail for the col
tpc_common::rsc_tail(colTail, d_colpolys, colNumStates, colEncoder_m);
-
+
// pre-allocate memory we use for encoding
inputSizeWithPad = d_bval+d_qval+inputSize;
inputWithPad.resize(inputSizeWithPad, 0);
-
+
numRowsToEncode = inputSizeWithPad/d_krow; // this should be OK w/
integer division -- TODO: check this?
rowToEncode.resize(d_krow,0);
rowEncoded_block.resize(d_krow+(rowEncoder_m*rowEncoder_n), 0);
rowEncodedBits.resize(d_kcol,
std::vector<uint8_t>(rowEncoder_m*rowEncoder_n,0) );
-
+
numColsToEncode = d_krow+(rowEncoder_m*rowEncoder_n);
colToEncode.resize(d_kcol,0);
colEncoded_block.resize(d_kcol+(colEncoder_m*colEncoder_n), 0);
@@ -112,11 +112,11 @@ int tpc_encoder::get_input_size() {
}
void tpc_encoder::block_conv_encode( std::vector<uint8_t> &output,
- std::vector<uint8_t> input,
+ std::vector<uint8_t> input,
std::vector< std::vector<int> > transOutputVec,
std::vector< std::vector<int> >
transNextStateVec,
std::vector<int> tail,
- size_t KK,
+ size_t KK,
size_t nn)
{
size_t outsym, ii, jj;
@@ -124,16 +124,16 @@ void tpc_encoder::block_conv_encode( std::vector<uint8_t>
&output,
size_t LL = input.size();
std::vector<int> binVec(nn,0);
-
+
// encode data bits one bit at a time
for (ii=0; ii<LL; ii++) {
-
+
// determine the output symbol
outsym = transOutputVec[(int)input[ii]][state];
// determine the next state
state = transNextStateVec[(int)input[ii]][state];
-
- // Convert symbol to a binary vector
+
+ // Convert symbol to a binary vector
tpc_common::itob( binVec, outsym, nn );
// Assign to output : TODO: investigate using memcpy for this?
@@ -144,12 +144,12 @@ void tpc_encoder::block_conv_encode( std::vector<uint8_t>
&output,
// encode tail
for (ii=LL;ii<LL+KK-1;ii++) {
-
+
// determine the output symbol
outsym = transOutputVec[tail[state]][state];
// determine the next state
state = transNextStateVec[tail[state]][state];
-
+
// Convert symbol to a binary vector
tpc_common::itob( binVec, outsym, nn );
@@ -165,49 +165,49 @@ void tpc_encoder::generic_work(void *inBuffer, void
*outBuffer) {
uint8_t *out = (uint8_t *) outBuffer;
size_t ii, jj; // indexing var
-
+
//DEBUG_PRINT_UCHAR_ARRAY(in, inputSize);
-
+
// TODO: probably a better way to do this than memcpy?
memcpy(&inputWithPad[d_bval+d_qval], in, sizeof(unsigned char)*inputSize);
-
+
//DEBUG_PRINT("Input with Pad -->\n");
//DEBUG_PRINT_UCHAR_ARRAY(&inputWithPad[0], inputSizeWithPad);
//DEBUG_PRINT_F(fp, "Input with Pad -->\n");
//DEBUG_PRINT_UCHAR_ARRAY_F(fp, &inputWithPad[0], inputSizeWithPad);
-
+
// encode the row data
for(ii=0; ii<numRowsToEncode; ii++) {
// populate rowToEncode
memcpy(&rowToEncode[0], &inputWithPad[ii*d_krow], sizeof(unsigned
char)*d_krow);
-
+
//DEBUG_PRINT("Encoding row=[%d] -->\n",ii);
//DEBUG_PRINT_UCHAR_ARRAY(&rowToEncode[0], d_krow);
//DEBUG_PRINT_F(fp, "Encoding row=[%d] -->\n",ii);
//DEBUG_PRINT_UCHAR_ARRAY_F(fp, &rowToEncode[0], d_krow);
-
+
// encode it
- block_conv_encode( rowEncoded_block,
- rowToEncode,
- rowOutputs,
- rowNextStates,
- rowTail,
+ block_conv_encode( rowEncoded_block,
+ rowToEncode,
+ rowOutputs,
+ rowNextStates,
+ rowTail,
rowEncoder_K,
rowEncoder_n);
-
+
//DEBUG_PRINT("Row Encoded Block=[%d] -->\n",ii);
//DEBUG_PRINT_FLOAT_ARRAY_AS_UCHAR(&rowEncoded_block[0], tmp);
//DEBUG_PRINT_F(fp, "Row Encoded Block=[%d] -->\n",ii);
//DEBUG_PRINT_FLOAT_ARRAY_AS_UCHAR_F(fp, &rowEncoded_block[0], tmp);
-
+
// store only the encoded bits, b/c we read out the data in a special
way
memcpy(&rowEncodedBits[ii][0], &rowEncoded_block[d_krow],
sizeof(uint8_t)*(rowEncoder_m*rowEncoder_n));
-
+
// DEBUG_PRINT("Row Encoded Bits");
// tmp = rowEncoder_m*rowEncoder_n;
// DEBUG_PRINT_FLOAT_ARRAY_AS_UCHAR(&rowEncodedBits[ii][0], tmp);
}
-
+
// encode the column data
size_t numDataColsToEncode = d_krow;
size_t numCheckColsToEncode = numColsToEncode-numDataColsToEncode;
@@ -216,76 +216,75 @@ void tpc_encoder::generic_work(void *inBuffer, void
*outBuffer) {
for(jj=0; jj<d_kcol; jj++) {
colToEncode[jj] = inputWithPad[jj*d_krow+ii];
}
-
+
//DEBUG_PRINT("Encoding col=[%d] -->\n",ii);
//DEBUG_PRINT_UCHAR_ARRAY(&colToEncode[0], d_kcol);
//DEBUG_PRINT_F(fp, "Encoding col=[%d] -->\n",ii);
//DEBUG_PRINT_UCHAR_ARRAY_F(fp, &colToEncode[0], d_kcol);
-
+
// encode it
- block_conv_encode( colEncoded_block,
- colToEncode,
- colOutputs,
- colNextStates,
- colTail,
+ block_conv_encode( colEncoded_block,
+ colToEncode,
+ colOutputs,
+ colNextStates,
+ colTail,
colEncoder_K,
colEncoder_n);
-
+
//DEBUG_PRINT("Col Encoded Block=[%d] -->\n",ii);
//DEBUG_PRINT_FLOAT_ARRAY_AS_UCHAR(&colEncoded_block[0], tmp);
//DEBUG_PRINT_F(fp, "Col Encoded Block=[%d] -->\n",ii);
//DEBUG_PRINT_FLOAT_ARRAY_AS_UCHAR_F(fp, &colEncoded_block[0], tmp);
-
+
// store only the encoded bits, b/c we read the data out in a special
way
memcpy(&colEncodedBits[ii][0], &colEncoded_block[d_kcol],
sizeof(uint8_t)*(colEncoder_m*colEncoder_n));
-
+
// DEBUG_PRINT("Col Encoded Bits");
// tmp = colEncoder_m*colEncoder_n;
// DEBUG_PRINT_FLOAT_ARRAY(&colEncodedBits[ii][0], tmp);
}
-
+
// encode checks on checks (encode the row-encoded bits)
for(ii=0; ii<numCheckColsToEncode; ii++) {
// populate colToEncode
for(jj=0; jj<d_kcol; jj++) {
colToEncode[jj] = rowEncodedBits[jj][ii]; // indexing is
wierd b/c of the way we declared the vector :(
}
-
+
//DEBUG_PRINT("Encoding col=[%d] -->\n",ii+numDataColsToEncode);
//DEBUG_PRINT_UCHAR_ARRAY(&colToEncode[0], d_kcol);
//DEBUG_PRINT_F(fp, "Encoding col=[%d] -->\n",ii+numDataColsToEncode);
//DEBUG_PRINT_UCHAR_ARRAY_F(fp, &colToEncode[0], d_kcol);
-
+
// encode it
- block_conv_encode( colEncoded_block,
- colToEncode,
- colOutputs,
- colNextStates,
- colTail,
+ block_conv_encode( colEncoded_block,
+ colToEncode,
+ colOutputs,
+ colNextStates,
+ colTail,
colEncoder_K,
colEncoder_n);
-
+
//DEBUG_PRINT("Col Encoded Block=[%d] -->\n",ii+numDataColsToEncode);
//DEBUG_PRINT_FLOAT_ARRAY_AS_UCHAR(&colEncoded_block[0], tmp);
-
+
//DEBUG_PRINT_F(fp, "Col Encoded Block=[%d]
-->\n",ii+numDataColsToEncode);
//DEBUG_PRINT_FLOAT_ARRAY_AS_UCHAR_F(fp, &colEncoded_block[0], tmp);
-
-
+
// store only the encoded bits, b/c we read the data out in a special
way
memcpy(&colEncodedBits[ii+numDataColsToEncode][0],
&colEncoded_block[d_kcol], sizeof(uint8_t)*(colEncoder_m*colEncoder_n));
-
+
// DEBUG_PRINT("Col Encoded Bits");
// tmp = colEncoder_m*colEncoder_n;
// DEBUG_PRINT_FLOAT_ARRAY(&colEncodedBits[ii][0], tmp);
}
-
+
unsigned char* inputDataPtr;
uint8_t *outputDataPtr = out;
-
+
int curRowInRowEncodedBits = 0;
// read out the data along the rows into the "out" array
-
+
// skip B zeros & do the first row
inputDataPtr = &inputWithPad[d_bval];
if(d_bval > d_krow){ throw std::runtime_error("bval must be < krow"); }
@@ -293,27 +292,27 @@ void tpc_encoder::generic_work(void *inBuffer, void
*outBuffer) {
for(ii=0; ii<firstRowRemainingBits; ii++) {
*outputDataPtr++ = (uint8_t)(*inputDataPtr++);
}
-
+
// copy the encoded bits
- memcpy(outputDataPtr, &rowEncodedBits[curRowInRowEncodedBits++][0],
+ memcpy(outputDataPtr, &rowEncodedBits[curRowInRowEncodedBits++][0],
sizeof(uint8_t)*(rowEncoder_m*rowEncoder_n));
-
+
outputDataPtr += (rowEncoder_m*rowEncoder_n);
-
+
// copy out the rest of the data
for(ii=1; ii<d_kcol; ii++) { // ii starts at 1, b/c we already did
idx=0
// copy systematic bits
for(jj=0; jj<d_krow; jj++) {
*outputDataPtr++ = (uint8_t)(*inputDataPtr++);
}
-
+
// copy the encoded bits
- memcpy(outputDataPtr, &rowEncodedBits[curRowInRowEncodedBits++][0],
+ memcpy(outputDataPtr, &rowEncodedBits[curRowInRowEncodedBits++][0],
sizeof(uint8_t)*(rowEncoder_m*rowEncoder_n));
-
+
outputDataPtr += (rowEncoder_m*rowEncoder_n);
}
-
+
// copy the encoded cols
for(ii=0; ii<(colEncoder_m*colEncoder_n); ii++) {
// copy checks
@@ -326,14 +325,13 @@ void tpc_encoder::generic_work(void *inBuffer, void
*outBuffer) {
*outputDataPtr++ = colEncodedBits[kk++][ii];
}
}
-
+
//DEBUG_PRINT("Output\n");
//DEBUG_PRINT_FLOAT_ARRAY_AS_UCHAR(out, outputSize);
//DEBUG_PRINT_F(fp, "Output\n");
//DEBUG_PRINT_FLOAT_ARRAY_AS_UCHAR_F(fp, out, outputSize);
}
-
tpc_encoder::~tpc_encoder()
{
if(fp)
- [Commit-gnuradio] [gnuradio] branch maint updated (0f738ac -> 5ae1e84), git, 2015/04/14
- [Commit-gnuradio] [gnuradio] 06/06: Merge remote-tracking branch 'tom/docs/rework0' into maint, git, 2015/04/14
- [Commit-gnuradio] [gnuradio] 04/06: fec: init debug file pointer in TPC encoder, git, 2015/04/14
- [Commit-gnuradio] [gnuradio] 05/06: Fixed non-virtual dtor pseudoissue in [flat_]flowgraph, git, 2015/04/14
- [Commit-gnuradio] [gnuradio] 01/06: docs: doxyfile maintenance., git, 2015/04/14
- [Commit-gnuradio] [gnuradio] 02/06: fec: fix segfault due to debug file pointer handling, git, 2015/04/14
- [Commit-gnuradio] [gnuradio] 03/06: fec: TPC encoder whitespace cleanup,
git <=