Пример #1
0
int WebPDemuxSelectFragment(WebPIterator* iter, int fragment_num) {
  if (iter != NULL && iter->private_ != NULL && fragment_num > 0) {
    const WebPDemuxer* const dmux = (WebPDemuxer*)iter->private_;
    const Frame* const frame = GetFrame(dmux, iter->frame_num);
    if (frame == NULL) return 0;

    return SynthesizeFrame(dmux, frame, fragment_num, iter);
  }
  return 0;
}
Пример #2
0
int WebPDemuxSelectTile(WebPIterator* iter, int tile) {
  if (iter != NULL && iter->private_ != NULL && tile > 0) {
    const WebPDemuxer* const dmux = (WebPDemuxer*)iter->private_;
    const Frame* const frame = GetFrame(dmux, iter->frame_num_);
    if (frame == NULL) return 0;

    return SynthesizeFrame(dmux, frame, tile, iter);
  }
  return 0;
}
Пример #3
0
static int SetFrame(int frame_num, WebPIterator* const iter) {
  const Frame* frame;
  const WebPDemuxer* const dmux = (WebPDemuxer*)iter->private_;
  if (dmux == NULL || frame_num < 0) return 0;
  if (frame_num > dmux->num_frames_) return 0;
  if (frame_num == 0) frame_num = dmux->num_frames_;

  frame = GetFrame(dmux, frame_num);
  return SynthesizeFrame(dmux, frame, 1, iter);
}
Пример #4
0
/*
 * 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;
}
Пример #5
0
INT16 CGEN_VPROTECTED CFBAproc::SynthesizeUsingInto(data *idFea, data *idInto, data *idSyn) {
  INT32         nSamplingPoints               = idInto->GetNRecs();
  INT32         iSamplingPoints1              = 0;
  INT32         iSamples                      = 0;
  INT32         iSamplesOld                   = 0;
  INT32         nSamples                      = 0;
  INT32         nSamplesOfLastUnits           = 0;
  INT32         nSampleOfLastF0SamplingPoint  = 0;
  INT32         nSampleOfNextF0SamplingPoint  = 0;
  INT32         nPer                          = 0;
  INT32         iFrames                       = 0;
  INT32         iFramesOld                    = 0;
  INT32         nFrames                       = idFea->GetNRecs();
  INT32         iLab                          = 0;
  INT32         nLab                          = 0;
  INT32         iFea                          = 0;
  INT32         nCompVuv                      = idFea->FindComp("v/uv");
  INT32         nFea                          = idFea->GetNNumericComps() - (nCompVuv >= 0 ? 1 : 0);
  const char*   nextF0Pho                     = NULL;
  FLOAT64       lastF0Val                     = 1.0;
  FLOAT64       currF0Val                     = 1.0;
  FLOAT64       nextF0Val                     = 1.0;
  FLOAT64       nextF0Pos                     = 0.0;
  FLOAT64       lastI0Val                     = 1.0;
  FLOAT64       currI0Val                     = 1.0;
  FLOAT64       nextI0Val                     = 1.0;
  FLOAT64*      exc                           = NULL;
  FLOAT64*      fea                           = NULL;
  FLOAT64*      feaBefore                     = NULL;
  FLOAT64*      feaUsed                       = NULL;
  FLOAT64*      feaUsedBefore                 = NULL;
  BOOL          isVoiceless                   = FALSE;
  BOOL          isSmoothable                  = FALSE;
  BOOL          isSmoothableBefore            = FALSE;
  SLAB*         sIntoLab                      = NULL;
  SLAB*         sFeaLab                       = NULL;

  if(nSamplingPoints <= 0) {
    return O_K;
  }

  if(SynthesizeUsingIntoGetFeaIntoLab(idFea, idInto, &sFeaLab, &sIntoLab, &nSamples, &nLab) != O_K) {
    if(sFeaLab != NULL) dlp_free(sFeaLab);
    if(sIntoLab != NULL) dlp_free(sIntoLab);
    return NOT_EXEC;
  }

  exc       = (FLOAT64*)dlp_malloc(nSamples * sizeof(FLOAT64));
  fea       = (FLOAT64*)dlp_malloc(nFea * sizeof(FLOAT64));
  feaBefore = (FLOAT64*)dlp_malloc(nFea * sizeof(FLOAT64));

  idSyn->Reset(TRUE);
  idSyn->AddComp("syn", T_DOUBLE);
  idSyn->Allocate(nSamples);

  iFrames = 0;
  iLab = 0;
  iSamplingPoints1 = 0;
  iSamples = 0;
  iSamplesOld = 0;
  iFramesOld = 0;
  nSamplesOfLastUnits = 0;
  while(iSamples < nSamples) {
    if(iSamples >= nSampleOfNextF0SamplingPoint) {
      lastF0Val = nextF0Val;
      lastI0Val = nextI0Val;
      nSampleOfLastF0SamplingPoint = nSampleOfNextF0SamplingPoint;
      while(iSamples >= nSampleOfNextF0SamplingPoint) {
        for(; iSamplingPoints1 < nSamplingPoints; iSamplingPoints1++) {
          nextF0Pho = idInto->Sfetch(iSamplingPoints1, 2);
          nextF0Val = idInto->Dfetch(iSamplingPoints1, 3);
          nextI0Val = idInto->Dfetch(iSamplingPoints1, 6);
          nextF0Pos = idInto->Dfetch(iSamplingPoints1, 4);
          if(iSamplingPoints1 && dlp_strcmp(idInto->Sfetch(iSamplingPoints1-1, 0), idInto->Sfetch(iSamplingPoints1, 0))) {
            nSamplesOfLastUnits += (INT32)idInto->Dfetch(iSamplingPoints1-1, 1);
          }
          if((nextF0Val > 0.0) && (nextF0Pos >= 0.0) && (nextF0Pho != NULL) && (dlp_strlen(nextF0Pho) > 0)) {
            break;
          } else {
            if(this->m_nCheck > 0) {
              dlp_message(__FILE__,__LINE__,"no next f0 value");
            }
          }

        }
        if(iSamplingPoints1 >= nSamplingPoints) {
          nextF0Val = 1.0;
          nextI0Val = 1.0;
          nSampleOfNextF0SamplingPoint = nSamples;
        } else {
          nSampleOfNextF0SamplingPoint = (INT32)(((FLOAT64)nSamplesOfLastUnits + idInto->Dfetch(iSamplingPoints1, 1) * nextF0Pos) * (FLOAT64)m_nSrate / 1000.0 + 0.5);
          iSamplingPoints1++;
        }
      }
    }

    currF0Val = lastF0Val + (nextF0Val - lastF0Val) * (iSamples - nSampleOfLastF0SamplingPoint) / (nSampleOfNextF0SamplingPoint+1 - nSampleOfLastF0SamplingPoint);
    nPer = (INT32)((FLOAT64)m_nSrate / (currF0Val * (FLOAT64)m_nBaseF0) + 0.5);
    if((iSamples+nPer) > nSamples) nPer = nSamples-iSamples;

    currI0Val = lastI0Val + (nextI0Val - lastI0Val) * (iSamples - nSampleOfLastF0SamplingPoint) / (nSampleOfNextF0SamplingPoint+1 - nSampleOfLastF0SamplingPoint);

    while((iLab < nLab) && (sIntoLab[iLab].pos < iSamples)) {
      iSamplesOld = sIntoLab[iLab].pos;
      iFramesOld = INT32((FLOAT64)sFeaLab[iLab].pos / (FLOAT64)m_nCrate + 0.5);
      iLab++;
    }
    while((iFrames < nFrames) &&
        (((FLOAT64)(((iFrames-iFramesOld+1L))*m_nCrate)/((iLab>0)?(FLOAT64)(sFeaLab[iLab].pos -sFeaLab[iLab-1].pos ):sFeaLab[iLab].pos )) <
          ((FLOAT64)(iSamples-iSamplesOld)              /((iLab>0)?(FLOAT64)(sIntoLab[iLab].pos-sIntoLab[iLab-1].pos):sIntoLab[iLab].pos))))
      iFrames++;

    dlp_memmove(fea, (FLOAT64*)idFea->XAddr(iFrames, 0), nFea*sizeof(FLOAT64));
    if(m_bSynEnhancement) {
      FeaEnhancement(fea, nFea);
    }

    if(nCompVuv>=0) {
      isVoiceless  = (*(INT16*)idFea->XAddr(iFrames, nCompVuv) & 1) == 0;
      isSmoothable = (*(INT16*)idFea->XAddr(iFrames, nCompVuv) & 2) == 0;
    } else {
      isVoiceless = IsFeaVoiceless(fea, nFea);
      isSmoothable = 1;
    }

    if(feaUsed == NULL) {
      feaUsed = (FLOAT64*)dlp_malloc(nFea*sizeof(FLOAT64));
      dlp_memmove(feaUsed, fea, nFea*sizeof(FLOAT64));
    }

    if(m_bSynSmoothFea) {
      if(feaUsedBefore == NULL) {
        feaUsedBefore = (FLOAT64*)dlp_malloc(nFea*sizeof(FLOAT64));
        dlp_memmove(feaUsedBefore, fea, nFea*sizeof(FLOAT64));
      } else {
        if(isSmoothableBefore && isSmoothable) {
          for(iFea = 0; iFea < nFea; iFea++) {
            feaUsed[iFea] = 0.29289322 * (feaBefore[iFea] + fea[iFea]) + 0.41421356 * feaUsedBefore[iFea];
          }
        } else if(isSmoothableBefore && !isSmoothable) {
          for(iFea = 0; iFea < nFea; iFea++) {
            feaUsed[iFea] = 0.75 * feaBefore[iFea] + 0.25 * fea[iFea];
          }
        } else if(!isSmoothableBefore && isSmoothable) {
          for(iFea = 0; iFea < nFea; iFea++) {
            feaUsed[iFea] = 0.25 * feaBefore[iFea] + 0.75 * fea[iFea];
          }
        } else {
          dlp_memmove(feaUsed, fea, nFea*sizeof(FLOAT64));
        }
      }
      isSmoothableBefore = isSmoothable;
      dlp_memmove(feaUsedBefore, feaUsed, nFea*sizeof(FLOAT64));
    } else {
      dlp_memmove(feaUsed, fea, nFea*sizeof(FLOAT64));
    }
    dlp_memmove(feaBefore, fea, nFea*sizeof(FLOAT64));

    FLOAT64 gain = ((m_nWnorm == 0 ) ? 1.0 : (FLOAT64)sqrt((double)nPer)) * exp(m_nBaseI0) * currI0Val;

    switch(m_lpsExcType[0]) {
    case 'P':
      dlm_getExcPeriod(nPer, !isVoiceless, DLM_PITCH_PULSE, 1.0/gain, m_nSrate, exc+iSamples);
      break;
    case 'G':
      dlm_getExcPeriod(nPer, !isVoiceless, DLM_PITCH_GLOTT, 1.0/gain, m_nSrate, exc+iSamples);
      break;
    case 'R':
      dlm_getExcPeriod(nPer, !isVoiceless, DLM_PITCH_RANDPHASE, 1.0/gain, m_nSrate, exc+iSamples);
      break;
    case 'V':
      dlm_getExcPeriod(nPer, !isVoiceless, DLM_PITCH_VOICED, 1.0/gain, m_nSrate, exc+iSamples);
      break;
    case 'U':
      dlm_getExcPeriod(nPer, !isVoiceless, DLM_PITCH_UNVOICED, 1.0/gain, m_nSrate, exc+iSamples);
      break;
    default:
      return IERROR(this,FBA_BADARG,m_lpsExcType,"exc_type","P, G, R, V or U");
    }

    if(this->m_nCheck > 0) {
      dlp_message(__FILE__,__LINE__,"nPer=%5d, uv/v=%1d, s/ns=%ld, pos=%7.1f, F0=%4.2f/%4.2f/%4.2f, idFea (%3d) %5s, Fea (%3d): %5s (%3d), Into (%3d) %5s (%3d)", \
          (int)nPer,
          (int)!isVoiceless,
          (int)isSmoothable,
          (double)((FLOAT64)iSamples*1000.0/(FLOAT64)m_nSrate),
          (double)lastF0Val,
          (double)currF0Val,
          (double)nextF0Val,
          (int)iFrames,
          idFea->Sfetch(iFrames, nFea),
          (int)iLab, sFeaLab[iLab].phoneme,
          (int)sFeaLab[iLab].pos,
          (int)iLab, sIntoLab[iLab].phoneme,
          (int)sIntoLab[iLab].pos);
    }

    if(SynthesizeFrame(feaUsed, nFea, &exc[iSamples], nPer, (FLOAT64*)idSyn->XAddr(iSamples, 0)) != O_K) return IERROR(this,FBA_SYNTHESISE, iFrames, 0,0);

    iSamples += nPer;
  }

  dlp_free(exc);
  dlp_free(sIntoLab);
  dlp_free(sFeaLab);
  dlp_free(fea);
  dlp_free(feaBefore);
  dlp_free(feaUsed);
  if(m_bSynSmoothFea) {
    dlp_free(feaUsedBefore);
  }

  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;
}