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 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., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
23 #include <qa_atsci_equalizer_nop.h>
24 #include <atsci_equalizer.h>
25 #include <atsci_equalizer_nop.h>
26 #include <atsci_pnXXX.h>
27 #include <atsc_types.h>
28 #include <cppunit/TestAssert.h>
36 static const int SYMBOLS_PER_FIELD = (ATSC_DSEGS_PER_FIELD + 1) * ATSC_DATA_SEGMENT_LENGTH;
37 static const int PAD = 500;
38 static const int NFIELDS = 2;
40 static const int INPUT_SIZE = PAD + (NFIELDS * SYMBOLS_PER_FIELD);
49 init_tags (atsc::syminfo *tags, int segnum, int fieldnum)
53 for (i = 0; i < ATSC_DATA_SEGMENT_LENGTH; i++){
54 tags[i].symbol_num = i;
55 tags[i].segment_num = segnum;
56 tags[i].field_num = fieldnum;
62 init_data_seg (float *p, atsc::syminfo *tags, int v, int segnum, int fieldnum)
64 init_tags (tags, segnum, fieldnum);
68 p[i++] = bin_map (1); // data segment sync pulse
73 for (; i < ATSC_DATA_SEGMENT_LENGTH; i++)
74 p[i] = (float) (i + v);
78 init_field_sync_tags (atsc::syminfo *tags, int fieldnum)
80 init_tags (tags, atsc::SI_FIELD_SYNC_SEGMENT_NUM, fieldnum);
84 init_field_sync_common (float *p, int mask)
89 p[i++] = bin_map (1); // data segment sync pulse
94 for (int j = 0; j < 511; j++) // PN511
95 p[i++] = bin_map (atsc_pn511[j]);
97 for (int j = 0; j < 63; j++) // PN63
98 p[i++] = bin_map (atsc_pn63[j]);
100 for (int j = 0; j < 63; j++) // PN63, toggled on field 2
101 p[i++] = bin_map (atsc_pn63[j] ^ mask);
103 for (int j = 0; j < 63; j++) // PN63
104 p[i++] = bin_map (atsc_pn63[j]);
106 p[i++] = bin_map (0); // 24 bits of VSB8 mode identifiera
107 p[i++] = bin_map (0);
108 p[i++] = bin_map (0);
109 p[i++] = bin_map (0);
111 p[i++] = bin_map (1);
112 p[i++] = bin_map (0);
113 p[i++] = bin_map (1);
114 p[i++] = bin_map (0);
116 p[i++] = bin_map (0);
117 p[i++] = bin_map (1);
118 p[i++] = bin_map (0);
119 p[i++] = bin_map (1);
121 p[i++] = bin_map (1);
122 p[i++] = bin_map (1);
123 p[i++] = bin_map (1);
124 p[i++] = bin_map (1);
126 p[i++] = bin_map (0);
127 p[i++] = bin_map (1);
128 p[i++] = bin_map (0);
129 p[i++] = bin_map (1);
131 p[i++] = bin_map (1);
132 p[i++] = bin_map (0);
133 p[i++] = bin_map (1);
134 p[i++] = bin_map (0);
137 for (int j = 0; j < 92; j++) // 92 more bits
138 p[i++] = bin_map (atsc_pn63[j % 63]);
140 // now copy the last 12 symbols of the previous segment
143 for (int j = 0; j < 12; j++)
144 p[i++] = bin_map (j & 1);
146 assert (i == ATSC_DATA_SEGMENT_LENGTH);
150 qa_atsci_equalizer_nop::setUp ()
152 eq = new atsci_equalizer_nop ();
156 qa_atsci_equalizer_nop::tearDown ()
163 setup_test_data (float *data, atsc::syminfo *tags)
168 for (i = 0; i < PAD; i++){
170 tags[i].symbol_num = 13 + i;
171 tags[i].segment_num = 17;
172 tags[i].field_num = 0;
176 for (int nfields = 0; nfields < NFIELDS; nfields++){
177 init_field_sync_common (&data[i], mask);
178 init_field_sync_tags (&tags[i], mask);
179 i += ATSC_DATA_SEGMENT_LENGTH;
181 for (int segnum = 0; segnum < 312; segnum++){
182 init_data_seg (&data[i], &tags[i], i, segnum, mask);
183 i += ATSC_DATA_SEGMENT_LENGTH;
187 assert (i == INPUT_SIZE);
191 qa_atsci_equalizer_nop::t0 ()
193 // these are dynamically allocated because they are bigger
194 // than the default stack limit.
196 float *input_data = new float[INPUT_SIZE];
197 atsc::syminfo *input_tags = new atsc::syminfo[INPUT_SIZE];
198 float *output_data = new float[INPUT_SIZE];
202 memset (input_data, 0, sizeof (input_data));
203 memset (input_tags, 0, sizeof (input_tags));
204 memset (output_data, 0, sizeof (output_data));
206 setup_test_data (input_data, input_tags);
208 eq->filter (input_data, input_tags,
209 output_data, INPUT_SIZE);
212 // now check that data values got copied correctly
214 for (int i = 0; i < INPUT_SIZE; i++){
216 if (input_tags[i].segment_num == atsc::SI_FIELD_SYNC_SEGMENT_NUM){
217 // ignore entire field sync data segment
219 else if (input_tags[i].symbol_num <= 3){
220 // ignore 4 symbols of data segment sync (+5, -5, -5, +5)
223 if (output_data[i] != (float) i){
224 cerr << "output_data[" << i << "] == " << output_data[i] << endl;
225 CPPUNIT_ASSERT_DOUBLES_EQUAL ((float) i, output_data[i], 1e-6);
230 delete [] input_data;
231 delete [] input_tags;
232 delete [] output_data;
236 delete [] input_data;
237 delete [] input_tags;
238 delete [] output_data;
243 qa_atsci_equalizer_nop::t1 ()
245 // think of another test...