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., 51 Franklin Street,
20 * Boston, MA 02110-1301, USA.
23 #include <atsci_fs_checker_naive.h>
24 #include <atsci_syminfo.h>
25 #include <atsci_pnXXX.h>
32 static const int PN511_ERROR_LIMIT = 20; // max number of bits wrong
33 static const int PN63_ERROR_LIMIT = 5;
35 unsigned char atsci_fs_checker_naive::s_511[LENGTH_511];
36 unsigned char atsci_fs_checker_naive::s_63[LENGTH_2ND_63];
39 init_s_511 (unsigned char *p)
41 *p++ = 1; // data segment sync pattern
46 for (int i = 0; i < 511; i++){
52 init_s_63 (unsigned char *p)
54 for (int i = 0; i < 63; i++){
59 atsci_fs_checker_naive::atsci_fs_checker_naive ()
66 atsci_fs_checker_naive::~atsci_fs_checker_naive ()
71 atsci_fs_checker_naive::reset ()
74 memset (d_sample_sr, 0, sizeof (d_sample_sr));
75 memset (d_tag_sr, 0, sizeof (d_tag_sr));
76 memset (d_bit_sr, 0, sizeof (d_bit_sr));
82 atsci_fs_checker_naive::filter (float input_sample, atsc::syminfo input_tag,
83 float *output_sample, atsc::syminfo *output_tag)
85 atsc::syminfo proto_tag = d_tag_sr[d_index]; // oldest tag in the queue
87 if (proto_tag.symbol_num == 0){ // check for field sync pattern
89 d_segment_num = (d_segment_num + 1) & atsc::SI_SEGMENT_NUM_MASK; // increment
91 // check for a hit on the PN 511 pattern
93 int start = wrap (d_index + OFFSET_511);
95 for (int i = 0; i < LENGTH_511 && errors < PN511_ERROR_LIMIT; i++)
96 errors += d_bit_sr[wrap (start + i)] ^ s_511[i];
98 if (errors < PN511_ERROR_LIMIT){ // 511 pattern is good.
99 // determine if this is field 1 or field 2
101 start = wrap (d_index + OFFSET_2ND_63);
102 for (int i = 0; i < LENGTH_2ND_63; i++)
103 errors += d_bit_sr[wrap (start + i)] ^ s_63[i];
105 // we should have either field 1 (== PN63) or field 2 (== ~PN63)
107 if (errors <= PN63_ERROR_LIMIT){
108 d_segment_num = atsc::SI_FIELD_SYNC_SEGMENT_NUM; // this is FIELD_SYNC_1
111 else if (errors >= (LENGTH_2ND_63 - PN63_ERROR_LIMIT)){
112 d_segment_num = atsc::SI_FIELD_SYNC_SEGMENT_NUM; // this is FIELD_SYNC_2
116 // should be extremely rare.
117 cerr << "!!! atsci_fs_checker_naive: PN63 error count = " << errors << endl;
122 proto_tag.segment_num = d_segment_num; // fill in segment number and field number
123 proto_tag.field_num = d_field_num;
125 // return oldest sample
126 *output_sample = d_sample_sr[d_index];
127 *output_tag = proto_tag;
129 // overwrite with newest sample;
130 d_sample_sr[d_index] = input_sample;
131 d_bit_sr[d_index] = input_sample < 0 ? 0 : 1;
132 d_tag_sr[d_index] = input_tag;
133 d_index = incr (d_index);
137 atsci_fs_checker_naive::delay () const