3 * Copyright 2004 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.
23 // WARNING: this file is machine generated. Edits will be over written
28 #include <gr_sig_source_c.h>
30 #include <gr_io_signature.h>
32 #include <gr_complex.h>
35 gr_sig_source_c::gr_sig_source_c (double sampling_freq, gr_waveform_t waveform,
36 double frequency, double ampl, gr_complex offset)
37 : gr_sync_block ("sig_source_c",
38 gr_make_io_signature (0, 0, 0),
39 gr_make_io_signature (1, 1, sizeof (gr_complex))),
40 d_sampling_freq (sampling_freq), d_waveform (waveform), d_frequency (frequency),
41 d_ampl (ampl), d_offset (offset)
43 d_nco.set_freq (2 * M_PI * d_frequency / d_sampling_freq);
47 gr_make_sig_source_c (double sampling_freq, gr_waveform_t waveform,
48 double frequency, double ampl, gr_complex offset)
50 return gr_sig_source_c_sptr (new gr_sig_source_c (sampling_freq, waveform, frequency, ampl, offset));
54 gr_sig_source_c::work (int noutput_items,
55 gr_vector_const_void_star &input_items,
56 gr_vector_void_star &output_items)
58 gr_complex *optr = (gr_complex *) output_items[0];
66 t = (gr_complex) d_ampl + d_offset;
67 for (int i = 0; i < noutput_items; i++) // FIXME unroll
73 d_nco.sincos (optr, noutput_items, d_ampl);
74 if (d_offset == gr_complex(0,0))
77 for (int i = 0; i < noutput_items; i++){
82 /* Implements a real square wave high from -PI to 0.
83 * The imaginary square wave leads by 90 deg.
86 for (int i = 0; i < noutput_items; i++){
87 if (d_nco.get_phase() < -1*M_PI/2)
88 optr[i] = gr_complex(d_ampl, 0)+d_offset;
89 else if (d_nco.get_phase() < 0)
90 optr[i] = gr_complex(d_ampl, d_ampl)+d_offset;
91 else if (d_nco.get_phase() < M_PI/2)
92 optr[i] = gr_complex(0, d_ampl)+d_offset;
99 /* Implements a real triangle wave rising from -PI to 0 and
100 * falling from 0 to PI. The imaginary triangle wave leads by 90 deg.
103 for (int i = 0; i < noutput_items; i++){
104 if (d_nco.get_phase() < -1*M_PI/2){
105 optr[i] = gr_complex(d_ampl*d_nco.get_phase()/M_PI + d_ampl,
106 -1*d_ampl*d_nco.get_phase()/M_PI - d_ampl/2)+d_offset;
108 else if (d_nco.get_phase() < 0){
109 optr[i] = gr_complex(d_ampl*d_nco.get_phase()/M_PI + d_ampl,
110 d_ampl*d_nco.get_phase()/M_PI + d_ampl/2)+d_offset;
112 else if (d_nco.get_phase() < M_PI/2){
113 optr[i] = gr_complex(-1*d_ampl*d_nco.get_phase()/M_PI + d_ampl,
114 d_ampl*d_nco.get_phase()/M_PI + d_ampl/2)+d_offset;
117 optr[i] = gr_complex(-1*d_ampl*d_nco.get_phase()/M_PI + d_ampl,
118 -1*d_ampl*d_nco.get_phase()/M_PI + 3*d_ampl/2)+d_offset;
124 /* Implements a real saw tooth wave rising from -PI to PI.
125 * The imaginary saw tooth wave leads by 90 deg.
128 for (int i = 0; i < noutput_items; i++){
129 if (d_nco.get_phase() < -1*M_PI/2){
130 optr[i] = gr_complex(d_ampl*d_nco.get_phase()/(2*M_PI) + d_ampl/2,
131 d_ampl*d_nco.get_phase()/(2*M_PI) + 5*d_ampl/4)+d_offset;
134 optr[i] = gr_complex(d_ampl*d_nco.get_phase()/(2*M_PI) + d_ampl/2,
135 d_ampl*d_nco.get_phase()/(2*M_PI) + d_ampl/4)+d_offset;
144 t = (gr_complex) d_ampl + d_offset;
145 for (int i = 0; i < noutput_items; i++) // FIXME unroll
150 d_nco.sin (optr, noutput_items, d_ampl);
154 for (int i = 0; i < noutput_items; i++){
160 d_nco.cos (optr, noutput_items, d_ampl);
164 for (int i = 0; i < noutput_items; i++){
169 /* The square wave is high from -PI to 0. */
171 t = (gr_complex) d_ampl + d_offset;
172 for (int i = 0; i < noutput_items; i++){
173 if (d_nco.get_phase() < 0)
181 /* The triangle wave rises from -PI to 0 and falls from 0 to PI. */
183 for (int i = 0; i < noutput_items; i++){
184 double t = d_ampl*d_nco.get_phase()/M_PI;
185 if (d_nco.get_phase() < 0)
186 optr[i] = static_cast<gr_complex>(t + d_ampl + d_offset);
188 optr[i] = static_cast<gr_complex>(-1*t + d_ampl + d_offset);
193 /* The saw tooth wave rises from -PI to PI. */
195 for (int i = 0; i < noutput_items; i++){
196 t = static_cast<gr_complex>(d_ampl*d_nco.get_phase()/(2*M_PI) + d_ampl/2 + d_offset);
205 throw std::runtime_error ("gr_sig_source: invalid waveform");
208 return noutput_items;
212 gr_sig_source_c::set_sampling_freq (double sampling_freq)
214 d_sampling_freq = sampling_freq;
215 d_nco.set_freq (2 * M_PI * d_frequency / d_sampling_freq);
219 gr_sig_source_c::set_waveform (gr_waveform_t waveform)
221 d_waveform = waveform;
225 gr_sig_source_c::set_frequency (double frequency)
227 d_frequency = frequency;
228 d_nco.set_freq (2 * M_PI * d_frequency / d_sampling_freq);
232 gr_sig_source_c::set_amplitude (double ampl)
238 gr_sig_source_c::set_offset (gr_complex offset)