/* * Manual page at fst_man.def */ INT16 CGEN_PUBLIC CFst_Intersect ( CFst* _this, CFst* itSrc1, CFst* itSrc2, INT32 nUnit1, INT32 nUnit2 ) { CFst* itAux1 = NULL; CFst* itAux2 = NULL; CData* idAux = NULL; INT32 nIcTis1 = -1; INT32 nIcTos1 = -1; INT32 nIcTis2 = -1; INT32 nIcTos2 = -1; INT16 nErr = O_K; nIcTis1 = CData_FindComp(AS(CData,itSrc1->td),NC_TD_TIS); nIcTos1 = CData_FindComp(AS(CData,itSrc1->td),NC_TD_TOS); nIcTis2 = CData_FindComp(AS(CData,itSrc2->td),NC_TD_TIS); nIcTos2 = CData_FindComp(AS(CData,itSrc2->td),NC_TD_TOS); if (nIcTis1<0) return IERROR(_this,FST_MISS,"input symbol component","","transition table of left operand"); if (nIcTis2<0) return IERROR(_this,FST_MISS,"input symbol component","","transition table of right operand"); ICREATEEX(CFst ,itAux1,"CFst_Intersect.itAux1",NULL); ICREATEEX(CFst ,itAux2,"CFst_Intersect.itAux2",NULL); ICREATEEX(CData,idAux ,"CFst_Intersect.idAux" ,NULL); CFst_Copy(BASEINST(itAux1),BASEINST(itSrc1)); CFst_Copy(BASEINST(itAux2),BASEINST(itSrc2)); if (nIcTos1>=0) { CData_DeleteComps(AS(CData,itAux1->td),nIcTos1,1); CData_SelectComps(idAux,AS(CData,itAux1->td),nIcTis1,1); CData_SetCname(idAux,0,NC_TD_TOS); CData_Join(AS(CData,itAux1->td),idAux); } if (nIcTos2>=0) { CData_DeleteComps(AS(CData,itAux2->td),nIcTos2,1); CData_SelectComps(idAux,AS(CData,itAux2->td),nIcTis2,1); CData_SetCname(idAux,0,NC_TD_TOS); CData_Join(AS(CData,itAux2->td),idAux); } nErr = CFst_Compose(_this,itAux1,itAux2,nUnit1,nUnit2); IDESTROY(itAux1); IDESTROY(itAux2); IDESTROY(idAux); return nErr; }
INT16 CGEN_PROTECTED CPMproc::Analyze(data* dSignal, data* dPM) { INT16 ret = NOT_EXEC; INT16 bLabels = FALSE; data* dLabels = NULL; ICREATEEX(CData,dLabels,"~lab",NULL); if(dlp_is_symbolic_type_code(dSignal->GetCompType(dSignal->GetNComps()-1))) { dLabels->SelectComps(dSignal,dSignal->GetNComps()-1,1); dSignal->DeleteComps(dSignal->GetNComps()-1,1); bLabels=TRUE; } if(m_bChfa == true) { ret = Chfa(dSignal, dPM); } else if(m_bGcida == true) { ret = Gcida(dSignal, dPM); } else if(m_bEpochdetect == true) { ret = Epochdetect(dSignal, dPM); } else { ret = Hybrid(dSignal, dPM); } if(bLabels==TRUE) { dSignal->Join(dLabels); } IDESTROY(dLabels); return ret; }
/* DP decoder initialize function * * This function initializes the decoder. * It prepares the internal memory. * * @param glob Pointer to the global memory structure * @return <code>NULL</code> if successfull, the error string otherwise */ const char *fsts_sdp_init(struct fsts_glob *glob){ CFst *itDst; if(glob->cfg.numpaths!=1) return FSTSERR("not implemented for multiple paths"); if(glob->src.nunits!=1) return FSTSERR("not implemented for multiple units"); if(!glob->src.itSrc) return FSTSERR("this algo does not work with fast loading"); ICREATEEX(CFst,itDst,"fsts_sdp_dst",NULL); if(!itDst) return FSTSERR("creation of destination object failed"); glob->algo=itDst; return NULL; }
/* * Synthesis using pitch marks. * * Derived instances of FBAproc should override method * SynthesizePM() to add the desired functionality * * @return O_K if successfull, NOT_EXEC otherwise */ INT16 CGEN_VPROTECTED CFBAproc::SynthesizeUsingPM(data *idFea, data *idPm, data *idSyn) { CData *idExcite = NULL; FLOAT64 *excitation = NULL; FLOAT64 *synthesis = NULL; INT32 nSamples = 0; INT16 nPer = 0; INT32 nCompVuv = idFea->FindComp("v/uv"); INT16 nCompFea = idFea->GetNNumericComps() - (nCompVuv >= 0 ? 1 : 0); INT32 iRecFea = 0; INT32 nRecFea = 0; AlignFramesToPitch(idPm, idFea, idFea); nRecFea = idFea->GetNRecs(); if(m_bSynEnhancement) { for(iRecFea = 0; iRecFea < nRecFea; iRecFea++) { FeaEnhancement((FLOAT64*)idFea->XAddr(iRecFea,0), nCompFea); } } Smooth(idFea, idPm, idFea); // Generate modulated excitation ICREATEEX(CData,idExcite,"~idExcite",NULL); DLPASSERT(O_K==ModEx(idPm,idExcite)); DLPASSERT(!idExcite->IsEmpty()); nSamples = idExcite->GetNRecs(); idSyn->Reset(); idSyn->AddComp("syn", T_DOUBLE); idSyn->Allocate(nSamples); excitation = (FLOAT64*)idExcite->XAddr(0, 0); synthesis = (FLOAT64*)idSyn->XAddr(0, 0); for(INT32 currSample = 0, currPer = 0; (currSample < nSamples) && (currPer < idFea->GetNRecs()); currSample += nPer, currPer++) { nPer = (INT16)idPm->Dfetch(currPer,0); if(SynthesizeFrame((FLOAT64*)idFea->XAddr(currPer,0), nCompFea, excitation+currSample, nPer, synthesis+currSample) != O_K) { IDESTROY(idExcite); return IERROR(this,FBA_SYNTHESISE, currPer, 0,0); } } IDESTROY(idExcite); if (m_nMinLog != 0.0) for (INT32 i=0; i<idSyn->GetNRecs(); i++) *((FLOAT64*)idSyn->XAddr(0, 0)+i) *= exp(m_nMinLog); return O_K; }
INT16 CGEN_PUBLIC CFBAproc::AlignFramesToPitch(CData *idPitch, CData *idFea, CData* idNewFea) { CData* idAuxF = NULL; INT32 nSamplesP = 0; INT32 nFea = 0; INT32 nPer = 0; INT32 i = 0; INT32 j = 0; if(m_nSync) return O_K; if(idFea == NULL) return IERROR(this,ERR_NULLINST,0,0,0); if(idFea->IsEmpty()) return IERROR(idPitch,DATA_EMPTY,idPitch->m_lpInstanceName,0,0); if(idPitch == NULL) return IERROR(this,ERR_NULLINST,0,0,0); if(idPitch->IsEmpty()) return IERROR(idPitch,DATA_EMPTY,idPitch->m_lpInstanceName,0,0); if(idPitch->GetNComps()!=2 || !dlp_is_numeric_type_code(idPitch->GetCompType(0)) || !dlp_is_numeric_type_code(idPitch->GetCompType(1))) { return IERROR(this,FBA_BADARG,idPitch,"idPitch","contains invalid data."); } CREATEVIRTUAL(CData,idFea,idNewFea); ICREATEEX(CData,idAuxF ,"~idAuxF" ,NULL); if(idFea->m_lpTable->m_fsr <= 0.0) { idFea->m_lpTable->m_fsr = 1000.0 * (FLOAT64)m_nCrate / (FLOAT64)m_nSrate; } nFea = idFea->GetNRecs(); for(i = 0, j = 0, nSamplesP = 0; i < idPitch->GetNRecs(); i++, nSamplesP+=nPer) { nPer = (INT32)idPitch->Dfetch(i,0); while((idFea->m_lpTable->m_fsr * (FLOAT64)(j+0.5)) < (1000.0 * (FLOAT64)nSamplesP / (FLOAT64)m_nSrate)) j++; j = (j>=nFea) ? nFea-1 : j; idAuxF->SelectRecs(idFea,j,1); idNewFea->Cat(idAuxF); } IDESTROY(idAuxF); DESTROYVIRTUAL(idFea, idNewFea); return O_K; }
INT16 CCPproc::Quantize() { INT16 __nErr = O_K; INT32 nQuant; INT32 nFirst; INT32 nCount; CData* idFea; CData* idRes; MIC_CHECK; nQuant = (INT32)MIC_GET_N(1,0); nCount = (INT32)MIC_GET_N(2,1); nFirst = (INT32)MIC_GET_N(3,2); idFea = (CData*)MIC_GET_I_EX(idFea,data,4,3); ICREATEEX(CData,idRes,"#TMP#-quantize",NULL); __nErr = QuantizeImpl(idFea, nFirst, nCount, nQuant, idRes); MIC_PUT_I(BASEINST(idRes)); return __nErr; return O_K; }
/** * <p>INTERNAL USE ONLY. This method is called by {@link -pool} to pool the * statistics blocks contained in <code>idSrc</code> and store the result in * <code>idPool</code>. The operation is controlled through the pooling mode * flag <code>nMode</code> as follows:</p> * * <ul> * <li>nMode=0: Pool sum data, <code>idPool</code> will be overwritten</li> * <li>nMode=1: Pool min data</li> * <li>nMode=2: Pool max data</li> * </ul> * * <h3>Remarks</h3> * <ul> * <li>In order to pool raw statistics data, there are three calls * (<code>nMode</code>=0,1 and 2) necessary. The first call of these * <em>must</em> be the one with <code>nMode</code>=0!</li> * <li>There are NO checks performed</li> * </ul> * * @param idPool * Pooled raw statistics data block * @param idSrc * Raw statistics data blocks to be pooled * @param nMode * Pooling mode, see above */ void CGEN_SPRIVATE CStatistics_PoolInt(CData* idPool, CData* idSrc, INT32 nMode) { CData* idAux = NULL; /* Auxilary data instance #1 */ if (nMode==0) /* Sum aggregation mode */ { /* >> */ ISETOPTION(idPool,"/block"); /* Switch target to block mode */ CData_Aggregate(idPool,idSrc,NULL,CMPLX(0),"sum"); /* Aggregate (sum up) */ IRESETOPTIONS(idPool); /* Switch target to normal mode */ } /* << */ else if (nMode==1 || nMode==2) /* Extrama aggregation modes */ { /* >> */ ICREATEEX(CData,idAux,"CStatistics_Pool_int.~idAux",NULL); /* Create auxilary data instance #1*/ ISETOPTION(idAux,"/block"); /* Switch target to block mode */ CData_Aggregate(idAux,idSrc,NULL,CMPLX(0),nMode==1?"min":"max"); /* Aggregate (minimum or maximum) */ dlp_memmove(CData_XAddr(idPool,nMode,0),CData_XAddr(idAux,nMode,0), /* Copy aggregated min. or max. ...*/ CData_GetRecLen(idAux)); /* | ... to target */ IRESETOPTIONS(idAux); /* Switch target to normal mode */ IDESTROY(idAux); /* Destroy auxilary data inst. #1 */ } /* << */ else /* Unknown mode */ DLPASSERT(FMSG("Invalid internal pooling mode")); /* Not so good ... */ }
CFWTproc* CFWTproc::CreateInstance(const char* lpName) { CFWTproc* lpNewInstance; ICREATEEX(CFWTproc,lpNewInstance,lpName,NULL); return lpNewInstance; }
/** * Analyse * * Derived instances of FBAproc should override method * Analyse() to add the desired functionality * * @return O_K if successfull, NOT_EXEC otherwise */ INT16 CGEN_PUBLIC CCPproc::AnalyzeFrame() { INT16 ret = O_K; if(!strcmp(m_lpsType, "MelFilter")) { CData* idCep = NULL; CData* idMel = NULL; ICREATEEX(CData, idCep, "~idCep", NULL); ICREATEEX(CData, idMel, "~idMel", NULL); if((ret = CMELproc::AnalyzeFrame()) != O_K) return ret; idMel->Select(m_idRealFrame, 0, m_nCoeff); if((ret = Mf2mcep(idMel, idCep, m_nCoeff)) != O_K) return ret; dlp_memmove(m_idRealFrame->XAddr(0, 0), idCep->XAddr(0, 0), m_nCoeff * sizeof(FLOAT64)); IDESTROY(idMel); IDESTROY(idCep); } else { if(!strcmp(m_lpsWarptype, "time")) { if(!strcmp(m_lpsType, "BurgLPC")) { dlm_calcmcep((FLOAT64*)m_idRealFrame->XAddr(0, 0), m_nWlen, (FLOAT64*)m_idRealFrame->XAddr(0, 0), m_nCoeff, 0.0, -m_nMinLog, DLM_CALCCEP_METHOD_S_MLPC_BURG_MCEP); } else if(!strcmp(m_lpsType, "LevinsonLPC")) { dlm_calcmcep((FLOAT64*)m_idRealFrame->XAddr(0, 0), m_nWlen, (FLOAT64*)m_idRealFrame->XAddr(0, 0), m_nCoeff, 0.0, -m_nMinLog, DLM_CALCCEP_METHOD_S_MLPC_LEVI_MCEP); } else if(!strcmp(m_lpsType, "Uels")) { dlm_calcmcep((FLOAT64*)m_idRealFrame->XAddr(0, 0), m_nLen, (FLOAT64*)m_idRealFrame->XAddr(0, 0), m_nCoeff, 0.0, -m_nMinLog, DLM_CALCCEP_METHOD_S_MCEP_UELS); } else if(!strcmp(m_lpsType, "LogFFT")) { dlp_memset(m_idImagFrame->XAddr(0, 0), 0L, m_nLen * sizeof(FLOAT64)); if((ret = dlm_fft((FLOAT64*)m_idRealFrame->XAddr(0, 0),(FLOAT64*)m_idImagFrame->XAddr(0, 0),m_nLen,FALSE)) != O_K) { if(ret == ERR_MDIM) IERROR(this, FBA_BADFRAMELEN, m_nLen, "FFT", 0); return NOT_EXEC; } LN(); if((ret = dlm_fft((FLOAT64*)m_idRealFrame->XAddr(0, 0), (FLOAT64*)m_idImagFrame->XAddr(0, 0), m_nLen, TRUE)) != O_K) { if(ret == ERR_MDIM) IERROR(this, FBA_BADFRAMELEN, m_nLen, "FFT", 0); return NOT_EXEC; } for(INT32 i = 1; i < m_nCoeff; i++) { ((FLOAT64*)m_idRealFrame->XAddr(0, 0))[i] *= 2.0; } } else { IERROR(this,ERR_NULLINST,0,0,0); return NOT_EXEC; } } else { if(!strcmp(m_lpsType, "BurgLPC")) { if(!strcmp(m_lpsWarptype, "lpc")) { dlm_calcmcep((FLOAT64*)m_idRealFrame->XAddr(0, 0), m_nWlen, (FLOAT64*)m_idRealFrame->XAddr(0, 0), m_nCoeff, m_nPfaLambda, -m_nMinLog, DLM_CALCCEP_METHOD_S_LPC_BURG_MLPC_MCEP); } else if(!strcmp(m_lpsWarptype, "cepstrum")) { dlm_calcmcep((FLOAT64*)m_idRealFrame->XAddr(0, 0), m_nWlen, (FLOAT64*)m_idRealFrame->XAddr(0, 0), m_nCoeff, m_nPfaLambda, -m_nMinLog, DLM_CALCCEP_METHOD_S_LPC_BURG_CEP_MCEP); } else if(!strcmp(m_lpsWarptype, "none")) { dlm_calcmcep((FLOAT64*)m_idRealFrame->XAddr(0, 0), m_nWlen, (FLOAT64*)m_idRealFrame->XAddr(0, 0), m_nCoeff, 0.0, -m_nMinLog, DLM_CALCCEP_METHOD_S_LPC_BURG_CEP); } else { IERROR(this, CP_WARPTYPE, m_lpsWarptype, 0, 0); return NOT_EXEC; } } else if(!strcmp(m_lpsType, "LevinsonLPC")) { if(!strcmp(m_lpsWarptype, "lpc")) { dlm_calcmcep((FLOAT64*)m_idRealFrame->XAddr(0, 0), m_nWlen, (FLOAT64*)m_idRealFrame->XAddr(0, 0), m_nCoeff, m_nPfaLambda, -m_nMinLog, DLM_CALCCEP_METHOD_S_LPC_LEVI_MLPC_MCEP); } else if(!strcmp(m_lpsWarptype, "cepstrum")) { dlm_calcmcep((FLOAT64*)m_idRealFrame->XAddr(0, 0), m_nWlen, (FLOAT64*)m_idRealFrame->XAddr(0, 0), m_nWlen / 2, m_nPfaLambda, -m_nMinLog, DLM_CALCCEP_METHOD_S_LPC_LEVI_CEP_MCEP); } else if(!strcmp(m_lpsWarptype, "none")) { dlm_calcmcep((FLOAT64*)m_idRealFrame->XAddr(0, 0), m_nWlen, (FLOAT64*)m_idRealFrame->XAddr(0, 0), m_nCoeff, 0.0, -m_nMinLog, DLM_CALCCEP_METHOD_S_LPC_LEVI_CEP); } else { IERROR(this, CP_WARPTYPE, m_lpsWarptype, 0, 0); return NOT_EXEC; } } else if(!strcmp(m_lpsType, "Uels")) { if((ret = dlm_calcmcep((FLOAT64*)m_idRealFrame->XAddr(0, 0), m_nLen, (FLOAT64*)m_idRealFrame->XAddr(0, 0), m_nCoeff, m_nPfaLambda, exp(-m_nMinLog), DLM_CALCCEP_METHOD_S_MCEP_UELS)) != O_K) { return NOT_EXEC; } } else if(!strcmp(m_lpsType, "LogFFT")) { dlp_memset(m_idImagFrame->XAddr(0, 0), 0L, m_nLen * sizeof(FLOAT64)); if((ret = dlm_fft((FLOAT64*)m_idRealFrame->XAddr(0, 0), (FLOAT64*)m_idImagFrame->XAddr(0, 0), m_nLen, FALSE)) != O_K) { if(ret == ERR_MDIM) IERROR(this, FBA_BADFRAMELEN, m_nLen, "FFT", 0); return NOT_EXEC; } LN(); if(!strcmp(m_lpsWarptype, "lpc")) { IERROR(this, CP_WARPTYPE, m_lpsWarptype, 0, 0); return NOT_EXEC; } else if(!strcmp(m_lpsWarptype, "cepstrum")) { dlp_memset(m_idImagFrame->XAddr(0, 0), 0L, m_nLen * sizeof(FLOAT64)); if((ret = dlm_fft((FLOAT64*)m_idRealFrame->XAddr(0, 0), (FLOAT64*)m_idImagFrame->XAddr(0, 0), m_nLen, TRUE)) != O_K) { if(ret == ERR_MDIM) IERROR(this, FBA_BADFRAMELEN, m_nLen, "FFT", 0); return NOT_EXEC; } dlm_cep2mcep((FLOAT64*)m_idRealFrame->XAddr(0, 0), m_nLen, (FLOAT64*)m_idRealFrame->XAddr(0, 0), m_nCoeff, m_nPfaLambda, NULL); } else if(!strcmp(m_lpsWarptype, "spectrum")) { WARP(); dlp_memset(m_idImagFrame->XAddr(0, 0), 0L, m_nLen * sizeof(FLOAT64)); if((ret = dlm_fft((FLOAT64*)m_idRealFrame->XAddr(0, 0), (FLOAT64*)m_idImagFrame->XAddr(0, 0), m_nLen, TRUE)) != O_K) { if(ret == ERR_MDIM) IERROR(this, FBA_BADFRAMELEN, m_nLen, "FFT", 0); return NOT_EXEC; } } else if(!strcmp(m_lpsWarptype, "none")) { dlp_memset(m_idImagFrame->XAddr(0, 0), 0L, m_nLen * sizeof(FLOAT64)); if((ret = dlm_fft((FLOAT64*)m_idRealFrame->XAddr(0, 0), (FLOAT64*)m_idImagFrame->XAddr(0, 0), m_nLen, TRUE)) != O_K) { if(ret == ERR_MDIM) IERROR(this, FBA_BADFRAMELEN, m_nLen, "FFT", 0); return NOT_EXEC; } } else { IERROR(this,ERR_NULLINST,0,0,0); } for(INT32 i = 1; i < m_nCoeff; i++) { ((FLOAT64*)m_idRealFrame->XAddr(0, 0))[i] *= 2.0; } } else if(strcmp(m_lpsWarptype, "none")) { IERROR(this,ERR_NULLINST,0,0,0); } } } return O_K; }
CFsttools* CFsttools_CreateInstance(const char* lpName) { CFsttools* lpNewInstance; ICREATEEX(CFsttools,lpNewInstance,lpName,NULL); return lpNewInstance; }
/* * Manual page at statistics.def */ INT16 CGEN_PUBLIC CStatistics_Pool ( CStatistics* _this, CStatistics* iSrc, CData* idMap ) { INT32 i = 0; /* Current component index */ INT32 nC = 0; /* Current pooled statistics class */ INT32 nCs = 0; /* Current source class index */ INT32 nXC = 0; /* Number of pooled classes */ INT32 nRpb = 0; /* Statistics raw data block size */ INT16 nCheckSave = 0; /* Saved check level */ CData* idAux = NULL; /* Auxilary data instance #1 */ CData* idPmp = NULL; /* Pooling map */ CData* idPcd = NULL; /* Pooled class raw data buffer */ /* Initialize */ /* --------------------------------- */ CHECK_THIS_RV(0); /* Check this instance */ IF_NOK(CStatistics_Check(iSrc)) /* Check source statistics */ return IERROR(_this,ERR_INVALARG,"iSrc",0,0); /* ... */ nCheckSave = _this->m_nCheck; /* Save check level */ CStatistics_Reset(BASEINST(_this),TRUE); /* Reset destination */ _this->m_nCheck = nCheckSave; /* Restore check level */ IFIELD_RESET(CData,"dat"); /* Create pool raw stats. data inst. */ /* Protocol */ /* --------------------------------- */ IFCHECK /* On verbose level 1 */ { /* >> */ printf("\n"); dlp_fprint_x_line(stdout,'-',dlp_maxprintcols()); /* Print protocol header */ printf("\n statistics -pool"); /* ... */ printf("\n"); dlp_fprint_x_line(stdout,'-',dlp_maxprintcols());printf("\n");/* ... */ } /* << */ /* No map --> pool all classes */ /* --------------------------------- */ if (CData_IsEmpty(idMap)) /* NULL or empty map instance */ { /* >> */ IFCHECK printf("\n Empty pooling map --> pool all classes"); /* Protocol (verbose level 1) */ CStatistics_PoolInt(_this->m_idDat,iSrc->m_idDat,0); /* Pool sum data */ CStatistics_PoolInt(_this->m_idDat,iSrc->m_idDat,1); /* Pool min data */ CStatistics_PoolInt(_this->m_idDat,iSrc->m_idDat,2); /* Pool max data */ STA_PROTOCOL_FOOTER(1,"done"); /* Print protocol footer */ return O_K; /* That's it */ } IFCHECK printf("\n Pooling by map"); /* Protocol (verbose level 1) */ ICREATEEX(CData,idAux,"CStatistics_Pool.~idAux",NULL); /* Create auxilary data instance #1 */ ICREATEEX(CData,idPmp,"CStatistics_Pool.~idPmp",NULL); /* Create pooling map */ ICREATEEX(CData,idPcd,"CStatistics_Pool.~idPcs",NULL); /* Create pooled raw stats.data inst.*/ /* Find and copy map component (pooled class) */ /* --------------------------------- */ for (i=0; i<CData_GetNComps(idMap); i++) /* Loop over components of idMap */ if (dlp_is_numeric_type_code(CData_GetCompType(idMap,i))) /* Is current component numeric? */ { /* >> (Yes) */ CData_SelectComps(idPmp,idMap,i,1); /* Copy component */ break; /* Have ready :) */ } /* << */ if (CData_IsEmpty(idPmp)) /* Have not got map component */ { /* >> */ IERROR(_this,STA_BADCOMP,"map",BASEINST(idMap)->m_lpInstanceName,"numeric");/* Error message */ DLPTHROW(STA_BADCOMP); /* Throw exception */ } /* << */ /* Create source class component */ /* --------------------------------- */ CData_AddComp(idPmp,"srcc",T_LONG); /* Add source class index component */ for (i=0; i<CData_GetNRecs(idPmp); i++) CData_Dstore(idPmp,i,i,1); /* Fill it */ /* Finish pooling map and initialize pooling */ /* --------------------------------- */ CData_Sortup(idPmp,idPmp,0); /* Sort map by pooled class index */ nXC = (INT32)CData_Dfetch(idPmp,CData_GetNRecs(idPmp)-1,0)+1; /* Get greatest pooled class index */ IFCHECK printf("\n Pooling %ld statistics classes",(long)nXC); /* Protocol (verbose level 1) */ IFCHECKEX(3) CData_Print(idPmp); /* Print pooling map (verbose lvl.3) */ nRpb = CData_GetNRecsPerBlock(iSrc->m_idDat); /* Get block size */ /* Prepare pooled statistics */ /* --------------------------------- */ CData_Scopy(_this->m_idDat,iSrc->m_idDat); /* Create target raw data components */ CData_Allocate(_this->m_idDat,nRpb*nXC); /* Allocate target raw data */ CData_SetNBlocks(_this->m_idDat,nXC); /* Set target statistics block number*/ /* Pooling loop */ /* --------------------------------- */ for (i=0; i<CData_GetNRecs(idPmp); ) /* Loop over pooling map */ { /* >> */ /* - Copy raw statistics data of one pooled class */ /* - - - - - - - - - - - - - - - - */ nC = (INT32)CData_Dfetch(idPmp,0,0); /* Get pooled class index */ IFCHECK printf("\n Pooled class %3ld"); /* Protocol (verbose level 1) */ for (i=0; i<CData_GetNRecs(idPmp); i++) /* Loop over partition of pool.map */ { /* >> */ if (nC != (INT32)CData_Dfetch(idPmp,0,0)) break; /* Not the current class anymore */ nCs = (INT32)CData_Dfetch(idPmp,i,1); /* Get source class index */ IFCHECK printf("\n - Source class %3ld",nCs); /* Protocol (verbose level 1) */ CData_SelectBlocks(idAux,iSrc->m_idDat,nCs,1); /* Copy raw stats. data block */ CData_Cat(idPcd,idAux); /* Append to buffer */ } /* << */ /* - Pool data */ /* - - - - - - - - - - - - - - - - */ CData_SetNBlocks(idPcd,CData_GetNRecs(idPcd)/nRpb); /* Set block count of aggr. buffer */ IFCHECK /* Protocol (verbose level 1) */ printf("\n - Aggregating %ld statistics classes", /* | */ (long)CData_GetNBlocks(idPcd)); /* | */ CStatistics_PoolInt(idAux,idPcd,0); /* Pool sum data */ CStatistics_PoolInt(idAux,idPcd,1); /* Pool min data */ CStatistics_PoolInt(idAux,idPcd,2); /* Pool max data */ /* - Store pooled raw statistics data block */ /* - - - - - - - - - - - - - - - - */ dlp_memmove /* Copy pooled raw stats. data */ ( /* | */ CData_XAddr(_this->m_idDat,nC*nRpb,0), /* | To target statistics block */ CData_XAddr(idAux,0,0), /* | From aggregation buffer */ CData_GetNRecs(idAux)*CData_GetRecLen(idAux) /* | Length of aggregation buffer */ ); /* | */ /* - Clean up auxilary instances */ /* - - - - - - - - - - - - - - - - */ CData_Reset(idPcd,TRUE); /* Clear aggregation buffer */ } /* Clean up */ /* --------------------------------- */ IDESTROY(idAux); /* Destroy auxilary data instance #1 */ IDESTROY(idPmp); /* Destroy pooling map */ IDESTROY(idPcd); /* Destroy pooled cls. raw data inst.*/ STA_PROTOCOL_FOOTER(1,"done"); /* Print protocol footer */ return O_K; /* Ok */ DLPCATCH(STA_BADCOMP) /* == Catch STA_BADCOMP exception */ IDESTROY(idAux); /* Destroy auxilary data instance #1 */ IDESTROY(idPmp); /* Destroy pooling map */ IDESTROY(idPcd); /* Destroy pooled cls. raw data inst.*/ STA_PROTOCOL_FOOTER(1,"FAILED"); /* Print protocol footer */ return NOT_EXEC; /* Not ok */ }
CDlpFile* CDlpFile_CreateInstance(const char* lpName) { CDlpFile* lpNewInstance; ICREATEEX(CDlpFile,lpNewInstance,lpName,NULL); return lpNewInstance; }
CHelloworld* CHelloworld_CreateInstance(const char* lpName) { CHelloworld* lpNewInstance; ICREATEEX(CHelloworld,lpNewInstance,lpName,NULL); return lpNewInstance; }
CFstsearch* CFstsearch_CreateInstance(const char* lpName) { CFstsearch* lpNewInstance; ICREATEEX(CFstsearch,lpNewInstance,lpName,NULL); return lpNewInstance; }
CDgen* CDgen::CreateInstance(const char* lpName) { CDgen* lpNewInstance; ICREATEEX(CDgen,lpNewInstance,lpName,NULL); return lpNewInstance; }
/* * Resample voiced parts of pitch to match a given mean fundamential frequency. * The length of voiced segments is preserved to avoid loss of synchronization * between pitch and corresponding signal * * @param idPitch Source data instance containing original pitch * @param idNewPitch Target data instance containing new pitch * @param nFFreq Target fundamential frequency (mean over voiced parts) */ INT16 CGEN_PUBLIC CFBAproc::ResamplePitch(CData *idPitch, CData *idNewPitch, INT32 nFFreq) { INT16 bVoiced = FALSE; INT32 i = 0; INT32 k = 0; INT32 nCount = 0; INT32 nStartL = 0; FLOAT32 nTargetPeriodLength = (FLOAT32)m_nSrate/(FLOAT32)nFFreq; FLOAT32 nMeanPeriodLengthL = 0.0; FLOAT32 nMeanPeriodLength = 0.0; CData* idVoiced = NULL; CData* idAux = NULL; // Validation if(idPitch == NULL) return IERROR(this,ERR_NULLINST,0,0,0); if(idPitch->IsEmpty()) return IERROR(idPitch,DATA_EMPTY,idPitch->m_lpInstanceName,0,0); if(nFFreq<50||nFFreq>500) return IERROR(this,FBA_BADARG,nFFreq,"nFFreq","a value between 50 and 500"); if ( idPitch->GetNComps()!=2 || !dlp_is_numeric_type_code(idPitch->GetCompType(0)) || !dlp_is_numeric_type_code(idPitch->GetCompType(1)) ) { return IERROR(this,FBA_BADARG,idPitch,"idPitch","contains invalid data."); } // Initialization CREATEVIRTUAL(CData,idPitch,idNewPitch); ICREATEEX(CData,idVoiced,"~idVoiced",NULL); ICREATEEX(CData,idAux ,"~idAux" ,NULL); idNewPitch->Reset(); idVoiced->AddComp("start",T_INT); idVoiced->AddComp("count",T_INT); idVoiced->AddComp("mplen",T_FLOAT); idVoiced->Alloc(10); // Determine start and length of voiced parts and mean of periods in samples for(i=0; i<idPitch->GetNRecs(); i++) { if(idPitch->Dfetch(i,1)>0) { if(bVoiced==FALSE) // Start of new voiced segment { bVoiced=TRUE; nStartL=i; nMeanPeriodLengthL=0; if(idVoiced->GetNRecs()==idVoiced->GetMaxRecs()) idVoiced->Realloc(idVoiced->GetNRecs()+10); idVoiced->IncNRecs(1); idVoiced->Dstore(i,idVoiced->GetNRecs()-1,0); } nMeanPeriodLength+=(INT32)idPitch->Dfetch(i,0); nMeanPeriodLengthL+=(INT32)idPitch->Dfetch(i,0); nCount++; } else if(bVoiced==TRUE) // End of voiced segment { bVoiced=FALSE; nMeanPeriodLengthL=nMeanPeriodLengthL/(FLOAT32)(i-nStartL); idVoiced->Dstore(i-nStartL,idVoiced->GetNRecs()-1,1); idVoiced->Dstore(nMeanPeriodLengthL,idVoiced->GetNRecs()-1,2); } } nMeanPeriodLength=nMeanPeriodLength/(FLOAT32)nCount; IFCHECK idVoiced->Print(); IFCHECK printf("\n Input mean period length in voiced parts: %f",nMeanPeriodLength); IFCHECK printf("\n Target mean period length: %f",nTargetPeriodLength); // Resample for(i=0,nStartL=0; i<idVoiced->GetNRecs(); i++) { INT32 j = 0; INT32 nSum = 0; INT32 nSumNew = 0; INT32 nDiff = 0; // Copy unvoiced idAux->SelectRecs(idPitch,nStartL,(INT32)idVoiced->Dfetch(i,0)-nStartL); idNewPitch->Cat(idAux); nStartL=(INT32)idVoiced->Dfetch(i,0)+(INT32)idVoiced->Dfetch(i,1); // Resample voiced idAux->SelectRecs(idPitch,(INT32)idVoiced->Dfetch(i,0),(INT32)idVoiced->Dfetch(i,1)); for(j=0,nSum=0;j<idAux->GetNRecs();j++) nSum+=(INT32)idAux->Dfetch(j,0); // Target sum idAux->Resample(idAux,nMeanPeriodLength/nTargetPeriodLength); idAux->Tconvert(idAux,T_FLOAT); idAux->Scalop(idAux,CMPLX(nTargetPeriodLength/nMeanPeriodLength),"mult"); idAux->Tconvert(idAux,T_INT); //DLPASSERT(FALSE); do { nSumNew=0; for(j=0,nSumNew=0;j<idAux->GetNRecs();j++) nSumNew+=(INT32)idAux->Dfetch(j,0); // New sum nDiff=nSumNew-nSum; // Distribute difference IFCHECK printf("\n Distribute difference d=%ld",(long)nDiff); for(j=0;j<idAux->GetNRecs()&&j<abs(nDiff);j++) { INT32 nValue = (INT32)idAux->Dfetch(j,0); if(nDiff<0) nValue+=1; else if(nDiff>0) nValue-=1; idAux->Dstore(nValue,j,0); } } while(nDiff!=0); //idAux->Fill_Int(1.0,0.0,1); for(k=0;k<idAux->GetNRecs();k++) idAux->Dstore(1.0,k,1); idNewPitch->Cat(idAux); } // Append last unvoiced segment nStartL = (INT32)idVoiced->Dfetch(idVoiced->GetNRecs()-1,0)+(INT32)idVoiced->Dfetch(idVoiced->GetNRecs()-1,1); idAux->SelectRecs(idPitch,nStartL,idPitch->GetNRecs()-nStartL); idNewPitch->Cat(idAux); DESTROYVIRTUAL(idPitch,idNewPitch); IDESTROY(idVoiced); IDESTROY(idAux); return O_K; }
/** * Base class implementation of the class factory. * The base class implementation does nothing because the base class * itself cannot be instanciated. * * @param lpsName Identifier for the instance to be created * @return NULL */ CDlpObject* CDlpObject_CreateInstance(const char* lpsName) { CDlpObject* iNewInstance; ICREATEEX(CDlpObject,iNewInstance,lpsName,NULL); return iNewInstance; }
/* * Manual page at fst_man.def */ INT16 CGEN_PUBLIC CFst_Rcs(CFst* _this, INT32 nUnit, FLOAT64 nSeed) { #ifdef __UNENTANGLE_FST return IERROR(_this,FST_INTERNAL,__FILE__,__LINE__,0); /* NOTE: __UNENTANGLE_FST was defined (probably in dlp_config.h or fst.def). * Undefine it to use this feature! */ #else /* #ifdef __UNENTANGLE_FST */ INT32 nU = 0; /* Current unit */ FST_ITYPE nS = 0; /* Current state */ FST_ITYPE nS2 = 0; /* Current state */ FST_ITYPE nFS = 0; /* First state of current unit */ FST_ITYPE nXS = 0; /* Number of states of current unit */ FST_ITYPE nT = 0; /* Current transition */ FST_ITYPE nFT = 0; /* First transition of current unit */ FST_ITYPE nXT = 0; /* Number of tran. of current unit */ CData* idP = NULL; /* Incidence matrix */ CData* idB = NULL; /* Constanct vector of (idP-E)idX=idB */ CData* idI = NULL; /* idI = (idP-E)^-1 */ CData* idX = NULL; /* Solution of (idP-E)idX=idB */ FST_WTYPE nPSum = 0.; /* Probability sum/state */ INT32 nIcW = -1; /* Index of probability comp. in td */ INT32 nIcRcs = -1; /* Index of ref. counter comp. in sd */ INT32 nIcRct = -1; /* Index of ref. counter comp. in td */ /* Validation */ CHECK_THIS_RV(NOT_EXEC); CFst_Check(_this); if (CFst_Wsr_GetType(_this,&nIcW)!=FST_WSR_PROB) return IERROR(_this,FST_MISS,"transition probability component",NC_TD_PSR,"transition table"); /* Initialize - Find or add reference counters */ nIcRcs = CData_FindComp(AS(CData,_this->sd),NC_SD_RC); nIcRct = CData_FindComp(AS(CData,_this->td),NC_TD_RC); if (nIcRcs<0) { CData_AddComp(AS(CData,_this->sd),NC_SD_RC,DLP_TYPE(FST_WTYPE)); nIcRcs = CData_GetNComps(AS(CData,_this->sd))-1; } if (nIcRct<0) { CData_AddComp(AS(CData,_this->td),NC_TD_RC,DLP_TYPE(FST_WTYPE)); nIcRct = CData_GetNComps(AS(CData,_this->td))-1; } /* Initialize - Create auxilary instances */ ICREATEEX(CData,idP,"~CFst_Reverse.idP",NULL); ICREATEEX(CData,idB,"~CFst_Reverse.idB",NULL); ICREATEEX(CData,idI,"~CFst_Reverse.idI",NULL); ICREATEEX(CData,idX,"~CFst_Reverse.idX",NULL); /* Loop over units */ for (nU=nUnit<0?0:nUnit; nU<UD_XXU(_this); nU++) { CData_Reset(BASEINST(idP),TRUE); CData_Reset(BASEINST(idB),TRUE); CData_Reset(BASEINST(idI),TRUE); CData_Reset(BASEINST(idX),TRUE); nFS = UD_FS(_this,nU); nXS = UD_XS(_this,nU); nFT = UD_FT(_this,nU); nXT = UD_XT(_this,nU); /* Export transposed ergodic incidence matrix */ IF_NOK(CData_AddNcomps(idP,DLP_TYPE(FST_WTYPE),UD_XS(_this,nU)+1)) break; IF_NOK(CData_Allocate (idP,UD_XS(_this,nU)+1) ) break; IF_NOK(CData_AddNcomps(idB,DLP_TYPE(FST_WTYPE),1 )) break; IF_NOK(CData_Allocate (idB,UD_XS(_this,nU)+1) ) break; /* Fill transposed incidence matrix (summing up probabilities of parallel transitions) */ for (nT=nFT; nT<nFT+nXT; nT++) *(FST_WTYPE*)CData_XAddr(idP,TD_TER(_this,nT),TD_INI(_this,nT)) += *(FST_WTYPE*)CData_XAddr(AS(CData,_this->td),nT,nIcW); for (nS=0; nS<nXS; nS++) { if ((SD_FLG(_this,nS+nFS)&0x01)==0x01) /* Connect final states with start state */ { for (nS2=1, nPSum=0.; nS2<nXS; nS2++) nPSum += *(FST_WTYPE*)CData_XAddr(idP,nS2,nS); *(FST_WTYPE*)CData_XAddr(idP,0,nS) = 1.-nPSum; } *(FST_WTYPE*)CData_XAddr(idP,nS,nS)-=1.; /* Subtract eigenvalue 1 from main diagonal */ *(FST_WTYPE*)CData_XAddr(idP,nXS,nS)=1.; /* Additional equation implementing constraint sum(P_state)=1 */ *(FST_WTYPE*)CData_XAddr(idP,nS,nXS)=1.; /* Additional variable making incidence matrix quadratic */ } /* Fill constant vector */ CData_Fill(idB,CMPLX(1.),CMPLX(0.)); /* Calculate eigenvector of length 1 and eigenvalue 1 --> stationary state probabilities */ CMatrix_Op(idI,idP,T_INSTANCE,NULL,T_IGNORE,OP_INVT); CMatrix_Op(idX,idB,T_INSTANCE,idI,T_INSTANCE,OP_MULT); /* Fill in state reference counters */ if (nSeed>0.) nSeed /= CData_Dfetch(idX,0,0); else nSeed = 1.; for (nS=0; nS<nXS; nS++) CData_Dstore(AS(CData,_this->sd),nSeed*CData_Dfetch(idX,nS,0),nS+nFS,nIcRcs); /* Calculate stationary transition probabilities */ for (nT=nFT; nT<nFT+nXT; nT++) CData_Dstore ( AS(CData,_this->td), CData_Dfetch(AS(CData,_this->sd),TD_INI(_this,nT)+nFS,nIcRcs) * CData_Dfetch(AS(CData,_this->td),nT,nIcW), nT,nIcRct ); /* Clean up */ IDESTROY(idP); IDESTROY(idB); IDESTROY(idI); IDESTROY(idX); /* Stop in single unit mode */ if (nUnit>=0) break; } return O_K; #endif /* #ifdef __UNENTANGLE_FST */ }
INT16 CGEN_PUBLIC CFBAproc::AdjustSpeechRate(CData *idPitch, CData *idNewPitch, CData* idFea, CData* idNewFea, FLOAT32 rate) { INT16 bVoiced = FALSE; INT32 i = 0; INT32 k = 0; INT32 nCount = 0; INT32 nStartL = 0; FLOAT32 nMeanPeriodLengthL = 0.0; FLOAT32 nMeanPeriodLength = 0.0; CData* idVoiced = NULL; CData* idAuxP = NULL; CData* idAuxF = NULL; // Validation if(idPitch == NULL) return IERROR(this,ERR_NULLINST,0,0,0); if(idPitch->IsEmpty()) return IERROR(idPitch,DATA_EMPTY,idPitch->m_lpInstanceName,0,0); if ( idPitch->GetNComps()!=2 || !dlp_is_numeric_type_code(idPitch->GetCompType(0)) || !dlp_is_numeric_type_code(idPitch->GetCompType(1)) ) { return IERROR(this,FBA_BADARG,idPitch,"idPitch","contains invalid data."); } // Initialization CREATEVIRTUAL(CData,idPitch,idNewPitch); CREATEVIRTUAL(CData,idFea,idNewFea); ICREATEEX(CData,idVoiced,"~idVoiced",NULL); ICREATEEX(CData,idAuxP ,"~idAuxP" ,NULL); ICREATEEX(CData,idAuxF ,"~idAuxF" ,NULL); idNewPitch->Reset(); idVoiced->AddComp("start",T_INT); idVoiced->AddComp("count",T_INT); idVoiced->AddComp("mplen",T_FLOAT); idVoiced->Alloc(10); AlignFramesToPitch(idPitch, idFea, idFea); // Determine start and length of voiced parts and mean of periods in samples for(i=0; i<idPitch->GetNRecs(); i++) { if(idPitch->Dfetch(i,1)>0) { if(bVoiced==FALSE) // Start of new voiced segment { bVoiced=TRUE; nStartL=i; nMeanPeriodLengthL=0; if(idVoiced->GetNRecs()==idVoiced->GetMaxRecs()) idVoiced->Realloc(idVoiced->GetNRecs()+10); idVoiced->IncNRecs(1); idVoiced->Dstore(i,idVoiced->GetNRecs()-1,0); } nMeanPeriodLength+=(INT32)idPitch->Dfetch(i,0); nMeanPeriodLengthL+=(INT32)idPitch->Dfetch(i,0); nCount++; } else if(bVoiced==TRUE) // End of voiced segment { bVoiced=FALSE; nMeanPeriodLengthL=nMeanPeriodLengthL/(FLOAT32)(i-nStartL); idVoiced->Dstore(i-nStartL,idVoiced->GetNRecs()-1,1); idVoiced->Dstore(nMeanPeriodLengthL,idVoiced->GetNRecs()-1,2); } } nMeanPeriodLength=nMeanPeriodLength/(FLOAT32)nCount; IFCHECK idVoiced->Print(); IFCHECK printf("\n Input mean period length in voiced parts: %f",nMeanPeriodLength); // Resample for(i=0,nStartL=0; i<idVoiced->GetNRecs(); i++) { INT32 j = 0; INT32 nSum = 0; INT32 nRecOld = 0; INT32 nRecNew = 0; // Copy unvoiced idAuxP->SelectRecs(idPitch,nStartL,(INT32)idVoiced->Dfetch(i,0)-nStartL); idNewPitch->Cat(idAuxP); idAuxF->SelectRecs(idFea,nStartL,(INT32)idVoiced->Dfetch(i,0)-nStartL); idNewFea->Cat(idAuxF); nStartL=(INT32)idVoiced->Dfetch(i,0)+(INT32)idVoiced->Dfetch(i,1); // Resample voiced idAuxP->SelectRecs(idPitch,(INT32)idVoiced->Dfetch(i,0),(INT32)idVoiced->Dfetch(i,1)); nRecOld = idAuxP->GetNRecs(); for(j=0,nSum=0;j<nRecOld;j++) nSum+=(INT32)idAuxP->Dfetch(j,0); // Target sum idAuxP->Resample(idAuxP, rate); nRecNew = idAuxP->GetNRecs(); for(j=0;j<nRecNew;j++) { INT32 tmp = (INT32)idAuxP->Dfetch(j,0); tmp = (INT32)MAX(m_nSrate/500, tmp); tmp = (INT32)MIN(m_nSrate/50, tmp); idAuxP->Dstore(tmp,j,0); } //idAux->Fill_Int(1.0,0.0,1); for(k=0;k<nRecNew;k++) idAuxP->Dstore(1.0,k,1); for(k=0;k<nRecNew;k++) { j = (INT32)((FLOAT64)k * (FLOAT64)nRecOld / (FLOAT64)nRecNew + 0.5); idAuxF->SelectRecs(idFea,j+(INT32)idVoiced->Dfetch(i,0),1); idNewFea->Cat(idAuxF); } idNewPitch->Cat(idAuxP); } // Append last unvoiced segment nStartL = (INT32)idVoiced->Dfetch(idVoiced->GetNRecs()-1,0)+(INT32)idVoiced->Dfetch(idVoiced->GetNRecs()-1,1); idAuxP->SelectRecs(idPitch,nStartL,idPitch->GetNRecs()-nStartL); idNewPitch->Cat(idAuxP); idAuxF->SelectRecs(idFea,nStartL,idPitch->GetNRecs()-nStartL); idNewFea->Cat(idAuxF); DESTROYVIRTUAL(idPitch,idNewPitch); DESTROYVIRTUAL(idFea,idNewFea); IDESTROY(idVoiced); IDESTROY(idAuxP); IDESTROY(idAuxF); return O_K; }