Merge branch 'upstream' into dfsg-orig
[debian/gnuradio] / gr-trellis / src / lib / trellis_viterbi_s.cc
index 6180dabc3e7a3ddd3f05ad432402e8548d135b4f..94a9c0be3da5878098e57cea9f718d8967995de7 100644 (file)
@@ -6,7 +6,7 @@
  * 
  * GNU Radio is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
+ * the Free Software Foundation; either version 3, or (at your option)
  * any later version.
  * 
  * GNU Radio is distributed in the hope that it will be useful,
  * 
  * You should have received a copy of the GNU General Public License
  * along with GNU Radio; see the file COPYING.  If not, write to
- * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
  */
 
+// WARNING: this file is machine generated.  Edits will be over written
+
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
@@ -34,26 +36,26 @@ static const float INF = 1.0e9;
 trellis_viterbi_s_sptr 
 trellis_make_viterbi_s (
     const fsm &FSM,
-    const int K,
-    const int S0,
-    const int SK)
+    int K,
+    int S0,
+    int SK)
 {
   return trellis_viterbi_s_sptr (new trellis_viterbi_s (FSM,K,S0,SK));
 }
 
 trellis_viterbi_s::trellis_viterbi_s (
     const fsm &FSM,
-    const int K,
-    const int S0,
-    const int SK)
+    int K,
+    int S0,
+    int SK)
   : gr_block ("viterbi_s",
                          gr_make_io_signature (1, -1, sizeof (float)),
                          gr_make_io_signature (1, -1, sizeof (short))),  
   d_FSM (FSM),
   d_K (K),
   d_S0 (S0),
-  d_SK (SK),
-  d_trace(FSM.S()*K)
+  d_SK (SK)//,
+  //d_trace(FSM.S()*K)
 {
     set_relative_rate (1.0 / ((double) d_FSM.O()));
     set_output_multiple (d_K);
@@ -74,16 +76,17 @@ trellis_viterbi_s::forecast (int noutput_items, gr_vector_int &ninput_items_requ
 
 
 
-void viterbi_algorithm(const int I, const int S, const int O, 
+void viterbi_algorithm(int I, int S, int O, 
              const std::vector<int> &NS,
              const std::vector<int> &OS,
-             const std::vector<int> &PS,
-             const std::vector<int> &PI,
-             const int K,
-             const int S0,const int SK,
-             const float *in, short *out,
-             std::vector<int> &trace) 
+             const std::vector< std::vector<int> > &PS,
+             const std::vector< std::vector<int> > &PI,
+             int K,
+             int S0,int SK,
+             const float *in, short *out)//,
+             //std::vector<int> &trace) 
 {
+  std::vector<int> trace(S*K);
   std::vector<float> alpha(S*2);
   int alphai;
   float norm,mm,minm;
@@ -105,9 +108,9 @@ void viterbi_algorithm(const int I, const int S, const int O,
       for(int j=0;j<S;j++) { // for each next state do ACS
           minm=INF;
           minmi=0;
-          for(int i=0;i<I;i++) {
-              int i0 = j*I+i;
-              if((mm=alpha[alphai*S+PS[i0]]+in[k*O+OS[PS[i0]*I+PI[i0]]])<minm)
+          for(unsigned int i=0;i<PS[j].size();i++) {
+              //int i0 = j*I+i;
+              if((mm=alpha[alphai*S+PS[j][i]]+in[k*O+OS[PS[j][i]*I+PI[j][i]]])<minm)
                   minm=mm,minmi=i;
           }
           trace[k*S+j]=minmi;
@@ -123,7 +126,7 @@ void viterbi_algorithm(const int I, const int S, const int O,
       minm=INF;
       minmi=0;
       for(int i=0;i<S;i++)
-          if((mm=trace[(K-1)*S+i])<minm) minm=mm,minmi=i;
+          if((mm=alpha[alphai*S+i])<minm) minm=mm,minmi=i;
       st=minmi;
   }
   else {
@@ -131,9 +134,9 @@ void viterbi_algorithm(const int I, const int S, const int O,
   }
 
   for(int k=K-1;k>=0;k--) { // traceback
-      int i0=st*I+trace[k*S+st];
-      out[k]= (short) PI[i0];
-      st=PS[i0];
+      int i0=trace[k*S+st];
+      out[k]= (short) PI[st][i0];
+      st=PS[st][i0];
   }
 
 }
@@ -158,7 +161,7 @@ trellis_viterbi_s::general_work (int noutput_items,
     const float *in = (const float *) input_items[m];
     short *out = (short *) output_items[m];
     for (int n=0;n<nblocks;n++) {
-      viterbi_algorithm(d_FSM.I(),d_FSM.S(),d_FSM.O(),d_FSM.NS(),d_FSM.OS(),d_FSM.PS(),d_FSM.PI(),d_K,d_S0,d_SK,&(in[n*d_K*d_FSM.O()]),&(out[n*d_K]),d_trace);
+      viterbi_algorithm(d_FSM.I(),d_FSM.S(),d_FSM.O(),d_FSM.NS(),d_FSM.OS(),d_FSM.PS(),d_FSM.PI(),d_K,d_S0,d_SK,&(in[n*d_K*d_FSM.O()]),&(out[n*d_K]));//,d_trace);
     }
   }