3 * Copyright 2002 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 3, 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.
27 #include <cppunit/TestAssert.h>
28 #include <qa_atsci_viterbi_decoder.h>
29 #include <qa_atsci_trellis_encoder.h>
35 #define NELEM(x) (sizeof (x) / sizeof (x[0]))
38 static const int NCODERS = atsci_viterbi_decoder::NCODERS;
42 map_to_soft_symbols (atsc_soft_data_segment &out,
43 const atsc_data_segment &in)
45 for (unsigned int i = 0; i < NELEM (in.data); i++){
46 out.data[i] = in.data[i] * 2 - 7;
52 pad_decoder_input (atsc_soft_data_segment out[NCODERS])
54 memset (out, 0, sizeof (out));
56 // add data segment sync
57 for (int i = 0; i < NCODERS; i++){
62 out[i].pli.set_regular_seg (false, i);
67 qa_atsci_viterbi_decoder::t0 ()
70 atsci_trellis_encoder enc;
71 atsc_mpeg_packet_rs_encoded encoder_in[NCODERS];
72 atsc_data_segment encoder_out[NCODERS];
73 atsc_soft_data_segment decoder_in[NCODERS];
74 atsc_soft_data_segment decoder_in_pad[NCODERS];
75 atsc_mpeg_packet_rs_encoded decoder_out[NCODERS];
76 atsc_mpeg_packet_rs_encoded decoder_out_pad[NCODERS];
79 memset (encoder_in, 0, sizeof (encoder_in));
80 memset (encoder_out, 0, sizeof (encoder_out));
81 memset (decoder_out_pad, 0, sizeof (decoder_out_pad));
85 for (int i = 0; i < NCODERS; i++){
86 for (unsigned int j = 0; j < NELEM (encoder_in[i].data); j++){
87 int t = (random () >> 8) & 0xff; // 8 random bits
88 encoder_in[i].data[j] = t;
93 printf ("@@@ ENCODER INPUT @@@\n");
94 for (int i = 0; i < NCODERS; i++){
95 for (unsigned int j = 0; j < NELEM (encoder_in[i].data); j++){
96 printf ("%d\n", encoder_in[i].data[j]);
101 enc.encode (encoder_out, encoder_in);
103 printf ("@@@ ENCODER OUTPUT @@@\n");
104 for (int i = 0; i < NCODERS; i++){
105 for (unsigned int j = 0; j < NELEM (encoder_out[i].data); j++){
106 printf ("%d\n", encoder_out[i].data[j]);
110 for (int i = 0; i < NCODERS; i++)
111 map_to_soft_symbols (decoder_in[i], encoder_out[i]);
115 // this has only the previous (non-existant) output
116 viterbi.decode (decoder_out_pad, decoder_in);
118 // now we'll see the real output
119 pad_decoder_input (decoder_in_pad);
120 viterbi.decode (decoder_out, decoder_in_pad);
122 printf ("@@@ DECODER OUTPUT @@@\n");
123 for (int i = 0; i < NCODERS; i++){
124 for (unsigned int j = 0; j < NELEM (decoder_out[i].data); j++){
125 printf ("%d\n", decoder_out[i].data[j]);
133 qa_atsci_viterbi_decoder::t1 ()
135 atsc_soft_data_segment decoder_in[NCODERS];
136 atsc_soft_data_segment decoder_in_pad[NCODERS];
137 atsc_mpeg_packet_rs_encoded decoder_out[NCODERS];
138 atsc_mpeg_packet_rs_encoded decoder_out_pad[NCODERS];
139 atsc_mpeg_packet_rs_encoded expected_out[NCODERS];
140 static const float raw_input[NCODERS * NELEM (decoder_in[0].data)] = {
141 #include "qa_atsci_viterbi_decoder_t1_input.dat"
143 static const unsigned char raw_output[NCODERS * NELEM (expected_out[0].data)] = {
144 #include "qa_atsci_viterbi_decoder_t1_output.dat"
149 const float *ri = &raw_input[0];
150 for (int i = 0; i < NCODERS; i++){
151 for (unsigned int j = 0; j < NELEM (decoder_in[i].data); j++){
152 decoder_in[i].data[j] = *ri++;
154 decoder_in[i].pli.set_regular_seg (false, i);
157 // load up expected output
158 const unsigned char *ro = &raw_output[0];
159 for (int i = 0; i < NCODERS; i++){
160 for (unsigned int j = 0; j < NELEM (expected_out[i].data); j++){
161 expected_out[i].data[j] = *ro++;
163 expected_out[i].pli.set_regular_seg (false, i);
168 // this has only the previous (non-existant) output
169 viterbi.decode (decoder_out_pad, decoder_in);
171 // now we'll see the real output
172 pad_decoder_input (decoder_in_pad);
173 viterbi.decode (decoder_out, decoder_in_pad);
175 for (int i = 0; i < NCODERS; i++){ // check the result
176 CPPUNIT_ASSERT (expected_out[i] == decoder_out[i]);