Imported Upstream version 3.2.2
[debian/gnuradio] / gnuradio-core / src / lib / general / gr_cpfsk_bc.cc
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2008 Free Software Foundation, Inc.
4  * 
5  * GNU Radio is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3, or (at your option)
8  * any later version.
9  * 
10  * GNU Radio is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  * 
15  * You should have received a copy of the GNU General Public License
16  * along with GNU Radio; see the file COPYING.  If not, write to
17  * the Free Software Foundation, Inc., 51 Franklin Street,
18  * Boston, MA 02110-1301, USA.
19  */
20
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24
25 #include <gr_cpfsk_bc.h>
26 #include <gr_io_signature.h>
27 #include <gr_expj.h>
28
29 #define M_TWOPI (2*M_PI)
30
31 gr_cpfsk_bc_sptr 
32 gr_make_cpfsk_bc(float k, float ampl, int samples_per_sym)
33 {
34   return gr_cpfsk_bc_sptr(new gr_cpfsk_bc(k, ampl, samples_per_sym));
35 }
36
37 gr_cpfsk_bc::gr_cpfsk_bc(float k, float ampl, int samples_per_sym)
38   : gr_sync_interpolator("cpfsk_bc",
39                          gr_make_io_signature(1, 1, sizeof(char)),
40                          gr_make_io_signature(1, 1, sizeof(gr_complex)),
41                          samples_per_sym)
42 {
43   d_samples_per_sym = samples_per_sym;
44   d_freq = k*M_PI/samples_per_sym;
45   d_ampl = ampl;
46   d_phase = 0.0;
47 }
48
49 gr_cpfsk_bc::~gr_cpfsk_bc()
50 {
51 }
52
53 int 
54 gr_cpfsk_bc::work(int noutput_items,
55                       gr_vector_const_void_star &input_items,
56                       gr_vector_void_star &output_items)
57 {
58   const char *in = (const char *)input_items[0];
59   gr_complex *out = (gr_complex *)output_items[0];
60
61   for (int i = 0; i < noutput_items/d_samples_per_sym; i++) {
62     for (int j = 0; j < d_samples_per_sym; j++) {
63       if (in[i] == 1)
64         d_phase += d_freq;
65       else
66         d_phase -= d_freq;
67       
68       while (d_phase > M_TWOPI)
69         d_phase -= M_TWOPI;
70       while (d_phase < -M_TWOPI)
71         d_phase += M_TWOPI;
72       
73       *out++ = gr_expj(d_phase)*d_ampl;
74     }
75   }
76
77   return noutput_items;
78 }