AmrCoder.h
Go to the documentation of this file.
/*
* Copyright 2013, 2014 Range Networks, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* This use of this software may be subject to additional restrictions.
* See the LEGAL file in the main directory for details.
*/
#ifndef _AMRCODER_H_
#define _AMRCODER_H_
#include <stdint.h>
#include "BitVector.h"
#include "Viterbi.h"
/**
Class to represent recursive systematic convolutional coders/decoders of rate 1/2, memory length 4.
*/
class ViterbiTCH_AFS12_2 : public ViterbiBase {
private:
/**name Lots of precomputed elements so the compiler can optimize like hell. */
//@{
/**@name Core values. */
//@{
static const unsigned mIRate = 2; ///< reciprocal of rate
static const unsigned mOrder = 4; ///< memory length of generators
//@}
/**@name Derived values. */
//@{
static const unsigned mIStates = 0x01 << mOrder; ///< number of states, number of survivors
static const uint32_t mSMask = mIStates-1; ///< survivor mask
static const uint32_t mCMask = (mSMask<<1) | 0x01; ///< candidate mask
static const uint32_t mOMask = (0x01<<mIRate)-1; ///< ouput mask, all iRate low bits set
static const unsigned mNumCands = mIStates*2; ///< number of candidates to generate during branching
static const unsigned mDeferral = 6*mOrder; ///< deferral to be used
//@}
//@}
/** Precomputed tables. */
//@{
uint32_t mCoeffs[mIRate]; ///< output polynomial for each generator
uint32_t mCoeffsFB[mIRate]; ///< feedback polynomial for each generator
uint32_t mStateTable[mIRate][2*mIStates]; ///< precomputed generator output tables
uint32_t mGeneratorTable[2*mIStates]; ///< precomputed coder output table
//@}
public:
/**
A candidate sequence in a Viterbi decoder.
The 32-bit state register can support a deferral of 6 with a 4th-order coder.
*/
typedef struct candStruct {
uint32_t iState; ///< encoder input associated with this candidate
uint32_t oState; ///< encoder output associated with this candidate
char rState[mIRate];///< real states of encoders associated with this candidate
float cost; ///< cost (metric value), float to support soft inputs
} vCand;
/** Clear a structure. */
void vitClear(vCand& v)
{
v.iState=0;
v.oState=0;
v.cost=0;
for (unsigned i = 0; i < mIRate; i++) v.rState[i] = 0;
}
private:
/**@name Survivors and candidates. */
//@{
vCand mSurvivors[mIStates]; ///< current survivor pool
vCand mCandidates[2*mIStates]; ///< current candidate pool
//@}
public:
unsigned iRate() const { return mIRate; }
uint32_t cMask() const { return mCMask; }
uint32_t stateTable(unsigned g, unsigned i) const { return mStateTable[g][i]; }
unsigned deferral() const { return mDeferral; }
ViterbiTCH_AFS12_2();
/** Set all cost metrics to zero. */
void initializeStates();
/**
Full cycle of the Viterbi algorithm: branch, metrics, prune, select.
@return reference to minimum-cost candidate.
*/
const vCand& step(uint32_t inSample, const float *probs, const float *iprobs);
private:
/** Branch survivors into new candidates. */
void branchCandidates();
/** Compute cost metrics for soft-inputs. */
void getSoftCostMetrics(uint32_t inSample, const float *probs, const float *iprobs);
/** Select survivors from the candidate set. */
void pruneCandidates();
/** Find the minimum cost survivor. */
const vCand& minCost() const;
/**
Precompute the state tables.
@param g Generator index 0..((1/rate)-1)
*/
void computeStateTables(unsigned g);
/**
Precompute the generator outputs.
mCoeffs must be defined first.
*/
void computeGeneratorTable();
void encode(const BitVector &in, BitVector& target) const;
void decode(const SoftVector &in, BitVector& target);
};
/**
Class to represent recursive systematic convolutional coders/decoders of rate 1/3, memory length 4.
*/
class ViterbiTCH_AFS10_2 : public ViterbiBase {
private:
/**name Lots of precomputed elements so the compiler can optimize like hell. */
//@{
/**@name Core values. */
//@{
static const unsigned mIRate = 3; ///< reciprocal of rate
static const unsigned mOrder = 4; ///< memory length of generators
//@}
/**@name Derived values. */
//@{
static const unsigned mIStates = 0x01 << mOrder; ///< number of states, number of survivors
static const uint32_t mSMask = mIStates-1; ///< survivor mask
static const uint32_t mCMask = (mSMask<<1) | 0x01; ///< candidate mask
static const uint32_t mOMask = (0x01<<mIRate)-1; ///< ouput mask, all iRate low bits set
static const unsigned mNumCands = mIStates*2; ///< number of candidates to generate during branching
static const unsigned mDeferral = 6*mOrder; ///< deferral to be used
//@}
//@}
/** Precomputed tables. */
//@{
uint32_t mCoeffs[mIRate]; ///< output polynomial for each generator
uint32_t mCoeffsFB[mIRate]; ///< feedback polynomial for each generator
uint32_t mStateTable[mIRate][2*mIStates]; ///< precomputed generator output tables
uint32_t mGeneratorTable[2*mIStates]; ///< precomputed coder output table
//@}
public:
/**
A candidate sequence in a Viterbi decoder.
The 32-bit state register can support a deferral of 6 with a 4th-order coder.
*/
typedef struct candStruct {
uint32_t iState; ///< encoder input associated with this candidate
uint32_t oState; ///< encoder output associated with this candidate
char rState[mIRate];///< real states of encoders associated with this candidate
float cost; ///< cost (metric value), float to support soft inputs
} vCand;
/** Clear a structure. */
void vitClear(vCand& v)
{
v.iState=0;
v.oState=0;
v.cost=0;
for (unsigned i = 0; i < mIRate; i++) v.rState[i] = 0;
}
private:
/**@name Survivors and candidates. */
//@{
vCand mSurvivors[mIStates]; ///< current survivor pool
vCand mCandidates[2*mIStates]; ///< current candidate pool
//@}
public:
unsigned iRate() const { return mIRate; }
uint32_t cMask() const { return mCMask; }
uint32_t stateTable(unsigned g, unsigned i) const { return mStateTable[g][i]; }
unsigned deferral() const { return mDeferral; }
ViterbiTCH_AFS10_2();
/** Set all cost metrics to zero. */
void initializeStates();
/**
Full cycle of the Viterbi algorithm: branch, metrics, prune, select.
@return reference to minimum-cost candidate.
*/
const vCand& step(uint32_t inSample, const float *probs, const float *iprobs);
private:
/** Branch survivors into new candidates. */
void branchCandidates();
/** Compute cost metrics for soft-inputs. */
void getSoftCostMetrics(uint32_t inSample, const float *probs, const float *iprobs);
/** Select survivors from the candidate set. */
void pruneCandidates();
/** Find the minimum cost survivor. */
const vCand& minCost() const;
/**
Precompute the state tables.
@param g Generator index 0..((1/rate)-1)
*/
void computeStateTables(unsigned g);
/**
Precompute the generator outputs.
mCoeffs must be defined first.
*/
void computeGeneratorTable();
void encode(const BitVector &in, BitVector& target) const;
void decode(const SoftVector &in, BitVector& target);
};
/**
Class to represent recursive systematic convolutional coders/decoders of rate 1/3, memory length 6.
*/
class ViterbiTCH_AFS7_95 : public ViterbiBase {
private:
/**name Lots of precomputed elements so the compiler can optimize like hell. */
//@{
/**@name Core values. */
//@{
static const unsigned mIRate = 3; ///< reciprocal of rate
static const unsigned mOrder = 6; ///< memory length of generators
//@}
/**@name Derived values. */
//@{
static const unsigned mIStates = 0x01 << mOrder; ///< number of states, number of survivors
static const uint32_t mSMask = mIStates-1; ///< survivor mask
static const uint32_t mCMask = (mSMask<<1) | 0x01; ///< candidate mask
static const uint32_t mOMask = (0x01<<mIRate)-1; ///< ouput mask, all iRate low bits set
static const unsigned mNumCands = mIStates*2; ///< number of candidates to generate during branching
static const unsigned mDeferral = 5*mOrder; ///< deferral to be used
//@}
//@}
/** Precomputed tables. */
//@{
uint32_t mCoeffs[mIRate]; ///< output polynomial for each generator
uint32_t mCoeffsFB[mIRate]; ///< feedback polynomial for each generator
uint32_t mStateTable[mIRate][2*mIStates]; ///< precomputed generator output tables
uint32_t mGeneratorTable[2*mIStates]; ///< precomputed coder output table
//@}
public:
/**
A candidate sequence in a Viterbi decoder.
The 32-bit state register can support a deferral of 5*order with a 6th-order coder.
*/
typedef struct candStruct {
uint32_t iState; ///< encoder input associated with this candidate
uint32_t oState; ///< encoder output associated with this candidate
char rState[mIRate];///< real states of encoders associated with this candidate
float cost; ///< cost (metric value), float to support soft inputs
} vCand;
/** Clear a structure. */
void vitClear(vCand& v)
{
v.iState=0;
v.oState=0;
v.cost=0;
for (unsigned i = 0; i < mIRate; i++) v.rState[i] = 0;
}
private:
/**@name Survivors and candidates. */
//@{
vCand mSurvivors[mIStates]; ///< current survivor pool
vCand mCandidates[2*mIStates]; ///< current candidate pool
//@}
public:
unsigned iRate() const { return mIRate; }
uint32_t cMask() const { return mCMask; }
uint32_t stateTable(unsigned g, unsigned i) const { return mStateTable[g][i]; }
unsigned deferral() const { return mDeferral; }
ViterbiTCH_AFS7_95();
/** Set all cost metrics to zero. */
void initializeStates();
/**
Full cycle of the Viterbi algorithm: branch, metrics, prune, select.
@return reference to minimum-cost candidate.
*/
const vCand& step(uint32_t inSample, const float *probs, const float *iprobs);
private:
/** Branch survivors into new candidates. */
void branchCandidates();
/** Compute cost metrics for soft-inputs. */
void getSoftCostMetrics(uint32_t inSample, const float *probs, const float *iprobs);
/** Select survivors from the candidate set. */
void pruneCandidates();
/** Find the minimum cost survivor. */
const vCand& minCost() const;
/**
Precompute the state tables.
@param g Generator index 0..((1/rate)-1)
*/
void computeStateTables(unsigned g);
/**
Precompute the generator outputs.
mCoeffs must be defined first.
*/
void computeGeneratorTable();
void encode(const BitVector &in, BitVector& target) const;
void decode(const SoftVector &in, BitVector& target);
};
/**
Class to represent recursive systematic convolutional coders/decoders of rate 1/3, memory length 4.
*/
class ViterbiTCH_AFS7_4 : public ViterbiBase {
private:
/**name Lots of precomputed elements so the compiler can optimize like hell. */
//@{
/**@name Core values. */
//@{
static const unsigned mIRate = 3; ///< reciprocal of rate
static const unsigned mOrder = 4; ///< memory length of generators
//@}
/**@name Derived values. */
//@{
static const unsigned mIStates = 0x01 << mOrder; ///< number of states, number of survivors
static const uint32_t mSMask = mIStates-1; ///< survivor mask
static const uint32_t mCMask = (mSMask<<1) | 0x01; ///< candidate mask
static const uint32_t mOMask = (0x01<<mIRate)-1; ///< ouput mask, all iRate low bits set
static const unsigned mNumCands = mIStates*2; ///< number of candidates to generate during branching
static const unsigned mDeferral = 6*mOrder; ///< deferral to be used
//@}
//@}
/** Precomputed tables. */
//@{
uint32_t mCoeffs[mIRate]; ///< output polynomial for each generator
uint32_t mCoeffsFB[mIRate]; ///< feedback polynomial for each generator
uint32_t mStateTable[mIRate][2*mIStates]; ///< precomputed generator output tables
uint32_t mGeneratorTable[2*mIStates]; ///< precomputed coder output table
//@}
public:
/**
A candidate sequence in a Viterbi decoder.
The 32-bit state register can support a deferral of 6 with a 4th-order coder.
*/
typedef struct candStruct {
uint32_t iState; ///< encoder input associated with this candidate
uint32_t oState; ///< encoder output associated with this candidate
char rState[mIRate];///< real states of encoders associated with this candidate
float cost; ///< cost (metric value), float to support soft inputs
} vCand;
/** Clear a structure. */
void vitClear(vCand& v)
{
v.iState=0;
v.oState=0;
v.cost=0;
for (unsigned i = 0; i < mIRate; i++) v.rState[i] = 0;
}
private:
/**@name Survivors and candidates. */
//@{
vCand mSurvivors[mIStates]; ///< current survivor pool
vCand mCandidates[2*mIStates]; ///< current candidate pool
//@}
public:
unsigned iRate() const { return mIRate; }
uint32_t cMask() const { return mCMask; }
uint32_t stateTable(unsigned g, unsigned i) const { return mStateTable[g][i]; }
unsigned deferral() const { return mDeferral; }
ViterbiTCH_AFS7_4();
/** Set all cost metrics to zero. */
void initializeStates();
/**
Full cycle of the Viterbi algorithm: branch, metrics, prune, select.
@return reference to minimum-cost candidate.
*/
const vCand& step(uint32_t inSample, const float *probs, const float *iprobs);
private:
/** Branch survivors into new candidates. */
void branchCandidates();
/** Compute cost metrics for soft-inputs. */
void getSoftCostMetrics(uint32_t inSample, const float *probs, const float *iprobs);
/** Select survivors from the candidate set. */
void pruneCandidates();
/** Find the minimum cost survivor. */
const vCand& minCost() const;
/**
Precompute the state tables.
@param g Generator index 0..((1/rate)-1)
*/
void computeStateTables(unsigned g);
/**
Precompute the generator outputs.
mCoeffs must be defined first.
*/
void computeGeneratorTable();
void encode(const BitVector &in, BitVector& target) const;
void decode(const SoftVector &in, BitVector& target);
};
/**
Class to represent recursive systematic convolutional coders/decoders of rate 1/4, memory length 4.
*/
class ViterbiTCH_AFS6_7 : public ViterbiBase {
private:
/**name Lots of precomputed elements so the compiler can optimize like hell. */
//@{
/**@name Core values. */
//@{
static const unsigned mIRate = 4; ///< reciprocal of rate
static const unsigned mOrder = 4; ///< memory length of generators
//@}
/**@name Derived values. */
//@{
static const unsigned mIStates = 0x01 << mOrder; ///< number of states, number of survivors
static const uint32_t mSMask = mIStates-1; ///< survivor mask
static const uint32_t mCMask = (mSMask<<1) | 0x01; ///< candidate mask
static const uint32_t mOMask = (0x01<<mIRate)-1; ///< ouput mask, all iRate low bits set
static const unsigned mNumCands = mIStates*2; ///< number of candidates to generate during branching
static const unsigned mDeferral = 6*mOrder; ///< deferral to be used
//@}
//@}
/** Precomputed tables. */
//@{
uint32_t mCoeffs[mIRate]; ///< output polynomial for each generator
uint32_t mCoeffsFB[mIRate]; ///< feedback polynomial for each generator
uint32_t mStateTable[mIRate][2*mIStates]; ///< precomputed generator output tables
uint32_t mGeneratorTable[2*mIStates]; ///< precomputed coder output table
//@}
public:
/**
A candidate sequence in a Viterbi decoder.
The 32-bit state register can support a deferral of 6 with a 4th-order coder.
*/
typedef struct candStruct {
uint32_t iState; ///< encoder input associated with this candidate
uint32_t oState; ///< encoder output associated with this candidate
char rState[mIRate];///< real states of encoders associated with this candidate
float cost; ///< cost (metric value), float to support soft inputs
} vCand;
/** Clear a structure. */
void vitClear(vCand& v)
{
v.iState=0;
v.oState=0;
v.cost=0;
for (unsigned i = 0; i < mIRate; i++) v.rState[i] = 0;
}
private:
/**@name Survivors and candidates. */
//@{
vCand mSurvivors[mIStates]; ///< current survivor pool
vCand mCandidates[2*mIStates]; ///< current candidate pool
//@}
public:
unsigned iRate() const { return mIRate; }
uint32_t cMask() const { return mCMask; }
uint32_t stateTable(unsigned g, unsigned i) const { return mStateTable[g][i]; }
unsigned deferral() const { return mDeferral; }
ViterbiTCH_AFS6_7();
/** Set all cost metrics to zero. */
void initializeStates();
/**
Full cycle of the Viterbi algorithm: branch, metrics, prune, select.
@return reference to minimum-cost candidate.
*/
const vCand& step(uint32_t inSample, const float *probs, const float *iprobs);
private:
/** Branch survivors into new candidates. */
void branchCandidates();
/** Compute cost metrics for soft-inputs. */
void getSoftCostMetrics(uint32_t inSample, const float *probs, const float *iprobs);
/** Select survivors from the candidate set. */
void pruneCandidates();
/** Find the minimum cost survivor. */
const vCand& minCost() const;
/**
Precompute the state tables.
@param g Generator index 0..((1/rate)-1)
*/
void computeStateTables(unsigned g);
/**
Precompute the generator outputs.
mCoeffs must be defined first.
*/
void computeGeneratorTable();
void encode(const BitVector &in, BitVector& target) const;
void decode(const SoftVector &in, BitVector& target);
};
/**
Class to represent recursive systematic convolutional coders/decoders of rate 1/4, memory length 6.
*/
class ViterbiTCH_AFS5_9 : public ViterbiBase {
private:
/**name Lots of precomputed elements so the compiler can optimize like hell. */
//@{
/**@name Core values. */
//@{
static const unsigned mIRate = 4; ///< reciprocal of rate
static const unsigned mOrder = 6; ///< memory length of generators
//@}
/**@name Derived values. */
//@{
static const unsigned mIStates = 0x01 << mOrder; ///< number of states, number of survivors
static const uint32_t mSMask = mIStates-1; ///< survivor mask
static const uint32_t mCMask = (mSMask<<1) | 0x01; ///< candidate mask
static const uint32_t mOMask = (0x01<<mIRate)-1; ///< ouput mask, all iRate low bits set
static const unsigned mNumCands = mIStates*2; ///< number of candidates to generate during branching
static const unsigned mDeferral = 5*mOrder; ///< deferral to be used
//@}
//@}
/** Precomputed tables. */
//@{
uint32_t mCoeffs[mIRate]; ///< output polynomial for each generator
uint32_t mCoeffsFB[mIRate]; ///< feedback polynomial for each generator
uint32_t mStateTable[mIRate][2*mIStates]; ///< precomputed generator output tables
uint32_t mGeneratorTable[2*mIStates]; ///< precomputed coder output table
//@}
public:
/**
A candidate sequence in a Viterbi decoder.
The 32-bit state register can support a deferral of 5*order with a 6th-order coder.
*/
typedef struct candStruct {
uint32_t iState; ///< encoder input associated with this candidate
uint32_t oState; ///< encoder output associated with this candidate
char rState[mIRate];///< real states of encoders associated with this candidate
float cost; ///< cost (metric value), float to support soft inputs
} vCand;
/** Clear a structure. */
void vitClear(vCand& v)
{
v.iState=0;
v.oState=0;
v.cost=0;
for (unsigned i = 0; i < mIRate; i++) v.rState[i] = 0;
}
private:
/**@name Survivors and candidates. */
//@{
vCand mSurvivors[mIStates]; ///< current survivor pool
vCand mCandidates[2*mIStates]; ///< current candidate pool
//@}
public:
unsigned iRate() const { return mIRate; }
uint32_t cMask() const { return mCMask; }
uint32_t stateTable(unsigned g, unsigned i) const { return mStateTable[g][i]; }
unsigned deferral() const { return mDeferral; }
ViterbiTCH_AFS5_9();
/** Set all cost metrics to zero. */
void initializeStates();
/**
Full cycle of the Viterbi algorithm: branch, metrics, prune, select.
@return reference to minimum-cost candidate.
*/
const vCand& step(uint32_t inSample, const float *probs, const float *iprobs);
private:
/** Branch survivors into new candidates. */
void branchCandidates();
/** Compute cost metrics for soft-inputs. */
void getSoftCostMetrics(uint32_t inSample, const float *probs, const float *iprobs);
/** Select survivors from the candidate set. */
void pruneCandidates();
/** Find the minimum cost survivor. */
const vCand& minCost() const;
/**
Precompute the state tables.
@param g Generator index 0..((1/rate)-1)
*/
void computeStateTables(unsigned g);
/**
Precompute the generator outputs.
mCoeffs must be defined first.
*/
void computeGeneratorTable();
void encode(const BitVector &in, BitVector& target) const;
void decode(const SoftVector &in, BitVector& target);
};
/**
Class to represent recursive systematic convolutional coders/decoders of rate 1/5, memory length 4.
*/
class ViterbiTCH_AFS5_15 : public ViterbiBase {
private:
/**name Lots of precomputed elements so the compiler can optimize like hell. */
//@{
/**@name Core values. */
//@{
static const unsigned mIRate = 5; ///< reciprocal of rate
static const unsigned mOrder = 4; ///< memory length of generators
//@}
/**@name Derived values. */
//@{
static const unsigned mIStates = 0x01 << mOrder; ///< number of states, number of survivors
static const uint32_t mSMask = mIStates-1; ///< survivor mask
static const uint32_t mCMask = (mSMask<<1) | 0x01; ///< candidate mask
static const uint32_t mOMask = (0x01<<mIRate)-1; ///< ouput mask, all iRate low bits set
static const unsigned mNumCands = mIStates*2; ///< number of candidates to generate during branching
static const unsigned mDeferral = 6*mOrder; ///< deferral to be used
//@}
//@}
/** Precomputed tables. */
//@{
uint32_t mCoeffs[mIRate]; ///< output polynomial for each generator
uint32_t mCoeffsFB[mIRate]; ///< feedback polynomial for each generator
uint32_t mStateTable[mIRate][2*mIStates]; ///< precomputed generator output tables
uint32_t mGeneratorTable[2*mIStates]; ///< precomputed coder output table
//@}
public:
/**
A candidate sequence in a Viterbi decoder.
The 32-bit state register can support a deferral of 6 with a 4th-order coder.
*/
typedef struct candStruct {
uint32_t iState; ///< encoder input associated with this candidate
uint32_t oState; ///< encoder output associated with this candidate
char rState[mIRate];///< real states of encoders associated with this candidate
float cost; ///< cost (metric value), float to support soft inputs
} vCand;
/** Clear a structure. */
void vitClear(vCand& v)
{
v.iState=0;
v.oState=0;
v.cost=0;
for (unsigned i = 0; i < mIRate; i++) v.rState[i] = 0;
}
private:
/**@name Survivors and candidates. */
//@{
vCand mSurvivors[mIStates]; ///< current survivor pool
vCand mCandidates[2*mIStates]; ///< current candidate pool
//@}
public:
unsigned iRate() const { return mIRate; }
uint32_t cMask() const { return mCMask; }
uint32_t stateTable(unsigned g, unsigned i) const { return mStateTable[g][i]; }
unsigned deferral() const { return mDeferral; }
ViterbiTCH_AFS5_15();
/** Set all cost metrics to zero. */
void initializeStates();
/**
Full cycle of the Viterbi algorithm: branch, metrics, prune, select.
@return reference to minimum-cost candidate.
*/
const vCand& step(uint32_t inSample, const float *probs, const float *iprobs);
private:
/** Branch survivors into new candidates. */
void branchCandidates();
/** Compute cost metrics for soft-inputs. */
void getSoftCostMetrics(uint32_t inSample, const float *probs, const float *iprobs);
/** Select survivors from the candidate set. */
void pruneCandidates();
/** Find the minimum cost survivor. */
const vCand& minCost() const;
/**
Precompute the state tables.
@param g Generator index 0..((1/rate)-1)
*/
void computeStateTables(unsigned g);
/**
Precompute the generator outputs.
mCoeffs must be defined first.
*/
void computeGeneratorTable();
void encode(const BitVector &in, BitVector& target) const;
void decode(const SoftVector &in, BitVector& target);
};
/**
Class to represent recursive systematic convolutional coders/decoders of rate 1/5, memory length 6.
*/
class ViterbiTCH_AFS4_75 : public ViterbiBase {
private:
/**name Lots of precomputed elements so the compiler can optimize like hell. */
//@{
/**@name Core values. */
//@{
static const unsigned mIRate = 5; ///< reciprocal of rate
static const unsigned mOrder = 6; ///< memory length of generators
//@}
/**@name Derived values. */
//@{
static const unsigned mIStates = 0x01 << mOrder; ///< number of states, number of survivors
static const uint32_t mSMask = mIStates-1; ///< survivor mask
static const uint32_t mCMask = (mSMask<<1) | 0x01; ///< candidate mask
static const uint32_t mOMask = (0x01<<mIRate)-1; ///< ouput mask, all iRate low bits set
static const unsigned mNumCands = mIStates*2; ///< number of candidates to generate during branching
static const unsigned mDeferral = 5*mOrder; ///< deferral to be used
//@}
//@}
/** Precomputed tables. */
//@{
uint32_t mCoeffs[mIRate]; ///< output polynomial for each generator
uint32_t mCoeffsFB[mIRate]; ///< feedback polynomial for each generator
uint32_t mStateTable[mIRate][2*mIStates]; ///< precomputed generator output tables
uint32_t mGeneratorTable[2*mIStates]; ///< precomputed coder output table
//@}
public:
/**
A candidate sequence in a Viterbi decoder.
The 32-bit state register can support a deferral of 5*order with a 6th-order coder.
*/
typedef struct candStruct {
uint32_t iState; ///< encoder input associated with this candidate
uint32_t oState; ///< encoder output associated with this candidate
char rState[mIRate];///< real states of encoders associated with this candidate
float cost; ///< cost (metric value), float to support soft inputs
} vCand;
/** Clear a structure. */
void vitClear(vCand& v)
{
v.iState=0;
v.oState=0;
v.cost=0;
for (unsigned i = 0; i < mIRate; i++) v.rState[i] = 0;
}
private:
/**@name Survivors and candidates. */
//@{
vCand mSurvivors[mIStates]; ///< current survivor pool
vCand mCandidates[2*mIStates]; ///< current candidate pool
//@}
public:
unsigned iRate() const { return mIRate; }
uint32_t cMask() const { return mCMask; }
uint32_t stateTable(unsigned g, unsigned i) const { return mStateTable[g][i]; }
unsigned deferral() const { return mDeferral; }
ViterbiTCH_AFS4_75();
/** Set all cost metrics to zero. */
void initializeStates();
/**
Full cycle of the Viterbi algorithm: branch, metrics, prune, select.
@return reference to minimum-cost candidate.
*/
const vCand& step(uint32_t inSample, const float *probs, const float *iprobs);
private:
/** Branch survivors into new candidates. */
void branchCandidates();
/** Compute cost metrics for soft-inputs. */
void getSoftCostMetrics(uint32_t inSample, const float *probs, const float *iprobs);
/** Select survivors from the candidate set. */
void pruneCandidates();
/** Find the minimum cost survivor. */
const vCand& minCost() const;
/**
Precompute the state tables.
@param g Generator index 0..((1/rate)-1)
*/
void computeStateTables(unsigned g);
/**
Precompute the generator outputs.
mCoeffs must be defined first.
*/
void computeGeneratorTable();
void encode(const BitVector &in, BitVector& target) const;
void decode(const SoftVector &in, BitVector& target);
};
#endif
BitVector.h
Viterbi.h
BitVector
Definition BitVector.h:116
SoftVector
Definition BitVector.h:328
ViterbiBase
Definition Viterbi.h:26
ViterbiTCH_AFS10_2
Definition AmrCoder.h:145
ViterbiTCH_AFS10_2::stateTable
uint32_t stateTable(unsigned g, unsigned i) const
Definition AmrCoder.h:209
ViterbiTCH_AFS10_2::iRate
unsigned iRate() const
Definition AmrCoder.h:207
ViterbiTCH_AFS10_2::step
const vCand & step(uint32_t inSample, const float *probs, const float *iprobs)
ViterbiTCH_AFS10_2::initializeStates
void initializeStates()
ViterbiTCH_AFS10_2::vCand
struct ViterbiTCH_AFS10_2::candStruct vCand
ViterbiTCH_AFS10_2::ViterbiTCH_AFS10_2
ViterbiTCH_AFS10_2()
ViterbiTCH_AFS10_2::deferral
unsigned deferral() const
Definition AmrCoder.h:210
ViterbiTCH_AFS10_2::cMask
uint32_t cMask() const
Definition AmrCoder.h:208
ViterbiTCH_AFS10_2::vitClear
void vitClear(vCand &v)
Definition AmrCoder.h:188
ViterbiTCH_AFS12_2
Definition AmrCoder.h:32
ViterbiTCH_AFS12_2::cMask
uint32_t cMask() const
Definition AmrCoder.h:95
ViterbiTCH_AFS12_2::vitClear
void vitClear(vCand &v)
Definition AmrCoder.h:75
ViterbiTCH_AFS12_2::stateTable
uint32_t stateTable(unsigned g, unsigned i) const
Definition AmrCoder.h:96
ViterbiTCH_AFS12_2::deferral
unsigned deferral() const
Definition AmrCoder.h:97
ViterbiTCH_AFS12_2::initializeStates
void initializeStates()
ViterbiTCH_AFS12_2::ViterbiTCH_AFS12_2
ViterbiTCH_AFS12_2()
ViterbiTCH_AFS12_2::iRate
unsigned iRate() const
Definition AmrCoder.h:94
ViterbiTCH_AFS12_2::vCand
struct ViterbiTCH_AFS12_2::candStruct vCand
ViterbiTCH_AFS12_2::step
const vCand & step(uint32_t inSample, const float *probs, const float *iprobs)
ViterbiTCH_AFS4_75
Definition AmrCoder.h:829
ViterbiTCH_AFS4_75::stateTable
uint32_t stateTable(unsigned g, unsigned i) const
Definition AmrCoder.h:893
ViterbiTCH_AFS4_75::ViterbiTCH_AFS4_75
ViterbiTCH_AFS4_75()
ViterbiTCH_AFS4_75::initializeStates
void initializeStates()
ViterbiTCH_AFS4_75::cMask
uint32_t cMask() const
Definition AmrCoder.h:892
ViterbiTCH_AFS4_75::iRate
unsigned iRate() const
Definition AmrCoder.h:891
ViterbiTCH_AFS4_75::step
const vCand & step(uint32_t inSample, const float *probs, const float *iprobs)
ViterbiTCH_AFS4_75::deferral
unsigned deferral() const
Definition AmrCoder.h:894
ViterbiTCH_AFS4_75::vCand
struct ViterbiTCH_AFS4_75::candStruct vCand
ViterbiTCH_AFS4_75::vitClear
void vitClear(vCand &v)
Definition AmrCoder.h:872
ViterbiTCH_AFS5_15
Definition AmrCoder.h:715
ViterbiTCH_AFS5_15::ViterbiTCH_AFS5_15
ViterbiTCH_AFS5_15()
ViterbiTCH_AFS5_15::deferral
unsigned deferral() const
Definition AmrCoder.h:780
ViterbiTCH_AFS5_15::vitClear
void vitClear(vCand &v)
Definition AmrCoder.h:758
ViterbiTCH_AFS5_15::stateTable
uint32_t stateTable(unsigned g, unsigned i) const
Definition AmrCoder.h:779
ViterbiTCH_AFS5_15::cMask
uint32_t cMask() const
Definition AmrCoder.h:778
ViterbiTCH_AFS5_15::vCand
struct ViterbiTCH_AFS5_15::candStruct vCand
ViterbiTCH_AFS5_15::step
const vCand & step(uint32_t inSample, const float *probs, const float *iprobs)
ViterbiTCH_AFS5_15::initializeStates
void initializeStates()
ViterbiTCH_AFS5_15::iRate
unsigned iRate() const
Definition AmrCoder.h:777
ViterbiTCH_AFS5_9
Definition AmrCoder.h:601
ViterbiTCH_AFS5_9::ViterbiTCH_AFS5_9
ViterbiTCH_AFS5_9()
ViterbiTCH_AFS5_9::vCand
struct ViterbiTCH_AFS5_9::candStruct vCand
ViterbiTCH_AFS5_9::stateTable
uint32_t stateTable(unsigned g, unsigned i) const
Definition AmrCoder.h:665
ViterbiTCH_AFS5_9::step
const vCand & step(uint32_t inSample, const float *probs, const float *iprobs)
ViterbiTCH_AFS5_9::initializeStates
void initializeStates()
ViterbiTCH_AFS5_9::deferral
unsigned deferral() const
Definition AmrCoder.h:666
ViterbiTCH_AFS5_9::cMask
uint32_t cMask() const
Definition AmrCoder.h:664
ViterbiTCH_AFS5_9::vitClear
void vitClear(vCand &v)
Definition AmrCoder.h:644
ViterbiTCH_AFS5_9::iRate
unsigned iRate() const
Definition AmrCoder.h:663
ViterbiTCH_AFS6_7
Definition AmrCoder.h:487
ViterbiTCH_AFS6_7::vitClear
void vitClear(vCand &v)
Definition AmrCoder.h:530
ViterbiTCH_AFS6_7::vCand
struct ViterbiTCH_AFS6_7::candStruct vCand
ViterbiTCH_AFS6_7::initializeStates
void initializeStates()
ViterbiTCH_AFS6_7::cMask
uint32_t cMask() const
Definition AmrCoder.h:550
ViterbiTCH_AFS6_7::ViterbiTCH_AFS6_7
ViterbiTCH_AFS6_7()
ViterbiTCH_AFS6_7::step
const vCand & step(uint32_t inSample, const float *probs, const float *iprobs)
ViterbiTCH_AFS6_7::stateTable
uint32_t stateTable(unsigned g, unsigned i) const
Definition AmrCoder.h:551
ViterbiTCH_AFS6_7::iRate
unsigned iRate() const
Definition AmrCoder.h:549
ViterbiTCH_AFS6_7::deferral
unsigned deferral() const
Definition AmrCoder.h:552
ViterbiTCH_AFS7_4
Definition AmrCoder.h:373
ViterbiTCH_AFS7_4::cMask
uint32_t cMask() const
Definition AmrCoder.h:436
ViterbiTCH_AFS7_4::deferral
unsigned deferral() const
Definition AmrCoder.h:438
ViterbiTCH_AFS7_4::stateTable
uint32_t stateTable(unsigned g, unsigned i) const
Definition AmrCoder.h:437
ViterbiTCH_AFS7_4::ViterbiTCH_AFS7_4
ViterbiTCH_AFS7_4()
ViterbiTCH_AFS7_4::vCand
struct ViterbiTCH_AFS7_4::candStruct vCand
ViterbiTCH_AFS7_4::iRate
unsigned iRate() const
Definition AmrCoder.h:435
ViterbiTCH_AFS7_4::step
const vCand & step(uint32_t inSample, const float *probs, const float *iprobs)
ViterbiTCH_AFS7_4::initializeStates
void initializeStates()
ViterbiTCH_AFS7_4::vitClear
void vitClear(vCand &v)
Definition AmrCoder.h:416
ViterbiTCH_AFS7_95
Definition AmrCoder.h:259
ViterbiTCH_AFS7_95::vCand
struct ViterbiTCH_AFS7_95::candStruct vCand
ViterbiTCH_AFS7_95::deferral
unsigned deferral() const
Definition AmrCoder.h:324
ViterbiTCH_AFS7_95::cMask
uint32_t cMask() const
Definition AmrCoder.h:322
ViterbiTCH_AFS7_95::stateTable
uint32_t stateTable(unsigned g, unsigned i) const
Definition AmrCoder.h:323
ViterbiTCH_AFS7_95::initializeStates
void initializeStates()
ViterbiTCH_AFS7_95::ViterbiTCH_AFS7_95
ViterbiTCH_AFS7_95()
ViterbiTCH_AFS7_95::iRate
unsigned iRate() const
Definition AmrCoder.h:321
ViterbiTCH_AFS7_95::step
const vCand & step(uint32_t inSample, const float *probs, const float *iprobs)
ViterbiTCH_AFS7_95::vitClear
void vitClear(vCand &v)
Definition AmrCoder.h:302
ViterbiTCH_AFS10_2::candStruct
Definition AmrCoder.h:180
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_AFS10_2::candStruct::cost
float cost
cost (metric value), float to support soft inputs
Definition AmrCoder.h:184
ViterbiTCH_AFS10_2::candStruct::rState
char rState[mIRate]
real states of encoders associated with this candidate
Definition AmrCoder.h:183
ViterbiTCH_AFS12_2::candStruct
Definition AmrCoder.h:67
ViterbiTCH_AFS12_2::candStruct::rState
char rState[mIRate]
real states of encoders associated with this candidate
Definition AmrCoder.h:70
ViterbiTCH_AFS12_2::candStruct::cost
float cost
cost (metric value), float to support soft inputs
Definition AmrCoder.h:71
ViterbiTCH_AFS12_2::candStruct::iState
uint32_t iState
encoder input associated with this candidate
Definition AmrCoder.h:68
ViterbiTCH_AFS12_2::candStruct::oState
uint32_t oState
encoder output associated with this candidate
Definition AmrCoder.h:69
ViterbiTCH_AFS4_75::candStruct
Definition AmrCoder.h:864
ViterbiTCH_AFS4_75::candStruct::oState
uint32_t oState
encoder output associated with this candidate
Definition AmrCoder.h:866
ViterbiTCH_AFS4_75::candStruct::iState
uint32_t iState
encoder input associated with this candidate
Definition AmrCoder.h:865
ViterbiTCH_AFS4_75::candStruct::cost
float cost
cost (metric value), float to support soft inputs
Definition AmrCoder.h:868
ViterbiTCH_AFS4_75::candStruct::rState
char rState[mIRate]
real states of encoders associated with this candidate
Definition AmrCoder.h:867
ViterbiTCH_AFS5_15::candStruct
Definition AmrCoder.h:750
ViterbiTCH_AFS5_15::candStruct::cost
float cost
cost (metric value), float to support soft inputs
Definition AmrCoder.h:754
ViterbiTCH_AFS5_15::candStruct::oState
uint32_t oState
encoder output associated with this candidate
Definition AmrCoder.h:752
ViterbiTCH_AFS5_15::candStruct::rState
char rState[mIRate]
real states of encoders associated with this candidate
Definition AmrCoder.h:753
ViterbiTCH_AFS5_15::candStruct::iState
uint32_t iState
encoder input associated with this candidate
Definition AmrCoder.h:751
ViterbiTCH_AFS5_9::candStruct
Definition AmrCoder.h:636
ViterbiTCH_AFS5_9::candStruct::iState
uint32_t iState
encoder input associated with this candidate
Definition AmrCoder.h:637
ViterbiTCH_AFS5_9::candStruct::oState
uint32_t oState
encoder output associated with this candidate
Definition AmrCoder.h:638
ViterbiTCH_AFS5_9::candStruct::cost
float cost
cost (metric value), float to support soft inputs
Definition AmrCoder.h:640
ViterbiTCH_AFS5_9::candStruct::rState
char rState[mIRate]
real states of encoders associated with this candidate
Definition AmrCoder.h:639
ViterbiTCH_AFS6_7::candStruct
Definition AmrCoder.h:522
ViterbiTCH_AFS6_7::candStruct::iState
uint32_t iState
encoder input associated with this candidate
Definition AmrCoder.h:523
ViterbiTCH_AFS6_7::candStruct::oState
uint32_t oState
encoder output associated with this candidate
Definition AmrCoder.h:524
ViterbiTCH_AFS6_7::candStruct::cost
float cost
cost (metric value), float to support soft inputs
Definition AmrCoder.h:526
ViterbiTCH_AFS6_7::candStruct::rState
char rState[mIRate]
real states of encoders associated with this candidate
Definition AmrCoder.h:525
ViterbiTCH_AFS7_4::candStruct
Definition AmrCoder.h:408
ViterbiTCH_AFS7_4::candStruct::cost
float cost
cost (metric value), float to support soft inputs
Definition AmrCoder.h:412
ViterbiTCH_AFS7_4::candStruct::oState
uint32_t oState
encoder output associated with this candidate
Definition AmrCoder.h:410
ViterbiTCH_AFS7_4::candStruct::rState
char rState[mIRate]
real states of encoders associated with this candidate
Definition AmrCoder.h:411
ViterbiTCH_AFS7_4::candStruct::iState
uint32_t iState
encoder input associated with this candidate
Definition AmrCoder.h:409
ViterbiTCH_AFS7_95::candStruct
Definition AmrCoder.h:294
ViterbiTCH_AFS7_95::candStruct::iState
uint32_t iState
encoder input associated with this candidate
Definition AmrCoder.h:295
ViterbiTCH_AFS7_95::candStruct::rState
char rState[mIRate]
real states of encoders associated with this candidate
Definition AmrCoder.h:297
ViterbiTCH_AFS7_95::candStruct::cost
float cost
cost (metric value), float to support soft inputs
Definition AmrCoder.h:298
ViterbiTCH_AFS7_95::candStruct::oState
uint32_t oState
encoder output associated with this candidate
Definition AmrCoder.h:296