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 <GrAtscConvert2xTo20.h>
24 #include <atsc_consts.h>
28 static const int N_OUTPUTS = 1;
29 static const double DEC_RATIO = (2.0 * ATSC_SYMBOL_RATE) / 20e6; // ~ 1.076
31 GrAtscConvert2xTo20::GrAtscConvert2xTo20 ()
32 : VrDecimatingSigProc<float,float> (N_OUTPUTS, (int) rint (DEC_RATIO))
36 history = 2 * d_interp.ntaps (); // some slack
39 GrAtscConvert2xTo20::~GrAtscConvert2xTo20 ()
45 GrAtscConvert2xTo20::pre_initialize ()
48 "GrAtscConvert2xTo20: input freq = %g\n", getInputSamplingFrequencyN(0));
50 "GrAtscConvert2xTo20: DEC_RATIO = %g\n", DEC_RATIO);
52 "GrAtscConvert2xTo20: argument to setSamplingFrequency = %g\n",
53 getInputSamplingFrequencyN(0) / DEC_RATIO);
56 r = setSamplingFrequency (getInputSamplingFrequencyN (0) / DEC_RATIO);
58 fprintf (stderr, "GrAtscConvert2xTo20: result = %d\n", r);
60 fprintf (stderr, "GrAtscConvert2xTo20: getSamplingFrequency = %g\n",
61 getSamplingFrequency ());
66 GrAtscConvert2xTo20::forecast (VrSampleRange output,
67 VrSampleRange inputs[])
69 assert (numberInputs == 1); // I hate these free references to
70 // superclass's instance variables...
72 inputs[0].index = d_next_input;
74 ((long unsigned int) (output.size * DEC_RATIO) + history - 1);
80 GrAtscConvert2xTo20::work (VrSampleRange output, void *ao[],
81 VrSampleRange inputs[], void *ai[])
83 float *in = ((float **) ai)[0];
84 float *out = ((float **) ao)[0];
88 unsigned long si = 0; // source index
89 unsigned long oi = 0; // output index
90 double frac_part = d_frac_part;
92 for (oi = 0; oi < output.size; oi++){
93 assert (si + d_interp.ntaps () < inputs[0].size);
94 out[oi] = d_interp.interpolate (&in[si], (1. - frac_part));
96 double s = frac_part + DEC_RATIO;
97 double float_incr = floor (s);
98 frac_part = s - float_incr;
99 int incr = (int) float_incr;
104 d_frac_part = frac_part;