示例#1
0
文件: cvsd.c 项目: 5in4/libsox.dll
int lsx_cvsdstopwrite(sox_format_t * ft)
{
        priv_t *p = (priv_t *) ft->priv;

        if (p->bit.cnt) {
                lsx_writeb(ft, p->bit.shreg);
                p->bytes_written++;
        }
        lsx_debug("cvsd: min slope %f, max slope %f",
               p->com.v_min, p->com.v_max);

        return (SOX_SUCCESS);
}
示例#2
0
static size_t cvsdwrite(sox_format_t * ft, sox_sample_t const * buf, size_t len)
{
  priv_t *p = (priv_t *) ft->priv;
  size_t i;

  for (i = 0; i < len; ++i) {
    decode(p, *buf++ > p->sample);
    p->byte >>= 1;
    p->byte |= p->last_n_bits << 7;
    if (!(++p->bit_count & 7))
      if (lsx_writeb(ft, p->byte) != SOX_SUCCESS)
        break;
  }
  return len;
}
示例#3
0
文件: cvsd.c 项目: 5in4/libsox.dll
size_t lsx_cvsdwrite(sox_format_t * ft, const sox_sample_t *buf, size_t nsamp)
{
        priv_t *p = (priv_t *) ft->priv;
        size_t done = 0;
        float inval;

        for(;;) {
                /*
                 * check if the next input is due
                 */
                if (p->com.phase >= 4) {
                        if (done >= nsamp)
                                return done;

                        /* shift input filter window in mirror cirular buffer. */
                        if (p->c.enc.offset != 0)
                                --p->c.enc.offset;
                        else p->c.enc.offset = CVSD_ENC_FILTERLEN - 1;

                        /* write into both halves of the mirror circular buffer */
                        p->c.enc.input_filter[p->c.enc.offset] = 
                                 p->c.enc.input_filter[p->c.enc.offset 
                                     + CVSD_ENC_FILTERLEN] = 
                                                (*buf++) /
                                                    ((float)SOX_SAMPLE_MAX);
                        done++;
                }
                p->com.phase &= 3;
                /* insert input filter here! */
                inval = float_conv_enc(
                                   p->c.enc.input_filter + p->c.enc.offset,
                                   (p->cvsd_rate < 24000) ?
                                   (enc_filter_16[(p->com.phase >= 2)]) :
                                   (enc_filter_32[p->com.phase]));
                /*
                 * encode one bit
                 */
                p->com.overload = (((p->com.overload << 1) |
                                    (inval >  p->c.enc.recon_int)) & 7);
                p->com.mla_int *= p->com.mla_tc0;
                if ((p->com.overload == 0) || (p->com.overload == 7))
                        p->com.mla_int += p->com.mla_tc1;
                if (p->com.mla_int > p->com.v_max)
                        p->com.v_max = p->com.mla_int;
                if (p->com.mla_int < p->com.v_min)
                        p->com.v_min = p->com.mla_int;
                if (p->com.overload & 1) {
                        p->c.enc.recon_int += p->com.mla_int;
                        p->bit.shreg |= p->bit.mask;
                } else
                        p->c.enc.recon_int -= p->com.mla_int;
                if ((++(p->bit.cnt)) >= 8) {
                        lsx_writeb(ft, p->bit.shreg);
                        p->bytes_written++;
                        p->bit.shreg = p->bit.cnt = 0;
                        p->bit.mask = 1;
                } else
                        p->bit.mask <<= 1;
                p->com.phase += p->com.phase_inc;
                lsx_debug_more("input %d %f\n", debug_count, inval);
                lsx_debug_more("recon %d %f\n", debug_count, p->c.enc.recon_int);
                debug_count++;
        }
}
示例#4
0
文件: avr.c 项目: Emisense/eTracks
static int startwrite(sox_format_t * ft)
{
    priv_t * avr = (priv_t *)ft->priv;
    int rc;

    if (!ft->seekable) {
        lsx_fail_errno(ft,SOX_EOF,"AVR: file is not seekable");
        return(SOX_EOF);
    }

    rc = lsx_rawstartwrite (ft);
    if (rc)
        return rc;

    /* magic */
    lsx_writes(ft, AVR_MAGIC);

    /* name */
    lsx_writeb(ft, 0);
    lsx_writeb(ft, 0);
    lsx_writeb(ft, 0);
    lsx_writeb(ft, 0);
    lsx_writeb(ft, 0);
    lsx_writeb(ft, 0);
    lsx_writeb(ft, 0);
    lsx_writeb(ft, 0);

    /* mono */
    if (ft->signal.channels == 1) {
        lsx_writew (ft, 0);
    }
    else if (ft->signal.channels == 2) {
        lsx_writew (ft, 0xffff);
    }
    else {
        lsx_fail_errno(ft,SOX_EFMT,"AVR: number of channels not supported");
        return(0);
    }

    /* rez */
    if (ft->encoding.bits_per_sample == 8) {
        lsx_writew (ft, 8);
    }
    else if (ft->encoding.bits_per_sample == 16) {
        lsx_writew (ft, 16);
    }
    else {
        lsx_fail_errno(ft,SOX_EFMT,"AVR: unsupported sample resolution");
        return(SOX_EOF);
    }

    /* sign */
    if (ft->encoding.encoding == SOX_ENCODING_SIGN2) {
        lsx_writew (ft, 0xffff);
    }
    else if (ft->encoding.encoding == SOX_ENCODING_UNSIGNED) {
        lsx_writew (ft, 0);
    }
    else {
        lsx_fail_errno(ft,SOX_EFMT,"AVR: unsupported encoding");
        return(SOX_EOF);
    }

    /* loop */
    lsx_writew (ft, 0xffff);

    /* midi */
    lsx_writew (ft, 0xffff);

    /* rate */
    lsx_writedw(ft, (unsigned)(ft->signal.rate + .5));

    /* size */
    /* Don't know the size yet. */
    lsx_writedw (ft, 0);

    /* lbeg */
    lsx_writedw (ft, 0);

    /* lend */
    /* Don't know the size yet, so we can't set lend, either. */
    lsx_writedw (ft, 0);

    /* res1 */
    lsx_writew (ft, 0);

    /* res2 */
    lsx_writew (ft, 0);

    /* res3 */
    lsx_writew (ft, 0);

    /* ext */
    lsx_writebuf(ft, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", sizeof(avr->ext));

    /* user */
    lsx_writebuf(ft,
                 "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
                 "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
                 "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
                 "\0\0\0\0", sizeof (avr->user));

    return(SOX_SUCCESS);
}