Beispiel #1
0
static unsigned bit_depth(uint32_t mask, double min, double max, unsigned * x)
{
  SOX_SAMPLE_LOCALS;
  unsigned result = 32, dummy = 0;

  for (; result && !(mask & 1); --result, mask >>= 1);
  if (x)
    *x = result;
  mask = SOX_FLOAT_64BIT_TO_SAMPLE(max, dummy);
  if (min < 0)
    mask |= ~(SOX_FLOAT_64BIT_TO_SAMPLE(min, dummy) << 1);
  for (; result && !(mask & SOX_SAMPLE_MIN); --result, mask <<= 1);
  return result;
}
Beispiel #2
0
static size_t sox_datread(sox_format_t * ft, sox_sample_t *buf, size_t nsamp)
{
    char inpstr[LINEWIDTH];
    int  inpPtr = 0;
    int  inpPtrInc = 0;
    double sampval = 0.0;
    int retc = 0;
    char sc = 0;
    size_t done = 0;
    size_t i=0;

    /* Always read a complete set of channels */
    nsamp -= (nsamp % ft->signal.channels);

    while (done < nsamp) {

      /* Read a line or grab the buffered first line */
      if (((priv_t *)ft->priv)->buffered) {
        strncpy(inpstr, ((priv_t *)ft->priv)->prevline, (size_t)LINEWIDTH);
        inpstr[LINEWIDTH-1] = 0;
        ((priv_t *)ft->priv)->buffered=0;
      } else {
        lsx_reads(ft, inpstr, LINEWIDTH-1);
        inpstr[LINEWIDTH-1] = 0;
        if (lsx_eof(ft)) return (done);
      }

      /* Skip over comments - ie. 0 or more whitespace, then ';' */
      if ((sscanf(inpstr," %c", &sc) != 0) && (sc==';')) continue;

      /* Read a complete set of channels */
      sscanf(inpstr," %*s%n", &inpPtr);
      for (i=0; i<ft->signal.channels; i++) {
        SOX_SAMPLE_LOCALS;
        retc = sscanf(&inpstr[inpPtr]," %lg%n", &sampval, &inpPtrInc);
        inpPtr += inpPtrInc;
        if (retc != 1) {
          lsx_fail_errno(ft,SOX_EOF,"Unable to read sample.");
          return 0;
        }
        *buf++ = SOX_FLOAT_64BIT_TO_SAMPLE(sampval, ft->clips);
        done++;
      }
    }

    return (done);
}
static int flow(sox_effect_t * effp, const sox_sample_t * ibuf,
                sox_sample_t * obuf, size_t * isamp, size_t * osamp)
{
  priv_t * p = (priv_t *)effp->priv;
  size_t i, odone = min(*osamp, (size_t)fifo_occupancy(&p->output_fifo));
  double const * s = fifo_read(&p->output_fifo, (int)odone, NULL);
  SOX_SAMPLE_LOCALS;

  for (i = 0; i < odone; ++i)
    *obuf++ = SOX_FLOAT_64BIT_TO_SAMPLE(*s++, effp->clips);
  p->samples_out += odone;

  if (*isamp && odone < *osamp) {
    double * t = fifo_write(&p->input_fifo, (int)*isamp, NULL);
    p->samples_in += (int)*isamp;

    for (i = *isamp; i; --i)
      *t++ = SOX_SAMPLE_TO_FLOAT_64BIT(*ibuf++, effp->clips);
    filter(p);
  }
  else *isamp = 0;
  *osamp = odone;
  return SOX_SUCCESS;
}