当前位置: 首页>>代码示例>>C++>>正文


C++ CData::GetNRecs方法代码示例

本文整理汇总了C++中CData::GetNRecs方法的典型用法代码示例。如果您正苦于以下问题:C++ CData::GetNRecs方法的具体用法?C++ CData::GetNRecs怎么用?C++ CData::GetNRecs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CData的用法示例。


在下文中一共展示了CData::GetNRecs方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: SynthesizeUsingPM

/*
 * 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;
}
开发者ID:thias42,项目名称:dLabPro,代码行数:60,代码来源:fba_synt.cpp

示例2: 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);
//.........这里部分代码省略.........
开发者ID:thias42,项目名称:dLabPro,代码行数:101,代码来源:fba_synt.cpp

示例3: 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);
//.........这里部分代码省略.........
开发者ID:thias42,项目名称:dLabPro,代码行数:101,代码来源:fba_synt.cpp


注:本文中的CData::GetNRecs方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。