Ejemplo n.º 1
0
/**
 * <p id=dlm_fft_C>Computes the complex (inverse) fast Fourier transform.</p>
 *
 * @param C
 *          Pointer to an array containing the input, will be
 *          overwritten with the result.
 * @param nXL
 *          Length of signals. If length not power of 2 {@link dlm_dftC} will be
 *          executed.
 * @param bInv
 *          If non-zero the function computes the inverse complex Fourier
 *          transform
 * @return <code>O_K</code> if successfull, a (begative) error code otherwise
 *
 * <h4>Remarks</h4>
 * <ul>
 *   <li>The function creates the tables by its own, stores them in static arrays and
 *   reuses them for all subsequent calls with the same value of
 *   <code>nXL</code>.</li>
 * </ul>
 */
INT16 dlm_fftC
(
  COMPLEX64*     C,
  INT32          nXL,
  INT16          bInv
)
{
  register INT32 i;
  INT16 ret = O_K;
  FLOAT64* RE = (FLOAT64*)dlp_calloc(nXL, sizeof(FLOAT64));
  FLOAT64* IM = (FLOAT64*)dlp_calloc(nXL, sizeof(FLOAT64));

  for(i = nXL-1; i >= 0; i--) {
    RE[i] = C[i].x;
    IM[i] = C[i].y;
  }
  if((ret = dlm_fft(RE,IM,nXL,bInv)) == O_K) {
    for(i = nXL-1; i >= 0; i--) {
      C[i].x = RE[i];
      C[i].y = IM[i];
    }
  }

  dlp_free(RE);
  dlp_free(IM);

  return ret;                                                                   /* All done                          */
}
Ejemplo n.º 2
0
/**
 * Destroys a string table.
 *
 * @param lpST String table data structure (returned by {@link Ssr_Init CFst_Ssr_Init})
 * @see Ssr_Init CFst_Ssr_Init
 */
void CGEN_SPROTECTED CFst_Ssr_Done(FST_SST_TYPE* lpST)
{
  INT32 i;

  for (i=0; i<CDlpTable_GetNRecs(lpST->iST); i++) __dlp_free(ST_LP(lpST,i));

  CDlpTable_DestroyInstance(lpST->iST);
  dlp_free(lpST->lpBuf);
  dlp_free(lpST);
}
Ejemplo n.º 3
0
/**
 * <p>Stabilises a polynomial. I.e. mirroring all roots located outside the unit circle into the unit circle.</p>
 *
 * @param poly
 *          Pointer to polynomial coefficients.
 * @param n_poly
 *          Number of polynomial coefficients stored in  <CODE>poly</CODE>.
 * @return  Number of mirrored roots.
 */
INT32 dlm_stabilise(FLOAT64* poly, INT32 n_poly) {
  COMPLEX64* roots = NULL;
  FLOAT64* a1 = NULL;
  FLOAT64* a2 = NULL;
  FLOAT64 a0;
  FLOAT64 r;
  FLOAT64 rr;
  INT16 is_stable;
  INT32 i_poly1;
  INT32 i_poly2;
  INT32 i_poly3;
  INT32 n_roots_stabilised = 0;

  roots = (COMPLEX64*) dlp_calloc(n_poly-1, sizeof(COMPLEX64));
  a1 = (FLOAT64*) dlp_calloc(2*n_poly, sizeof(FLOAT64));
  a2 = a1 + n_poly;

  a0 = poly[0];

  dlm_roots(poly, roots, n_poly);
  is_stable = 1;
  rr = 1.0;
  for (i_poly1 = 0; i_poly1 < (n_poly - 1); i_poly1++) {
    r = roots[i_poly1].x * roots[i_poly1].x + roots[i_poly1].y * roots[i_poly1].y;
    if (r > 1.0) {
      n_roots_stabilised++;
      is_stable = 0;
      roots[i_poly1].x /= r;
      roots[i_poly1].y /= r;
      rr = rr * sqrt(r);
    }
  }
  if (is_stable == 0) {
    a1[0] = 1.0;
    memset(a1 + 1, 0L, (n_poly - 1) * sizeof(FLOAT64));
    memset(a2, 0L, n_poly * sizeof(FLOAT64));
    for (i_poly2 = 0; i_poly2 < (n_poly - 1); i_poly2++) {
      for (i_poly3 = i_poly2 + 1; i_poly3 > 0; i_poly3--) {
        a1[i_poly3] -= roots[i_poly2].x * a1[i_poly3 - 1] - roots[i_poly2].y * a2[i_poly3 - 1];
        a2[i_poly3] -= roots[i_poly2].x * a2[i_poly3 - 1] + roots[i_poly2].y * a1[i_poly3 - 1];
      }
    }
    for (i_poly2 = 1; i_poly2 < n_poly; i_poly2++) {
      poly[i_poly2] = a1[i_poly2];
    }
    *poly = a0 * rr;
  }

  dlp_free(roots);
  dlp_free(a1);

  return n_roots_stabilised;
}
Ejemplo n.º 4
0
/*
 * Replaces phoneme durations with durations from inventory, if
 * durations are equal to zero.
 * idFea is supposed to contain the concatenated inventory units.
 * *
 * @return O_K if successfull, NOT_EXEC otherwise
 */
INT16 CGEN_VPROTECTED CFBAproc::GetDurationsFromInventory(data *idFea, data *idInto) {
  INT16 ret      = O_K;
  INT32 nSamples = 0;
  INT32 nLab     = 0;
  SLAB* sFeaLab  = NULL;
  SLAB* sIntoLab = NULL;

  ret = SynthesizeUsingIntoGetFeaIntoLab(idFea, idInto, &sFeaLab, &sIntoLab, &nSamples, &nLab);
  dlp_free(sFeaLab);
  dlp_free(sIntoLab);
  return ret;
}
Ejemplo n.º 5
0
/**
 *  Expand/reduce number of pitch markers to fit new target sum of period length.
 *
 * @param idSrc        source object
 * @param idDst        target object
 * @param n            target length
 * @return O_K if sucessfull, not exec otherwise
 */
INT16 CGEN_PUBLIC CPMproc::ExpandPm(CData *idSrc, CData* idDst, INT32 n)
{
  if(CData_IsEmpty(idSrc) == TRUE) return NOT_EXEC;
  if(n <= 0)                       return NOT_EXEC;

  CREATEVIRTUAL(CData,idSrc,idDst);

  DLPASSERT(CData_GetNComps(idSrc) == 2);

  CData_Reset(idDst, TRUE);
  CData_Scopy(idDst,idSrc);

  INT32    nRecsNew = 0;
  INT32    nRecs    = (INT32)CData_GetNRecs(idSrc);
  INT16* pm_new = NULL;

  if(dlm_pm_expand((INT16*)CData_XAddr(idSrc,0,0), nRecs, &pm_new, &nRecsNew, n) != O_K) {
    return IERROR(this,ERR_NULLARG, "", NULL, NULL);
  }
  CData_Allocate(idDst,nRecsNew);
  dlp_memmove(CData_XAddr(idDst,0,0), pm_new, nRecsNew*2*sizeof(INT16));
  dlp_free(pm_new);
  CData_CopyDescr(idDst,idSrc);

  /* clean up */
  DESTROYVIRTUAL(idSrc,idDst)

  return(O_K);
}
Ejemplo n.º 6
0
/**
 *  Convert f0-contour with equal spaced sampling points to pitch markers.
 *
 * @param idSrc        source f0-contour
 * @param idDst        target pitch marker
 * @param n            target sum of pitch marker lengths
 * @param srate        sampling rate
 * @return O_K if sucessfull, not exec otherwise
 */
INT16 CGEN_PUBLIC CPMproc::F02pm(CData *idSrc, CData* idDst, INT32 n, INT32 srate) {

  INT16* p_pm = NULL;
  INT32    n_pm = 0;

  if(CData_IsEmpty(idSrc) == TRUE) return NOT_EXEC;
  if(n <= 0)                       return NOT_EXEC;

  DLPASSERT(CData_GetNComps(idSrc) == 1);

  CREATEVIRTUAL(CData,idSrc,idDst);

  CData_Reset(idDst, TRUE);

  dlm_f02pm((FLOAT64*)idSrc->XAddr(0,0), idSrc->GetNRecs(), &p_pm, &n_pm, n, srate);

  CData_AddComp(idDst, "pm",   T_SHORT);
  CData_AddComp(idDst, "v/uv", T_SHORT);
  CData_Allocate(idDst, n_pm);
  ISETFIELD_RVALUE(idDst, "fsr", 1000.0/srate);

  dlp_memmove(idDst->XAddr(0,0), p_pm, 2*n_pm*sizeof(INT16));

  /* clean up */
  DESTROYVIRTUAL(idSrc,idDst)

  dlp_free(p_pm);

  return(O_K);
}
Ejemplo n.º 7
0
void CDlpFile_Destructor(CDlpObject* __this)
{
	GET_THIS_VIRTUAL(CDlpFile);
	{
	/*{{CGEN_DONECODE */

  /* free list of filetypes */
  if(_this->m_lpFtypes)
  {
  list_process(_this->m_lpFtypes,NULL,CDlpFile_FreeFTypeList);
  list_destroy_nodes(_this->m_lpFtypes);
  list_destroy(_this->m_lpFtypes);
  _this->m_lpFtypes = NULL;
  }

  DONE;

	/*}}CGEN_DONECODE */
	}

#ifndef __cplusplus

	/* Destroy base instance */
	CDlpObject_Destructor(_this->m_lpBaseInstance);
	dlp_free(_this->m_lpBaseInstance);
	_this->m_lpBaseInstance = NULL;

#endif /* #ifndef __cplusplus */
}
Ejemplo n.º 8
0
CLPCproc::~CLPCproc()
{
  //{{CGEN_DONECODE
  if(m_lpMemLpc != NULL) dlp_free(m_lpMemLpc);
  DONE;
  //}}CGEN_DONECODE
}
Ejemplo n.º 9
0
/**
 * <p>Calculates polynomial from roots.</p>
 *
 * @param rtr
 *          Real roots.
 * @param rti
 *          Imaginary roots.
 * @param m
 *          Number of roots stored in  <CODE>rtr</CODE> and <CODE>rti</CODE>.
 * @param ar
 *          Pointer to resulting real polynomial coefficients.
 * @param ai
 *          Pointer to resulting imaginary polynomial coefficients (or <code>NULL</code>).
 * @return <code>O_K</code> if successful, a (negative) error code otherwise
 */
INT16 dlm_poly(FLOAT64 rtr[], FLOAT64 rti[], INT16 m, FLOAT64 ar[], FLOAT64 ai[]) {
  INT16 i = 0;
  INT16 j = 0;
  FLOAT64* arp = NULL;
  FLOAT64* aip = NULL;

  if ((!ar) || (!rtr) || (!rti)) return NOT_EXEC;

  if (ai == NULL) {
    aip = (FLOAT64*) dlp_calloc(m+1, sizeof(FLOAT64));
    if (!aip) return ERR_MEM;
    arp = ar;
  } else {
    aip = ai;
    arp = ar;
  }

  dlp_memset(arp, 0L, (m + 1) * sizeof(FLOAT64));
  dlp_memset(aip, 0L, (m + 1) * sizeof(FLOAT64));
  arp[0] = 1.0;

  for (i = 0; i < m; i++) {
    for (j = i; j >= 0; j--) {
      arp[j + 1] = arp[j + 1] - rtr[i] * arp[j] + rti[i] * aip[j];
      aip[j + 1] = aip[j + 1] - rti[i] * arp[j] - rtr[i] * aip[j];
    }
  }

  if (ai == NULL) dlp_free(aip);

  return O_K;
}
Ejemplo n.º 10
0
INT16 CGEN_IGNORE dlm_pam(FLOAT64* X, INT32 nC, INT32 nRX, FLOAT64* Q, INT32 nRQ) {
  INT32* clusters = (INT32*) dlp_calloc(nRQ,sizeof(INT32));
  INT32* classify = (INT32*) dlp_calloc(nRX,sizeof(INT32));
  INT32 iRX1 = 0;
  INT32 iRX2 = 0;
  INT32 iRQ = 0;
  FLOAT64 min = T_DOUBLE_MAX;
  FLOAT64 distance = 0.0;
  FLOAT64 error = T_DOUBLE_MAX;
  FLOAT64 error_old = T_DOUBLE_MAX;
  FLOAT64* pX = X;


  for(iRQ = 0; iRQ < nRQ; iRQ++) {
    clusters[iRQ] = iRQ * nRX / nRQ;
  }
  while(1) {
    error_old = error;
    error = dlm_pam_assign(X,nC,classify,nRX,clusters,nRQ);
    if(error_old <= error) break;
    for(iRQ = 0; iRQ < nRQ; iRQ++) {
      min = T_DOUBLE_MAX;
      for(iRX1 = 0; iRX1 < nRX; iRX1++) {
        if(classify[iRX1] != iRQ) continue;
        pX = X+iRX1*nC;
        distance = 0.0;
        for(iRX2 = 0; iRX2 < nRX; iRX2++) {
          if(classify[iRX2] != iRQ) continue;
          distance += dlm_pam_norm2(pX,X+iRX2*nC,nC);
        }
        if(min > distance) {
          min = distance;
          clusters[iRQ] = iRX1;
        }
      }
    }
  }
  for(iRQ = 0; iRQ < nRQ; iRQ++) {
    dlp_memmove(Q+iRQ*nC,X+clusters[iRQ]*nC,nC*sizeof(FLOAT64));
  }
  dlp_free(clusters);
  dlp_free(classify);

  return O_K;
}
Ejemplo n.º 11
0
INT16 dlm_routh(FLOAT64* poly, INT16 order) {
  INT16 i;
  INT16 j;
  INT16 n = (order + 1) / 2 * 2 + 2;
  FLOAT64* b1 = NULL;
  FLOAT64* b2 = NULL;
  FLOAT64* a = NULL;

  a = (FLOAT64*) dlp_calloc(order+n+n, sizeof(FLOAT64));
  b1 = a + order;
  b2 = b1 + n;

  for (i = order - 1; i >= 0; i--)
    a[i] = poly[i] / poly[0];

  dlm_z2s(a, order);

  for (i = order - 1; i >= 0; i--) {
    b1[n - order + i] = a[order - i - 1];
    b2[i] = 0.0;
  }
  for (; n - order + i >= 0; i--) {
    b1[n - order + i] = 0.0;
    b2[i] = 0.0;
  }

  for (j = n - 3; j > 2; j -= 2) {
    for (i = 0; i < n - 3; i += 2)
      b2[n - 1 - i] = b1[n - 3 - i] - b1[n - 1] * b1[n - 4 - i] / b1[n - 2];
    for (i = 1; i < n - 3; i += 2)
      b2[n - 1 - i] = b1[n - 3 - i] - b1[n - 2] * b2[n - 2 - i] / b2[n - 1];
    if ((b2[n - 1] < 0.0) || (b2[n - 2] < 0.0)) {
      dlp_free(a);
      return DLM_ROOTS_UNSTABLE;
    }
    memcpy(b1, b2, n * sizeof(FLOAT64));
  }

  dlp_free(a);

  return DLM_ROOTS_STABLE;
}
Ejemplo n.º 12
0
INT16 CGEN_VPROTECTED CLSFproc::SynthesizeFrameImpl(FLOAT64* lsf, INT16 n_lsf, FLOAT64* exc, INT32 n_exc, FLOAT64 nPfaLambda, FLOAT64 nSynLambda, FLOAT64* syn) {
  INT16   ret   = O_K;
  INT16   n_lpc = n_lsf;
  FLOAT64* lpc   = NULL;

  if(m_bSynLsf) {
    if(nPfaLambda == nSynLambda) {
      return dlm_lsf_synthesize(lsf, n_lsf, exc, n_exc, syn, &m_lpMemLsf);
    } else {
      return dlm_mlsf_synthesize(lsf, n_lsf, exc, n_exc, (nPfaLambda-nSynLambda)/(1.0-nSynLambda*nPfaLambda), syn, &m_lpMemLsf);
    }
  }

  if(nPfaLambda != nSynLambda) n_lpc = 4*n_lsf;

  lpc = (FLOAT64*)dlp_calloc(n_lpc, sizeof(FLOAT64));
  if(!lpc) return IERROR(this, ERR_MEM, "lpc", 0, 0);

  if(nPfaLambda == nSynLambda) {
    if(m_bSynLpcFilt) {
      if(dlm_lsf2poly_filt(lsf, n_lsf, lpc, n_lpc, &m_lpMemLsf) != O_K) { dlp_free(lpc); return NOT_EXEC; }
    } else {
      if(dlm_lsf2poly(lsf, lpc, n_lsf) != O_K) { dlp_free(lpc); return NOT_EXEC; }
    }
  } else {
    if(m_bSynLpcFilt) {
      if(dlm_mlsf2poly_filt(lsf, n_lsf, lpc, n_lpc, (nPfaLambda-nSynLambda)/(1.0-nSynLambda*nPfaLambda), &m_lpMemLsf) != O_K) { dlp_free(lpc); return NOT_EXEC; }
    } else {
      if(dlm_lsf2poly(lsf, lpc, n_lsf) != O_K) { dlp_free(lpc); return NOT_EXEC; }
      if(dlm_mlpc2lpc(lpc,n_lsf,lpc,n_lpc,(nPfaLambda-nSynLambda)/(1.0-nSynLambda*nPfaLambda)) != O_K) { dlp_free(lpc); return NOT_EXEC; }
    }
    nPfaLambda = nSynLambda = 0.0;
  }

  if(dlm_gmult(lpc, lpc, n_lpc, -1.0) != O_K) return NOT_EXEC;

  ret = CLPCproc::SynthesizeFrameImpl(lpc, n_lpc, exc, n_exc, nPfaLambda, nSynLambda, syn);

  dlp_free(lpc);
  return ret;
}
Ejemplo n.º 13
0
/**
 * Deletes auxiliary components created by CFst_Cps_AddSdAux from the state table.
 *
 * @param _this Pointer to automaton instance
 * @see Cps_AddSdAux CFst_Cps_AddSdAux
 * @see Cps_SetSdAux CFst_Cps_SetSdAux
 * @see Cps_FindState CFst_Cps_FindState
 */
void CGEN_PRIVATE CFst_Cps_DelSdAux(CFst* _this)
{
  INT32 i = 0;

  /* Destroy composed state hash map */
  /* NOTE: MUST be done before deleting auxiliary state components! */
  hash_free_nodes((hash_t*)_this->m_lpCpsHash);
  hash_destroy((hash_t*)_this->m_lpCpsHash);
  _this->m_lpCpsHash = NULL;

  /* Destroy hash node pool */
  if (_this->m_lpCpsHnpool)
    for (i=0; i<(INT32)(dlp_size(_this->m_lpCpsHnpool)/sizeof(hnode_t*)); i++)
      dlp_free(_this->m_lpCpsHnpool[i]);
  dlp_free(_this->m_lpCpsHnpool);
  _this->m_lpCpsHnpool    = NULL;
  _this->m_nCpsHnpoolSize = 0;

  /* Delete auxiliary components from state table */
  CData_DeleteComps(AS(CData,_this->sd),_this->m_nIcSdAux,3);
  _this->m_nIcSdAux = -1;
}
Ejemplo n.º 14
0
/**
 * <p>Converts a coefficient vector of a polynomial in z: a(1)z^0+a(2)z^1+...
 * to a coefficient vector of a polynomial in s: b(1)s^0+b(2)s^1+...
 * by a bilinear map z:= (s+1)/(s-1)
 * which converts zeros of z inside the unit circle
 * into zeros of s in the left halfplane,
 * i.e. prepares a polynomial for the Routh/Hurwitz-test.</p>
 *
 * @param poly
 *          Pointer to polynomial coefficients.
 * @param n_order
 *          Number of polynomial coefficients stored in  <CODE>poly</CODE>.
 * @return <code>O_K</code> if successful, a (negative) error code otherwise
 */
INT16 dlm_z2s(FLOAT64* poly, INT16 n_order) {
  INT16 i_order1;
  INT16 i_order2;
  INT32 n_order2 = n_order * n_order;
  FLOAT64* pp = NULL;
  FLOAT64* pm = NULL;
  FLOAT64* ppd = NULL;
  FLOAT64* pmd = NULL;
  FLOAT64* poly_z = NULL;
  FLOAT64* poly_s = NULL;

  pp = (FLOAT64*) dlp_calloc(2*n_order2+4*n_order, sizeof(FLOAT64));
  pm = pp + n_order2;
  ppd = pm + n_order2;
  pmd = ppd + n_order;
  poly_z = pmd + n_order;
  poly_s = poly_z + n_order;

  if (dlm_pascal(pp, n_order) != O_K) return NOT_EXEC;

  dlp_memmove(pm, pp, n_order2 * sizeof(FLOAT64));

  for (i_order1 = 1; i_order1 < n_order; i_order1 += 2) {
    for (i_order2 = 0; i_order2 < n_order; i_order2++) {
      pm[i_order2 * n_order + i_order1] = -pp[i_order2 * n_order + i_order1];
    }
  }

  for (i_order1 = 0; i_order1 < n_order; i_order1++) {
    for (i_order2 = 0; i_order2 < (n_order - i_order1); i_order2++) {
      pmd[i_order2] = pm[i_order2 * n_order + n_order - i_order1 - 1 - i_order2];
    }
    for (i_order2 = n_order - i_order1; i_order2 < n_order; i_order2++) {
      pmd[i_order2] = 0.0;
    }
    for (i_order2 = 0; i_order2 <= i_order1; i_order2++) {
      ppd[i_order2] = pp[i_order2 * n_order + i_order1 - i_order2];
    }
    for (i_order2 = i_order1 + 1; i_order2 < n_order; i_order2++) {
      ppd[i_order2] = 0.0;
    }
    dlm_filter_fir(ppd, n_order, pmd, poly_z, n_order, NULL, 0);
    for (i_order2 = 0; i_order2 < n_order; i_order2++) {
      poly_s[i_order2] += poly_z[i_order2] * poly[n_order - 1 - i_order1];
    }
  }
  dlp_memmove(poly, poly_s, n_order * sizeof(FLOAT64));
  dlp_free(pp);
  return O_K;
}
Ejemplo n.º 15
0
INT16 CGEN_VPROTECTED CLPCproc::SynthesizeFrameImpl(FLOAT64* lpcCoef, INT16 n_lpcCoeff, FLOAT64* exc, INT32 n_exc, FLOAT64 nPfaLambda, FLOAT64 nSynLambda, FLOAT64* syn) {
  INT32    i    = 0;
  FLOAT64  gain = 0.0;
  FLOAT64* lpc  = NULL;

  if(n_lpcCoeff != m_nCoeff) {
    if(m_lpMemLpc != NULL) {
      dlp_free(m_lpMemLpc);
    }
  }
  if(m_lpMemLpc == NULL) {
    m_lpMemLpc = (FLOAT64*)dlp_calloc(n_lpcCoeff - 1, sizeof(FLOAT64));        //  allocate memory
    if(!m_lpMemLpc) return ERR_MEM;
    m_nCoeff = n_lpcCoeff;
  }

  lpc = (FLOAT64*)dlp_calloc(n_lpcCoeff, sizeof(FLOAT64));
  if(!lpc) return IERROR(this, ERR_MEM, "lpc", 0, 0);

  gain = *lpcCoef;
  *lpcCoef = 1.0;
  if(nPfaLambda != nSynLambda) {
    dlm_mlpc2lpc(lpcCoef, n_lpcCoeff, lpc, n_lpcCoeff, (nPfaLambda-nSynLambda)/(1-nPfaLambda*nSynLambda));
  } else {
    dlp_memmove(lpc, lpcCoef, n_lpcCoeff*sizeof(FLOAT64));
  }

  gain = gain/ *lpc;
  *lpc = 1.0;
  dlm_filter_iir(lpc, n_lpcCoeff, exc, syn, n_exc, m_lpMemLpc, n_lpcCoeff - 1);
  for(i = 0; i < n_exc; i++) {
    syn[i] *= gain;
  }

  dlp_free(lpc);
  return O_K;
}
Ejemplo n.º 16
0
/**
 * <p id="dlm_invert_gel">Inverts a matrix and computes its determinant through Gaussian
 * elimination.</p>
 *
 * @param A
 *          Pointer to input matrix, replaced in computation by resultant
 *          inverse
 * @param nXA
 *          Order of matrix (number of rows and columns)
 * @param lpnDet
 *          Pointer to be filled with resultant determinant (may be
 *          <code>NULL</code>)
 * @return <code>O_K</code> if successfull, a (negative) error code otherwise
 */
INT16 dlm_invert_gel(FLOAT64* A, INT32 nXA, FLOAT64* lpnDet) {
  integer n = (integer) nXA;
  integer c__1 = 1;
  integer c_n1 = -1;
  integer info = 0;
  integer* ipiv = dlp_calloc(n, sizeof(integer));
  void* work = NULL;
  char opts[1] = { ' ' };
  extern integer ilaenv_(integer*,char*,char*,integer*,integer*,integer*,integer*,ftnlen,ftnlen);

#ifdef __MAX_TYPE_32BIT
  extern int sgetrf_(integer*,integer*,real*,integer*,integer*,integer*);
  extern int sgetri_(integer*,real*,integer*,integer*,real*,integer*,integer*);
  char name[8] = { 'S', 'G', 'E', 'T', 'R', 'I' };
  integer lwork = n * ilaenv_(&c__1, name, opts, &n, &c_n1, &c_n1, &c_n1, (ftnlen)6, (ftnlen)1);
  work = dlp_calloc(lwork, sizeof(real));
  if(!ipiv || !work) return ERR_MEM;
  sgetrf_(&n,&n,A,&n,ipiv,&info);
  if(lpnDet != NULL) *lpnDet = (info > 0) ? 0.0 : dlm_get_det_trf(A, nXA, ipiv);
  sgetri_(&n,A,&n,ipiv,work,&lwork,&info);
#else
  extern int dgetrf_(integer*,integer*,doublereal*,integer*,integer*,integer*);
  extern int dgetri_(integer*,doublereal*,integer*,integer*,doublereal*,integer*,integer*);
  char name[8] = { 'D', 'G', 'E', 'T', 'R', 'I' };
  integer lwork = n * ilaenv_(&c__1, name, opts, &n, &c_n1, &c_n1, &c_n1, (ftnlen) 6, (ftnlen) 1);
  work = dlp_calloc(lwork, sizeof(doublereal));
  if (!ipiv || !work) return ERR_MEM;
  dgetrf_(&n, &n, A, &n, ipiv, &info);
  if (lpnDet != NULL) *lpnDet = (info > 0) ? 0.0 : dlm_get_det_trf(A, nXA, ipiv);
  dgetri_(&n, A, &n, ipiv, work, &lwork, &info);
#endif

  dlp_free(work);
  dlp_free(ipiv);
  return (info == 0) ? O_K : NOT_EXEC;
}
Ejemplo n.º 17
0
/**
 * <p>Same as {@link dlm_invert_gel} but for complex input</p>
 *
 */
INT16 dlm_invert_gelC(COMPLEX64* A, INT32 nXA, COMPLEX64* lpnDet) {
  integer n = (integer) nXA;
  integer c__1 = 1;
  integer c_n1 = -1;
  integer info = 0;
  integer* ipiv = dlp_calloc(n, sizeof(integer));
  void* work = NULL;
  char opts[1] = { ' ' };
  extern integer ilaenv_(integer*,char*,char*,integer*,integer*,integer*,integer*,ftnlen,ftnlen);

#ifdef __MAX_TYPE_32BIT
  extern int cgetrf_(integer*,integer*,complex*,integer*,integer*,integer*);
  extern int cgetri_(integer*,complex*,integer*,integer*,complex*,integer*,integer*);
  char name[8] = { 'C', 'G', 'E', 'T', 'R', 'I' };
  integer lwork = n * ilaenv_(&c__1, name, opts, &n, &c_n1, &c_n1, &c_n1, (ftnlen)6, (ftnlen)1);
  work = dlp_calloc(lwork, sizeof(complex));
  if(!ipiv || !work) return ERR_MEM;
  cgetrf_(&n,&n,(complex*)A,&n,ipiv,&info);
  if(lpnDet != NULL) *lpnDet = (info > 0) ? CMPLX(0.0) : dlm_get_det_trfC(A, nXA, ipiv);
  cgetri_(&n,(complex*)A,&n,ipiv,work,&lwork,&info);
#else
  extern int zgetrf_(integer*,integer*,doublecomplex*,integer*,integer*,integer*);
  extern int zgetri_(integer*,doublecomplex*,integer*,integer*,doublecomplex*,integer*,integer*);
  char name[8] = { 'Z', 'G', 'E', 'T', 'R', 'I' };
  integer lwork = n * ilaenv_(&c__1, name, opts, &n, &c_n1, &c_n1, &c_n1, (ftnlen) 6, (ftnlen) 1);
  work = dlp_calloc(lwork, sizeof(doublecomplex));
  if (!ipiv || !work) return ERR_MEM;
  zgetrf_(&n, &n, (doublecomplex*) A, &n, ipiv, &info);
  if (lpnDet != NULL) *lpnDet = (info > 0) ? CMPLX(0.0) : dlm_get_det_trfC(A, nXA, ipiv);
  zgetri_(&n, (doublecomplex*) A, &n, ipiv, work, &lwork, &info);
#endif

  dlp_free(work);
  dlp_free(ipiv);
  return (info == 0) ? O_K : NOT_EXEC;
}
Ejemplo n.º 18
0
/**
 * <p id=dlm_unwrap>Unwraps radian phases given in imaginary part of <code>C</code> to their 2&pi; complement if the
 * phase jumps greater than &pi;.</p>
 *
 * @param S
 *          Pointer to an array containing radian complex numbers, overwritten with the result.
 * @param nSL
 *          Length of input <code>S</code>.
 * @return <code>O_K</code> if successfull, a (negative) error code otherwise
 */
INT16 dlm_unwrapC(COMPLEX64* S, INT32 nSL) {
  INT32 iSL = 0;
  INT16* nCorr = (INT16*) dlp_calloc(nSL, sizeof(INT16));
  if (nCorr == NULL) return ERR_MEM;

  for (iSL = 1; iSL < nSL; iSL++) {
    if (((S + iSL)->y - (S + iSL - 1)->y) > F_PI) *(nCorr + iSL) = *(nCorr + iSL - 1) - 1;
    else if (((S + iSL)->y - (S + iSL - 1)->y) < -F_PI) *(nCorr + iSL) = *(nCorr + iSL - 1) + 1;
    else *(nCorr + iSL) = *(nCorr + iSL - 1);
  }
  for (iSL = 1; iSL < nSL; iSL++) {
    (S + iSL)->y += *(nCorr + iSL) * 2 * F_PI;
  }
  dlp_free(nCorr);
  return O_K;
}
Ejemplo n.º 19
0
/**
 * Inverse Scalar Vector Quantization
 *
 * <p>This is the inverse of {@link dlm_svq}. The according to the coded input indices stream <code>I</code> and the
 * code book <code>Q</code> the output vector sequence <code>Y</code> is restored.
 *
 * @param Q Code book
 * @param nCQ Number of compnents of <code>Q</code>
 * @param nRQ Number of records of <code>Q</code>
 * @param I Input byte stream containing the indices to the code book
 * @param nRI Number of records of <code>I</code>
 * @param nCI Number of components of <code>I</code>
 * @param B Bit table containing the number of bits of the indices of each component
 * @param nRB Number of records of <code>B</code>
 * @param Y restored <code>nCQ&times;nRI</code> vector sequence
 */
INT16 CGEN_PUBLIC dlm_isvq(FLOAT64* Q, INT32 nCQ, INT32 nRQ, BYTE* I, INT32 nRI, INT32 nCI, INT32* B, INT32 nRB, FLOAT64* Y) {
  INT16 ret = O_K;
  INT32 iRI = 0;
  INT32 iCQ = 0;
  INT32 iCI = 0;
  INT32 iBB = 0;
  INT32 iBI = 0;
  INT32* pI = (INT32*) dlp_calloc(nCQ*nRI, sizeof(INT32));

  if ((Q == NULL) || (B == NULL) || (Y == NULL)) return NOT_EXEC;

  for (iRI = 0; iRI < nRI; iRI++) {
    iCQ = 0;
    iCI = 0;
    iBI = 0;
    iBB = B[0] - 1;
    pI[iRI * nCQ] = 0;
    while (iCI < nCI) {
      pI[iRI * nCQ + iCQ] |= ((I[iRI * nCI + iCI] >> iBI) & 0x1) << iBB;
      iBB--;
      iBI++;
      if (iBB < 0) {
        iCQ++;
        if (iCQ >= nCQ) break;
        iBB = B[iCQ] - 1;
      }
      if (iBI >= 8) {
        iCI++;
        iBI = 0;
      }
    }
  }

  for (iRI = 0; iRI < nRI; iRI++) {
    for (iCQ = 0; iCQ < nCQ; iCQ++) {
      if (pI[iRI * nCQ + iCQ] < nRQ) {
        Y[iRI * nCQ + iCQ] = Q[pI[iRI * nCQ + iCQ] * nCQ + iCQ];
      } else {
        ret = NOT_EXEC;
      }
    }
  }

  dlp_free(pI);

  return ret;
}
Ejemplo n.º 20
0
/////////////////////////////////////////////////////////////////////////////////////
//
// ModEx - generates excitation from pitch file
//
// CData *gain       -> gains of excitation per frame
// CData *idPm       -> both components must be type long
// CData *idExcite   -> type FBA_FLOAT
//
INT16 CGEN_PUBLIC CFBAproc::ModEx(CData *idPm, CData *idExcite) {
  // Error handling
  if (idPm == NULL)                return IERROR(this,ERR_NULLINST,0,0,0);
  if (idPm -> IsEmpty() == TRUE)   return IERROR(idPm,DATA_EMPTY,idPm->m_lpInstanceName,0,0);
  if (idExcite == NULL)            return IERROR(this,ERR_NULLINST,idExcite->m_lpInstanceName,0,0);

  DLPASSERT(idPm->GetNComps()>1);

  FLOAT64* exc = NULL;
  INT32    n_exc = 0;

  switch(m_lpsExcType[0]) {
    case 'P':
      if(dlm_pm2exc((INT16*)idPm->XAddr(0,0),(INT32)idPm->GetNRecs(),&exc,&n_exc,m_nSrate, (BOOL)TRUE,DLM_PITCH_PULSE    ) != O_K) return NOT_EXEC;
      break;
    case 'G':
      if(dlm_pm2exc((INT16*)idPm->XAddr(0,0),(INT32)idPm->GetNRecs(),&exc,&n_exc,m_nSrate, (BOOL)TRUE,DLM_PITCH_GLOTT    ) != O_K) return NOT_EXEC;
      break;
    case 'R':
      if(dlm_pm2exc((INT16*)idPm->XAddr(0,0),(INT32)idPm->GetNRecs(),&exc,&n_exc,m_nSrate, (BOOL)TRUE,DLM_PITCH_RANDPHASE) != O_K) return NOT_EXEC;
      break;
    case 'V':
      if(dlm_pm2exc((INT16*)idPm->XAddr(0,0),(INT32)idPm->GetNRecs(),&exc,&n_exc,m_nSrate, (BOOL)TRUE,DLM_PITCH_VOICED   ) != O_K) return NOT_EXEC;
      break;
    case 'U':
      if(dlm_pm2exc((INT16*)idPm->XAddr(0,0),(INT32)idPm->GetNRecs(),&exc,&n_exc,m_nSrate, (BOOL)TRUE,DLM_PITCH_UNVOICED ) != O_K) return NOT_EXEC;
      break;
    case 'C':
      if(m_idExc == NULL) return IERROR(this,ERR_BADPTR,NULL,"of CFBAproc->m_lpExc","(FBAproc.exc)");
      for(INT32 i_pm=0; i_pm < idPm->GetNRecs(); i_pm++) n_exc += (INT16)idPm->Dfetch(i_pm,0);
      if(CData_GetNRecs(m_idExc) < n_exc) return IERROR(this,FBA_BADEXCLEN,0,0,0);
      exc = (FLOAT64*)dlp_malloc(n_exc*sizeof(FLOAT64));
      dlp_memmove(exc,m_idExc->XAddr(0,0),n_exc*sizeof(FLOAT64));
      break;
    default:
      return IERROR(this,FBA_BADARG,m_lpsExcType,"exc_type","P, G, R, V, U or C");
  }

  idExcite->Reset(TRUE);
  idExcite->AddComp("exc", T_DOUBLE);
  idExcite->Allocate(n_exc);
  dlp_memmove(idExcite->XAddr(0,0), exc, n_exc*sizeof(FLOAT64));
  dlp_free(exc);

  return O_K;
}
Ejemplo n.º 21
0
INT16 CGEN_IGNORE __dlm_getNewCentroids(FLOAT64* X, INT32* pI, INT32 nRX, INT32 nCX, FLOAT64* Q, INT32 nRQ) {
  INT32 iRX = 0;
  INT32 iRQ = 0;
  INT32* C = (INT32*) dlp_calloc(nRQ, sizeof(INT32));

  for (iRQ = 0; iRQ < nRQ; iRQ++) {
    Q[iRQ * nCX] = 0;
  }
  for (iRX = 0; iRX < nRX; iRX++) {
    Q[pI[iRX * nCX] * nCX] += X[iRX * nCX];
    C[pI[iRX * nCX]]++;
  }
  for (iRQ = 0; iRQ < nRQ; iRQ++) {
    Q[iRQ * nCX] /= (FLOAT64) C[iRQ];
  }
  dlp_free(C);
  return O_K;
}
Ejemplo n.º 22
0
void CFsttools_Destructor(CDlpObject* __this)
{
    GET_THIS_VIRTUAL(CFsttools);
    {
        /*{{CGEN_DONECODE */
        DONE;
        /*}}CGEN_DONECODE */
    }

#ifndef __cplusplus

    /* Destroy base instance */
    CDlpObject_Destructor(_this->m_lpBaseInstance);
    dlp_free(_this->m_lpBaseInstance);
    _this->m_lpBaseInstance = NULL;

#endif /* #ifndef __cplusplus */
}
Ejemplo n.º 23
0
INT16 CGEN_IGNORE dlm_lbg(FLOAT64* X, INT32 nC, INT32 nRX, FLOAT64* Q, INT32 nRQ) {
  FLOAT64* icb = (FLOAT64*) dlp_calloc(nC,sizeof(FLOAT64));
  INT32 iC = 0;
  INT32 iRX = 0;
  extern void lbg(FLOAT64*, const INT32, const INT32, FLOAT64*, INT32, FLOAT64*, const INT32, const INT32, const INT32, const INT32, const INT32, const FLOAT64, const FLOAT64);

  for (iRX = 0; iRX < nRX; iRX++) {
    for (iC = 0; iC < nC; iC++) {
      icb[iC] += X[iRX * nC + iC];
    }
  }
  for (iC = 0; iC < nC; iC++) {
    icb[iC] /= (FLOAT64) nRX;
  }

  lbg(X, nC, nRX, icb, 1, Q, nRQ, 1000, 1, 1, 1, 0.0001, 0.0001);

  dlp_free(icb);
  return O_K;
}
Ejemplo n.º 24
0
 /*   Daubechies D4 transform
 *
 *    FLOAT64* sig         signal array
 *    FLOAT64* trans       transformed signal
 *    INT32    size        signal size
 *    INT16   level       detail level (max. level = -1)  
  */
INT16 CGEN_IGNORE dlm_fwt_d4(FLOAT64* sig, FLOAT64* trans, INT32 size, INT16 level)
{
  register INT32 i;
  register INT32 n;
  register INT32 size2;
  FLOAT64* sigTemp;
  

  if(size < 4)
  {
    return NOT_EXEC;
  } 
  
  sigTemp = (FLOAT64*)dlp_calloc(size, sizeof(FLOAT64));
  dlp_memmove(sigTemp, sig, size * sizeof(FLOAT64));
  
  for (n = size; n >= 4; n >>= 1)
  {
    size2 = n >> 1;
    for (i = 0; i <= size2-2; i++)
    {
      trans[i]       = sigTemp[i*2]*h0 + sigTemp[i*2+1]*h1 + sigTemp[i*2+2]*h2 + sigTemp[i*2+3]*h3; /* scaling function coefficients */
      trans[i+size2] = sigTemp[i*2]*h3 - sigTemp[i*2+1]*h2 + sigTemp[i*2+2]*h1 - sigTemp[i*2+3]*h0; /* wavelet function coefficents */
    }

    trans[i]       = sigTemp[n-2]*h0 + sigTemp[n-1]*h1 + sigTemp[0]*h2 + sigTemp[1]*h3;
    trans[i+size2] = sigTemp[n-2]*h3 - sigTemp[n-1]*h2 + sigTemp[0]*h1 - sigTemp[1]*h0;

    dlp_memmove(sigTemp, trans, n * sizeof(FLOAT64));
    level--;
    if(level == 0) break; /* reduce detail level and exit if reaching 0; if detail level is max. (-1) nothing happens */
  }
  
  dlp_free(sigTemp);
  
  return O_K;
}
Ejemplo n.º 25
0
INT16 CGEN_IGNORE dlm_pascal(FLOAT64* p, INT16 n_order) {
  INT16 i_order1;
  INT16 i_order2;
  INT16 i_order3;
  FLOAT64* pp = NULL;

  if ((!p) || (n_order < 1)) return NOT_EXEC;

  pp = (FLOAT64*) dlp_calloc(n_order*n_order, sizeof(FLOAT64));

  for (i_order1 = 0; i_order1 < n_order; i_order1++) {
    pp[i_order1 * n_order] = 1.0;
    pp[i_order1 * n_order + i_order1] = (i_order1 % 2) ? -1 : 1;
  }

  for (i_order1 = 1; i_order1 < n_order - 1; i_order1++) {
    for (i_order2 = i_order1 + 1; i_order2 < n_order; i_order2++) {
      pp[i_order2 * n_order + i_order1] =
          pp[(i_order2 - 1) * n_order + i_order1] - pp[(i_order2 - 1) * n_order + i_order1 - 1];
    }
  }
  for (i_order1 = 0; i_order1 < n_order; i_order1++) {
    for (i_order2 = i_order1; i_order2 < n_order; i_order2++) {
      p[i_order1 * n_order + i_order2] = 0.0;
      for (i_order3 = 0; i_order3 < n_order; i_order3++) {
        p[i_order1 * n_order + i_order2] += pp[i_order1 * n_order + i_order3] * pp[i_order2 * n_order + i_order3];
      }
    }
  }
  for (i_order1 = 0; i_order1 < n_order; i_order1++) {
    for (i_order2 = 0; i_order2 < i_order1; i_order2++) {
      p[i_order1 * n_order + i_order2] = p[i_order2 * n_order + i_order1];
    }
  }
  dlp_free(pp);
  return O_K;
}
Ejemplo n.º 26
0
/*
 * Manual page at fst_man.def
 */
INT16 CGEN_PUBLIC CFst_Product
(
  CFst* _this,
  CFst* itSrc1,
  CFst* itSrc2,
  INT32  nUnit1,
  INT32  nUnit2
)
{
  INT32      nC           = 0;                                                   /* Current component                  */
  INT32      nFCS2        = 0;                                                   /* 1st data comp. of state tab.itSrc2 */
  INT32      nXCS1        = 0;                                                   /* No. of comps. of state tab. itSrc1 */
  INT32      nXCS2        = 0;                                                   /* No. of comps. of state tab. itSrc2 */
  INT32      nFCT2        = 0;                                                   /* 1st data comp. of trans.tab.itSrc2 */
  INT32      nXCT1        = 0;                                                   /* No. of comps. of trans.tab. itSrc1 */
  INT32      nXCT2        = 0;                                                   /* No. of comps. of trans.tab. itSrc2 */
  INT32      nRls1        = 0;                                                   /* Rec. len. of state table of itSrc1 */
  INT32      nRls2        = 0;                                                   /* Rec. len. of state table of itSrc2 */
  INT32      nRlt1        = 0;                                                   /* Rec. len. of trans.table of itSrc1 */
  INT32      nRlt2        = 0;                                                   /* Rec. len. of trans.table of itSrc2 */
  FST_ITYPE nS1          = 0;
  FST_ITYPE nS2          = 0;
  FST_ITYPE nFS1         = 0;
  FST_ITYPE nFS2         = 0;
  FST_ITYPE nXS1         = 0;
  FST_ITYPE nXS2         = 0;
  FST_ITYPE nT           = 0;
  FST_ITYPE nIni         = 0;
  FST_ITYPE nTer         = 0;
  FST_ITYPE nT1          = 0;
  FST_ITYPE nT2          = 0;
  FST_ITYPE nFT1         = 0;
  FST_ITYPE nFT2         = 0;
  FST_ITYPE nXT1         = 0;
  FST_ITYPE nXT2         = 0;
  char*     lpsBuf       = NULL;                                                /* String buffer                      */
  INT16     nVirt        = 0;                                                   /* Auxiliary: patching ovrl.args. bug */
  BOOL      bNoloopsSave = FALSE;                                               /* Save buffer for /noloops option    */

  /* Validate */
  CHECK_THIS_RV(NOT_EXEC);
  if (itSrc1==NULL || itSrc2==NULL)
  {
    CFst_Reset(BASEINST(_this),TRUE);
    return O_K;
  }
  if (nUnit1<0 || nUnit1>=UD_XXU(itSrc1)) return IERROR(_this,FST_BADID,"unit",nUnit1,0);
  if (nUnit2<0 || nUnit2>=UD_XXU(itSrc2)) return IERROR(_this,FST_BADID,"unit",nUnit2,0);

  /* Initialize */
  /* HACK: Multiple overlapping arguments on _this not handled correctly by
           CREATEVIRTUAL --> */
  if (_this==itSrc1 && _this==itSrc2) return IERROR(_this,ERR_GENERIC,"Invalid arguments",0,0);
  if      (itSrc1==_this) { CREATEVIRTUAL(CFst,itSrc1,_this); nVirt=1; }
  else if (itSrc2==_this) { CREATEVIRTUAL(CFst,itSrc2,_this); nVirt=2; }
  /* <-- */
  bNoloopsSave = _this->m_bNoloops;
  CFst_Reset(BASEINST(_this),TRUE);
  _this->m_bNoloops = bNoloopsSave;

  /* Initialize destination state table */
  nFS1  = UD_FS(itSrc1,nUnit1);
  nXS1  = UD_XS(itSrc1,nUnit1);
  nFS2  = UD_FS(itSrc2,nUnit2);
  nXS2  = UD_XS(itSrc2,nUnit2);
  nRls1 = CData_GetRecLen(AS(CData,itSrc1->sd)) - CData_GetCompOffset(AS(CData,itSrc1->sd),IC_SD_DATA);
  nRls2 = CData_GetRecLen(AS(CData,itSrc2->sd)) - CData_GetCompOffset(AS(CData,itSrc2->sd),IC_SD_DATA);
  nXCS1 = CData_GetNComps(AS(CData,itSrc1->sd)) - IC_SD_DATA;
  nXCS2 = CData_GetNComps(AS(CData,itSrc2->sd)) - IC_SD_DATA;
  nFCS2 = IC_SD_DATA + nXCS1;
  for (nC=IC_SD_DATA; nC<IC_SD_DATA+nXCS1; nC++)
    CData_AddComp
    (
      AS(CData,_this->sd),
      CData_GetCname(AS(CData,itSrc1->sd),nC),
      CData_GetCompType(AS(CData,itSrc1->sd),nC)
    );
  for (nC=IC_SD_DATA; nC<IC_SD_DATA+nXCS2; nC++)
    CData_AddComp
    (
      AS(CData,_this->sd),
      CData_GetCname(AS(CData,itSrc2->sd),nC),
      CData_GetCompType(AS(CData,itSrc2->sd),nC)
    );

  /* Initialize destination transition table */
  nFT1  = UD_FT(itSrc1,nUnit1);
  nXT1  = UD_XT(itSrc1,nUnit1);
  nFT2  = UD_FT(itSrc2,nUnit2);
  nXT2  = UD_XT(itSrc2,nUnit2);
  nRlt1 = CData_GetRecLen(AS(CData,itSrc1->td)) - CData_GetCompOffset(AS(CData,itSrc1->td),IC_TD_DATA);
  nRlt2 = CData_GetRecLen(AS(CData,itSrc2->td)) - CData_GetCompOffset(AS(CData,itSrc2->td),IC_TD_DATA);
  nXCT1 = CData_GetNComps(AS(CData,itSrc1->td)) - IC_TD_DATA;
  nXCT2 = CData_GetNComps(AS(CData,itSrc2->td)) - IC_TD_DATA;
  nFCT2 = IC_TD_DATA + nXCT1;
  for (nC=IC_TD_DATA; nC<IC_TD_DATA+nXCT1; nC++)
    CData_AddComp
    (
      AS(CData,_this->td),
      CData_GetCname(AS(CData,itSrc1->td),nC),
      CData_GetCompType(AS(CData,itSrc1->td),nC)
    );
  for (nC=IC_TD_DATA; nC<IC_TD_DATA+nXCT2; nC++)
    CData_AddComp
    (
      AS(CData,_this->td),
      CData_GetCname(AS(CData,itSrc2->td),nC),
      CData_GetCompType(AS(CData,itSrc2->td),nC)
    );

  /* Copy input and output symbol tables */
  CData_Copy(_this->is,itSrc1->is);
  CData_Copy(_this->os,itSrc2->os);

  /* Initialize destination unit */
  lpsBuf = (char*)dlp_calloc
  (
    CData_GetCompType(AS(CData,itSrc1->ud),IC_UD_NAME) +
    CData_GetCompType(AS(CData,itSrc2->ud),IC_UD_NAME) + 2,
    sizeof(char)
  );
  sprintf
  (
    lpsBuf,"%s.%s",
    (const char*)CData_XAddr(AS(CData,itSrc1->ud),nUnit1,IC_UD_NAME),
    (const char*)CData_XAddr(AS(CData,itSrc2->ud),nUnit2,IC_UD_NAME)
  );
  CFst_Addunit(_this,lpsBuf);
  dlp_free(lpsBuf);

  /* Add product states */
  CFst_Addstates(_this,0,nXS1*nXS2,FALSE);

  /* Copy state qualification (including final state flag) */
  for (nS1=0; nS1<nXS1; nS1++)
    for (nS2=0; nS2<nXS2; nS2++)
    {
      if ((SD_FLG(itSrc1,nS1+nFS1)&0x01)==0x01 && (SD_FLG(itSrc2,nS2+nFS2)&0x01)==0x01)
        SD_FLG(_this,nS1*nXS2+nS2) |= 0x01;
      if (nRls1>0)
        dlp_memmove
        (
          CData_XAddr(AS(CData,_this ->sd),nS1*nXS2+nS2,IC_SD_DATA),
          CData_XAddr(AS(CData,itSrc1->sd),nS1+nFS1    ,IC_SD_DATA),
          nRls1
        );
      if (nRls2>0)
        dlp_memmove
        (
          CData_XAddr(AS(CData,_this ->sd),nS1*nXS2+nS2,nFCS2     ),
          CData_XAddr(AS(CData,itSrc2->sd),nS2+nFS2    ,IC_SD_DATA),
          nRls2
        );
    }

  CData_AddRecs(AS(CData,_this->td),nXT1*nXT2,_this->m_nGrany);
  /* Loop over all transitions of both factors */
  for (nT=0, nT1=nFT1; nT1<nFT1+nXT1; nT1++)
    for (nT2=nFT2; nT2<nFT2+nXT2; nT2++, nT++)
    {
      /* Get product of initial and terminal state */
      nIni = TD_INI(itSrc1,nT1)*nXS2 + TD_INI(itSrc2,nT2);
      nTer = TD_TER(itSrc1,nT1)*nXS2 + TD_TER(itSrc2,nT2);
      if (_this->m_bNoloops && nIni==nTer) continue;

      /* Add product transition */
      *(FST_ITYPE*)CData_XAddr(AS(CData,_this->td),nT,IC_TD_INI) = nIni;
      *(FST_ITYPE*)CData_XAddr(AS(CData,_this->td),nT,IC_TD_TER) = nTer;

      /* Copy transition qualification */
      dlp_memmove
      (
        CData_XAddr(AS(CData,_this ->td),nT ,IC_TD_DATA),
        CData_XAddr(AS(CData,itSrc1->td),nT1,IC_TD_DATA),
        nRlt1
      );
      dlp_memmove
      (
        CData_XAddr(AS(CData,_this ->td),nT ,nFCT2     ),
        CData_XAddr(AS(CData,itSrc2->td),nT2,IC_TD_DATA),
        nRlt2
      );
    }

  /* Finish destination instance */
  CData_SelectRecs(AS(CData,_this->td),AS(CData,_this->td),0,nT);
  UD_XT(_this,0) = nT;
  /* TODO: Trim result !? */

  /* Clean up */
  if (nVirt==1) { DESTROYVIRTUAL(itSrc1,_this); }
  if (nVirt==2) { DESTROYVIRTUAL(itSrc2,_this); }
  return O_K;
}
Ejemplo n.º 27
0
INT16 CGEN_PRIVATE CProsody::EnergyContour(data *dSignal, data *dEnergy)
{
  /* Initialization */
  INT32 i = 0;
  INT32 j = 0;
  INT32 nSrate = 0;             // Sample Rate
  INT32 nSamples = 0;         // Number of samples in WAV-signal (number of records in data instance)
  INT32 nWindowShift = 0;      // Shift of Windows (samples)
  INT32 nWindowLength = 0;      // Length of Window (samples)
  INT32 nShiftNumber = 0;      // Number of Shifts in the signal
  INT32 nWindowNumber = 0;      // Number of windows
  FLOAT64 nAuxEner = 0;      // Auxiliary variable to calculate the energy for one window
  FLOAT64 *samples = NULL;         // WAV Signal in double
  FLOAT64 *dEnergyContour = NULL;  // Short Time Energy Contour
  
  
  /* Validation of data instance dEnergy */
  if (!dEnergy || !dEnergy->IsEmpty())    // If dEnergy not exist or empty then return false
    return NOT_EXEC;                  // NOT_EXEC = -1 (Generic error)
 
  /* Definition of data instance dEnergy */
  // One column is the values of energy contour  
    dEnergy->AddNcomps(T_DOUBLE, 1);
    dEnergy->SetCname(0, "nEnergy");


  
  /* Compute Sample Rate (SR) */
  //nSrate = m_nSrate;
  //nSrate  = (INT32)(1000.0/CData_GetDescr(dSignal,RINC));
  
  //# "\n Distance between two Samples = ${idSig.rinc} [msec] "  -echo;
  //# 1000 idSig.rinc / nSrate =;          # Compute Sample Rate (SR)  
  nSrate = (INT32)((1000.0/CData_GetDescr(dSignal,RINC)) + 0.5);  /* +0.5 forces cast to round up or down */    
  //fprintf(stdout,"Sample Rate:   %d Hz\n\n",nSrate);
  
  
     /* Number of samples in WAV-signal */
  nSamples  = dSignal->GetNRecs();  // GetNRecs returns the number of valid records in the data instance
  //fprintf(stdout,"Number of samples in WAV-signal:   %i\n\n",nSamples);


  /* Copies data from memory area to another memory area */
  samples = (FLOAT64*)dlp_calloc(nSamples, sizeof(FLOAT64));  // dlp_calloc(NUM,SIZE) Allocates zero-initialize memory
    dlp_memmove(samples, dSignal->XAddr(0,0), nSamples * sizeof(FLOAT64));
      
    /*
    fprintf(stdout,"\n The samples of speech signal are: \n");  // show data 
  for(i=0; i<nSamples; i++)               
    fprintf(stdout,"Signal Sample %i = %f\n",i,samples[i]);
  */

  /* Calculate the Window-Length and the Window-Shift */
  nWindowShift = nSrate / 100;      // Shift = 10 msec = 16000 / 100 = 160 samples
  nWindowLength = nWindowShift * 3;  // Window Length = 30 msec = Window Shift * 3
  
  
  nShiftNumber = nSamples / nWindowShift;    // Number of Shifts in the whole signal
  nWindowNumber = nShiftNumber - 2;      // Number of Windows
  
  if (nWindowNumber < 1)            // There is no window (signal is too short)
  {
    nWindowNumber = 1;            // Set number of windows to 1
    nWindowLength = nSamples;
  }
  
  dEnergyContour = (FLOAT64*)dlp_calloc(nWindowNumber, sizeof(FLOAT64));
  
  
  /* Fensterung des Signals und Berechnung der Energy f�r jedes Fensters */
  for (i=0; i<nWindowNumber; i++)
  {
    nAuxEner = 0;
    for (j=0; j<nWindowLength; j++)
    {
      nAuxEner = nAuxEner + samples[i*nWindowShift+j]*samples[i*nWindowShift+j];  
    }
    dEnergyContour[i] = nAuxEner;
  }
    
    

  /* Write Energy values in struct */
    STEnergy_CONTOUR *Energy_contour = NULL;  // (Energy_contour) is an object of struct (STEnergy_CONTOUR)


  Energy_contour = (STEnergy_CONTOUR*)dlp_calloc(nWindowNumber, sizeof(STEnergy_CONTOUR));  // Allocates zero-initialize memory

  for(i = 0; i < nWindowNumber; i++)  
  {
        (Energy_contour + i)->nEnergyValue = dEnergyContour[i];
        //fprintf( stdout,"nEnergyValue  %i = %f\n",i,dEnergyContour[i] );
  }


    
  /* Copy Energy values from (struct Energy_contour) to output data object (dEnergy) */
  dEnergy->AddRecs(nWindowNumber, 1); // AddRecs: Appends (n) records to the end of the table (data object)  
  for( i = 0; i < nWindowNumber; i++ )
  {
      dEnergy->Dstore((FLOAT64)(Energy_contour + i)->nEnergyValue, i, 0);
  }


  /*
  FLOAT64 nAuxCopy = 0;
  
  for (i = 0; i < nWindowNumber; i++)
  {
    nAuxCopy = (FLOAT64)CData_Dfetch(dEnergy,i,0);
    fprintf(stdout,"F0 value %i = %f\n",i,nAuxCopy);  
  }
  */  
  
  dlp_free(samples);    
  dlp_free(dEnergyContour);
  dlp_free(Energy_contour);    
      
  return O_K;
}
Ejemplo n.º 28
0
/**
 * Copies the one field from iSrc to this instance
 *
 * @param _this  This (destination) instance
 * @param lpWord Pointer to a SWord structure identifying the field to copy
 * @param iSrc   The source instance to copy the field from
 * @return O_K if successful, an error code otherwise
 *
 * HACK: This implementation copies simple types and strings only!!!
 * TODO: Implement instance and pointer copying
 */
INT16 CDlpObject_CopyField(CDlpObject* _this, SWord* lpWord, CDlpObject* iSrc)
{
  SWord* lpWordSrc = NULL;

  /* Validate input */
  CHECK_THIS_RV(NOT_EXEC);
  if (!lpWord) return NOT_EXEC;
  if (!iSrc  ) return NOT_EXEC;
  if (lpWord->nFlags & (FF_NONAUTOMATIC|FF_NOSAVE)) return NOT_EXEC;

  /* Get source word */
  lpWordSrc = CDlpObject_FindWord(iSrc,lpWord->lpName,WL_TYPE_FIELD);
  DLPASSERT(lpWordSrc);                                     /* Instance type?     */
  DLPASSERT(lpWord->nWordType   ==lpWordSrc->nWordType   ); /* Field overwritten? */
  DLPASSERT(lpWord->ex.fld.nType==lpWordSrc->ex.fld.nType); /* Field overwritten? */

  /*printf("\n Copy field %s.%s --> %s.%s",BASEINST(iSrc)->m_lpInstanceName,lpWord->lpName,BASEINST(_this)->m_lpInstanceName,lpWord->lpName);*/

  /* Copy data */
  switch (lpWord->ex.fld.nType)
  {
  case T_BOOL   : dlp_memmove(lpWord->lpData,lpWordSrc->lpData,sizeof(     BOOL)); return O_K;
  case T_UCHAR  : dlp_memmove(lpWord->lpData,lpWordSrc->lpData,sizeof(    UINT8)); return O_K;
  case T_CHAR   : dlp_memmove(lpWord->lpData,lpWordSrc->lpData,sizeof(     INT8)); return O_K;
  case T_USHORT : dlp_memmove(lpWord->lpData,lpWordSrc->lpData,sizeof(   UINT16)); return O_K;
  case T_SHORT  : dlp_memmove(lpWord->lpData,lpWordSrc->lpData,sizeof(    INT16)); return O_K;
  case T_UINT   : dlp_memmove(lpWord->lpData,lpWordSrc->lpData,sizeof(   UINT32)); return O_K;
  case T_INT    : dlp_memmove(lpWord->lpData,lpWordSrc->lpData,sizeof(    INT32)); return O_K;
  case T_ULONG  : dlp_memmove(lpWord->lpData,lpWordSrc->lpData,sizeof(   UINT64)); return O_K;
  case T_LONG   : dlp_memmove(lpWord->lpData,lpWordSrc->lpData,sizeof(    INT64)); return O_K;
  case T_FLOAT  : dlp_memmove(lpWord->lpData,lpWordSrc->lpData,sizeof(  FLOAT32)); return O_K;
  case T_DOUBLE : dlp_memmove(lpWord->lpData,lpWordSrc->lpData,sizeof(  FLOAT64)); return O_K;
  case T_COMPLEX: dlp_memmove(lpWord->lpData,lpWordSrc->lpData,sizeof(COMPLEX64)); return O_K;
  case T_STRING :
  case T_CSTRING:
  case T_TEXT   :
    dlp_free(*(char**)lpWord->lpData);
    *(char**)lpWord->lpData = NULL;
    if (*(char**)lpWordSrc->lpData)
    {
      *(char**)lpWord->lpData = (char*)dlp_malloc(dlp_size(*(char**)lpWordSrc->lpData));
      dlp_strcpy(*(char**)lpWord->lpData,*(char**)lpWordSrc->lpData);
    }
    return O_K;
  case T_INSTANCE:
    if (*(CDlpObject**)lpWordSrc->lpData)
    {
      if (*(CDlpObject**)lpWord->lpData==NULL)
      {
      #ifdef __cplusplus
        *(CDlpObject**)lpWord->lpData = CDlpObject_CreateInstanceOf(lpWordSrc->ex.fld.lpType,lpWordSrc->lpName);
      #else
        *(CDlpObject**)lpWord->lpData = *(CDlpObject**)CDlpObject_CreateInstanceOf(lpWordSrc->ex.fld.lpType,lpWordSrc->lpName);
      #endif
        if (!*(CDlpObject**)lpWord->lpData)
          IERROR(_this,ERR_CREATEINSTANCE,lpWord->lpName,0,0);
        else
          (*(CDlpObject**)lpWord->lpData)->m_lpContainer=lpWord;
      }
    #ifdef __cplusplus
      return (*(CDlpObject**)lpWord->lpData)->Copy(*(CDlpObject**)lpWordSrc->lpData);
    #else
      return (*(CDlpObject**)lpWord->lpData)->Copy(*(CDlpObject**)lpWord->lpData,*(CDlpObject**)lpWordSrc->lpData);
    #endif
    }
    else if (*(CDlpObject**)lpWord->lpData)
    {
      IDESTROY((*(CDlpObject**)lpWord->lpData));
    }
  default:
    if (lpWord->ex.fld.nType>0 && lpWord->ex.fld.nType<=255)
    {
      dlp_memmove(lpWord->lpData,lpWordSrc->lpData,lpWord->ex.fld.nType);
      return O_K;
    }
    return NOT_EXEC;
  }
}
Ejemplo n.º 29
0
/**
 * <p>Calculates roots by tracking from known roots using coefficient matching
 * method by Starer, Nehorai, 1991, Transactions - Adaptive Polynomial Factorization
 * By Coefficient Matching.</p>
 *
 * @param poly1
 *          Polynomial of predecessor
 * @param rtr1
 *          Real part of roots of predecessor.
 * @param rti1
 *          Imaginary part of roots of predecessor.
 * @param poly2
 *          Polynomial of successor where the roots are calculated from.
 * @param rtr2
 *          Real part of roots of successor to be calculated.
 * @param rti2
 *          Imaginary part of roots of successor to be calculated.
 * @param m
 *          Number of roots, i.e. size of <CODE>rtr[12]</CODE> and <CODE>rti[12]</CODE>.
 * @param n_iter
 *          Maximum number of iterations of newtons method per interim point
 * @param eps
 *          Maximum error used for breaking condition at newtons method
 * @return <code>O_K</code> if successful, a (negative) error code otherwise
 */
FLOAT64 dlm_roots_track_match_poly(COMPLEX64 poly1[], COMPLEX64 rt1[], COMPLEX64 poly2[], COMPLEX64 rt2[], INT16 m, INT16 n_iter, FLOAT64 eps) {
  INT16 i = 0;
  INT16 j = 0;
  INT16 i_iter = 0;
  FLOAT64 alpha = 1.0;
  FLOAT64 e0 = 0.0;
  FLOAT64 e1 = 0.0;
  FLOAT64 e2 = 0.0;
  COMPLEX64* poly_c = NULL;
  COMPLEX64* T = NULL;
  COMPLEX64* L = NULL;
  COMPLEX64* E = NULL;
  COMPLEX64* D = NULL;
  COMPLEX64* P1 = NULL;
  COMPLEX64* P2 = NULL;

  if (!poly1 || !poly2 || !rt1 || !rt2) return NOT_EXEC;

  poly_c = (COMPLEX64*) dlp_calloc(m+1, sizeof(COMPLEX64));
  P1 = (COMPLEX64*) dlp_calloc(m, sizeof(COMPLEX64));
  P2 = (COMPLEX64*) dlp_calloc(m, sizeof(COMPLEX64));
  E = (COMPLEX64*) dlp_calloc(m, sizeof(COMPLEX64));
  D = (COMPLEX64*) dlp_calloc(m, sizeof(COMPLEX64));
  T = (COMPLEX64*) dlp_calloc(m*m, sizeof(COMPLEX64));
  L = (COMPLEX64*) dlp_calloc(m*m, sizeof(COMPLEX64));

  dlp_memmove(rt2, rt1, m * sizeof(COMPLEX64));
  for (i = 0; i <= m; i++) {
    poly_c[i] = dlp_scalopC(poly1[i], poly1[0], OP_DIV);
  }

  for (e1 = 0.0, i = 0; i < m; i++) {
    P1[i] = rt2[i];
    E[i] =
        dlp_scalopC(dlp_scalopC(poly2[i + 1], poly2[0], OP_DIV), dlp_scalopC(poly1[i + 1], poly1[0], OP_DIV), OP_DIFF);
    e0 += E[i].x * E[i].x;
  }

  e1 = e0;

  while ((i_iter < n_iter) && (sqrt(e1 / (FLOAT64) m) > eps)) {

    for (i = 0; i < m; i++) {
      for (j = 0; j <= i; j++) {
        (*(T + (i) * m + j)).x = poly_c[i - j].x;
        (*(T + (i) * m + j)).y = poly_c[i - j].y;
      }
    }
    for (j = 0; j < m; j++) {
      (*(L + (0) * m + j)).x = 1.0;
      (*(L + (0) * m + j)).y = 0.0;
      (*(L + (1) * m + j)).x = P1[j].x;
      (*(L + (1) * m + j)).y = P1[j].y;
    }
    for (i = 2; i < m; i++) {
      for (j = 0; j < m; j++) {
        (*(L + (i) * m + j)).x = (*(L + (i - 1) * m + j)).x * P1[j].x - (*(L + (i - 1) * m + j)).y * P1[j].y;
        (*(L + (i) * m + j)).y = (*(L + (i - 1) * m + j)).x * P1[j].y + (*(L + (i - 1) * m + j)).y * P1[j].x;
      }
    }

    dlm_solve_ludC(T, m, E, 1);
    dlm_solve_ludC(L, m, E, 1);

    dlp_memmove(D, E, m * sizeof(COMPLEX64));

    alpha = 1.0;

    do {
      for (i = 0; i < m; i++) {
        P2[i].x = P1[i].x - alpha * D[i].x;
        P2[i].y = P1[i].y - alpha * D[i].y;
      }

      dlm_polyC(P2, m, poly_c);

      for (e2 = 0.0, i = 0; i < m; i++) {
        E[i].x = dlp_scalopC(poly2[i + 1], poly2[0], OP_DIV).x - poly_c[i + 1].x;
        E[i].y = -poly_c[i + 1].y;
        e2 += E[i].x * E[i].x + E[i].y * E[i].y;
      }
      alpha /= 2.0;
    } while ((alpha > 1.0e-10) && (e2 / e1 > 1.0));
    dlp_memmove(P1, P2, m * sizeof(COMPLEX64));
    e1 = e2;
    i_iter++;
  }

  for (i = 0; i < m; i++) {
    rt2[i] = P1[i];
  }

  dlp_free(D);
  dlp_free(E);
  dlp_free(P1);
  dlp_free(P2);
  dlp_free(T);
  dlp_free(L);
  dlp_free(poly_c);

  return e2 / e0;
}
Ejemplo n.º 30
0
/**
 * Destroys the class registry and frees all associated memory.
 *
 * @see CDlpObject_RegisterClass
 * @see CDlpObject_CreateInstanceOf
 */
void CDlpObject_UnregisterAllClasses()
{
  dlp_free(__lpClassRegistry);
  __lpClassRegistry=NULL;
}