3 * Copyright 2008 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.
28 #include <gr_squash_ff.h>
29 #include <gr_io_signature.h>
31 // expect input vector of igrid.size y-values,
32 // produce output vector of ogrid.size y-values
35 gr_make_squash_ff(const std::vector<float> &igrid,
36 const std::vector<float> &ogrid)
38 return gr_squash_ff_sptr(new gr_squash_ff(igrid, ogrid));
41 gr_squash_ff::gr_squash_ff(const std::vector<float> &igrid,
42 const std::vector<float> &ogrid)
43 : gr_sync_block("squash_ff",
44 gr_make_io_signature(1, 1, sizeof(float) * igrid.size()),
45 gr_make_io_signature(1, 1, sizeof(float) * ogrid.size()))
47 d_inum = igrid.size();
48 d_onum = ogrid.size();
49 d_igrid = (double *) malloc(d_inum * sizeof(double));
50 d_iwork = (double *) malloc(d_inum * sizeof(double));
51 d_ogrid = (double *) malloc(d_onum * sizeof(double));
52 for (unsigned int i = 0; i < d_inum; i++)
53 d_igrid[i] = igrid[i];
54 for (unsigned int i = 0; i < d_onum; i++)
55 d_ogrid[i] = ogrid[i];
57 d_accel = gsl_interp_accel_alloc();
58 d_spline = gsl_spline_alloc(gsl_interp_cspline, d_inum); // FIXME check w/ Frank
61 gr_squash_ff::~gr_squash_ff()
63 free((char *) d_igrid);
64 free((char *) d_iwork);
65 free((char *) d_ogrid);
66 gsl_interp_accel_free(d_accel);
67 gsl_spline_free(d_spline);
71 gr_squash_ff::work(int noutput_items,
72 gr_vector_const_void_star &input_items,
73 gr_vector_void_star &output_items)
75 const float *in = (const float *) input_items[0];
76 float *out = (float *) output_items[0];
78 for (int count = 0; count < noutput_items; count++) {
80 for (unsigned int i = 0; i < d_inum; i++)
83 gsl_spline_init(d_spline, d_igrid, d_iwork, d_inum);
85 for (unsigned int i = 0; i < d_onum; i++)
86 out[i] = gsl_spline_eval(d_spline, d_ogrid[i], d_accel);