Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

GrMixer.h

Go to the documentation of this file.
00001 /* -*- c++ -*- */
00002 /*
00003  * Copyright 2002 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 2, 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., 59 Temple Place - Suite 330,
00020  * Boston, MA 02111-1307, USA.
00021  */
00022 
00023 #ifndef _GRMIXER_H_
00024 #define _GRMIXER_H_
00025 
00026 #include <VrSigProc.h>
00027 #include <gr_nco.h>
00028 
00029 template<class iType,class oType> 
00030 class GrMixer : public VrSigProc {
00031 
00032 public: 
00033   GrMixer(double carrier_freq, double gain)
00034     : VrSigProc(1,sizeof(iType), sizeof(oType)),
00035       carrier_freq (carrier_freq), gain (gain) {}
00036     
00037   const char *name() { return "GrMixer"; }
00038 
00039   int work (VrSampleRange output, void *ao[],
00040             VrSampleRange inputs[], void *ai[]);
00041 
00042 
00043 protected:
00044 
00045   void initialize ();
00046 
00047   double                carrier_freq;
00048   double                gain;
00049   gr_nco<float,float>   nco;
00050 };
00051 
00052 template<class iType,class oType> void
00053 GrMixer<iType,oType>::initialize ()
00054 {
00055   double Fs = getSamplingFrequency ();
00056   nco.set_freq (carrier_freq / Fs * 2 * M_PI);
00057   nco.set_phase (0);
00058 }
00059 
00060 template<class iType,class oType>
00061 int
00062 GrMixer<iType,oType>::work (VrSampleRange output, void *ao[],
00063                             VrSampleRange inputs[], void *ai[])
00064 {
00065   iType *in =  ((iType**) ai)[0];
00066   oType *out = ((iType**) ao)[0];
00067 
00068   sync (output.index);  // we've got state, must compute in order
00069   
00070   for (unsigned oo = 0; oo < output.size; oo++){
00071     out[oo] = (oType) (gain * in[oo] * nco.sin ());
00072     nco.step ();
00073   }
00074 
00075   return output.size;
00076 }
00077 
00078 
00079 #endif /* _GRMIXER_H_ */

Generated on Tue Mar 15 23:55:33 2005 for GNU Radio by  doxygen 1.4.0