3 * Copyright 2006 Free Software Foundation, Inc.
5 * This file is part of GNU Radio
7 * GNU Radio is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
12 * GNU Radio is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Radio; see the file COPYING. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street,
20 * Boston, MA 02110-1301, USA.
30 #define DO_PRINT_DEBUG 0
33 * decode a certain number of output bits
35 * the 'in_buf' and 'out_buf' must have enough memory to handle the
36 * number of input items and output bits; no error checking is done!
38 * n_bits_to_output: the number of bits per output stream to decode.
40 * returns the actual number of items used per input stream.
45 (const code_input_ptr in_buf,
46 code_output_ptr out_buf,
47 size_t n_bits_to_output)
50 std::cerr << "decoder::decode{output}: Error: input buffer is NULL.\n";
54 std::cerr << "decoder::decode{output}: Error: output buffer is NULL.\n";
57 if (n_bits_to_output == 0) {
58 std::cerr << "decoder::decode{output}: Warning: "
59 "no output bits requested.\n";
63 // set the class-internal number of input metrics
64 // and output bits left to decode
69 // check that there are enough output buffer items
71 if (d_out_buf->n_items_left() < n_bits_to_output) {
72 std::cerr << "encoder::encode{output}: Warning: output buffer size (" <<
73 d_out_buf->n_items_left() << ") is less than the desired number "
74 "of output items (" << n_bits_to_output <<
75 ") ... using lower number.\n";
76 n_bits_to_output = d_out_buf->n_items_left();
79 // check that there are enough input buffer items
81 size_t n_items_to_input = compute_n_input_items (n_bits_to_output);
83 if (d_in_buf->n_items_left() < n_items_to_input) {
84 std::cerr << "encoder::encode{output}: Warning: input buffer size (" <<
85 d_in_buf->n_items_left() << ") is less than the computed number "
86 "of required input items (" << n_items_to_input <<
87 ") ... using lower number.\n";
88 n_items_to_input = d_in_buf->n_items_left();
89 n_bits_to_output = compute_n_output_bits (n_items_to_input);
92 // set the correct number of I/O bits
94 d_n_items_to_input = n_items_to_input;
95 d_n_bits_to_output = n_bits_to_output;
99 "Before Decoding{output}:\n"
100 " # output bits = " << d_n_bits_to_output << "\n"
101 " # input items = " << d_n_items_to_input << "\n"
102 " # output bits used = " << d_out_buf->n_items_used() << "\n"
103 " # input items used = " << d_in_buf->n_items_used() << "\n";
106 // call the private decode function
110 if (DO_PRINT_DEBUG) {
112 "After Encoding{output}:\n"
113 " # output bits = " << d_n_bits_to_output << "\n"
114 " # input items = " << d_n_items_to_input << "\n"
115 " # output bits used = " << d_out_buf->n_items_used() << "\n"
116 " # input items used = " << d_in_buf->n_items_used() << "\n";
119 size_t n_items_used = d_in_buf->n_items_used ();
121 // clear these buffers, just in case
126 // return the actual number of input bits used
128 return (n_items_used);
132 * decode a certain number of input metrics
134 * the 'in_buf' and 'out_buf' must have enough memory to handle the
135 * number of input items and output bits; no error checking is done!
137 * n_items_to_input: the number of items per input stream to decode
139 * returns the actual number of bits written per output stream
144 (const code_input_ptr in_buf,
145 size_t n_items_to_input,
146 code_output_ptr out_buf)
149 std::cerr << "encoder::encode{input}: Error: input buffer is NULL.\n";
153 std::cerr << "encoder::encode{input}: Error: output buffer is NULL.\n";
156 if (n_items_to_input == 0) {
157 std::cerr << "encoder::encode{input}: Warning: "
158 "no input items requested.\n";
162 // set the class-internal number of input metrics and
163 // output bits left to decode
168 // check that there are enough input buffer items
170 if (d_in_buf->n_items_left() < n_items_to_input) {
171 std::cerr << "encoder::encode{input}: Warning: input buffer size (" <<
172 d_in_buf->n_items_left() << ") is less than the desired number "
173 "of input items (" << n_items_to_input <<
174 ") ... using lower number.\n";
175 n_items_to_input = d_in_buf->n_items_left();
178 // check that there are enough output buffer items
180 size_t n_bits_to_output = compute_n_output_bits (n_items_to_input);
182 if (d_out_buf->n_items_left() < n_bits_to_output) {
183 std::cerr << "encoder::encode{input}: Warning: output buffer size (" <<
184 d_out_buf->n_items_left() << ") is less than the computed number "
185 "of required output items (" << n_bits_to_output <<
186 ") ... using lower number.\n";
187 n_bits_to_output = d_out_buf->n_items_left();
188 n_items_to_input = compute_n_input_items (n_bits_to_output);
191 // set the correct number of I/O bits
193 d_n_items_to_input = n_items_to_input;
194 d_n_bits_to_output = n_bits_to_output;
196 if (DO_PRINT_DEBUG) {
198 "Before Decoding{output}:\n"
199 " # output bits = " << d_n_bits_to_output << "\n"
200 " # input items = " << d_n_items_to_input << "\n"
201 " # output bits used = " << d_out_buf->n_items_used() << "\n"
202 " # input items used = " << d_in_buf->n_items_used() << "\n";
205 // call the private decode function
209 if (DO_PRINT_DEBUG) {
211 "After Encoding{output}:\n"
212 " # output bits = " << d_n_bits_to_output << "\n"
213 " # input items = " << d_n_items_to_input << "\n"
214 " # output bits used = " << d_out_buf->n_items_used() << "\n"
215 " # input items used = " << d_in_buf->n_items_used() << "\n";
218 size_t n_items_used = d_out_buf->n_items_used();
220 // clear these buffers, just in case
225 // return the actual number of output bits written
227 return (n_items_used);