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