static size_t sox_datwrite(sox_format_t * ft, const sox_sample_t *buf, size_t nsamp) { priv_t * dat = (priv_t *) ft->priv; size_t done = 0; double sampval=0.0; char s[LINEWIDTH]; size_t i=0; /* Always write a complete set of channels */ nsamp -= (nsamp % ft->signal.channels); /* Write time, then sample values, then CRLF newline */ while(done < nsamp) { sprintf(s," %15.8g ",dat->timevalue); lsx_writes(ft, s); for (i=0; i<ft->signal.channels; i++) { sampval = SOX_SAMPLE_TO_FLOAT_64BIT(*buf++, ft->clips); sprintf(s," %15.8g", sampval); lsx_writes(ft, s); done++; } sprintf(s," \r\n"); lsx_writes(ft, s); dat->timevalue += dat->deltat; } return done; }
static int sox_datstartwrite(sox_format_t * ft) { priv_t * dat = (priv_t *) ft->priv; char s[LINEWIDTH]; dat->timevalue = 0.0; dat->deltat = 1.0 / (double)ft->signal.rate; /* Write format comments to start of file */ sprintf(s,"; Sample Rate %ld\015\n", (long)ft->signal.rate); lsx_writes(ft, s); sprintf(s,"; Channels %d\015\n", (int)ft->signal.channels); lsx_writes(ft, s); return (SOX_SUCCESS); }
static int write_header(sox_format_t * ft) { char buf[128]; uint64_t samples = (ft->olength ? ft->olength : ft->signal.length) / ft->signal.channels; lsx_writes(ft, "NIST_1A\n"); lsx_writes(ft, " 1024\n"); if (samples) { sprintf(buf, "sample_count -i %" PRIu64 "\n", samples); lsx_writes(ft, buf); } sprintf(buf, "sample_n_bytes -i %d\n", ft->encoding.bits_per_sample >> 3); lsx_writes(ft, buf); sprintf(buf, "channel_count -i %d\n", ft->signal.channels); lsx_writes(ft, buf); if (ft->encoding.bits_per_sample == 8) sprintf(buf, "sample_byte_format -s1 1\n"); else sprintf(buf, "sample_byte_format -s2 %s\n", ft->encoding.reverse_bytes != MACHINE_IS_BIGENDIAN ? "10" : "01"); lsx_writes(ft, buf); sprintf(buf, "sample_rate -i %u\n", (unsigned) (ft->signal.rate + .5)); lsx_writes(ft, buf); if (ft->encoding.encoding == SOX_ENCODING_ULAW) lsx_writes(ft, "sample_coding -s4 ulaw\n"); else lsx_writes(ft, "sample_coding -s3 pcm\n"); lsx_writes(ft, "end_head\n"); lsx_padbytes(ft, 1024 - (size_t)lsx_tell(ft)); return SOX_SUCCESS; }
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); }