//------------------------------------------------------------------------------------------------- // copy all fields from this message to 'to' where the field is legal for 'to' and it is not // already present in 'to'; includes repeating groups; // if force, copy all fields regardless, replacing any existing, adding any new unsigned MessageBase::copy_legal(MessageBase *to, bool force) const { unsigned copied(0); for (Presence::const_iterator itr(_fp.get_presence().begin()); itr != _fp.get_presence().end(); ++itr) { if (itr->_field_traits & FieldTrait::present && (force || (to->_fp.has(itr->_fnum) && !to->_fp.get(itr->_fnum)))) { if (itr->_field_traits & FieldTrait::group) { GroupBase *gb(find_group(itr->_fnum)), *gb1(to->find_group(itr->_fnum)); for (GroupElement::const_iterator gitr(gb->_msgs.begin()); gitr != gb->_msgs.end(); ++gitr) { MessageBase *grc(gb1->create_group()); (*gitr)->copy_legal(grc, force); *gb1 += grc; } } BaseField *nf(get_field(itr->_fnum)->copy()); #if defined POPULATE_METADATA to->check_set_rlm(nf); #endif Presence::const_iterator fpitr(_fp.get_presence().end()); if (force && to->_fp.get(itr->_fnum, fpitr, FieldTrait::present)) delete to->replace(itr->_fnum, fpitr, nf); else to->add_field(nf); ++copied; } } return copied; }
/* Markel&Gray, LP of S, page 221 work[1..m(m+1)/2+m+m+1+m+m+1] b = & work[1] grc = & work[m*(m+1)/2+1]; a = & work[m*(m+1)/2+m+1]; beta = & work [m+1)/2+m+m+1+1]; cc = & work[m+1)/2+m+m+1+m+1] for (i=1; i<=m(m+1)/2+m+m+1+m+m+1;i++) work[i] = 0; */ static int Sound_into_LPC_Frame_covar (Sound me, LPC_Frame thee) { long i = 1, n = my nx, m = thy nCoefficients; double *x = my z[1]; autoNUMvector<double> b (1, m * (m + 1) / 2); autoNUMvector<double> grc (1, m); autoNUMvector<double> a (1, m + 1); autoNUMvector<double> beta (1, m); autoNUMvector<double> cc (1, m + 1); thy gain = 0.0; for (i = m + 1; i <= n; i++) { thy gain += x[i] * x[i]; cc[1] += x[i] * x[i - 1]; cc[2] += x[i - 1] * x[i - 1]; } if (thy gain == 0.0) { i = 1; /* ! */ goto end; } b[1] = 1.0; beta[1] = cc[2]; a[1] = 1.0; a[2] = grc[1] = -cc[1] / cc[2]; thy gain += grc[1] * cc[1]; for (i = 2; i <= m; i++) { /*130*/ double s = 0.0; /* 20 */ for (long j = 1; j <= i; j++) { cc[i - j + 2] = cc[i - j + 1] + x[m - i + 1] * x[m - i + j] - x[n - i + 1] * x[n - i + j]; } cc[1] = 0.0; for (long j = m + 1; j <= n; j++) { cc[1] += x[j - i] * x[j]; /* 30 */ } b[i * (i + 1) / 2] = 1.0; for (long j = 1; j <= i - 1; j++) { /* 70 */ double gam = 0.0; if (beta[j] < 0.0) { goto end; } else if (beta[j] == 0.0) { continue; } for (long k = 1; k <= j; k++) { gam += cc[k + 1] * b[j * (j - 1) / 2 + k]; /*50*/ } gam /= beta[j]; for (long k = 1; k <= j; k++) { b[i * (i - 1) / 2 + k] -= gam * b[j * (j - 1) / 2 + k]; /*60*/ } } beta[i] = 0.0; for (long j = 1; j <= i; j++) { beta[i] += cc[j + 1] * b[i * (i - 1) / 2 + j]; /*80*/ } if (beta[i] <= 0.0) { goto end; } for (long j = 1; j <= i; j++) { s += cc[j] * a[j]; /*100*/ } grc[i] = -s / beta[i]; for (long j = 2; j <= i; j++) { a[j] += grc[i] * b[i * (i - 1) / 2 + j - 1]; /*110*/ } a[i + 1] = grc[i]; s = grc[i] * grc[i] * beta[i]; thy gain -= s; if (thy gain <= 0.0) { goto end; } } end: i--; for (long j = 1; j <= i; j++) { thy a[j] = a[j + 1]; } if (i == m) { return 1; } thy nCoefficients = i; for (long j = i + 1; j <= m; j++) { thy a[j] = 0.0; } return 0; // Melder_warning ("Less coefficienst than asked for."); }