#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include "segCommon.h"
#include "segStdLib.h"
#include "segDecoder.h"
Data Structures | |
struct | node |
Node probability buffer storing SNPs and an ENP. More... | |
struct | StartNodeParameter |
Parameters realising rolling-SNP-array mechanism. More... | |
Defines | |
#define | ALLOC_ERR -2 |
Function return value when memory allocation failed. | |
#define | ERROR -1 |
Function return value when an error occurred. | |
#define | NO_ERROR 0 |
Function return value when the function was executed successfully. | |
#define | PERMIT_BOTH 0x03 |
Status for nodes that can be both start and end nodes (assigned by pre-cost partition). | |
#define | PERMIT_START 0x02 |
Status for nodes that can be only a start node (assigned by pre-cost partition). | |
#define | PERMIT_END 0x01 |
Status for nodes that can be only an end node (assigned by pre-cost partition). | |
#define | NO_PERMIT 0x00 |
Status for nodes that can be neither start nor end node (assigned by pre-cost partition). | |
Typedefs | |
typedef node | NODE |
Node probability buffer storing SNPs and an ENP. | |
typedef StartNodeParameter | SNP_PARAM |
Parameters realising rolling-SNP-array mechanism. | |
Functions | |
static int | firstPropagator (SEG_DP_ITEM **dpMat, NODE **prob, int t, SEG_SYNTAX_ITEM *nodeList, int breakPt, int maxDur, int numStates) |
Calculate SNP and determine best state transition for the first time frame. | |
static int | propagator (SEG_DP_ITEM **dpMat, NODE **prob, int t, SEG_SYNTAX_ITEM *nodeList, int breakPt, int maxDur, int numStates) |
Calculate SNP and determine best state transition. | |
static int | selector (SEG_DP_ITEM **dpMat, NODE **prob, int t, int numVecs, int sT, int maxDur, int *breakPt, double **spData, SEG_SYNTAX *synt, SEG_DEC_PARAM *decParam) |
Calculate ENP and determine best segment duration. | |
static int | lastPropagator (SEG_DP_ITEM **dpMat, NODE **prob, int t, SEG_SYNTAX_ITEM *nodeList, int breakPt, int maxDur, int numStates) |
Calculate ENP and determine best segment duration for the last frame. | |
static double | lastSelector (SEG_DP_ITEM **dpm, int t, int numStates, NODE **prob, SEG_SYNTAX_ITEM *nodeList) |
Selector for the last frame. | |
static long | startNodeProb (NODE **prob, int probIdx, int state, SEG_SYNTAX_ITEM *nodeList, int breakPt, int maxDur) |
Compute start node probability (SNP). | |
static int | endNodeProb (NODE **prob, int *probIdx, int curTime, SEG_SYNTAX_ITEM *nodeList, int *breakPt, int maxDur, double **spData, int vecSize, int targetVecSize, int sT, SEG_DEC_PARAM *decParam) |
Compute end node probability (ENP). | |
static double | segOutputProb (SEG_STATE *state, double **data, int vecSize, int targetVecSize, double **map, int sTime, int eTime) |
Compute linear-segment output probability. | |
static SNP_PARAM * | initDecoder (int maxDur) |
Initialise decoder parameters. | |
static int * | snpIdxPtr () |
Get index array to refer to SNP arrays. | |
static int | curSnpIdx () |
Get an index at the current time. | |
static int | incSnpIdx () |
Shunt (rotate) the index array for the next processing. | |
static SEG_DP_ITEM ** | allocDpHistory (int numStates, int numVecs) |
Allocate a node matrix for storing DP paths in the trellis. | |
static NODE * | allocNode (int maxDur) |
Allocate a NODE variable (to a state) that stores SNPs and ENP. | |
static void | freeNode (NODE **node) |
Free memory space for a specified NODE variable. | |
static void | freeAllNode (NODE **node, int numStates) |
Free memory space for all allocated NODE variables. | |
static void | preCostPartition (SEG_DP_ITEM **dpMat, int numStates, int numFrames, SEG_SYNTAX_ITEM *nodeList, int *breakPoint, int maxDur) |
Pre-cost partitioning for valid start and end nodes in the trellis. | |
static void | firstBackPropagation (SEG_DP_ITEM **dpMat, int numStates, SEG_SYNTAX_ITEM *nodeList, int t) |
Set "possible end-node" attribute to nodes at the end frame. | |
static void | backPropagation (SEG_DP_ITEM **dpMat, int numStates, SEG_SYNTAX_ITEM *nodeList, int breakPt, int t) |
Set "possible end-node" attribute to nodes in the trellis. | |
static void | finalBackPropagation (SEG_DP_ITEM **dpMat, int numStates, SEG_SYNTAX_ITEM *nodeList, int t) |
Set "possible end-node" attribute to nodes at the start frame. | |
static void | segDurExtension (SEG_DP_ITEM **dpMat, int numStates, SEG_SYNTAX_ITEM *nodeList, int *breakPoint, int maxDur, int t) |
Set "possible start-node" attribute to nodes in the trellis. | |
static int | compsnp (const void *node1, const void *node2) |
Compare the SNPs of two states at the current time frame. | |
static int | compenp (const void *node1, const void *node2) |
Compare the ENPs of two states at the current time frame. | |
static void | prunStartNode (NODE **node, SEG_SYNTAX *syntax, SEG_DEC_PARAM *decParam) |
Start node pruning. | |
static void | prunEndNode (NODE **node, SEG_SYNTAX *syntax, SEG_DEC_PARAM *decParam) |
End node pruning. | |
double | segViterbiDecoder (SEG_DP_ITEM ***dpHist, SEG_SYNTAX *synt, double **spData, int *breakPt, int sT, int eT, int maxDur, SEG_DEC_PARAM *decParam) |
Generic Viterbi-type decorder for segmental HMMs. | |
int | segFreeDecoder (SEG_DP_ITEM **dpHist, int numStates) |
Free memory space storing all the paths in the trellis. | |
Variables | |
static SNP_PARAM | snpParam = {NULL,NULL,0,0} |
static SEG_DP_ITEM ** allocDpHistory | ( | int | numStates, | |
int | numVecs | |||
) | [static] |
Allocate a node matrix for storing DP paths in the trellis.
[in] | numStates | Number of states |
[in] | numVecs | Number of frames |
NULL | Memory allocation error | |
Otherwise | Pointer to the allocated paths history matrix |
static NODE * allocNode | ( | int | maxDur | ) | [static] |
Allocate a NODE variable (to a state) that stores SNPs and ENP.
[in] | maxDur | Maximal segment-duration |
static void backPropagation | ( | SEG_DP_ITEM ** | dpMat, | |
int | numStates, | |||
SEG_SYNTAX_ITEM * | nodeList, | |||
int | breakPt, | |||
int | t | |||
) | [static] |
Set "possible end-node" attribute to nodes in the trellis.
[in,out] | dpMat | Paths in the trellis for back-tracing |
[in] | numStates | Number of states |
[in] | nodeList | Node list in the syntax |
[in] | breakPt | Break point array |
[in] | t | Time (frame #) |
static int compenp | ( | const void * | node1, | |
const void * | node2 | |||
) | [static] |
Compare the ENPs of two states at the current time frame.
[in] | node1 | Pointer to SNPs and ENP buffer |
[in] | node2 | Pointer to SNPs and ENP buffer |
static int compsnp | ( | const void * | node1, | |
const void * | node2 | |||
) | [static] |
Compare the SNPs of two states at the current time frame.
[in] | node1 | Pointer to SNPs and ENP buffer |
[in] | node2 | Pointer to SNPs and ENP buffer |
static int curSnpIdx | ( | ) | [static] |
Get an index at the current time.
static int endNodeProb | ( | NODE ** | prob, | |
int * | probIdx, | |||
int | curTime, | |||
SEG_SYNTAX_ITEM * | nodeList, | |||
int * | breakPt, | |||
int | maxDur, | |||
double ** | spData, | |||
int | vecSize, | |||
int | targetVecSize, | |||
int | sT, | |||
SEG_DEC_PARAM * | decParam | |||
) | [static] |
Compute end node probability (ENP).
[out] | prob | Pointer array pointing SNPs and ENP buffer |
[in] | probIdx | Indeces to retrieve the current SNP array |
[in] | curTime | Current time (frame #) |
[in] | nodeList | Node list in the syntax |
[in] | breakPt | Break point array |
[in] | maxDur | Maximal segment-duration |
[in] | spData | Feature vectors of utterance |
[in] | vecSize | Dimension of feature vectors |
[in] | targetVecSize | Dimension of target/articulatory vectors |
[in] | sT | Start time in spData |
[in] | decParam | Decoder parameters |
static void finalBackPropagation | ( | SEG_DP_ITEM ** | dpMat, | |
int | numStates, | |||
SEG_SYNTAX_ITEM * | nodeList, | |||
int | t | |||
) | [static] |
Set "possible end-node" attribute to nodes at the start frame.
[in,out] | dpMat | Paths in the trellis for back-tracing |
[in] | numStates | Number of states |
[in] | nodeList | Node list in the syntax |
[in] | t | Time (frame #) |
static void firstBackPropagation | ( | SEG_DP_ITEM ** | dpMat, | |
int | numStates, | |||
SEG_SYNTAX_ITEM * | nodeList, | |||
int | t | |||
) | [static] |
Set "possible end-node" attribute to nodes at the end frame.
[in,out] | dpMat | Paths in the trellis for back-tracing |
[in] | numStates | Number of states |
[in] | nodeList | Node list in the syntax |
[in] | t | Time (frame #) |
static int firstPropagator | ( | SEG_DP_ITEM ** | dpMat, | |
NODE ** | prob, | |||
int | t, | |||
SEG_SYNTAX_ITEM * | nodeList, | |||
int | breakPt, | |||
int | maxDur, | |||
int | numStates | |||
) | [static] |
Calculate SNP and determine best state transition for the first time frame.
[out] | dpMat | Paths in the trellis for back-tracing |
[out] | prob | Pointer array pointing SNPs and ENP buffer |
[in] | t | Cuurent time (frame #) |
[in] | nodeList | Node list in syntax |
[in] | breakPt | Break point at time t |
[in] | maxDur | Maximal segment-duration |
[in] | numStates | Number of states |
ERROR | Memory allocation error | |
NO_ERROR | Successfully executed |
static void freeAllNode | ( | NODE ** | node, | |
int | numStates | |||
) | [static] |
Free memory space for all allocated NODE variables.
[in] | node | SNPs and ENP storage for all states |
[in] | numStates | Number of states |
static void freeNode | ( | NODE ** | node | ) | [static] |
Free memory space for a specified NODE variable.
[in] | node | SNPs and ENP storage for a state |
static int incSnpIdx | ( | ) | [static] |
Shunt (rotate) the index array for the next processing.
static SNP_PARAM * initDecoder | ( | int | maxDur | ) | [static] |
Initialise decoder parameters.
[in] | maxDur | Maximal segment-duration |
NULL | Memory allocation error | |
otherwise | Pointer to the allocated array |
static int lastPropagator | ( | SEG_DP_ITEM ** | dpMat, | |
NODE ** | prob, | |||
int | t, | |||
SEG_SYNTAX_ITEM * | nodeList, | |||
int | breakPt, | |||
int | maxDur, | |||
int | numStates | |||
) | [static] |
Calculate ENP and determine best segment duration for the last frame.
[out] | dpMat | Paths in the trellis for back-tracing |
[out] | prob | Pointer array pointing SNPs and ENP buffer |
[in] | t | Cuurent time (frame #) |
[in] | nodeList | Node list in the syntax |
[in] | breakPt | Break point at time t |
[in] | maxDur | Maximal segment-duration |
[in] | numStates | Number of states in the syntax |
ERROR | Memory allocation error | |
NO_ERROR | Successfully executed |
static double lastSelector | ( | SEG_DP_ITEM ** | dpm, | |
int | t, | |||
int | numStates, | |||
NODE ** | prob, | |||
SEG_SYNTAX_ITEM * | nodeList | |||
) | [static] |
Selector for the last frame.
[out] | dpm | Paths in the trellis for back-tracing |
[in] | t | Cuurent time (frame #) |
[in] | numStates | Number of states in the syntax |
[in] | prob | Pointer array pointing SNPs and ENP buffer |
[in] | nodeList | Node list in the syntax |
ERROR | Memory allocation error | |
NO_ERROR | Successfully executed |
static void preCostPartition | ( | SEG_DP_ITEM ** | dpMat, | |
int | numStates, | |||
int | numFrames, | |||
SEG_SYNTAX_ITEM * | nodeList, | |||
int * | breakPoint, | |||
int | maxDur | |||
) | [static] |
Pre-cost partitioning for valid start and end nodes in the trellis.
[in,out] | dpMat | Paths in the trellis for back-tracing |
[in] | numStates | Number of states |
[in] | numFrames | Number of frames of feature vectors |
[in] | nodeList | Node list in the syntax |
[in] | breakPoint | Break point array |
[in] | maxDur | Maxmal segment-duration |
static int propagator | ( | SEG_DP_ITEM ** | dpMat, | |
NODE ** | prob, | |||
int | t, | |||
SEG_SYNTAX_ITEM * | nodeList, | |||
int | breakPt, | |||
int | maxDur, | |||
int | numStates | |||
) | [static] |
Calculate SNP and determine best state transition.
[out] | dpMat | Paths in the trellis for back-tracing |
[out] | prob | Pointer array pointing SNPs and ENP buffer |
[in] | t | Cuurent time (frame #) |
[in] | nodeList | Node list in syntax |
[in] | breakPt | Break point at time t |
[in] | maxDur | Maximal segment-duration |
[in] | numStates | Number of states |
ERROR | Memory allocation error | |
NO_ERROR | Successfully executed |
static void prunEndNode | ( | NODE ** | node, | |
SEG_SYNTAX * | syntax, | |||
SEG_DEC_PARAM * | decParam | |||
) | [static] |
End node pruning.
[out] | node | Pointer array pointing SNPs and ENP buffer |
[in] | syntax | Syntax |
[in] | decParam | Decoder parameters |
static void prunStartNode | ( | NODE ** | node, | |
SEG_SYNTAX * | syntax, | |||
SEG_DEC_PARAM * | decParam | |||
) | [static] |
Start node pruning.
[out] | node | Pointer array pointing SNPs and ENP buffer |
[in] | syntax | Syntax |
[in] | decParam | Decoder parameters |
static void segDurExtension | ( | SEG_DP_ITEM ** | dpMat, | |
int | numStates, | |||
SEG_SYNTAX_ITEM * | nodeList, | |||
int * | breakPoint, | |||
int | maxDur, | |||
int | t | |||
) | [static] |
Set "possible start-node" attribute to nodes in the trellis.
[in,out] | dpMat | Paths in the trellis for back-tracing |
[in] | numStates | Number of states |
[in] | nodeList | Node list in the syntax |
[in] | breakPoint | Break point array |
[in] | maxDur | Maxmal segment-duration |
[in] | t | Time (frame #) |
int segFreeDecoder | ( | SEG_DP_ITEM ** | dpHist, | |
int | numStates | |||
) |
Free memory space storing all the paths in the trellis.
[in] | dpHist | Paths in the trellis for back-tracing |
[in] | numStates | Number of states |
NO_ERROR | Successful execution |
static double segOutputProb | ( | SEG_STATE * | state, | |
double ** | data, | |||
int | vecSize, | |||
int | targetVecSize, | |||
double ** | map, | |||
int | sTime, | |||
int | eTime | |||
) | [static] |
Compute linear-segment output probability.
[in] | state | Model parameters for a state that produces the segment |
[in] | data | Feature vectors (of the acoustic layer) |
[in] | vecSize | Dimension of articulatory feature vectors |
[in] | targetVecSize | Dimension of the acoustic feature vectors |
[in] | map | Articulatory-acoustic linear-mapping matrix |
[in] | sTime | Start time of the segment in data |
[in] | eTime | End time of the segment in data |
double segViterbiDecoder | ( | SEG_DP_ITEM *** | dpHist, | |
SEG_SYNTAX * | synt, | |||
double ** | spData, | |||
int * | breakPt, | |||
int | sT, | |||
int | eT, | |||
int | maxDur, | |||
SEG_DEC_PARAM * | decParam | |||
) |
Generic Viterbi-type decorder for segmental HMMs.
[out] | dpHist | Paths in the trellis for back-tracing |
[in] | synt | Syntax |
[in] | spData | Acoustic feature vectors |
[in] | breakPt | Break point attributes |
[in] | sT | Utterance start time (frame #) |
[in] | eT | Utterance end time (frame #) |
[in] | maxDur | Maximal segment-duration (Dmax) |
[in] | decParam | Decoder parameters |
RTN_ERROR | Memory allocation error | |
Otherwise | The best cost (minProb) computed |
static int selector | ( | SEG_DP_ITEM ** | dpMat, | |
NODE ** | prob, | |||
int | t, | |||
int | numVecs, | |||
int | sT, | |||
int | maxDur, | |||
int * | breakPt, | |||
double ** | spData, | |||
SEG_SYNTAX * | synt, | |||
SEG_DEC_PARAM * | decParam | |||
) | [static] |
Calculate ENP and determine best segment duration.
[out] | dpMat | Paths in the trellis for back-tracing |
[out] | prob | Pointer array pointing SNPs and ENP buffer |
[in] | t | Cuurent time (frame #) |
[in] | numVecs | Number of observed feature vectors |
[in] | sT | Start time (frame #) in spData |
[in] | maxDur | Maximal segment-duration |
[in] | breakPt | Break point array |
[in] | spData | Feature vectors |
[in] | synt | Syntax |
[in] | decParam | Decoder parameters |
ERROR | Memory allocation error | |
NO_ERROR | Successfully executed |
static int * snpIdxPtr | ( | ) | [static] |
Get index array to refer to SNP arrays.
static long startNodeProb | ( | NODE ** | prob, | |
int | probIdx, | |||
int | state, | |||
SEG_SYNTAX_ITEM * | nodeList, | |||
int | breakPt, | |||
int | maxDur | |||
) | [static] |
Compute start node probability (SNP).
[out] | prob | Pointer array pointing SNPs and ENP buffer |
[in] | probIdx | Index pointing current SNP element |
[in] | state | State number |
[in] | nodeList | Node list in the syntax |
[in] | breakPt | Break point at time t |
[in] | maxDur | Maximal segment-duration |
ALLOC_ERR | Memory allocation error | |
otherwise | The best path from a predessor to the current node |