--- ../sox-14.0.0-orig/src/8svx.c 2007-07-08 10:20:18 +0900 +++ src/8svx.c 2007-09-30 23:13:18 +0900 @@ -20,6 +20,13 @@ FILE *ch[4]; }*svx_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); /*======================================================================*/ @@ -71,8 +78,11 @@ sox_fail_errno(ft, SOX_EHDR, "VHDR chunk has bad size"); return(SOX_EOF); } - sox_seeki(ft,12,SEEK_CUR); + sox_readdw(ft, &svx_oneshot); + sox_readdw(ft, &svx_repeat); + sox_readdw(ft, &svx_cycle); sox_readw(ft, &rate); + svx_baserate = rate; sox_seeki(ft,1,SEEK_CUR); sox_readbuf(ft, buf,1); if (buf[0] != 0) @@ -338,9 +348,23 @@ sox_writes(ft, "VHDR"); sox_writedw(ft, 20); /* number of bytes to follow */ - sox_writedw(ft, nsamples/ft->signal.channels); /* samples, 1-shot */ - sox_writedw(ft, 0); /* samples, repeat */ - sox_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; + sox_writedw(ft, oneshot); /* samples, 1-shot */ + sox_writedw(ft, repeat); /* samples, repeat */ + sox_writedw(ft, cycle); /* samples per repeat cycle */ + } else { + sox_writedw(ft, nsamples / ft->signal.channels); + sox_writedw(ft, 0); + sox_writedw(ft, 0); + } sox_writew(ft, (uint16_t)ft->signal.rate); /* samples per second */ sox_writeb(ft,1); /* number of octabes */ sox_writeb(ft,0); /* data compression (none) */