本文整理汇总了C++中CData::AddComp方法的典型用法代码示例。如果您正苦于以下问题:C++ CData::AddComp方法的具体用法?C++ CData::AddComp怎么用?C++ CData::AddComp使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CData
的用法示例。
在下文中一共展示了CData::AddComp方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ResamplePitch
/*
* 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);
//.........这里部分代码省略.........
示例2: AdjustSpeechRate
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);
//.........这里部分代码省略.........