Пример #1
0
void
PQavgMOVB (const struct PQ_MOVBC *MOVC, int Nchan, int Nwup, int Np,
	   double MOV[])

{
  int N500ms, N50ms, Nloud, Ndel;
  const double tdel = 0.5;
  const double tex = 0.050;
  const double Fss = PQ_FS / PQ_CB_ADV;

  /* BandwidthRefB, BandwidthTestB */
  PQavgBW (&MOVC->BW, Nchan, Np, &MOV[0], &MOV[1]);

  /* Total NMRB, RelDistFramesB */
  PQavgNMRB (&MOVC->NMR, Nchan, Np, &MOV[2], &MOV[10]);

  /* WinModDiff1B, AvgModDiff1B, AvgModDiff2B */
  N500ms = (int) ceil (tdel * Fss);	/* 0.5 sec delay */
  Ndel = MAXV (0, N500ms - Nwup);
  PQavgModDiffB (Ndel, &MOVC->MDiff, Nchan, Np, &MOV[3], &MOV[6], &MOV[7]);

  /* RmsNoiseLoudB */
  N50ms = (int) ceil (tex * Fss);	/* 50 ms delay */
  Nloud = PQloudTest (&MOVC->Loud, Nchan, Np);
  Ndel = MAXV (Nloud + N50ms, Ndel);
  MOV[8] = PQavgNLoud (Ndel, &MOVC->NLoud, Nchan, Np);

  /* ADBB, MFPDB */
  PQavgPD (&MOVC->PD, Np, &MOV[4], &MOV[9]);

  /* EHSB */
  MOV[5] = PQavgEHS (&MOVC->EHS, Nchan, Np);

  return;
}
Пример #2
0
int main()
{
    int i,j,N,M;

    scanf("%d%d",&N,&M);
    for(i=0;i<N;i++)
    {
        scanf("%d%d",&c[i],&v[i]);
    }
    memset(dp,0,sizeof dp);
    for(i=c[0];i<=M;i++)
    {
        dp[0][i] = v[0];
    }
    for(i=1;i<N;i++)
    {
        for(j=0;j<=M;j++)
        {
            if(c[i]>j)
            {
                dp[i][j] = dp[i-1][j];
            }
            else
            {
                dp[i][j] = MAXV(dp[i-1][j-c[i]]+v[i],dp[i-1][j]);
            }
        }
    }
    printf("%d\n",dp[N-1][M]);
    return 0;
}
Пример #3
0
static void		calculate_chars(t_argf *arg, t_print_i *d, char *s)
{
	d->l = ft_strlen(s);
	if (arg->precision > -1 || arg->flag[FL_LESS])
		arg->flag[FL_ZERO] = FALSE;
	if ((arg->flag[FL_MORE] || arg->flag[FL_SPCE]) && *s != '-')
		d->l++;
	d->w = arg->width > d->l && arg->width > arg->precision;
	d->pl = arg->precision - d->l + (SIGN_FLAG(arg) || *s == '-');
	d->wl = arg->width - MAXV(arg->precision, d->l) -
		((SIGN_FLAG(arg) || *s == '-') && d->pl > 0) - (arg->oxfl ? 2 : 0);
	d->wl = d->wl < 0 ? 0 : d->wl;
	d->l += arg->oxfl ? 2 : 0;
}
Пример #4
0
int
AFfWriteData (AFILE *AFp, const float Dbuff[], int Nval)

{
  int Nw;
  long int Novld;
  struct AF_opt *AFopt;

  assert (AFp->Op == FO_WO);

/* The file writing routines write scaled data to the file.  They write to the
   current file position.  They use the following AFp fields:
     AFp->fp - file pointer
     AFp->Swapb - data swap flag
     AFp->ScaleF - data scaling factor
     AFp->Ovld - overload counter

  This routine updates the following AFp values
    AFp->Error - error flag
    AFp->Isamp - current data sample.  This value is incremented by the
      number of samples written.
    AFp->Nsamp - last sample (updated if AFp->Isamp is beyond it)
*/

/* Transfer data to the audio file */
  Novld = AFp->Novld;	/* Save the value before writing */
  Nw = (*AF_Write[AFp->Format]) (AFp, Dbuff, Nval);
  AFp->Isamp += Nw;
  AFp->Nsamp = MAXV (AFp->Isamp, AFp->Nsamp);

/* Check for an error */
  if (Nw < Nval) {
    UTsysMsg ("AFfWriteData: %s", AFM_WriteErr);
    AFopt = AFoptions ();
    if (AFopt->ErrorHalt)
      exit (EXIT_FAILURE);
    AFp->Error = AF_IOERR;
  }

/* Check for overloads (print a message the first time only) */
  if (Novld == 0L && AFp->Novld != 0L)
    UTwarn ("AFfWriteData - %s", AFM_OClip);

  return Nw;
}
Пример #5
0
double
PQloud (const double Ehs[], const struct Par_Loud *Loud)

{
  int m;
  double sN, Nm, Ntot;
  static const double e = 0.23;

  const int Nc = Loud->Nc;
  const double *s = Loud->s;
  const double *Et = Loud->Et;
  const double *Ets = Loud->Ets;

  sN = 0;
  for (m = 0; m < Nc; ++m) {
    Nm = Ets[m] * (pow (1 - s[m] + s[m] * Ehs[m] / Et[m], e) - 1);
    sN += MAXV (Nm, 0);
  }

  Ntot = (24. / Nc) * sN;

  return Ntot;
}
Пример #6
0
int32_t svdcmp_c(int32_t m, double* a, double* w, double* v) {
    // C port of PLINK stats.cpp svdcmp().
    // now thread-safe.
    double* rv1 = &(w[(uint32_t)m]);
    int32_t n = m;
    int32_t flag;
    int32_t l = 0; // suppress compile warning
    int32_t i,its,j,jj,k,nm;
    double anorm,c,f,g,h,s,scale,x,y,z;
    double temp;

    g=scale=anorm=0.0;
    for (i=0; i<n; i++) {
        l=i+2;
        rv1[i]=scale*g;
        g=s=scale=0.0;
        if (i < m) {
            for (k=i; k<m; k++) scale += fabs(a[k * m + i]);
            if (scale != 0.0) {
                for (k=i; k<m; k++) {
                    a[k * m + i] /= scale;
                    s += a[k * m + i]*a[k * m + i];
                }
                f=a[i * m + i];
                g = -SIGN(sqrt(s),f);
                h=f*g-s;
                a[i * m + i]=f-g;
                for (j=l-1; j<n; j++) {
                    for (s=0.0,k=i; k<m; k++) s += a[k * m + i]*a[k * m + j];
                    f=s/h;
                    for (k=i; k<m; k++) a[k * m + j] += f*a[k * m + i];
                }
                for (k=i; k<m; k++) a[k * m + i] *= scale;
            }
        }
        w[i]=scale *g;
        g=s=scale=0.0;
        if (i+1 <= m && i+1 != n) {
            for (k=l-1; k<n; k++) scale += fabs(a[i * m + k]);
            if (scale != 0.0) {
                for (k=l-1; k<n; k++) {
                    a[i * m + k] /= scale;
                    s += a[i * m + k]*a[i * m + k];
                }
                f=a[i * m + l-1];
                g = -SIGN(sqrt(s),f);
                h=f*g-s;
                a[i * m + l-1]=f-g;
                for (k=l-1; k<n; k++) rv1[k]=a[i * m + k]/h;
                for (j=l-1; j<m; j++) {
                    for (s=0.0,k=l-1; k<n; k++) s += a[j * m + k]*a[i * m + k];
                    for (k=l-1; k<n; k++) a[j * m + k] += s*rv1[k];
                }
                for (k=l-1; k<n; k++) a[i * m + k] *= scale;
            }
        }
        anorm=MAXV(anorm,(fabs(w[i])+fabs(rv1[i])));
    }
    for (i=n-1; i>=0; i--) {
        if (i < n-1) {
            if (g != 0.0) {
                for (j=l; j<n; j++)
                    v[j * m + i]=(a[i * m + j]/a[i * m + l])/g;
                for (j=l; j<n; j++) {
                    for (s=0.0,k=l; k<n; k++) s += a[i * m + k]*v[k * m + j];
                    for (k=l; k<n; k++) v[k * m + j] += s*v[k * m + i];
                }
            }
            for (j=l; j<n; j++) v[i * m + j]=v[j * m + i]=0.0;
        }
        v[i * m + i]=1.0;
        g=rv1[i];
        l=i;
    }
    for (i=MINV(m,n)-1; i>=0; i--) {
        l=i+1;
        g=w[i];
        for (j=l; j<n; j++) a[i * m + j]=0.0;
        if (g != 0.0) {
            g=1.0/g;
            for (j=l; j<n; j++) {
                for (s=0.0,k=l; k<m; k++) s += a[k * m + i]*a[k * m + j];
                f=(s/a[i * m + i])*g;
                for (k=i; k<m; k++) a[k * m + j] += f*a[k * m + i];
            }
            for (j=i; j<m; j++) a[j * m + i] *= g;
        } else for (j=i; j<m; j++) a[j * m + i]=0.0;
        ++a[i * m + i];
    }
    for (k=n-1; k>=0; k--) {
        for (its=0; its<30; its++) {
            flag=1;
            for (l=k; l>=0; l--) {
                nm=l-1;
                temp=fabs(rv1[l])+anorm;
                if (temp == anorm) {
                    flag=0;
                    break;
                }
                temp=fabs(w[nm])+anorm;
                if (temp == anorm) break;
            }
            if (flag) {
                c=0.0;
                s=1.0;
                for (i=l; i<k+1; i++) {
                    f=s*rv1[i];
                    rv1[i]=c*rv1[i];
                    temp = fabs(f)+anorm;
                    if (temp == anorm) break;
                    g=w[i];
                    h=pythag(f,g);
                    w[i]=h;
                    h=1.0/h;
                    c=g*h;
                    s = -f*h;
                    for (j=0; j<m; j++) {
                        y=a[j * m + nm];
                        z=a[j * m + i];
                        a[j * m + nm]=y*c+z*s;
                        a[j * m + i]=z*c-y*s;
                    }
                }
            }
            z=w[k];
            if (l == k) {
                if (z < 0.0) {
                    w[k] = -z;
                    for (j=0; j<n; j++) v[j * m + k] = -v[j * m + k];
                }
                break;
            }
            if (its == 29)
                return 0; // cannot converge: multi-collinearity?
            x=w[l];
            nm=k-1;
            y=w[nm];
            g=rv1[nm];
            h=rv1[k];
            f=((y-z)*(y+z)+(g-h)*(g+h))/(2.0*h*y);
            g=pythag(f,1.0);
            f=((x-z)*(x+z)+h*((y/(f+SIGN(g,f)))-h))/x;
            c=s=1.0;
            for (j=l; j<=nm; j++) {
                i=j+1;
                g=rv1[i];
                y=w[i];
                h=s*g;
                g=c*g;
                z=pythag(f,h);
                rv1[j]=z;
                c=f/z;
                s=h/z;
                f=x*c+g*s;
                g=g*c-x*s;
                h=y*s;
                y *= c;
                for (jj=0; jj<n; jj++) {
                    x=v[jj * m + j];
                    z=v[jj * m + i];
                    v[jj * m + j]=x*c+z*s;
                    v[jj * m + i]=z*c-x*s;
                }
                z=pythag(f,h);
                w[j]=z;
                if (z) {
                    z=1.0/z;
                    c=f*z;
                    s=h*z;
                }
                f=c*g+s*y;
                x=c*y-s*g;
                for (jj=0; jj<m; jj++) {
                    y=a[jj * m + j];
                    z=a[jj * m + i];
                    a[jj * m + j]=y*c+z*s;
                    a[jj * m + i]=z*c-y*s;
                }
            }
            rv1[l]=0.0;
            rv1[k]=f;
            w[k]=x;
        }
    }
    return 1;
}
Пример #7
0
void
PQadapt (const double *Ehs[2], const struct Par_Patt *Patt,
	 double *EP[2], struct Mem_Adap *Adap)

{
  int m, i, iL, iU, M1, M2;
  double sn, sd, s1, s2, CL;
  double R[2][PQ_MAXNC];

  double **P = Adap->P;
  double **PC = Adap->PC;
  double *Rn = Adap->Rn;
  double *Rd = Adap->Rd;

  const int Nc = Patt->Nc;
  const double *a = Patt->a;
  const double *b = Patt->b;

  /* Smooth the excitation patterns */
  /* Calculate the correlation terms */
  sn = 0;
  sd = 0;
  for (m = 0; m < Nc; ++m) {
    P[0][m] = a[m] * P[0][m] + b[m] * Ehs[0][m];
    P[1][m] = a[m] * P[1][m] + b[m] * Ehs[1][m];
    sn += sqrt (P[1][m] * P[0][m]);
    sd += P[1][m];
  }

  /* Level correlation */
  CL = SQRV (sn / sd);

  for (m = 0; m < Nc; ++m) {

    /* Scale one of the signals to match levels */
    if (CL > 1) {
      EP[0][m] = Ehs[0][m] / CL;
      EP[1][m] = Ehs[1][m];
    }
    else {
      EP[0][m] = Ehs[0][m];
      EP[1][m] = Ehs[1][m] * CL;
    }

    /* Calculate a pattern match correction factor */
    Rn[m] = a[m] * Rn[m] + EP[1][m] * EP[0][m];
    Rd[m] = a[m] * Rd[m] + EP[0][m] * EP[0][m];
    assert (Rd[m] > 0 && Rn[m] > 0);
    if (Rn[m] >= Rd[m]) {
      R[0][m] = 1;
      R[1][m] = Rd[m] / Rn[m];
    }
    else {
      R[0][m] = Rn[m] / Rd[m];
      R[1][m] = 1;
    }
  }

  /* Average the correction factors over M channels and smooth with time */
  M1 = Patt->M1;
  M2 = Patt->M2;
  for (m = 0; m < Nc; ++m) {
    iL = MAXV (m - M1, 0);
    iU = MINV (m + M2, Nc-1);
    s1 = 0;
    s2 = 0;
    for (i = iL; i <= iU; ++i) {
      s1 += R[0][i];
      s2 += R[1][i];
    }
    PC[0][m] = a[m] * PC[0][m] + b[m] * s1 / (iU-iL+1);
    PC[1][m] = a[m] * PC[1][m] + b[m] * s2 / (iU-iL+1);

    /* Final correction factor => spectrally adapted patterns */
    EP[0][m] = EP[0][m] * PC[0][m];
    EP[1][m] = EP[1][m] * PC[1][m];
  }

  return;
}
Пример #8
0
static long int
CP_combN (AFILE *AFp[], const long int StartF[], int Nifiles, long int Nframe,
	  const struct CP_Chgain *Chgain, AFILE *AFpO)

{
  int i, j, k, m, n, Nt, NI, NO, Nc, Ns, Nfr, NchanMax;
  long int offr, offs, Nj, Nrem;
  double g;
  double Dbuff[BFSIZE];
  double *Dbuffi, *Dbuffo;

  assert (Nframe != AF_NFRAME_UNDEF);
  assert (AFpO->Nchan == Chgain->NO);

/* Number of channels to be read (all files), maximum MAXNI */
  NI = 0;
  for (j = 0; j < Nifiles; ++j)
    NI += (int) MINV (AFp[j]->Nchan, MAXNI - NI);
  assert (NI >= Chgain->NI);

/* Maximum number of channels from any single file */
  Nt = 0;
  NchanMax = 0;
  for (j = 0; j < Nifiles; ++j) {
    Nc = (int) MINV (AFp[j]->Nchan, NI - Nt);
    NchanMax = MAXV (NchanMax, Nc);
    Nt += Nc;
  }

  NO = (int) AFpO->Nchan;

/* Split the buffer space up for the input and output buffers */
  Ns = BFSIZE / (NchanMax + NO);
  Dbuffi = Dbuff;
  Dbuffo = Dbuff + NchanMax * Ns;

/*
   The copying operation takes scaled samples from the input si(n,i)
   (channel n, sample i) and sums them to form so(k,i) (channel k, sample i)

     so(k,i) = SUM g(k,n) * si(n,i)
              n
   However, samples from different channels are interleaved.  Thus so(k,i) is
   really so(i * No + k), where No is the number of output channels.  For the
   input data, the channels appear in different files.

   The copying operation loops over the input channels n, the output channels
   k and the samples i.  The inner loop is chosen to be over the samples, so
   that this loop can be skipped if the gain for an input/output channel
   combination is zero.  The looping over input channels is actually two loops;
   one over files and the other for channels within a file.  The loop over
   files is outermost, so that the data from the input files need only be read
   once.
*/

/* Main loop */
  offr = 0L;
  Nrem = Nframe;
  while (Nrem > 0) {

    Nfr = (int) MINV (Nrem, Ns);
    for (k = 0; k < NO; ++k) {
      for (i = 0; i < Nfr; ++i)
	Dbuffo[i*NO+k] = Chgain->Offset[k];	/* dc offset */
    }
    n = 0;
    Nt = 0;
    for (j = 0; j < Nifiles; ++j) {
      Nj = AFp[j]->Nchan;
      Nc = (int) MINV (NI - Nt, Nj);

      /* Read Nc channels (out of Nj) channels from file j */
      offs = Nj * (offr + StartF[j]);
      if (Nc == Nj)
	AFdReadData (AFp[j], offs, Dbuffi, Nfr * Nc);
      else if (Nc > 0) {
	for (i = 0; i < Nfr; ++i)
	  AFdReadData (AFp[j], offs + i * Nj, &Dbuffi[i*Nc], Nc);
      }
      Nt += Nc;

      /* Add the contribution from file j to the output */
      for (m = 0; m < Nc; ++m) {
	for (k = 0; k < NO; ++k) {
	  g = Chgain->Gain[k][n];
	  if (g != 0.0) {
	    for (i = 0; i < Nfr; ++i)
	      Dbuffo[i*NO+k] += g * Dbuffi[i*Nc+m];
	  }
	}
	++n;
      }
    }
    /* Write the samples to the output file */
    AFdWriteData (AFpO, Dbuffo, Nfr * NO);
    offr += Nfr;
    Nrem -= Nfr;
  }

  return Nframe;
}
Пример #9
0
void
FAfiltIIR (AFILE *AFpI, AFILE *AFpO, long int NsampO, const double h[][5],
	   int Nsec, int Nsub, long int loffs)

{
  double x[NBUF];
  int mem, Nxmax, Nx;
  long int l, k, NyO;

/*
   Notes:
   - The input signal d(.) is the data in the file, with d(0) corresponding to
     the first data value in the file.
   - Indexing: l is an offset into d(), referring to sample d(l).
*/

/* Batch processing
   - The data will be processed in batches by reading into a buffer x(.,.).
     The batches of input samples will be of equal size, Nx, except for the
     last batch.  For batch j,
       x(j,l') = d(loffs+j*Nx+l'), for 0 <= l' < Nx,
   - The k'th output point y(k) is calculated at position d(loffs+k), that is
     the start of the impulse response, h(0), is aligned with d(loffs+k).
       y(k) --> h[0] <==> d(l),    where l=loffs+k
                h[0] <==> x(j,l').
   - For batch j=0,
       l = loffs  - pointer to d(loffs),
       l' = 0     - pointer to x(0,0) = d(loffs),
       k = 0      - pointer to y(0).
   - For each batch, k and l' advance by Nx,
       k <- k + Nx,
       l' <- l' + Nx.
   - When the index l' for x(j,l') advances beyond Nx, we bring l' back
     into range by subtracting Nx from it and incrementing the batch number,
*/

/* Buffer allocation
   The buffer is allocated to filter memory (mem) and the input data (Nx).
   The output data will overlay the input data.
*/
  mem = 2 * (Nsec + 1);
  Nxmax = NBUF - mem;
  if (Nxmax <= 0)
    UThalt ("%s: %s", PROGRAM, FAM_XIIRSect);
  NyO = (NsampO - 1) * Nsub + 1;

/* Main processing loop */
  /* if (l < loffs), processing warm-up points, no output */
  VRdZero (x, mem);
  l = MINV (loffs, MAXV (0, loffs - MAXWUP));
  k = 0;
  while (k < NyO) {

/* Read the input data into the input buffer */
    if (l < loffs)
      Nx = (int) MINV (Nxmax, loffs - l);
    else
      Nx = (int) MINV (Nxmax, NyO - k);
    AFdReadData (AFpI, l, &x[mem], Nx);

/* Convolve the input samples with the filter response */
    FIdFiltIIR (&x[mem-2], x, Nx, h, Nsec);

/* Write the output data to the output audio file */
    if (l >= loffs) {
      if (Nsub == 1)
	AFdWriteData (AFpO, &x[2], Nx);
      else
	FA_writeSubData (AFpO, k, Nsub, &x[2], Nx);
      k = k + Nx;
    }
    l = l + Nx;

/* Update the filter memory */
    VRdShift (x, mem, Nx);
  }

  return;
}