One question about gr_chunks_to_symbols_bc

Hi, All,

I looked through the gr_chunks_to_symbols_bc code, my understanding is
that it handles a two-dimension array. Based on the following work()
function, my understanding is that each input_items[m] is a list of
chunk (called stream in this function), and the input_items itself is
a list of stream. Then the function maps each chunk to a complex based
on the symbol table. Am I right?

=============================
int
gr_chunks_to_symbols_bc::work (int noutput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items)
{
assert (noutput_items % d_D == 0);
assert (input_items.size() == output_items.size());
int nstreams = input_items.size();

for (int m=0;m<nstreams;m++) {
const unsigned char *in = (unsigned char *) input_items[m];
gr_complex *out = (gr_complex *) output_items[m];

// per stream processing
for (int i = 0; i < noutput_items / d_D; i++){
  assert (((unsigned int)in[i]*d_D+d_D) <= d_symbol_table.size());
  memcpy(out, &d_symbol_table[(unsigned int)in[i]*d_D],

d_D*sizeof(gr_complex));
out+=d_D;
}
// end of per stream processing

}
return noutput_items;
}

==========================

Another question is that what the gr_chunks_to_symbols_bc constructor
means? Based on the following code, I do not understand d_D(D) and
d_symbol_table (symbol_table). I know gr_sync_interpolator() is called
explicitly in gr_chunks_to_symbols_bc’s constructor. are d_D and
d_symbol_table other classes? or something else?

=========================
gr_chunks_to_symbols_bc::gr_chunks_to_symbols_bc (const
std::vector<gr_complex> &symbol_table, const int D)
: gr_sync_interpolator (“chunks_to_symbols_bc”,
gr_make_io_signature (1, -1, sizeof (unsigned char)),
gr_make_io_signature (1, -1, sizeof (gr_complex)),
D),
d_D (D),
d_symbol_table (symbol_table)
{
}

=========================

Thanks for your help.

Jiangfan

Can anyone offer some explanations? Thanks.

Jiangfan

On Sat, Sep 20, 2008 at 09:13:31PM -0500, jiangfan shi wrote:

chunk (called stream in this function), and the input_items itself is
a list of stream. Then the function maps each chunk to a complex based
on the symbol table. Am I right?

Each entry in the table is d_D complex’s long.
Each input byte is mapped to d_D complex’s.
If d_D is 1 – the usual case – then each byte on the input is mapped
to a single complex value.

for (int m=0;m<nstreams;m++) {
// end of per stream processing
explicitly in gr_chunks_to_symbols_bc’s constructor. are d_D and
d_symbol_table other classes? or something else?

Look in the .h file for the answer to the types of d_D and
d_symbol_table.

}
Eric

On Sun, Sep 21, 2008 at 11:56:08AM -0500, jiangfan shi wrote:

Thanks, Eric.

for (int m=0;m<nstreams;m++) {
const unsigned char *in = (unsigned char *) input_items[m];

Maybe I do not express my questions clearly. Basically I am asking
what the above code statement means. My understanding is that the
input_items is a 2-dimension array.

input_items is of type gr_vector_const_void_star.

Searching for the definition of gr_vector_const_void_star reveals it’s
a typedef living in gr_types.h:

typedef std::vector<const void *> gr_vector_const_void_star;

Thus, it’s not a 2-dimensional array, but rather an STL vector of void
*.

The void*'s point into memory allocated by the system that holds the
input data for the block.

Please see
http://www.gnu.org/software/gnuradio/doc/howto-write-a-block.html
for additional information.

The following lines cast the void * to a type that matches the actual
type of the input. In this case it’s unsigned char.

for (int m=0;m<nstreams;m++) {
const unsigned char *in = (unsigned char *) input_items[m];

If any of this is still not clear, you may want to refer to a good C++
and/or STL introduction.

Eric

Thanks very much, Eric.

“…an STL vector of void *” gives me a very clear idea of the
input_items.

I will definitely look into the gnuradio code more broadly to
understand it more deeply.

Jiangfan

Thanks, Eric.

for (int m=0;m<nstreams;m++) {
const unsigned char *in = (unsigned char *) input_items[m];

Maybe I do not express my questions clearly. Basically I am asking
what the above code statement means. My understanding is that the
input_items is a 2-dimension array. So after executing the above
statement, the “in” points to a list of chunk, which is mapped to a
symbol in the following statement.

 memcpy(out, &d_symbol_table[(unsigned int)in[i]*d_D], d_D*sizeof(gr_complex));

And input_items includes a list of a list of chunk. Is my understanding
right?

For the second question, what I am trying to ask is if d_D(D) means it
assigns the parameter D to d_D field in the chunk_to_symbols_cc
class.

I am a newbie in the gnu radio, and I really appreciate these kind of
detailed explanation.

Thanks again.

Jiangfan