GNU Radio 3.5.1 C++ API
convolutional_interleaver.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 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 _CONVOLUTIONAL_INTERLEAVER_H_
00024 #define _CONVOLUTIONAL_INTERLEAVER_H_
00025 
00026 #include <vector>
00027 #include <interleaver_fifo.h>
00028 #include <assert.h>
00029 
00030 /*!
00031  * \brief template class for generic convolutional interleaver
00032  */
00033 
00034 template<class symbol_type>
00035 class convolutional_interleaver {
00036  public:
00037 
00038   convolutional_interleaver (bool interleave_p, int nbanks, int fifo_size_incr);
00039   virtual ~convolutional_interleaver ();
00040 
00041   //! reset interleaver (flushes contents and resets commutator)
00042   void reset ();
00043   
00044   //! sync interleaver (resets commutator, but doesn't flush fifos)
00045   void sync () { m_commutator = 0; }
00046 
00047   //! return end to end delay in symbols (delay through concatenated interleaver / deinterleaver)
00048   int end_to_end_delay ();
00049 
00050   //! transform a single symbol
00051   symbol_type transform (symbol_type input){
00052     symbol_type retval = m_fifo[m_commutator]->stuff (input);
00053     m_commutator++;
00054     if (m_commutator >= m_nbanks)
00055       m_commutator = 0;
00056     return retval;
00057   }
00058 
00059   //! transform a bunch of symbols
00060   void transform (symbol_type *out, const symbol_type *in, int nsymbols);
00061 
00062 protected:
00063   int   m_commutator;
00064   int   m_nbanks;
00065   int   m_fifo_size_incr;
00066   std::vector<interleaver_fifo<symbol_type> *> m_fifo;
00067 };
00068 
00069 template<class symbol_type>
00070 convolutional_interleaver<symbol_type>::convolutional_interleaver (
00071                                            bool interleave_p,
00072                                            int nbanks,
00073                                            int fifo_size_incr)
00074 {
00075   assert (nbanks >= 1);
00076   assert (fifo_size_incr >= 1);
00077 
00078   m_nbanks = nbanks;
00079   m_fifo_size_incr = fifo_size_incr;
00080 
00081   m_fifo.resize (nbanks);
00082   
00083   if (interleave_p){    // configure as interleaver
00084     for (int i = 0; i < nbanks; i++)
00085       m_fifo[i] = new interleaver_fifo<symbol_type>(i * fifo_size_incr);
00086   }
00087   else {                // configure as de-interleaver
00088     for (int i = 0; i < nbanks; i++)
00089       m_fifo[nbanks - 1 - i] = new interleaver_fifo<symbol_type>(i * fifo_size_incr);
00090   }
00091   sync ();
00092 }
00093 
00094 template<class symbol_type>
00095 convolutional_interleaver<symbol_type>::~convolutional_interleaver ()
00096 {
00097   for (int i = 0; i < m_nbanks; i++)
00098     delete m_fifo[i];
00099 }
00100 
00101 template<class symbol_type> void
00102 convolutional_interleaver<symbol_type>::reset ()
00103 {
00104   sync ();
00105   for (int i = 0; i < m_nbanks; i++)
00106     m_fifo[i]->reset ();
00107 }
00108 
00109 template<class symbol_type> int
00110 convolutional_interleaver<symbol_type>::end_to_end_delay ()
00111 {
00112   int m = m_nbanks * m_fifo_size_incr;
00113   return m * (m_nbanks - 1);
00114 }
00115 
00116 template<class symbol_type> void
00117 convolutional_interleaver<symbol_type>::transform (symbol_type *out,
00118                                                    const symbol_type *in,
00119                                                    int nsymbols)
00120 {
00121   // we may want to unroll this a couple of times...
00122   for (int i = 0; i < nsymbols; i++)
00123     out[i] = transform (in[i]);
00124 }
00125 
00126 #endif /* _CONVOLUTIONAL_INTERLEAVER_H_ */