summaryrefslogtreecommitdiff
path: root/gr-error-correcting-codes/src/lib/libecc/encoder.cc
diff options
context:
space:
mode:
Diffstat (limited to 'gr-error-correcting-codes/src/lib/libecc/encoder.cc')
-rw-r--r--gr-error-correcting-codes/src/lib/libecc/encoder.cc91
1 files changed, 51 insertions, 40 deletions
diff --git a/gr-error-correcting-codes/src/lib/libecc/encoder.cc b/gr-error-correcting-codes/src/lib/libecc/encoder.cc
index 967000fd0..7e7718af1 100644
--- a/gr-error-correcting-codes/src/lib/libecc/encoder.cc
+++ b/gr-error-correcting-codes/src/lib/libecc/encoder.cc
@@ -47,15 +47,18 @@ encoder::encode
size_t n_bits_to_output)
{
if (in_buf == 0) {
- std::cerr << "encoder::encode: Error: input buffer is NULL.\n";
+ std::cerr << "encoder::encode{output}: Error: "
+ "input buffer is NULL.\n";
assert (0);
}
if (out_buf == 0) {
- std::cerr << "encoder::encode: Error: output buffer is NULL.\n";
+ std::cerr << "encoder::encode{output}: Error: "
+ "output buffer is NULL.\n";
assert (0);
}
if (n_bits_to_output == 0) {
- std::cerr << "encoder::encode: Warning: no output bits requested.\n";
+ std::cerr << "encoder::encode{output}: Warning: "
+ "no output bits requested.\n";
return (0);
}
@@ -68,10 +71,10 @@ encoder::encode
// check that there are enough output buffer items
if (d_out_buf->n_items_left() < n_bits_to_output) {
- std::cerr << "encoder::encode: Warning: output buffer size (" <<
- d_out_buf->n_items_left() << "is less than the desired number "
- "of output items (" << n_bits_to_output <<
- ") ... using lower number.\n";
+ std::cerr << "encoder::encode{output}: Warning: "
+ "output buffer size (" << d_out_buf->n_items_left() <<
+ ") is less than the desired number of output items (" <<
+ n_bits_to_output << ") ... using lower number.\n";
n_bits_to_output = d_out_buf->n_items_left();
}
@@ -80,18 +83,26 @@ encoder::encode
size_t n_bits_to_input = compute_n_input_bits (n_bits_to_output);
if (d_in_buf->n_items_left() < n_bits_to_input) {
- std::cerr << "encoder::encode: Warning: input buffer size (" <<
- d_in_buf->n_items_left() << "is less than the computed number "
+ std::cerr << "encoder::encode{output}: Warning: input buffer size (" <<
+ d_in_buf->n_items_left() << ") is less than the computed number "
"of required input items (" << n_bits_to_input <<
") ... using lower number.\n";
n_bits_to_input = d_in_buf->n_items_left();
n_bits_to_output = compute_n_output_bits (n_bits_to_input);
}
+ // set the correct number of I/O bits
+
+ d_n_bits_to_input = n_bits_to_input;
+ d_n_bits_to_output = n_bits_to_output;
+
if (DO_PRINT_DEBUG) {
std::cout <<
- "# output bits = " << n_bits_to_output << "\n"
- "# input bits = " << n_bits_to_input << "\n";
+ "Before Encoding{output}:\n"
+ " # output bits = " << d_n_bits_to_output << "\n"
+ " # input bits = " << d_n_bits_to_input << "\n"
+ " # output bits used = " << d_out_buf->n_items_used() << "\n"
+ " # input bits used = " << d_in_buf->n_items_used() << "\n";
}
// call the private encode function
@@ -100,20 +111,16 @@ encoder::encode
if (DO_PRINT_DEBUG) {
std::cout <<
- "# input bits used = " << d_in_buf->n_items_used() << "\n"
- "# output bits used = " << d_out_buf->n_items_used() << "\n";
+ "After Encoding{output}:\n"
+ " # output bits = " << d_n_bits_to_output << "\n"
+ " # input bits = " << d_n_bits_to_input << "\n"
+ " # output bits used = " << d_out_buf->n_items_used() << "\n"
+ " # input bits used = " << d_in_buf->n_items_used() << "\n";
}
- size_t n_items_used = d_in_buf->n_items_used ();
-
- // clear these buffers, just in case
-
- d_in_buf = 0;
- d_out_buf = 0;
-
// return the actual number of input bits used
- return (n_items_used);
+ return (n_bits_to_input - d_n_bits_to_input);
}
/*
@@ -134,15 +141,15 @@ encoder::encode
code_output_ptr out_buf)
{
if (in_buf == 0) {
- std::cerr << "encoder::encode: Error: input buffer is NULL.\n";
+ std::cerr << "encoder::encode{input}: Error: input buffer is NULL.\n";
assert (0);
}
if (out_buf == 0) {
- std::cerr << "encoder::encode: Error: output buffer is NULL.\n";
+ std::cerr << "encoder::encode{input}: Error: output buffer is NULL.\n";
assert (0);
}
if (n_bits_to_input == 0) {
- std::cerr << "encoder::encode: Warning: no input bits requested.\n";
+ std::cerr << "encoder::encode{input}: Warning: no input bits requested.\n";
return (0);
}
@@ -155,8 +162,8 @@ encoder::encode
// check that there are enough input buffer items
if (d_in_buf->n_items_left() < n_bits_to_input) {
- std::cerr << "encoder::encode: Warning: input buffer size (" <<
- d_in_buf->n_items_left() << "is less than the desired number "
+ std::cerr << "encoder::encode{input}: Warning: input buffer size (" <<
+ d_in_buf->n_items_left() << ") is less than the desired number "
"of input items (" << n_bits_to_input <<
") ... using lower number.\n";
n_bits_to_input = d_in_buf->n_items_left();
@@ -167,18 +174,26 @@ encoder::encode
size_t n_bits_to_output = compute_n_output_bits (n_bits_to_input);
if (d_out_buf->n_items_left() < n_bits_to_output) {
- std::cerr << "encoder::encode: Warning: output buffer size (" <<
- d_out_buf->n_items_left() << "is less than the computed number "
+ std::cerr << "encoder::encode{input}: Warning: output buffer size (" <<
+ d_out_buf->n_items_left() << ") is less than the computed number "
"of required output items (" << n_bits_to_output <<
") ... using lower number.\n";
n_bits_to_output = d_out_buf->n_items_left();
n_bits_to_input = compute_n_input_bits (n_bits_to_output);
}
+ // set the correct number of I/O bits
+
+ d_n_bits_to_input = n_bits_to_input;
+ d_n_bits_to_output = n_bits_to_output;
+
if (DO_PRINT_DEBUG) {
std::cout <<
- "# output bits = " << n_bits_to_output << "\n"
- "# input bits = " << n_bits_to_input << "\n";
+ "Before Encoding{input}:\n"
+ " # output bits = " << d_n_bits_to_output << "\n"
+ " # input bits = " << d_n_bits_to_input << "\n"
+ " # output bits used = " << d_out_buf->n_items_used() << "\n"
+ " # input bits used = " << d_in_buf->n_items_used() << "\n";
}
// call the private encode function
@@ -187,18 +202,14 @@ encoder::encode
if (DO_PRINT_DEBUG) {
std::cout <<
- "# input bits used = " << d_in_buf->n_items_used() << "\n"
- "# output bits used = " << d_out_buf->n_items_used() << "\n";
+ "After Encoding{input}:\n"
+ " # output bits = " << d_n_bits_to_output << "\n"
+ " # input bits = " << d_n_bits_to_input << "\n"
+ " # output bits used = " << d_out_buf->n_items_used() << "\n"
+ " # input bits used = " << d_in_buf->n_items_used() << "\n";
}
- size_t n_items_used = d_out_buf->n_items_used();
-
- // clear these buffers, just in case
-
- d_in_buf = 0;
- d_out_buf = 0;
-
// return the actual number of output bits written
- return (n_items_used);
+ return (n_bits_to_output - d_n_bits_to_output);
}