GNU Radio's GSM Package
AmrCoder.h
Go to the documentation of this file.
1 /*
2  * Copyright 2013, 2014 Range Networks, Inc.
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Affero General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8 
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Affero General Public License for more details.
13  *
14  * You should have received a copy of the GNU Affero General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  *
17  * This use of this software may be subject to additional restrictions.
18  * See the LEGAL file in the main directory for details.
19  */
20 
21 #ifndef _AMRCODER_H_
22 #define _AMRCODER_H_
23 #include <stdint.h>
24 #include "BitVector.h"
25 #include "Viterbi.h"
26 
27 
28 
29 /**
30  Class to represent recursive systematic convolutional coders/decoders of rate 1/2, memory length 4.
31 */
33 
34  private:
35  /**name Lots of precomputed elements so the compiler can optimize like hell. */
36  //@{
37  /**@name Core values. */
38  //@{
39  static const unsigned mIRate = 2; ///< reciprocal of rate
40  static const unsigned mOrder = 4; ///< memory length of generators
41  //@}
42  /**@name Derived values. */
43  //@{
44  static const unsigned mIStates = 0x01 << mOrder; ///< number of states, number of survivors
45  static const uint32_t mSMask = mIStates-1; ///< survivor mask
46  static const uint32_t mCMask = (mSMask<<1) | 0x01; ///< candidate mask
47  static const uint32_t mOMask = (0x01<<mIRate)-1; ///< ouput mask, all iRate low bits set
48  static const unsigned mNumCands = mIStates*2; ///< number of candidates to generate during branching
49  static const unsigned mDeferral = 6*mOrder; ///< deferral to be used
50  //@}
51  //@}
52 
53  /** Precomputed tables. */
54  //@{
55  uint32_t mCoeffs[mIRate]; ///< output polynomial for each generator
56  uint32_t mCoeffsFB[mIRate]; ///< feedback polynomial for each generator
57  uint32_t mStateTable[mIRate][2*mIStates]; ///< precomputed generator output tables
58  uint32_t mGeneratorTable[2*mIStates]; ///< precomputed coder output table
59  //@}
60 
61  public:
62 
63  /**
64  A candidate sequence in a Viterbi decoder.
65  The 32-bit state register can support a deferral of 6 with a 4th-order coder.
66  */
67  typedef struct candStruct {
68  uint32_t iState; ///< encoder input associated with this candidate
69  uint32_t oState; ///< encoder output associated with this candidate
70  char rState[mIRate];///< real states of encoders associated with this candidate
71  float cost; ///< cost (metric value), float to support soft inputs
72  } vCand;
73 
74  /** Clear a structure. */
75  void vitClear(vCand& v)
76  {
77  v.iState=0;
78  v.oState=0;
79  v.cost=0;
80  for (unsigned i = 0; i < mIRate; i++) v.rState[i] = 0;
81  }
82 
83 
84  private:
85 
86  /**@name Survivors and candidates. */
87  //@{
88  vCand mSurvivors[mIStates]; ///< current survivor pool
89  vCand mCandidates[2*mIStates]; ///< current candidate pool
90  //@}
91 
92  public:
93 
94  unsigned iRate() const { return mIRate; }
95  uint32_t cMask() const { return mCMask; }
96  uint32_t stateTable(unsigned g, unsigned i) const { return mStateTable[g][i]; }
97  unsigned deferral() const { return mDeferral; }
98 
99 
101 
102  /** Set all cost metrics to zero. */
104 
105  /**
106  Full cycle of the Viterbi algorithm: branch, metrics, prune, select.
107  @return reference to minimum-cost candidate.
108  */
109  const vCand& step(uint32_t inSample, const float *probs, const float *iprobs);
110 
111  private:
112 
113  /** Branch survivors into new candidates. */
114  void branchCandidates();
115 
116  /** Compute cost metrics for soft-inputs. */
117  void getSoftCostMetrics(uint32_t inSample, const float *probs, const float *iprobs);
118 
119  /** Select survivors from the candidate set. */
120  void pruneCandidates();
121 
122  /** Find the minimum cost survivor. */
123  const vCand& minCost() const;
124 
125  /**
126  Precompute the state tables.
127  @param g Generator index 0..((1/rate)-1)
128  */
129  void computeStateTables(unsigned g);
130 
131  /**
132  Precompute the generator outputs.
133  mCoeffs must be defined first.
134  */
135  void computeGeneratorTable();
136  void encode(const BitVector &in, BitVector& target) const;
137  void decode(const SoftVector &in, BitVector& target);
138 };
139 
140 
141 
142 /**
143  Class to represent recursive systematic convolutional coders/decoders of rate 1/3, memory length 4.
144 */
146 
147  private:
148  /**name Lots of precomputed elements so the compiler can optimize like hell. */
149  //@{
150  /**@name Core values. */
151  //@{
152  static const unsigned mIRate = 3; ///< reciprocal of rate
153  static const unsigned mOrder = 4; ///< memory length of generators
154  //@}
155  /**@name Derived values. */
156  //@{
157  static const unsigned mIStates = 0x01 << mOrder; ///< number of states, number of survivors
158  static const uint32_t mSMask = mIStates-1; ///< survivor mask
159  static const uint32_t mCMask = (mSMask<<1) | 0x01; ///< candidate mask
160  static const uint32_t mOMask = (0x01<<mIRate)-1; ///< ouput mask, all iRate low bits set
161  static const unsigned mNumCands = mIStates*2; ///< number of candidates to generate during branching
162  static const unsigned mDeferral = 6*mOrder; ///< deferral to be used
163  //@}
164  //@}
165 
166  /** Precomputed tables. */
167  //@{
168  uint32_t mCoeffs[mIRate]; ///< output polynomial for each generator
169  uint32_t mCoeffsFB[mIRate]; ///< feedback polynomial for each generator
170  uint32_t mStateTable[mIRate][2*mIStates]; ///< precomputed generator output tables
171  uint32_t mGeneratorTable[2*mIStates]; ///< precomputed coder output table
172  //@}
173 
174  public:
175 
176  /**
177  A candidate sequence in a Viterbi decoder.
178  The 32-bit state register can support a deferral of 6 with a 4th-order coder.
179  */
180  typedef struct candStruct {
181  uint32_t iState; ///< encoder input associated with this candidate
182  uint32_t oState; ///< encoder output associated with this candidate
183  char rState[mIRate];///< real states of encoders associated with this candidate
184  float cost; ///< cost (metric value), float to support soft inputs
185  } vCand;
186 
187  /** Clear a structure. */
188  void vitClear(vCand& v)
189  {
190  v.iState=0;
191  v.oState=0;
192  v.cost=0;
193  for (unsigned i = 0; i < mIRate; i++) v.rState[i] = 0;
194  }
195 
196 
197  private:
198 
199  /**@name Survivors and candidates. */
200  //@{
201  vCand mSurvivors[mIStates]; ///< current survivor pool
202  vCand mCandidates[2*mIStates]; ///< current candidate pool
203  //@}
204 
205  public:
206 
207  unsigned iRate() const { return mIRate; }
208  uint32_t cMask() const { return mCMask; }
209  uint32_t stateTable(unsigned g, unsigned i) const { return mStateTable[g][i]; }
210  unsigned deferral() const { return mDeferral; }
211 
212 
214 
215  /** Set all cost metrics to zero. */
217 
218  /**
219  Full cycle of the Viterbi algorithm: branch, metrics, prune, select.
220  @return reference to minimum-cost candidate.
221  */
222  const vCand& step(uint32_t inSample, const float *probs, const float *iprobs);
223 
224  private:
225 
226  /** Branch survivors into new candidates. */
227  void branchCandidates();
228 
229  /** Compute cost metrics for soft-inputs. */
230  void getSoftCostMetrics(uint32_t inSample, const float *probs, const float *iprobs);
231 
232  /** Select survivors from the candidate set. */
233  void pruneCandidates();
234 
235  /** Find the minimum cost survivor. */
236  const vCand& minCost() const;
237 
238  /**
239  Precompute the state tables.
240  @param g Generator index 0..((1/rate)-1)
241  */
242  void computeStateTables(unsigned g);
243 
244  /**
245  Precompute the generator outputs.
246  mCoeffs must be defined first.
247  */
248  void computeGeneratorTable();
249  void encode(const BitVector &in, BitVector& target) const;
250  void decode(const SoftVector &in, BitVector& target);
251 
252 };
253 
254 
255 
256 /**
257  Class to represent recursive systematic convolutional coders/decoders of rate 1/3, memory length 6.
258 */
260 
261  private:
262  /**name Lots of precomputed elements so the compiler can optimize like hell. */
263  //@{
264  /**@name Core values. */
265  //@{
266  static const unsigned mIRate = 3; ///< reciprocal of rate
267  static const unsigned mOrder = 6; ///< memory length of generators
268  //@}
269  /**@name Derived values. */
270  //@{
271  static const unsigned mIStates = 0x01 << mOrder; ///< number of states, number of survivors
272  static const uint32_t mSMask = mIStates-1; ///< survivor mask
273  static const uint32_t mCMask = (mSMask<<1) | 0x01; ///< candidate mask
274  static const uint32_t mOMask = (0x01<<mIRate)-1; ///< ouput mask, all iRate low bits set
275  static const unsigned mNumCands = mIStates*2; ///< number of candidates to generate during branching
276  static const unsigned mDeferral = 5*mOrder; ///< deferral to be used
277  //@}
278  //@}
279 
280  /** Precomputed tables. */
281  //@{
282  uint32_t mCoeffs[mIRate]; ///< output polynomial for each generator
283  uint32_t mCoeffsFB[mIRate]; ///< feedback polynomial for each generator
284  uint32_t mStateTable[mIRate][2*mIStates]; ///< precomputed generator output tables
285  uint32_t mGeneratorTable[2*mIStates]; ///< precomputed coder output table
286  //@}
287 
288  public:
289 
290  /**
291  A candidate sequence in a Viterbi decoder.
292  The 32-bit state register can support a deferral of 5*order with a 6th-order coder.
293  */
294  typedef struct candStruct {
295  uint32_t iState; ///< encoder input associated with this candidate
296  uint32_t oState; ///< encoder output associated with this candidate
297  char rState[mIRate];///< real states of encoders associated with this candidate
298  float cost; ///< cost (metric value), float to support soft inputs
299  } vCand;
300 
301  /** Clear a structure. */
302  void vitClear(vCand& v)
303  {
304  v.iState=0;
305  v.oState=0;
306  v.cost=0;
307  for (unsigned i = 0; i < mIRate; i++) v.rState[i] = 0;
308  }
309 
310 
311  private:
312 
313  /**@name Survivors and candidates. */
314  //@{
315  vCand mSurvivors[mIStates]; ///< current survivor pool
316  vCand mCandidates[2*mIStates]; ///< current candidate pool
317  //@}
318 
319  public:
320 
321  unsigned iRate() const { return mIRate; }
322  uint32_t cMask() const { return mCMask; }
323  uint32_t stateTable(unsigned g, unsigned i) const { return mStateTable[g][i]; }
324  unsigned deferral() const { return mDeferral; }
325 
326 
328 
329  /** Set all cost metrics to zero. */
331 
332  /**
333  Full cycle of the Viterbi algorithm: branch, metrics, prune, select.
334  @return reference to minimum-cost candidate.
335  */
336  const vCand& step(uint32_t inSample, const float *probs, const float *iprobs);
337 
338  private:
339 
340  /** Branch survivors into new candidates. */
341  void branchCandidates();
342 
343  /** Compute cost metrics for soft-inputs. */
344  void getSoftCostMetrics(uint32_t inSample, const float *probs, const float *iprobs);
345 
346  /** Select survivors from the candidate set. */
347  void pruneCandidates();
348 
349  /** Find the minimum cost survivor. */
350  const vCand& minCost() const;
351 
352  /**
353  Precompute the state tables.
354  @param g Generator index 0..((1/rate)-1)
355  */
356  void computeStateTables(unsigned g);
357 
358  /**
359  Precompute the generator outputs.
360  mCoeffs must be defined first.
361  */
362  void computeGeneratorTable();
363  void encode(const BitVector &in, BitVector& target) const;
364  void decode(const SoftVector &in, BitVector& target);
365 
366 };
367 
368 
369 
370 /**
371  Class to represent recursive systematic convolutional coders/decoders of rate 1/3, memory length 4.
372 */
374 
375  private:
376  /**name Lots of precomputed elements so the compiler can optimize like hell. */
377  //@{
378  /**@name Core values. */
379  //@{
380  static const unsigned mIRate = 3; ///< reciprocal of rate
381  static const unsigned mOrder = 4; ///< memory length of generators
382  //@}
383  /**@name Derived values. */
384  //@{
385  static const unsigned mIStates = 0x01 << mOrder; ///< number of states, number of survivors
386  static const uint32_t mSMask = mIStates-1; ///< survivor mask
387  static const uint32_t mCMask = (mSMask<<1) | 0x01; ///< candidate mask
388  static const uint32_t mOMask = (0x01<<mIRate)-1; ///< ouput mask, all iRate low bits set
389  static const unsigned mNumCands = mIStates*2; ///< number of candidates to generate during branching
390  static const unsigned mDeferral = 6*mOrder; ///< deferral to be used
391  //@}
392  //@}
393 
394  /** Precomputed tables. */
395  //@{
396  uint32_t mCoeffs[mIRate]; ///< output polynomial for each generator
397  uint32_t mCoeffsFB[mIRate]; ///< feedback polynomial for each generator
398  uint32_t mStateTable[mIRate][2*mIStates]; ///< precomputed generator output tables
399  uint32_t mGeneratorTable[2*mIStates]; ///< precomputed coder output table
400  //@}
401 
402  public:
403 
404  /**
405  A candidate sequence in a Viterbi decoder.
406  The 32-bit state register can support a deferral of 6 with a 4th-order coder.
407  */
408  typedef struct candStruct {
409  uint32_t iState; ///< encoder input associated with this candidate
410  uint32_t oState; ///< encoder output associated with this candidate
411  char rState[mIRate];///< real states of encoders associated with this candidate
412  float cost; ///< cost (metric value), float to support soft inputs
413  } vCand;
414 
415  /** Clear a structure. */
416  void vitClear(vCand& v)
417  {
418  v.iState=0;
419  v.oState=0;
420  v.cost=0;
421  for (unsigned i = 0; i < mIRate; i++) v.rState[i] = 0;
422  }
423 
424 
425  private:
426 
427  /**@name Survivors and candidates. */
428  //@{
429  vCand mSurvivors[mIStates]; ///< current survivor pool
430  vCand mCandidates[2*mIStates]; ///< current candidate pool
431  //@}
432 
433  public:
434 
435  unsigned iRate() const { return mIRate; }
436  uint32_t cMask() const { return mCMask; }
437  uint32_t stateTable(unsigned g, unsigned i) const { return mStateTable[g][i]; }
438  unsigned deferral() const { return mDeferral; }
439 
440 
442 
443  /** Set all cost metrics to zero. */
445 
446  /**
447  Full cycle of the Viterbi algorithm: branch, metrics, prune, select.
448  @return reference to minimum-cost candidate.
449  */
450  const vCand& step(uint32_t inSample, const float *probs, const float *iprobs);
451 
452  private:
453 
454  /** Branch survivors into new candidates. */
455  void branchCandidates();
456 
457  /** Compute cost metrics for soft-inputs. */
458  void getSoftCostMetrics(uint32_t inSample, const float *probs, const float *iprobs);
459 
460  /** Select survivors from the candidate set. */
461  void pruneCandidates();
462 
463  /** Find the minimum cost survivor. */
464  const vCand& minCost() const;
465 
466  /**
467  Precompute the state tables.
468  @param g Generator index 0..((1/rate)-1)
469  */
470  void computeStateTables(unsigned g);
471 
472  /**
473  Precompute the generator outputs.
474  mCoeffs must be defined first.
475  */
476  void computeGeneratorTable();
477  void encode(const BitVector &in, BitVector& target) const;
478  void decode(const SoftVector &in, BitVector& target);
479 
480 };
481 
482 
483 
484 /**
485  Class to represent recursive systematic convolutional coders/decoders of rate 1/4, memory length 4.
486 */
488 
489  private:
490  /**name Lots of precomputed elements so the compiler can optimize like hell. */
491  //@{
492  /**@name Core values. */
493  //@{
494  static const unsigned mIRate = 4; ///< reciprocal of rate
495  static const unsigned mOrder = 4; ///< memory length of generators
496  //@}
497  /**@name Derived values. */
498  //@{
499  static const unsigned mIStates = 0x01 << mOrder; ///< number of states, number of survivors
500  static const uint32_t mSMask = mIStates-1; ///< survivor mask
501  static const uint32_t mCMask = (mSMask<<1) | 0x01; ///< candidate mask
502  static const uint32_t mOMask = (0x01<<mIRate)-1; ///< ouput mask, all iRate low bits set
503  static const unsigned mNumCands = mIStates*2; ///< number of candidates to generate during branching
504  static const unsigned mDeferral = 6*mOrder; ///< deferral to be used
505  //@}
506  //@}
507 
508  /** Precomputed tables. */
509  //@{
510  uint32_t mCoeffs[mIRate]; ///< output polynomial for each generator
511  uint32_t mCoeffsFB[mIRate]; ///< feedback polynomial for each generator
512  uint32_t mStateTable[mIRate][2*mIStates]; ///< precomputed generator output tables
513  uint32_t mGeneratorTable[2*mIStates]; ///< precomputed coder output table
514  //@}
515 
516  public:
517 
518  /**
519  A candidate sequence in a Viterbi decoder.
520  The 32-bit state register can support a deferral of 6 with a 4th-order coder.
521  */
522  typedef struct candStruct {
523  uint32_t iState; ///< encoder input associated with this candidate
524  uint32_t oState; ///< encoder output associated with this candidate
525  char rState[mIRate];///< real states of encoders associated with this candidate
526  float cost; ///< cost (metric value), float to support soft inputs
527  } vCand;
528 
529  /** Clear a structure. */
530  void vitClear(vCand& v)
531  {
532  v.iState=0;
533  v.oState=0;
534  v.cost=0;
535  for (unsigned i = 0; i < mIRate; i++) v.rState[i] = 0;
536  }
537 
538 
539  private:
540 
541  /**@name Survivors and candidates. */
542  //@{
543  vCand mSurvivors[mIStates]; ///< current survivor pool
544  vCand mCandidates[2*mIStates]; ///< current candidate pool
545  //@}
546 
547  public:
548 
549  unsigned iRate() const { return mIRate; }
550  uint32_t cMask() const { return mCMask; }
551  uint32_t stateTable(unsigned g, unsigned i) const { return mStateTable[g][i]; }
552  unsigned deferral() const { return mDeferral; }
553 
554 
556 
557  /** Set all cost metrics to zero. */
559 
560  /**
561  Full cycle of the Viterbi algorithm: branch, metrics, prune, select.
562  @return reference to minimum-cost candidate.
563  */
564  const vCand& step(uint32_t inSample, const float *probs, const float *iprobs);
565 
566  private:
567 
568  /** Branch survivors into new candidates. */
569  void branchCandidates();
570 
571  /** Compute cost metrics for soft-inputs. */
572  void getSoftCostMetrics(uint32_t inSample, const float *probs, const float *iprobs);
573 
574  /** Select survivors from the candidate set. */
575  void pruneCandidates();
576 
577  /** Find the minimum cost survivor. */
578  const vCand& minCost() const;
579 
580  /**
581  Precompute the state tables.
582  @param g Generator index 0..((1/rate)-1)
583  */
584  void computeStateTables(unsigned g);
585 
586  /**
587  Precompute the generator outputs.
588  mCoeffs must be defined first.
589  */
590  void computeGeneratorTable();
591  void encode(const BitVector &in, BitVector& target) const;
592  void decode(const SoftVector &in, BitVector& target);
593 
594 };
595 
596 
597 
598 /**
599  Class to represent recursive systematic convolutional coders/decoders of rate 1/4, memory length 6.
600 */
602 
603  private:
604  /**name Lots of precomputed elements so the compiler can optimize like hell. */
605  //@{
606  /**@name Core values. */
607  //@{
608  static const unsigned mIRate = 4; ///< reciprocal of rate
609  static const unsigned mOrder = 6; ///< memory length of generators
610  //@}
611  /**@name Derived values. */
612  //@{
613  static const unsigned mIStates = 0x01 << mOrder; ///< number of states, number of survivors
614  static const uint32_t mSMask = mIStates-1; ///< survivor mask
615  static const uint32_t mCMask = (mSMask<<1) | 0x01; ///< candidate mask
616  static const uint32_t mOMask = (0x01<<mIRate)-1; ///< ouput mask, all iRate low bits set
617  static const unsigned mNumCands = mIStates*2; ///< number of candidates to generate during branching
618  static const unsigned mDeferral = 5*mOrder; ///< deferral to be used
619  //@}
620  //@}
621 
622  /** Precomputed tables. */
623  //@{
624  uint32_t mCoeffs[mIRate]; ///< output polynomial for each generator
625  uint32_t mCoeffsFB[mIRate]; ///< feedback polynomial for each generator
626  uint32_t mStateTable[mIRate][2*mIStates]; ///< precomputed generator output tables
627  uint32_t mGeneratorTable[2*mIStates]; ///< precomputed coder output table
628  //@}
629 
630  public:
631 
632  /**
633  A candidate sequence in a Viterbi decoder.
634  The 32-bit state register can support a deferral of 5*order with a 6th-order coder.
635  */
636  typedef struct candStruct {
637  uint32_t iState; ///< encoder input associated with this candidate
638  uint32_t oState; ///< encoder output associated with this candidate
639  char rState[mIRate];///< real states of encoders associated with this candidate
640  float cost; ///< cost (metric value), float to support soft inputs
641  } vCand;
642 
643  /** Clear a structure. */
644  void vitClear(vCand& v)
645  {
646  v.iState=0;
647  v.oState=0;
648  v.cost=0;
649  for (unsigned i = 0; i < mIRate; i++) v.rState[i] = 0;
650  }
651 
652 
653  private:
654 
655  /**@name Survivors and candidates. */
656  //@{
657  vCand mSurvivors[mIStates]; ///< current survivor pool
658  vCand mCandidates[2*mIStates]; ///< current candidate pool
659  //@}
660 
661  public:
662 
663  unsigned iRate() const { return mIRate; }
664  uint32_t cMask() const { return mCMask; }
665  uint32_t stateTable(unsigned g, unsigned i) const { return mStateTable[g][i]; }
666  unsigned deferral() const { return mDeferral; }
667 
668 
670 
671  /** Set all cost metrics to zero. */
673 
674  /**
675  Full cycle of the Viterbi algorithm: branch, metrics, prune, select.
676  @return reference to minimum-cost candidate.
677  */
678  const vCand& step(uint32_t inSample, const float *probs, const float *iprobs);
679 
680  private:
681 
682  /** Branch survivors into new candidates. */
683  void branchCandidates();
684 
685  /** Compute cost metrics for soft-inputs. */
686  void getSoftCostMetrics(uint32_t inSample, const float *probs, const float *iprobs);
687 
688  /** Select survivors from the candidate set. */
689  void pruneCandidates();
690 
691  /** Find the minimum cost survivor. */
692  const vCand& minCost() const;
693 
694  /**
695  Precompute the state tables.
696  @param g Generator index 0..((1/rate)-1)
697  */
698  void computeStateTables(unsigned g);
699 
700  /**
701  Precompute the generator outputs.
702  mCoeffs must be defined first.
703  */
704  void computeGeneratorTable();
705  void encode(const BitVector &in, BitVector& target) const;
706  void decode(const SoftVector &in, BitVector& target);
707 
708 };
709 
710 
711 
712 /**
713  Class to represent recursive systematic convolutional coders/decoders of rate 1/5, memory length 4.
714 */
716 
717  private:
718  /**name Lots of precomputed elements so the compiler can optimize like hell. */
719  //@{
720  /**@name Core values. */
721  //@{
722  static const unsigned mIRate = 5; ///< reciprocal of rate
723  static const unsigned mOrder = 4; ///< memory length of generators
724  //@}
725  /**@name Derived values. */
726  //@{
727  static const unsigned mIStates = 0x01 << mOrder; ///< number of states, number of survivors
728  static const uint32_t mSMask = mIStates-1; ///< survivor mask
729  static const uint32_t mCMask = (mSMask<<1) | 0x01; ///< candidate mask
730  static const uint32_t mOMask = (0x01<<mIRate)-1; ///< ouput mask, all iRate low bits set
731  static const unsigned mNumCands = mIStates*2; ///< number of candidates to generate during branching
732  static const unsigned mDeferral = 6*mOrder; ///< deferral to be used
733  //@}
734  //@}
735 
736  /** Precomputed tables. */
737  //@{
738  uint32_t mCoeffs[mIRate]; ///< output polynomial for each generator
739  uint32_t mCoeffsFB[mIRate]; ///< feedback polynomial for each generator
740  uint32_t mStateTable[mIRate][2*mIStates]; ///< precomputed generator output tables
741  uint32_t mGeneratorTable[2*mIStates]; ///< precomputed coder output table
742  //@}
743 
744  public:
745 
746  /**
747  A candidate sequence in a Viterbi decoder.
748  The 32-bit state register can support a deferral of 6 with a 4th-order coder.
749  */
750  typedef struct candStruct {
751  uint32_t iState; ///< encoder input associated with this candidate
752  uint32_t oState; ///< encoder output associated with this candidate
753  char rState[mIRate];///< real states of encoders associated with this candidate
754  float cost; ///< cost (metric value), float to support soft inputs
755  } vCand;
756 
757  /** Clear a structure. */
758  void vitClear(vCand& v)
759  {
760  v.iState=0;
761  v.oState=0;
762  v.cost=0;
763  for (unsigned i = 0; i < mIRate; i++) v.rState[i] = 0;
764  }
765 
766 
767  private:
768 
769  /**@name Survivors and candidates. */
770  //@{
771  vCand mSurvivors[mIStates]; ///< current survivor pool
772  vCand mCandidates[2*mIStates]; ///< current candidate pool
773  //@}
774 
775  public:
776 
777  unsigned iRate() const { return mIRate; }
778  uint32_t cMask() const { return mCMask; }
779  uint32_t stateTable(unsigned g, unsigned i) const { return mStateTable[g][i]; }
780  unsigned deferral() const { return mDeferral; }
781 
782 
784 
785  /** Set all cost metrics to zero. */
787 
788  /**
789  Full cycle of the Viterbi algorithm: branch, metrics, prune, select.
790  @return reference to minimum-cost candidate.
791  */
792  const vCand& step(uint32_t inSample, const float *probs, const float *iprobs);
793 
794  private:
795 
796  /** Branch survivors into new candidates. */
797  void branchCandidates();
798 
799  /** Compute cost metrics for soft-inputs. */
800  void getSoftCostMetrics(uint32_t inSample, const float *probs, const float *iprobs);
801 
802  /** Select survivors from the candidate set. */
803  void pruneCandidates();
804 
805  /** Find the minimum cost survivor. */
806  const vCand& minCost() const;
807 
808  /**
809  Precompute the state tables.
810  @param g Generator index 0..((1/rate)-1)
811  */
812  void computeStateTables(unsigned g);
813 
814  /**
815  Precompute the generator outputs.
816  mCoeffs must be defined first.
817  */
818  void computeGeneratorTable();
819  void encode(const BitVector &in, BitVector& target) const;
820  void decode(const SoftVector &in, BitVector& target);
821 
822 };
823 
824 
825 
826 /**
827  Class to represent recursive systematic convolutional coders/decoders of rate 1/5, memory length 6.
828 */
830 
831  private:
832  /**name Lots of precomputed elements so the compiler can optimize like hell. */
833  //@{
834  /**@name Core values. */
835  //@{
836  static const unsigned mIRate = 5; ///< reciprocal of rate
837  static const unsigned mOrder = 6; ///< memory length of generators
838  //@}
839  /**@name Derived values. */
840  //@{
841  static const unsigned mIStates = 0x01 << mOrder; ///< number of states, number of survivors
842  static const uint32_t mSMask = mIStates-1; ///< survivor mask
843  static const uint32_t mCMask = (mSMask<<1) | 0x01; ///< candidate mask
844  static const uint32_t mOMask = (0x01<<mIRate)-1; ///< ouput mask, all iRate low bits set
845  static const unsigned mNumCands = mIStates*2; ///< number of candidates to generate during branching
846  static const unsigned mDeferral = 5*mOrder; ///< deferral to be used
847  //@}
848  //@}
849 
850  /** Precomputed tables. */
851  //@{
852  uint32_t mCoeffs[mIRate]; ///< output polynomial for each generator
853  uint32_t mCoeffsFB[mIRate]; ///< feedback polynomial for each generator
854  uint32_t mStateTable[mIRate][2*mIStates]; ///< precomputed generator output tables
855  uint32_t mGeneratorTable[2*mIStates]; ///< precomputed coder output table
856  //@}
857 
858  public:
859 
860  /**
861  A candidate sequence in a Viterbi decoder.
862  The 32-bit state register can support a deferral of 5*order with a 6th-order coder.
863  */
864  typedef struct candStruct {
865  uint32_t iState; ///< encoder input associated with this candidate
866  uint32_t oState; ///< encoder output associated with this candidate
867  char rState[mIRate];///< real states of encoders associated with this candidate
868  float cost; ///< cost (metric value), float to support soft inputs
869  } vCand;
870 
871  /** Clear a structure. */
872  void vitClear(vCand& v)
873  {
874  v.iState=0;
875  v.oState=0;
876  v.cost=0;
877  for (unsigned i = 0; i < mIRate; i++) v.rState[i] = 0;
878  }
879 
880 
881  private:
882 
883  /**@name Survivors and candidates. */
884  //@{
885  vCand mSurvivors[mIStates]; ///< current survivor pool
886  vCand mCandidates[2*mIStates]; ///< current candidate pool
887  //@}
888 
889  public:
890 
891  unsigned iRate() const { return mIRate; }
892  uint32_t cMask() const { return mCMask; }
893  uint32_t stateTable(unsigned g, unsigned i) const { return mStateTable[g][i]; }
894  unsigned deferral() const { return mDeferral; }
895 
896 
898 
899  /** Set all cost metrics to zero. */
901 
902  /**
903  Full cycle of the Viterbi algorithm: branch, metrics, prune, select.
904  @return reference to minimum-cost candidate.
905  */
906  const vCand& step(uint32_t inSample, const float *probs, const float *iprobs);
907 
908  private:
909 
910  /** Branch survivors into new candidates. */
911  void branchCandidates();
912 
913  /** Compute cost metrics for soft-inputs. */
914  void getSoftCostMetrics(uint32_t inSample, const float *probs, const float *iprobs);
915 
916  /** Select survivors from the candidate set. */
917  void pruneCandidates();
918 
919  /** Find the minimum cost survivor. */
920  const vCand& minCost() const;
921 
922  /**
923  Precompute the state tables.
924  @param g Generator index 0..((1/rate)-1)
925  */
926  void computeStateTables(unsigned g);
927 
928  /**
929  Precompute the generator outputs.
930  mCoeffs must be defined first.
931  */
932  void computeGeneratorTable();
933  void encode(const BitVector &in, BitVector& target) const;
934  void decode(const SoftVector &in, BitVector& target);
935 
936 };
937 
938 
939 
940 
941 #endif
ViterbiTCH_AFS5_15::step
const vCand & step(uint32_t inSample, const float *probs, const float *iprobs)
ViterbiTCH_AFS7_4
Definition: AmrCoder.h:373
ViterbiTCH_AFS5_15::candStruct
Definition: AmrCoder.h:750
ViterbiTCH_AFS7_95::vitClear
void vitClear(vCand &v)
Definition: AmrCoder.h:302
ViterbiTCH_AFS5_15::candStruct::iState
uint32_t iState
encoder input associated with this candidate
Definition: AmrCoder.h:751
ViterbiTCH_AFS5_9
Definition: AmrCoder.h:601
ViterbiTCH_AFS6_7::candStruct::rState
char rState[mIRate]
real states of encoders associated with this candidate
Definition: AmrCoder.h:525
ViterbiTCH_AFS7_95::cMask
uint32_t cMask() const
Definition: AmrCoder.h:322
ViterbiTCH_AFS4_75::candStruct
Definition: AmrCoder.h:864
ViterbiTCH_AFS7_95::candStruct
Definition: AmrCoder.h:294
ViterbiTCH_AFS12_2::deferral
unsigned deferral() const
Definition: AmrCoder.h:97
ViterbiTCH_AFS12_2::stateTable
uint32_t stateTable(unsigned g, unsigned i) const
Definition: AmrCoder.h:96
ViterbiTCH_AFS5_9::vitClear
void vitClear(vCand &v)
Definition: AmrCoder.h:644
ViterbiTCH_AFS5_15::deferral
unsigned deferral() const
Definition: AmrCoder.h:780
ViterbiTCH_AFS7_4::candStruct::cost
float cost
cost (metric value), float to support soft inputs
Definition: AmrCoder.h:412
ViterbiTCH_AFS12_2::iRate
unsigned iRate() const
Definition: AmrCoder.h:94
ViterbiTCH_AFS6_7::stateTable
uint32_t stateTable(unsigned g, unsigned i) const
Definition: AmrCoder.h:551
BitVector
Definition: BitVector.h:116
ViterbiTCH_AFS4_75::vCand
struct ViterbiTCH_AFS4_75::candStruct vCand
ViterbiTCH_AFS10_2::candStruct::rState
char rState[mIRate]
real states of encoders associated with this candidate
Definition: AmrCoder.h:183
ViterbiTCH_AFS12_2::vCand
struct ViterbiTCH_AFS12_2::candStruct vCand
ViterbiTCH_AFS5_9::candStruct::rState
char rState[mIRate]
real states of encoders associated with this candidate
Definition: AmrCoder.h:639
ViterbiTCH_AFS12_2::vitClear
void vitClear(vCand &v)
Definition: AmrCoder.h:75
ViterbiTCH_AFS7_4::vitClear
void vitClear(vCand &v)
Definition: AmrCoder.h:416
ViterbiTCH_AFS6_7::deferral
unsigned deferral() const
Definition: AmrCoder.h:552
ViterbiTCH_AFS5_9::ViterbiTCH_AFS5_9
ViterbiTCH_AFS5_9()
ViterbiTCH_AFS5_9::candStruct
Definition: AmrCoder.h:636
ViterbiTCH_AFS5_9::vCand
struct ViterbiTCH_AFS5_9::candStruct vCand
ViterbiTCH_AFS5_9::step
const vCand & step(uint32_t inSample, const float *probs, const float *iprobs)
ViterbiTCH_AFS10_2::vCand
struct ViterbiTCH_AFS10_2::candStruct vCand
ViterbiTCH_AFS7_4::cMask
uint32_t cMask() const
Definition: AmrCoder.h:436
ViterbiTCH_AFS12_2::candStruct::cost
float cost
cost (metric value), float to support soft inputs
Definition: AmrCoder.h:71
ViterbiTCH_AFS7_4::initializeStates
void initializeStates()
ViterbiTCH_AFS7_4::ViterbiTCH_AFS7_4
ViterbiTCH_AFS7_4()
ViterbiTCH_AFS12_2::candStruct::iState
uint32_t iState
encoder input associated with this candidate
Definition: AmrCoder.h:68
ViterbiTCH_AFS7_95::candStruct::cost
float cost
cost (metric value), float to support soft inputs
Definition: AmrCoder.h:298
ViterbiTCH_AFS7_95::stateTable
uint32_t stateTable(unsigned g, unsigned i) const
Definition: AmrCoder.h:323
ViterbiTCH_AFS12_2::initializeStates
void initializeStates()
ViterbiTCH_AFS7_4::vCand
struct ViterbiTCH_AFS7_4::candStruct vCand
ViterbiTCH_AFS4_75::ViterbiTCH_AFS4_75
ViterbiTCH_AFS4_75()
ViterbiTCH_AFS5_9::cMask
uint32_t cMask() const
Definition: AmrCoder.h:664
ViterbiTCH_AFS10_2::initializeStates
void initializeStates()
ViterbiTCH_AFS6_7::candStruct::oState
uint32_t oState
encoder output associated with this candidate
Definition: AmrCoder.h:524
ViterbiTCH_AFS4_75::step
const vCand & step(uint32_t inSample, const float *probs, const float *iprobs)
ViterbiTCH_AFS5_15::candStruct::cost
float cost
cost (metric value), float to support soft inputs
Definition: AmrCoder.h:754
ViterbiTCH_AFS7_95::initializeStates
void initializeStates()
BitVector.h
ViterbiTCH_AFS5_9::candStruct::iState
uint32_t iState
encoder input associated with this candidate
Definition: AmrCoder.h:637
ViterbiTCH_AFS7_95
Definition: AmrCoder.h:259
ViterbiTCH_AFS6_7::iRate
unsigned iRate() const
Definition: AmrCoder.h:549
ViterbiTCH_AFS4_75::stateTable
uint32_t stateTable(unsigned g, unsigned i) const
Definition: AmrCoder.h:893
ViterbiTCH_AFS10_2::iRate
unsigned iRate() const
Definition: AmrCoder.h:207
ViterbiTCH_AFS5_15::candStruct::oState
uint32_t oState
encoder output associated with this candidate
Definition: AmrCoder.h:752
ViterbiTCH_AFS5_15
Definition: AmrCoder.h:715
ViterbiTCH_AFS6_7::candStruct::cost
float cost
cost (metric value), float to support soft inputs
Definition: AmrCoder.h:526
ViterbiTCH_AFS5_15::stateTable
uint32_t stateTable(unsigned g, unsigned i) const
Definition: AmrCoder.h:779
ViterbiTCH_AFS10_2::cMask
uint32_t cMask() const
Definition: AmrCoder.h:208
ViterbiTCH_AFS7_4::step
const vCand & step(uint32_t inSample, const float *probs, const float *iprobs)
ViterbiTCH_AFS6_7
Definition: AmrCoder.h:487
ViterbiTCH_AFS6_7::step
const vCand & step(uint32_t inSample, const float *probs, const float *iprobs)
ViterbiTCH_AFS4_75::iRate
unsigned iRate() const
Definition: AmrCoder.h:891
ViterbiTCH_AFS10_2::step
const vCand & step(uint32_t inSample, const float *probs, const float *iprobs)
ViterbiTCH_AFS5_15::candStruct::rState
char rState[mIRate]
real states of encoders associated with this candidate
Definition: AmrCoder.h:753
SoftVector
Definition: BitVector.h:328
ViterbiTCH_AFS5_9::deferral
unsigned deferral() const
Definition: AmrCoder.h:666
Viterbi.h
ViterbiTCH_AFS7_95::iRate
unsigned iRate() const
Definition: AmrCoder.h:321
ViterbiTCH_AFS12_2::candStruct::rState
char rState[mIRate]
real states of encoders associated with this candidate
Definition: AmrCoder.h:70
ViterbiTCH_AFS5_15::ViterbiTCH_AFS5_15
ViterbiTCH_AFS5_15()
ViterbiTCH_AFS10_2::ViterbiTCH_AFS10_2
ViterbiTCH_AFS10_2()
ViterbiTCH_AFS4_75::deferral
unsigned deferral() const
Definition: AmrCoder.h:894
ViterbiTCH_AFS4_75::candStruct::rState
char rState[mIRate]
real states of encoders associated with this candidate
Definition: AmrCoder.h:867
ViterbiTCH_AFS6_7::vitClear
void vitClear(vCand &v)
Definition: AmrCoder.h:530
ViterbiTCH_AFS6_7::candStruct
Definition: AmrCoder.h:522
ViterbiTCH_AFS5_9::initializeStates
void initializeStates()
ViterbiTCH_AFS6_7::cMask
uint32_t cMask() const
Definition: AmrCoder.h:550
ViterbiTCH_AFS5_15::cMask
uint32_t cMask() const
Definition: AmrCoder.h:778
ViterbiTCH_AFS12_2::ViterbiTCH_AFS12_2
ViterbiTCH_AFS12_2()
ViterbiTCH_AFS12_2::step
const vCand & step(uint32_t inSample, const float *probs, const float *iprobs)
ViterbiTCH_AFS5_9::iRate
unsigned iRate() const
Definition: AmrCoder.h:663
ViterbiTCH_AFS10_2::vitClear
void vitClear(vCand &v)
Definition: AmrCoder.h:188
ViterbiTCH_AFS7_4::iRate
unsigned iRate() const
Definition: AmrCoder.h:435
ViterbiTCH_AFS12_2::cMask
uint32_t cMask() const
Definition: AmrCoder.h:95
ViterbiTCH_AFS5_9::stateTable
uint32_t stateTable(unsigned g, unsigned i) const
Definition: AmrCoder.h:665
ViterbiTCH_AFS4_75::cMask
uint32_t cMask() const
Definition: AmrCoder.h:892
ViterbiTCH_AFS4_75
Definition: AmrCoder.h:829
ViterbiTCH_AFS7_4::candStruct::iState
uint32_t iState
encoder input associated with this candidate
Definition: AmrCoder.h:409
ViterbiTCH_AFS7_4::candStruct::oState
uint32_t oState
encoder output associated with this candidate
Definition: AmrCoder.h:410
ViterbiTCH_AFS6_7::candStruct::iState
uint32_t iState
encoder input associated with this candidate
Definition: AmrCoder.h:523
ViterbiTCH_AFS5_9::candStruct::oState
uint32_t oState
encoder output associated with this candidate
Definition: AmrCoder.h:638
ViterbiTCH_AFS10_2::candStruct
Definition: AmrCoder.h:180
ViterbiTCH_AFS10_2
Definition: AmrCoder.h:145
ViterbiTCH_AFS6_7::initializeStates
void initializeStates()
ViterbiTCH_AFS7_4::candStruct
Definition: AmrCoder.h:408
ViterbiTCH_AFS7_95::vCand
struct ViterbiTCH_AFS7_95::candStruct vCand
ViterbiTCH_AFS10_2::candStruct::cost
float cost
cost (metric value), float to support soft inputs
Definition: AmrCoder.h:184
ViterbiTCH_AFS5_15::initializeStates
void initializeStates()
ViterbiTCH_AFS10_2::stateTable
uint32_t stateTable(unsigned g, unsigned i) const
Definition: AmrCoder.h:209
ViterbiBase
Definition: Viterbi.h:26
ViterbiTCH_AFS12_2::candStruct::oState
uint32_t oState
encoder output associated with this candidate
Definition: AmrCoder.h:69
ViterbiTCH_AFS12_2
Definition: AmrCoder.h:32
ViterbiTCH_AFS4_75::vitClear
void vitClear(vCand &v)
Definition: AmrCoder.h:872
ViterbiTCH_AFS5_15::vCand
struct ViterbiTCH_AFS5_15::candStruct vCand
ViterbiTCH_AFS4_75::candStruct::iState
uint32_t iState
encoder input associated with this candidate
Definition: AmrCoder.h:865
ViterbiTCH_AFS4_75::initializeStates
void initializeStates()
ViterbiTCH_AFS10_2::candStruct::oState
uint32_t oState
encoder output associated with this candidate
Definition: AmrCoder.h:182
ViterbiTCH_AFS10_2::candStruct::iState
uint32_t iState
encoder input associated with this candidate
Definition: AmrCoder.h:181
ViterbiTCH_AFS7_4::stateTable
uint32_t stateTable(unsigned g, unsigned i) const
Definition: AmrCoder.h:437
ViterbiTCH_AFS4_75::candStruct::oState
uint32_t oState
encoder output associated with this candidate
Definition: AmrCoder.h:866
ViterbiTCH_AFS12_2::candStruct
Definition: AmrCoder.h:67
ViterbiTCH_AFS7_95::candStruct::oState
uint32_t oState
encoder output associated with this candidate
Definition: AmrCoder.h:296
ViterbiTCH_AFS7_4::candStruct::rState
char rState[mIRate]
real states of encoders associated with this candidate
Definition: AmrCoder.h:411
ViterbiTCH_AFS10_2::deferral
unsigned deferral() const
Definition: AmrCoder.h:210
ViterbiTCH_AFS7_95::deferral
unsigned deferral() const
Definition: AmrCoder.h:324
ViterbiTCH_AFS7_95::candStruct::rState
char rState[mIRate]
real states of encoders associated with this candidate
Definition: AmrCoder.h:297
ViterbiTCH_AFS7_4::deferral
unsigned deferral() const
Definition: AmrCoder.h:438
ViterbiTCH_AFS7_95::candStruct::iState
uint32_t iState
encoder input associated with this candidate
Definition: AmrCoder.h:295
ViterbiTCH_AFS7_95::step
const vCand & step(uint32_t inSample, const float *probs, const float *iprobs)
ViterbiTCH_AFS4_75::candStruct::cost
float cost
cost (metric value), float to support soft inputs
Definition: AmrCoder.h:868
ViterbiTCH_AFS5_15::iRate
unsigned iRate() const
Definition: AmrCoder.h:777
ViterbiTCH_AFS7_95::ViterbiTCH_AFS7_95
ViterbiTCH_AFS7_95()
ViterbiTCH_AFS6_7::ViterbiTCH_AFS6_7
ViterbiTCH_AFS6_7()
ViterbiTCH_AFS5_9::candStruct::cost
float cost
cost (metric value), float to support soft inputs
Definition: AmrCoder.h:640
ViterbiTCH_AFS6_7::vCand
struct ViterbiTCH_AFS6_7::candStruct vCand
ViterbiTCH_AFS5_15::vitClear
void vitClear(vCand &v)
Definition: AmrCoder.h:758