--- sox-14.1.0-orig/src/8svx.c 2008-07-21 11:05:03 +0900 +++ sox-14.1.0/src/8svx.c 2008-08-06 15:51:47 +0900 @@ -13,6 +13,13 @@ FILE * ch[4]; } priv_t; +/* Repeat data, if input was 8SVX */ +static uint32_t svx_oneshot; +static uint32_t svx_repeat; +static uint32_t svx_cycle; +/* Base rate for the previous two values */ +static uint32_t svx_baserate = 0; + static void svxwriteheader(sox_format_t *, sox_size_t); /*======================================================================*/ @@ -64,8 +71,11 @@ lsx_fail_errno(ft, SOX_EHDR, "VHDR chunk has bad size"); return(SOX_EOF); } - lsx_seeki(ft,12,SEEK_CUR); + lsx_readdw(ft, &svx_oneshot); + lsx_readdw(ft, &svx_repeat); + lsx_readdw(ft, &svx_cycle); lsx_readw(ft, &rate); + svx_baserate = rate; lsx_seeki(ft,1,SEEK_CUR); lsx_readbuf(ft, buf,1); if (buf[0] != 0) @@ -331,9 +341,23 @@ lsx_writes(ft, "VHDR"); lsx_writedw(ft, 20); /* number of bytes to follow */ - lsx_writedw(ft, nsamples/ft->signal.channels); /* samples, 1-shot */ - lsx_writedw(ft, 0); /* samples, repeat */ - lsx_writedw(ft, 0); /* samples per repeat cycle */ + if (svx_baserate) { + uint32_t len = nsamples / ft->signal.channels; + uint32_t oneshot = (double)svx_oneshot * ft->signal.rate / svx_baserate; + uint32_t repeat = (double)svx_repeat * ft->signal.rate / svx_baserate; + uint32_t cycle = (double)svx_cycle * ft->signal.rate / svx_baserate; + if (oneshot > len) + oneshot = len; + if (repeat > len-oneshot) + repeat = len-oneshot; + lsx_writedw(ft, oneshot); /* samples, 1-shot */ + lsx_writedw(ft, repeat); /* samples, repeat */ + lsx_writedw(ft, cycle); /* samples per repeat cycle */ + } else { + lsx_writedw(ft, nsamples / ft->signal.channels); + lsx_writedw(ft, 0); + lsx_writedw(ft, 0); + } lsx_writew(ft, min(65535, (unsigned)(ft->signal.rate + .5))); lsx_writeb(ft,1); /* number of octabes */ lsx_writeb(ft,0); /* data compression (none) */