// the actual parsing routine bool Parser::parseXMLString(QString data, bool cont) { // add the data to what was left over from a previous parse run // search the buffer for the nearest closetag int index = 0; QRegExp rx( "</MSG_Notification>|</Argument>|</AreaName>"); m_xml->addData( data ); if ( (index = rx.indexIn( data )) != -1 ) { // end found in last part QString residu( data ); do { parse(); m_xml->clear(); // add make residu int len = index + rx.matchedLength(); residu = residu.right( residu.length() - len ); m_xml->addData( residu ); // loop until no end found in residu } while ( (index = rx.indexIn( residu )) != -1 ); } if (!cont) { m_xml->clear(); } return true; }
/*! Least squares method used to make the tracking more robust. It ensures that the points taken into account to compute the right equation belong to the line. */ void vpMeLine::leastSquare() { vpMatrix A(numberOfSignal(),2) ; vpColVector x(2), x_1(2) ; x_1 = 0; unsigned int i ; vpRobust r(numberOfSignal()) ; r.setThreshold(2); r.setIteration(0) ; vpMatrix D(numberOfSignal(),numberOfSignal()) ; D.eye() ; vpMatrix DA, DAmemory ; vpColVector DAx ; vpColVector w(numberOfSignal()) ; vpColVector B(numberOfSignal()) ; w =1 ; vpMeSite p_me ; unsigned int iter =0 ; unsigned int nos_1 = 0 ; double distance = 100; if (list.size() <= 2 || numberOfSignal() <= 2) { //vpERROR_TRACE("Not enough point") ; vpCDEBUG(1) << "Not enough point"; throw(vpTrackingException(vpTrackingException::notEnoughPointError, "not enough point")) ; } if ((fabs(b) >=0.9)) // Construction du systeme Ax=B // a i + j + c = 0 // A = (i 1) B = (-j) { nos_1 = numberOfSignal() ; unsigned int k =0 ; for(std::list<vpMeSite>::const_iterator it=list.begin(); it!=list.end(); ++it){ p_me = *it; if (p_me.getState() == vpMeSite::NO_SUPPRESSION) { A[k][0] = p_me.ifloat ; A[k][1] = 1 ; B[k] = -p_me.jfloat ; k++ ; } } while (iter < 4 && distance > 0.05) { DA = D*A ; x = DA.pseudoInverse(1e-26) *D*B ; vpColVector residu(nos_1); residu = B - A*x; r.setIteration(iter) ; r.MEstimator(vpRobust::TUKEY,residu,w) ; k = 0; for (i=0 ; i < nos_1 ; i++) { D[k][k] =w[k] ; k++; } iter++ ; distance = fabs(x[0]-x_1[0])+fabs(x[1]-x_1[1]); x_1 = x; } k =0 ; for(std::list<vpMeSite>::iterator it=list.begin(); it!=list.end(); ++it){ p_me = *it; if (p_me.getState() == vpMeSite::NO_SUPPRESSION) { if (w[k] < 0.2) { p_me.setState(vpMeSite::M_ESTIMATOR); *it = p_me; } k++ ; } } // mise a jour de l'equation de la droite a = x[0] ; b = 1 ; c = x[1] ; double s =sqrt( vpMath::sqr(a)+vpMath::sqr(b)) ; a /= s ; b /= s ; c /= s ; } else // Construction du systeme Ax=B // i + bj + c = 0 // A = (j 1) B = (-i) { nos_1 = numberOfSignal() ; unsigned int k =0 ; for(std::list<vpMeSite>::const_iterator it=list.begin(); it!=list.end(); ++it){ p_me = *it; if (p_me.getState() == vpMeSite::NO_SUPPRESSION) { A[k][0] = p_me.jfloat ; A[k][1] = 1 ; B[k] = -p_me.ifloat ; k++ ; } } while (iter < 4 && distance > 0.05) { DA = D*A ; x = DA.pseudoInverse(1e-26) *D*B ; vpColVector residu(nos_1); residu = B - A*x; r.setIteration(iter) ; r.MEstimator(vpRobust::TUKEY,residu,w) ; k = 0; for (i=0 ; i < nos_1 ; i++) { D[k][k] =w[k] ; k++; } iter++ ; distance = fabs(x[0]-x_1[0])+fabs(x[1]-x_1[1]); x_1 = x; } k =0 ; for(std::list<vpMeSite>::iterator it=list.begin(); it!=list.end(); ++it){ p_me = *it; if (p_me.getState() == vpMeSite::NO_SUPPRESSION) { if (w[k] < 0.2) { p_me.setState(vpMeSite::M_ESTIMATOR); *it = p_me; } k++ ; } } a = 1 ; b = x[0] ; c = x[1] ; double s = sqrt(vpMath::sqr(a)+vpMath::sqr(b)) ; a /= s ; b /= s ; c /= s ; } // mise a jour du delta delta = atan2(a,b) ; normalizeAngle(delta) ; }
/*! Least squares method used to make the tracking more robust. It ensures that the points taken into account to compute the right equation belong to the ellipse. */ void vpMeEllipse::leastSquare() { // Construction du systeme Ax=b //! i^2 + K0 j^2 + 2 K1 i j + 2 K2 i + 2 K3 j + K4 // A = (j^2 2ij 2i 2j 1) x = (K0 K1 K2 K3 K4)^T b = (-i^2 ) unsigned int i ; vpMeSite p_me ; unsigned int iter =0 ; vpColVector b_(numberOfSignal()) ; vpRobust r(numberOfSignal()) ; r.setThreshold(2); r.setIteration(0) ; vpMatrix D(numberOfSignal(),numberOfSignal()) ; D.setIdentity() ; vpMatrix DA, DAmemory ; vpColVector DAx ; vpColVector w(numberOfSignal()) ; w =1 ; unsigned int nos_1 = numberOfSignal() ; if (list.size() < 3) { vpERROR_TRACE("Not enough point") ; throw(vpTrackingException(vpTrackingException::notEnoughPointError, "not enough point")) ; } if (circle ==false) { vpMatrix A(numberOfSignal(),5) ; vpColVector x(5); unsigned int k =0 ; for(std::list<vpMeSite>::const_iterator it=list.begin(); it!=list.end(); ++it){ p_me = *it; if (p_me.getState() == vpMeSite::NO_SUPPRESSION) { A[k][0] = vpMath::sqr(p_me.jfloat) ; A[k][1] = 2 * p_me.ifloat * p_me.jfloat ; A[k][2] = 2 * p_me.ifloat ; A[k][3] = 2 * p_me.jfloat ; A[k][4] = 1 ; b_[k] = - vpMath::sqr(p_me.ifloat) ; k++ ; } } while (iter < 4 ) { DA = D*A ; vpMatrix DAp ; x = DA.pseudoInverse(1e-26) *D*b_ ; vpColVector residu(nos_1); residu = b_ - A*x; r.setIteration(iter) ; r.MEstimator(vpRobust::TUKEY,residu,w) ; k = 0; for (i=0 ; i < nos_1 ; i++) { D[k][k] =w[k] ; k++; } iter++; } k =0 ; for(std::list<vpMeSite>::iterator it=list.begin(); it!=list.end(); ++it){ p_me = *it; if (p_me.getState() == vpMeSite::NO_SUPPRESSION) { if (w[k] < thresholdWeight) { p_me.setState(vpMeSite::M_ESTIMATOR); *it = p_me; } k++ ; } } for(i = 0; i < 5; i ++) K[i] = x[i]; } else { vpMatrix A(numberOfSignal(),3) ; vpColVector x(3); unsigned int k =0 ; for(std::list<vpMeSite>::const_iterator it=list.begin(); it!=list.end(); ++it){ p_me = *it; if (p_me.getState() == vpMeSite::NO_SUPPRESSION) { A[k][0] = 2* p_me.ifloat ; A[k][1] = 2 * p_me.jfloat ; A[k][2] = 1 ; b_[k] = - vpMath::sqr(p_me.ifloat) - vpMath::sqr(p_me.jfloat) ; k++ ; } } while (iter < 4 ) { DA = D*A ; vpMatrix DAp ; x = DA.pseudoInverse(1e-26) *D*b_ ; vpColVector residu(nos_1); residu = b_ - A*x; r.setIteration(iter) ; r.MEstimator(vpRobust::TUKEY,residu,w) ; k = 0; for (i=0 ; i < nos_1 ; i++) { D[k][k] =w[k]; k++; } iter++; } k =0 ; for(std::list<vpMeSite>::iterator it=list.begin(); it!=list.end(); ++it){ p_me = *it; if (p_me.getState() == vpMeSite::NO_SUPPRESSION) { if (w[k] < thresholdWeight) { p_me.setState(vpMeSite::M_ESTIMATOR); *it = p_me; } k++ ; } } for(i = 0; i < 3; i ++) K[i+2] = x[i]; } getParameters() ; }
void coder_ld8a( int ana[] /* output: analysis parameters */ ) { /* LPC coefficients */ FLOAT Aq_t[(MP1)*2]; /* A(z) quantized for the 2 subframes */ FLOAT Ap_t[(MP1)*2]; /* A(z) with spectral expansion */ FLOAT *Aq, *Ap; /* Pointer on Aq_t and Ap_t */ /* Other vectors */ FLOAT h1[L_SUBFR]; /* Impulse response h1[] */ FLOAT xn[L_SUBFR]; /* Target vector for pitch search */ FLOAT xn2[L_SUBFR]; /* Target vector for codebook search */ FLOAT code[L_SUBFR]; /* Fixed codebook excitation */ FLOAT y1[L_SUBFR]; /* Filtered adaptive excitation */ FLOAT y2[L_SUBFR]; /* Filtered fixed codebook excitation */ FLOAT g_coeff[5]; /* Correlations between xn, y1, & y2: <y1,y1>, <xn,y1>, <y2,y2>, <xn,y2>,<y1,y2>*/ /* Scalars */ int i, j, i_subfr; int T_op, T0, T0_min, T0_max, T0_frac; int index; FLOAT gain_pit, gain_code; int taming; /*------------------------------------------------------------------------* * - Perform LPC analysis: * * * autocorrelation + lag windowing * * * Levinson-durbin algorithm to find a[] * * * convert a[] to lsp[] * * * quantize and code the LSPs * * * find the interpolated LSPs and convert to a[] for the 2 * * subframes (both quantized and unquantized) * *------------------------------------------------------------------------*/ { /* Temporary vectors */ FLOAT r[MP1]; /* Autocorrelations */ FLOAT rc[M]; /* Reflexion coefficients */ FLOAT lsp_new[M]; /* lsp coefficients */ FLOAT lsp_new_q[M]; /* Quantized lsp coeff. */ /* LP analysis */ autocorr(p_window, M, r); /* Autocorrelations */ lag_window(M, r); /* Lag windowing */ levinson(r, Ap_t, rc); /* Levinson Durbin */ az_lsp(Ap_t, lsp_new, lsp_old); /* Convert A(z) to lsp */ /* LSP quantization */ qua_lsp(lsp_new, lsp_new_q, ana); ana += 2; /* Advance analysis parameters pointer */ /*--------------------------------------------------------------------* * Find interpolated LPC parameters in all subframes * * The interpolated parameters are in array Aq_t[]. * *--------------------------------------------------------------------*/ int_qlpc(lsp_old_q, lsp_new_q, Aq_t); /* Compute A(z/gamma) */ weight_az(&Aq_t[0], GAMMA1, M, &Ap_t[0]); weight_az(&Aq_t[MP1], GAMMA1, M, &Ap_t[MP1]); /* update the LSPs for the next frame */ copy(lsp_new, lsp_old, M); copy(lsp_new_q, lsp_old_q, M); } /*----------------------------------------------------------------------* * - Find the weighted input speech w_sp[] for the whole speech frame * * - Find the open-loop pitch delay for the whole speech frame * * - Set the range for searching closed-loop pitch in 1st subframe * *----------------------------------------------------------------------*/ residu(&Aq_t[0], &speech[0], &exc[0], L_SUBFR); residu(&Aq_t[MP1], &speech[L_SUBFR], &exc[L_SUBFR], L_SUBFR); { FLOAT Ap1[MP1]; Ap = Ap_t; Ap1[0] = (F)1.0; for(i=1; i<=M; i++) Ap1[i] = Ap[i] - (F)0.7 * Ap[i-1]; syn_filt(Ap1, &exc[0], &wsp[0], L_SUBFR, mem_w, 1); Ap += MP1; for(i=1; i<=M; i++) Ap1[i] = Ap[i] - (F)0.7 * Ap[i-1]; syn_filt(Ap1, &exc[L_SUBFR], &wsp[L_SUBFR], L_SUBFR, mem_w, 1); } /* Find open loop pitch lag for whole speech frame */ T_op = pitch_ol_fast(wsp, L_FRAME); /* Range for closed loop pitch search in 1st subframe */ T0_min = T_op - 3; if (T0_min < PIT_MIN) T0_min = PIT_MIN; T0_max = T0_min + 6; if (T0_max > PIT_MAX) { T0_max = PIT_MAX; T0_min = T0_max - 6; } /*------------------------------------------------------------------------* * Loop for every subframe in the analysis frame * *------------------------------------------------------------------------* * To find the pitch and innovation parameters. The subframe size is * * L_SUBFR and the loop is repeated L_FRAME/L_SUBFR times. * * - find the weighted LPC coefficients * * - find the LPC residual signal * * - compute the target signal for pitch search * * - compute impulse response of weighted synthesis filter (h1[]) * * - find the closed-loop pitch parameters * * - encode the pitch delay * * - find target vector for codebook search * * - codebook search * * - VQ of pitch and codebook gains * * - update states of weighting filter * *------------------------------------------------------------------------*/ Aq = Aq_t; /* pointer to interpolated quantized LPC parameters */ Ap = Ap_t; /* pointer to weighted LPC coefficients */ for (i_subfr = 0; i_subfr < L_FRAME; i_subfr += L_SUBFR) { /*---------------------------------------------------------------* * Compute impulse response, h1[], of weighted synthesis filter * *---------------------------------------------------------------*/ h1[0] = (F)1.0; set_zero(&h1[1], L_SUBFR-1); syn_filt(Ap, h1, h1, L_SUBFR, &h1[1], 0); /*-----------------------------------------------* * Find the target vector for pitch search: * *----------------------------------------------*/ syn_filt(Ap, &exc[i_subfr], xn, L_SUBFR, mem_w0, 0); /*-----------------------------------------------------------------* * Closed-loop fractional pitch search * *-----------------------------------------------------------------*/ T0 = pitch_fr3_fast(&exc[i_subfr], xn, h1, L_SUBFR, T0_min, T0_max, i_subfr, &T0_frac); index = enc_lag3(T0, T0_frac, &T0_min, &T0_max, PIT_MIN, PIT_MAX, i_subfr); *ana++ = index; if (i_subfr == 0) *ana++ = parity_pitch(index); /*-----------------------------------------------------------------* * - find filtered pitch exc * * - compute pitch gain and limit between 0 and 1.2 * * - update target vector for codebook search * * - find LTP residual. * *-----------------------------------------------------------------*/ syn_filt(Ap, &exc[i_subfr], y1, L_SUBFR, mem_zero, 0); gain_pit = g_pitch(xn, y1, g_coeff, L_SUBFR); /* clip pitch gain if taming is necessary */ taming = test_err(T0, T0_frac); if( taming == 1){ if (gain_pit > GPCLIP) { gain_pit = GPCLIP; } } for (i = 0; i < L_SUBFR; i++) xn2[i] = xn[i] - y1[i]*gain_pit; /*-----------------------------------------------------* * - Innovative codebook search. * *-----------------------------------------------------*/ index = ACELP_code_A(xn2, h1, T0, sharp, code, y2, &i); *ana++ = index; /* Positions index */ *ana++ = i; /* Signs index */ /*------------------------------------------------------* * - Compute the correlations <y2,y2>, <xn,y2>, <y1,y2>* * - Vector quantize gains. * *------------------------------------------------------*/ corr_xy2(xn, y1, y2, g_coeff); *ana++ =qua_gain(code, g_coeff, L_SUBFR, &gain_pit, &gain_code, taming); /*------------------------------------------------------------* * - Update pitch sharpening "sharp" with quantized gain_pit * *------------------------------------------------------------*/ sharp = gain_pit; if (sharp > SHARPMAX) sharp = SHARPMAX; if (sharp < SHARPMIN) sharp = SHARPMIN; /*------------------------------------------------------* * - Find the total excitation * * - update filters' memories for finding the target * * vector in the next subframe (mem_w0[]) * *------------------------------------------------------*/ for (i = 0; i < L_SUBFR; i++) exc[i+i_subfr] = gain_pit*exc[i+i_subfr] + gain_code*code[i]; update_exc_err(gain_pit, T0); for (i = L_SUBFR-M, j = 0; i < L_SUBFR; i++, j++) mem_w0[j] = xn[i] - gain_pit*y1[i] - gain_code*y2[i]; Aq += MP1; /* interpolated LPC parameters for next subframe */ Ap += MP1; } /*--------------------------------------------------* * Update signal for next frame. * * -> shift to the left by L_FRAME: * * speech[], wsp[] and exc[] * *--------------------------------------------------*/ copy(&old_speech[L_FRAME], &old_speech[0], L_TOTAL-L_FRAME); copy(&old_wsp[L_FRAME], &old_wsp[0], PIT_MAX); copy(&old_exc[L_FRAME], &old_exc[0], PIT_MAX+L_INTERPOL); return; }