Ejemplo n.º 1
0
/**
 * Composed state hash map node allocation function. Hash nodes are taken from
 * a pool: {@link grany m_nGrany} nodes are allocated at a time to save memory
 * allocations.
 */
hnode_t* CFst_Cps_HashAllocNode(void* lpContext)
{
  CFst*    _this = NULL;
  INT32    nPool = 0;
  INT32    nItem = 0;
  hnode_t* lpRet = NULL;

  /* Get this pointer and locate next hash node */
  _this = (CFst*)lpContext;
  nPool = _this->m_nCpsHnpoolSize / _this->m_nGrany;
  nItem = _this->m_nCpsHnpoolSize - nPool*_this->m_nGrany;

  /* Grow size of hash node pool table if necessary */
  if (nPool>=(INT32)(dlp_size(_this->m_lpCpsHnpool)/sizeof(hnode_t*)))
    _this->m_lpCpsHnpool =
      (void**)dlp_realloc(_this->m_lpCpsHnpool,nPool+100,sizeof(hnode_t*));

  /* Allocate a new hash node pool if necessary */
  if (_this->m_lpCpsHnpool[nPool]==NULL)
    ((hnode_t**)_this->m_lpCpsHnpool)[nPool] =
    	(hnode_t*)dlp_calloc(_this->m_nGrany,sizeof(hnode_t));

  /* Increment pool size and return pointer to new hash node */
  _this->m_nCpsHnpoolSize++;
  lpRet = &((hnode_t**)_this->m_lpCpsHnpool)[nPool][nItem];
  return lpRet;
}
Ejemplo n.º 2
0
/**
 * Registers an instanciation function and assosicates it with a dLabPro class
 * name.
 *
 * @param lpClassWord
 *         <code>SWord</code> struct containing dLabPro class info
 * @see CDlpObject_CreateInstanceOf
 * @see CDlpObject_UnregisterAllClasses
 */
void CDlpObject_RegisterClass(const SWord* lpClassWord)
{
  INT32 nXC = 0;

  if (!lpClassWord                           ) return;
  if (lpClassWord->nWordType!=WL_TYPE_FACTORY) return;

  nXC               = __nXClassRegistry++;
  __lpClassRegistry = (SWord*)dlp_realloc(__lpClassRegistry,__nXClassRegistry,sizeof(SWord));
  dlp_memmove(&__lpClassRegistry[nXC],lpClassWord,sizeof(SWord));
}
Ejemplo n.º 3
0
INT16 CGEN_PRIVATE CProsody::PmFo(data *dPM, INT32 nSrate, INT32 nSrateF0, data *dF0)    
{
  /* Initialization */
  INT32 i = 0;
  INT32 ii = 0;
  INT32 j = 0;  
  INT32 nPitchMark = 0;         // Number of Pitch Marks  
  FLOAT64 nAuxValue = 0;         // Auxiliary value
  INT32 nSumSamplePM = 0;         // Sum of PM from (0) to last PM in (samples)
  INT32 nSrate_Ratio = 0;        // Sample Rate Ratio = nSrate / nSrateF0


  
  /* Validation of data instance dF0 */
  if (!dF0 || !dF0->IsEmpty())    // If dF0 not exist or empty then return false
    return NOT_EXEC;            // NOT_EXEC = -1 (Generic error)
 
 
  /* Definition of data instance dF0 */
  // One column for F0 values (Hz)  
    dF0->AddNcomps(T_DOUBLE, 1);
    dF0->SetCname(0, "nF0");

  
     /* Number of Pitch Marks */
  nPitchMark  = dPM->GetNRecs();  // GetNRecs returns the number of valid records in the data object 
  //fprintf(stdout,"\nNumber of Pitch Marks:   %i\n",nPitchMark);

  /* Validation of data instance dPM */
  if ( nPitchMark == 0 )    // If there is no Pitch mark
  {
    //fprintf(stdout,"\nError: There is no Pitch Marks in the speech signal.");
    //return NOT_EXEC;            // NOT_EXEC = -1 (Generic error)
    return IERROR(this,NO_PM,0,0,0);
  }  

    
  /* Validation of sample rate */
    if(nSrate == 0)
    {
      //fprintf(stdout, "\nError: Sample rate for speech signal (PM file) is not specified");
      //return NOT_EXEC;
      return IERROR(this,NO_SRate,0,0,0);
    }


  /* Convert PM data object (2 columns [nPer][anreg]) to two separate columns */
  /*----------------------------------------------------------------------- 
     Important Information:
     The output of the method (-analyze) for PMA is a PM data object of type short.
     This data object consist of two separate columns:
     nPer  : is the distance between PM in samples
       anreg : is the Anregung [ (0) for (voiceless or stimmlos) and (1) for (voiced or stimmhaft)] 
                       *** Important ***
       * The data object of PMproc class or data objects with more than one component
       * were stored in memory (record after record) (the first line, second line, third line, ...)
       * i.e. [r,c] = {[0,0],[0,1],[1,0],[1,1],[2,0],[2,1],....}
       ---------------------------------------------------------------------*/
  INT16 *idPMnPer = NULL;  // PMA [nPer] = column 1 
  INT16 *idPManreg = NULL; // PMA [anreg] = column 2
  
  idPMnPer = (INT16*)dlp_calloc(nPitchMark, sizeof(INT16));  // Allocates zero-initialize memory
  idPManreg = (INT16*)dlp_calloc(nPitchMark, sizeof(INT16));  // Allocates zero-initialize memory
  
  

  for (i = 0; i < nPitchMark; i++)
  {
    nAuxValue = CData_Dfetch(dPM,i,0);
    idPMnPer[i] = (INT16)nAuxValue;
    //fprintf(stdout,"PMA-nPer %i = %i",i,idPMnPer[i]);
      
    nAuxValue = CData_Dfetch(dPM,i,1);
    idPManreg[i] = (INT16)nAuxValue;
    //fprintf(stdout,"\t\tPMA-Anreg %i = %i\n",i,idPManreg[i]);  
  }
  
  /*
  fprintf(stdout,"\n\nThe nPer and Anreg of PM: \n");  // show data 
  //for(i=0; i<nPitchMark; i++)
  for(i=0; i<100; i++)  
    fprintf(stdout,"nPer %i = %i \t\t Anreg %i = %i \n",i,idPMnPer[i],i,idPManreg[i]);
  */


  /* Calculate the length of PM from (0) to last PM in (samples) 
     and allocate a vector with this length */
  for (i=0; i<nPitchMark; i++)
  {
    nSumSamplePM = nSumSamplePM + idPMnPer[i];
  }
  //fprintf(stdout,"\n\nNumber of samples from (0) to last PM:   %i\n",nSumSamplePM);

  
  // Allocate memory
  INT32 *idExpandPM = NULL; 
  idExpandPM = (INT32*)dlp_calloc(nSumSamplePM, sizeof(INT32));  // Allocates zero-initialize memory

  /*----- Produce Zahlenvektor for PMs -----*/
  INT16 nCurrentPMnPer = 0;    // Length of current PM in samples
  INT16 nCurrentPManreg = 0;    // Anregung of current PM
  INT16 nNextPManreg = 0;      // Anregung of next PM


  for (i = 0; i < nPitchMark-1; i++)
  {
    nCurrentPMnPer = idPMnPer[i];    // Length of current PM in samples
    nCurrentPManreg = idPManreg[i];    // Anregung of current PM
    nNextPManreg = idPManreg[i+1];    // Anregung of next PM
    
     /*----- Produce Zahlenvektor for (nPitchMark-1) PMs -----*/
     // PM current is unvoiced && PM next is unvoiced  =>  Values = 0
     if ( nCurrentPManreg == 0 && nNextPManreg == 0 )
     {
       for( ii = 0; ii < nCurrentPMnPer ; ii++ )
       {
         idExpandPM[j] = (INT32) 0;
         j++;
       }
     }
     // PM current is unvoiced && PM next is voiced  =>  Values = 0     
     else if ( nCurrentPManreg == 0 && nNextPManreg == 1 )
     {
       for( ii = 0; ii < nCurrentPMnPer ; ii++ )
       {
         idExpandPM[j] = (INT32) 0;
         j++;
       }
     }     
     // PM current is voiced && PM next is unvoiced  =>  Values = nCurrentPMnPer
     else if ( nCurrentPManreg == 1 && nNextPManreg == 0 )
     {
       for( ii = 0; ii < nCurrentPMnPer ; ii++ )
       {
         idExpandPM[j] = (INT32) nCurrentPMnPer;
         //idExpandPM[j] = (INT32) 0;
         j++;
       }
     }     
     // PM current is voiced && PM next is voiced  =>  Values = nCurrentPMnPer
     else   // else if( nCurrentPManreg == 1 && nNextPManreg == 1 )
     {
       for( ii = 0; ii < nCurrentPMnPer ; ii++ )
       {
         idExpandPM[j] = (INT32) nCurrentPMnPer;
         j++;
       }
     }     
  }



    /*----- Produce Zahlenvektor for last PM -----*/
  nCurrentPMnPer = idPMnPer[nPitchMark-1];    // Length of last PM in samples
  nCurrentPManreg = idPManreg[nPitchMark-1];    // Anregung of last PM
  
  if ( nCurrentPManreg == 1 )
  {
     for( ii = 0; ii < nCurrentPMnPer ; ii++ )
     {
       idExpandPM[j] = (INT32) nCurrentPMnPer;
       j++;
     }
  }
  else 
  {
     for( ii = 0; ii < nCurrentPMnPer ; ii++ )
     {
       idExpandPM[j] = (INT32) 0;
       j++;
     }    
  }  
  
  /*  
  fprintf(stdout,"\n\nThe expand values of PM: \n");  // show data 
  //for(i=0; i<nPitchMark; i++)
  for(i=0; i<300; i++)  
    fprintf(stdout,"Expand values of PM %i = %i \n",i,idExpandPM[i]);
  */
  
  

  /*---------- Calculate F0 values ----------*/
  // Calculate Sample Rate Ratio = nSrate / nSrateF0;
  if ( nSrateF0 == 0 )      // Divide by zero (false !!!)
  {
      //fprintf(stdout, "\nError: Divide by zero.");
      //return NOT_EXEC;
      return IERROR(this,Div_Zero,0,0,0);
  }
  else
  {
    nSrate_Ratio = (INT32) nSrate / nSrateF0;
  }
  //fprintf(stdout,"\nSample Rate Ratio:   %i\n",nSrate_Ratio);



  // Allocate memory for F0 values
  FLOAT64 *idContourF0 = NULL;

  INT32 nNumberF0 = 0;  // Number of F0 values in file

  for ( i = 0; i < (nSumSamplePM-nSrate_Ratio); i+=nSrate_Ratio )
  {
    if( idExpandPM[i+nSrate_Ratio] == 0 )
    {
      idContourF0 = (FLOAT64*)dlp_realloc(idContourF0, (nNumberF0+1), sizeof(FLOAT64));
      idContourF0[nNumberF0] = (FLOAT64) 0;
      nNumberF0 = nNumberF0 + 1;
    }
    else
    {
      idContourF0 = (FLOAT64*)dlp_realloc(idContourF0, (nNumberF0+1), sizeof(FLOAT64));
      //idContourF0[nNumberF0] = (FLOAT64) nSrate / idExpandPM[i+nSrate_Ratio];
      nAuxValue =  (FLOAT64) nSrate / idExpandPM[i+nSrate_Ratio];
      idContourF0[nNumberF0] = nAuxValue;
      nNumberF0 = nNumberF0 + 1;
    }    
    
  }

  // Delete single F0 value
  for ( i=1; i<nNumberF0-2; i++)
  {
    if(idContourF0[i]!=0 && idContourF0[i-1]==0 && idContourF0[i+1]==0)
    {
      idContourF0[i]=0;
    }
  }
  

  /* Write F0 values in struct */
    F0_CONTOUR *F0_contour = NULL;  // (F0_contour) is an object of struct (F0_CONTOUR)


  F0_contour = (F0_CONTOUR*)dlp_calloc(nNumberF0, sizeof(F0_CONTOUR));  // Allocates zero-initialize memory

  for(i = 0; i < nNumberF0; i++)  
  {
        (F0_contour + i)->nF0value = idContourF0[i];
        //fprintf( stdout,"nF0value  %i = %f\n",i,idContourF0[i] );
  }


    
  /* Copy F0 values from (struct F0_contour) to output data object (dF0) */
  dF0->AddRecs(nNumberF0, 1); // AddRecs: Appends (n) records to the end of the table (data object)  
  for( i = 0; i < nNumberF0; i++ )
  {
      dF0->Dstore((FLOAT64)(F0_contour + i)->nF0value, i, 0);
  }


  /*
  FLOAT64 nAuxCopy = 0;
  
  for (i = 0; i < nNumberF0; i++)
  {
    nAuxCopy = (FLOAT64)CData_Dfetch(dF0,i,0);
    fprintf(stdout,"F0 value %i = %f\n",i,nAuxCopy);  
  }
  */  
  
  dlp_free(idPMnPer);
  dlp_free(idPManreg);  
  dlp_free(idExpandPM);    
  dlp_free(idContourF0);
  dlp_free(F0_contour);    
      
  return O_K;
}
Ejemplo n.º 4
0
/**
 * Polymorphic set operations.
 * 
 * @param lpsOpname
 *          <p>Operator name</p>
 *          <table>
 *            <tr><th><code>lpsOpname</code></th><th>Boolean</th><th>Numeric</th><th>String</th><th>Instance</th></tr>
 *            <tr><td><code>=  </code></td><td>x</td><td>x</td><td>x</td><td>x</td></tr>
 *            <tr><td><code>+= </code></td><td>x</td><td>x</td><td>x</td><td>-</td></tr>
 *            <tr><td><code>-= </code></td><td>-</td><td>x</td><td>-</td><td>-</td></tr>
 *            <tr><td><code>*= </code></td><td>x</td><td>x</td><td>-</td><td>-</td></tr>
 *            <tr><td><code>/= </code></td><td>-</td><td>x</td><td>-</td><td>-</td></tr>
 *            <tr><td><code>++=</code></td><td>-</td><td>x</td><td>-</td><td>-</td></tr>
 *            <tr><td><code>--=</code></td><td>-</td><td>x</td><td>-</td><td>-</td></tr>
 *          </table>
 *          <p>For type conversion rules see
 *            <code><a href="function.html"><code�class="link">CFunction</code></a><code>::StackLogic</code>,
 *            <code><a href="function.html"><code�class="link">CFunction</code></a><code>::StackNumber</code>,
 *            <code><a href="function.html"><code�class="link">CFunction</code></a><code>::StackString</code> and
 *            <code><a href="function.html"><code�class="link">CFunction</code></a><code>::StackInstance</code>.
 *          </p>
 * @return <code>O_K</code> if successfull, a (negative) error code otherwise
 */
INT16 CGEN_PROTECTED CVar_SetOp(CVar *_this,const char* lpsOpname)
{
  StkItm si;
  if (dlp_strcmp(lpsOpname,"++=")!=0 && dlp_strcmp(lpsOpname,"--=")!=0)
  {
    if (!CDlpObject_MicGet(BASEINST(_this))->GetX)
      return
        IERROR(_this,VAR_NOTSUPPORTED,"Polymorphic signatures"," by caller",0);
    if (!MIC_GET_X(1,&si)) return NOT_EXEC;
  }
    
  if (dlp_strcmp(lpsOpname,"=")==0)
    switch (si.nType)
    {
      case T_BOOL    : return CVar_Bset(_this,si.val.b);
      case T_COMPLEX : return CVar_Vset(_this,si.val.n);
      case T_STRING  : return CVar_Sset(_this,si.val.s);
      case T_INSTANCE: return CVar_Iset(_this,si.val.i);
      default:
        DLPASSERT(FMSG("Unknown variable type"));
        return NOT_EXEC;
    }
  else if (dlp_strcmp(lpsOpname,"+=")==0)
  {
    if (_this->m_nType==T_COMPLEX) return CVar_Vset(_this,CMPLX_PLUS(_this->m_nNVal,si.val.n));
    if (_this->m_nType==T_STRING)
    {
      char* lpsSi = NULL;
      MIC_PUT_X(&si);
      lpsSi = MIC_GET_S(1,0);
      _this->m_lpsSVal = (char*)dlp_realloc(_this->m_lpsSVal,
        dlp_strlen(_this->m_lpsSVal)+dlp_strlen(lpsSi)+1,sizeof(char));
      if (!_this->m_lpsSVal) return IERROR(_this,ERR_NOMEM,0,0,0);
      dlp_strcat(_this->m_lpsSVal,lpsSi);
      return O_K;
    }
    if (_this->m_nType==T_BOOL)
    {
      MIC_PUT_X(&si);
      _this->m_bBVal|=MIC_GET_B(1,0);
      return O_K;
    }
    return
      IERROR(_this,VAR_NOTSUPPORTED,"Operator +="," for this variable type",0);
  }
  else if (dlp_strcmp(lpsOpname,"*=")==0)
  {
    if (_this->m_nType==T_COMPLEX) return CVar_Vset(_this,CMPLX_MULT(_this->m_nNVal,si.val.n));
    if (_this->m_nType==T_BOOL)
    {
      MIC_PUT_X(&si);
      _this->m_bBVal&=MIC_GET_B(1,0);
      return O_K;
    }
    return
      IERROR(_this,VAR_NOTSUPPORTED,"Operator *="," for this variable type",0);
  }
  else if (dlp_strcmp(lpsOpname,"-=")==0)
  {
    if (_this->m_nType==T_COMPLEX) return CVar_Vset(_this,CMPLX_MINUS(_this->m_nNVal,si.val.n));
    return
      IERROR(_this,VAR_NOTSUPPORTED,"Operator -="," for this variable type",0);
  }
  else if (dlp_strcmp(lpsOpname,"/=")==0)
  {
    if (_this->m_nType==T_COMPLEX) return CVar_Vset(_this,CMPLX_MULT(_this->m_nNVal,CMPLX_INVT(si.val.n)));
    return
      IERROR(_this,VAR_NOTSUPPORTED,"Operator /="," for this variable type",0);
  }
  else if (dlp_strcmp(lpsOpname,"++=")==0)
  {
    if (_this->m_nType==T_COMPLEX) return CVar_Vset(_this,CMPLX_INC(_this->m_nNVal));
    return
      IERROR(_this,VAR_NOTSUPPORTED,"Operator ++="," for this variable type",0);
  }
  else if (dlp_strcmp(lpsOpname,"--=")==0)
  {
    if (_this->m_nType==T_COMPLEX) return CVar_Vset(_this,CMPLX_DEC(_this->m_nNVal));
    return 
      IERROR(_this,VAR_NOTSUPPORTED,"Operator --="," for this variable type",0);
  }
  
  return NOT_EXEC;
}
Ejemplo n.º 5
0
INT16 CGEN_PRIVATE CFBAproc::SynthesizeUsingIntoGetFeaIntoLab(CData* idFea, CData* idInto, SLAB** sFeaLab, SLAB** sIntoLab, INT32* nSamples, INT32* nLab) {
  INT32         nSamplingPoints               = idInto->GetNRecs();
  INT32         iSamplingPoints1              = 0;
  INT32         iSamplingPoints2              = 0;
  INT32         nCompPho                      = -1;
  INT32         iFrames                       = 0;
  INT32         nFrames                       = idFea->GetNRecs();
  INT32         iLab                          = 0;
  const char*   lastUnit                      = NULL;
  const char*   currUnit                      = NULL;
  FLOAT64       currDura                      = 0.0;

  nCompPho = idFea->FindComp("~PHO");
  if(nCompPho < 0) nCompPho = idFea->FindComp("lab");
  if(nCompPho < 0) return IERROR(this,FBA_SYNTHESISE,0,"Missing label track.",0);

  iLab = 0;
  iFrames = 1;
  lastUnit = idFea->Sfetch(0, nCompPho);
  while(iFrames < nFrames) {
    currUnit = idFea->Sfetch(iFrames, nCompPho);
    if(dlp_strcmp(currUnit, lastUnit)) {
      (*sFeaLab) = (SLAB*)dlp_realloc((*sFeaLab), iLab+1, sizeof(SLAB));
      (*sFeaLab)[iLab].phoneme = lastUnit;
      (*sFeaLab)[iLab].pos = iFrames*m_nCrate;
      lastUnit = currUnit;
      iLab++;
    }
    iFrames++;
  }
  (*sFeaLab) = (SLAB*)dlp_realloc((*sFeaLab), iLab+1, sizeof(SLAB));
  (*sFeaLab)[iLab].phoneme = lastUnit;
  (*sFeaLab)[iLab].pos = iFrames*m_nCrate;
  iLab++;

  *nLab = 0;
  lastUnit = "";
  iSamplingPoints1 = 0;
  while(iSamplingPoints1 < nSamplingPoints) {
    currUnit  = idInto->Sfetch(iSamplingPoints1, 0);
    currDura  = idInto->Dfetch(iSamplingPoints1, 1);
    if((currDura <= 0) || (idInto->m_lpCunit[0] == '%')) {
      if(*nLab < iLab) {
        if((currDura >= 0) && (idInto->m_lpCunit[0] == '%')) {
          currDura = (((*sFeaLab)[*nLab].pos - ((*nLab==0)? 0: (*sFeaLab)[*nLab-1].pos)) * 1000 / m_nSrate) * (currDura / 100.0);
        } else {
          currDura = ((*sFeaLab)[*nLab].pos - ((*nLab==0)? 0: (*sFeaLab)[*nLab-1].pos)) * 1000 / m_nSrate;
        }
        iSamplingPoints2 = iSamplingPoints1;
        while((iSamplingPoints2 < nSamplingPoints) && !dlp_strcmp(idInto->Sfetch(iSamplingPoints2, 0), currUnit) && (idInto->Dfetch(iSamplingPoints2,1) <= 0)) {
          idInto->Dstore(currDura, iSamplingPoints2, 1);
          iSamplingPoints2++;
        }
      } else {
        dlp_free(*sFeaLab);
        return IERROR(this, FBA_SYNINTOLAB, currUnit, iLab-1, 0);
      }
    }
    if(dlp_strcmp(currUnit, lastUnit)) {
      if(dlp_strcmp(currUnit, (*sFeaLab)[*nLab].phoneme)) {
        dlp_free(*sFeaLab);
        return IERROR(this, FBA_SYNINTOLAB, lastUnit, iLab, 0);
      }
      lastUnit = currUnit;
      *nSamples += (INT32)(currDura * (FLOAT64)m_nSrate / 1000.0 +0.5);
      (*sIntoLab) = (SLAB*)dlp_realloc((*sIntoLab), *nLab+1, sizeof(SLAB));
      (*sIntoLab)[*nLab].phoneme = currUnit;
      (*sIntoLab)[*nLab].pos = *nSamples;
      (*nLab)++;
    }
    iSamplingPoints1++;
  }
  return O_K;
}