GNU Radio 3.5.3.2 C++ API
gr_fxpt_vco.h
Go to the documentation of this file.
00001 /* -*- c++ -*- */
00002 /*
00003  * Copyright 2002,2004,2005 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 #ifndef INCLUDED_GR_FXPT_VCO_H
00023 #define INCLUDED_GR_FXPT_VCO_H
00024 
00025 #include <gr_core_api.h>
00026 #include <gr_fxpt.h>
00027 #include <gr_complex.h>
00028 
00029 /*!
00030  * \brief Voltage Controlled Oscillator (VCO)
00031  * \ingroup misc
00032  */
00033 class GR_CORE_API gr_fxpt_vco {
00034   gr_int32      d_phase;
00035 
00036 public:
00037   gr_fxpt_vco () : d_phase (0) {}
00038 
00039   ~gr_fxpt_vco () {}
00040 
00041   // radians
00042   void set_phase (float angle) {
00043     d_phase = gr_fxpt::float_to_fixed (angle);
00044   }
00045 
00046   void adjust_phase (float delta_phase) {
00047     d_phase += gr_fxpt::float_to_fixed (delta_phase);
00048   }
00049 
00050   float get_phase () const { return gr_fxpt::fixed_to_float (d_phase); }
00051 
00052   // compute sin and cos for current phase angle
00053   void sincos (float *sinx, float *cosx) const
00054   {
00055     *sinx = gr_fxpt::sin (d_phase);
00056     *cosx = gr_fxpt::cos (d_phase);
00057   }
00058 
00059   // compute a block at a time
00060   void cos (float *output, const float *input, int noutput_items, float k, float ampl = 1.0)
00061   {
00062     for (int i = 0; i < noutput_items; i++){
00063       output[i] = (float)(gr_fxpt::cos (d_phase) * ampl);
00064       adjust_phase(input[i] * k);
00065     }
00066   }
00067 
00068   // compute cos or sin for current phase angle
00069   float cos () const { return gr_fxpt::cos (d_phase); }
00070   float sin () const { return gr_fxpt::sin (d_phase); }
00071 };
00072 
00073 #endif /* INCLUDED_GR_FXPT_VCO_H */