GNU Radio 3.7.1 C++ API
fxpt_vco.h
Go to the documentation of this file.
00001 /* -*- c++ -*- */
00002 /*
00003  * Copyright 2002,2004,2005,2013 Free Software Foundation, Inc.
00004  *
00005  * This file is part of GNU Radio
00006  *
00007  * GNU Radio is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 3, or (at your option)
00010  * any later version.
00011  *
00012  * GNU Radio is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with GNU Radio; see the file COPYING.  If not, write to
00019  * the Free Software Foundation, Inc., 51 Franklin Street,
00020  * Boston, MA 02110-1301, USA.
00021  */
00022 
00023 #ifndef INCLUDED_GR_FXPT_VCO_H
00024 #define INCLUDED_GR_FXPT_VCO_H
00025 
00026 #include <gnuradio/api.h>
00027 #include <gnuradio/fxpt.h>
00028 #include <gnuradio/gr_complex.h>
00029 
00030 namespace gr {
00031 
00032   /*!
00033    * \brief Voltage Controlled Oscillator (VCO)
00034    * \ingroup misc
00035    */
00036   class /*GR_RUNTIME_API*/ fxpt_vco {
00037     gr_int32 d_phase;
00038 
00039   public:
00040     fxpt_vco () : d_phase(0) {}
00041 
00042     ~fxpt_vco() {}
00043 
00044     // radians
00045     void set_phase(float angle) {
00046       d_phase = fxpt::float_to_fixed(angle);
00047     }
00048 
00049     void adjust_phase(float delta_phase) {
00050       d_phase += fxpt::float_to_fixed(delta_phase);
00051     }
00052 
00053     float get_phase() const { 
00054       return fxpt::fixed_to_float(d_phase);
00055     }
00056 
00057     // compute sin and cos for current phase angle
00058     void sincos(float *sinx, float *cosx) const
00059     {
00060       *sinx = fxpt::sin(d_phase);
00061       *cosx = fxpt::cos(d_phase);
00062     }
00063 
00064     // compute complex sine a block at a time
00065     void sincos(gr_complex *output, const float *input, int noutput_items,
00066                 float k, float ampl = 1.0)
00067     {
00068       for(int i = 0; i < noutput_items; i++) {
00069         output[i] = gr_complex((float)(fxpt::cos(d_phase) * ampl),
00070                                (float)(fxpt::sin(d_phase) * ampl));
00071         adjust_phase(input[i] * k);
00072       }
00073     }
00074 
00075     // compute a block at a time
00076     void cos(float *output, const float *input, int noutput_items, float k, float ampl = 1.0)
00077     {
00078       for(int i = 0; i < noutput_items; i++) {
00079         output[i] = (float)(fxpt::cos(d_phase) * ampl);
00080         adjust_phase(input[i] * k);
00081       }
00082     }
00083 
00084     // compute cos or sin for current phase angle
00085     float cos() const { return fxpt::cos(d_phase); }
00086     float sin() const { return fxpt::sin(d_phase); }
00087   };
00088 
00089 } /* namespace gr */
00090 
00091 #endif /* INCLUDED_GR_FXPT_VCO_H */