ref: 3927f747f919a38eada78fd77c3c5db224e96007
parent: 3f144c8151678710061922aade7463c1007a9e36
author: cbagwell <cbagwell>
date: Thu Jun 13 15:00:58 EDT 2002
Minor compile fixes
--- a/src/adpcm.c
+++ b/src/adpcm.c
@@ -38,8 +38,8 @@
#include "adpcm.h"
typedef struct MsState {
- st_sample_t step; /* step size */
- short iCoef[2];
+ st_sample_t step; /* step size */
+ short iCoef[2];
} MsState_t;
#define lsbshortldi(x,p) { (x)=((short)((int)(p)[0] + ((int)(p)[1]<<8))); (p) += 2; }
@@ -53,8 +53,8 @@
*/
static const
st_sample_t stepAdjustTable[] = {
- 230, 230, 230, 230, 307, 409, 512, 614,
- 768, 614, 512, 409, 307, 230, 230, 230
+ 230, 230, 230, 230, 307, 409, 512, 614,
+ 768, 614, 512, 409, 307, 230, 230, 230
};
/* TODO : The first 7 iCoef sets are always hardcoded and must
@@ -62,194 +62,194 @@
in case a sound program added extras to the list. */
const short iCoef[7][2] = {
- { 256, 0},
- { 512,-256},
- { 0, 0},
- { 192, 64},
- { 240, 0},
- { 460,-208},
- { 392,-232}
+ { 256, 0},
+ { 512,-256},
+ { 0, 0},
+ { 192, 64},
+ { 240, 0},
+ { 460,-208},
+ { 392,-232}
};
-inline static st_sample_t AdpcmDecode(st_sample_t c, MsState_t *state,
- st_sample_t sample1, st_sample_t sample2)
+inline static st_sample_t AdpcmDecode(st_sample_t c, MsState_t *state,
+ st_sample_t sample1, st_sample_t sample2)
{
- st_sample_t vlin;
- st_sample_t sample;
- st_sample_t step;
+ st_sample_t vlin;
+ st_sample_t sample;
+ st_sample_t step;
- /** Compute next step value **/
- step = state->step;
- {
- st_sample_t nstep;
- nstep = (stepAdjustTable[c] * step) >> 8;
- state->step = (nstep < 16)? 16:nstep;
- }
+ /** Compute next step value **/
+ step = state->step;
+ {
+ st_sample_t nstep;
+ nstep = (stepAdjustTable[c] * step) >> 8;
+ state->step = (nstep < 16)? 16:nstep;
+ }
- /** make linear prediction for next sample **/
- vlin =
- ((sample1 * state->iCoef[0]) +
- (sample2 * state->iCoef[1])) >> 8;
- /** then add the code*step adjustment **/
- c -= (c & 0x08) << 1;
- sample = (c * step) + vlin;
+ /** make linear prediction for next sample **/
+ vlin =
+ ((sample1 * state->iCoef[0]) +
+ (sample2 * state->iCoef[1])) >> 8;
+ /** then add the code*step adjustment **/
+ c -= (c & 0x08) << 1;
+ sample = (c * step) + vlin;
- if (sample > 0x7fff) sample = 0x7fff;
- else if (sample < -0x8000) sample = -0x8000;
+ if (sample > 0x7fff) sample = 0x7fff;
+ else if (sample < -0x8000) sample = -0x8000;
- return (sample);
+ return (sample);
}
/* AdpcmBlockExpandI() outputs interleaved samples into one output buffer */
const char *AdpcmBlockExpandI(
- int chans, /* total channels */
- int nCoef,
- const short *iCoef,
- const unsigned char *ibuff,/* input buffer[blockAlign] */
- SAMPL *obuff, /* output samples, n*chans */
- int n /* samples to decode PER channel */
+ int chans, /* total channels */
+ int nCoef,
+ const short *iCoef,
+ const unsigned char *ibuff,/* input buffer[blockAlign] */
+ SAMPL *obuff, /* output samples, n*chans */
+ int n /* samples to decode PER channel */
)
{
- const unsigned char *ip;
- int ch;
- const char *errmsg = NULL;
- MsState_t state[4]; /* One decompressor state for each channel */
+ const unsigned char *ip;
+ int ch;
+ const char *errmsg = NULL;
+ MsState_t state[4]; /* One decompressor state for each channel */
- /* Read the four-byte header for each channel */
- ip = ibuff;
- for (ch = 0; ch < chans; ch++) {
- unsigned char bpred = *ip++;
- if (bpred >= nCoef) {
- errmsg = "MSADPCM bpred >= nCoef, arbitrarily using 0\n";
- bpred = 0;
- }
- state[ch].iCoef[0] = iCoef[(int)bpred*2+0];
- state[ch].iCoef[1] = iCoef[(int)bpred*2+1];
-
- }
+ /* Read the four-byte header for each channel */
+ ip = ibuff;
+ for (ch = 0; ch < chans; ch++) {
+ unsigned char bpred = *ip++;
+ if (bpred >= nCoef) {
+ errmsg = "MSADPCM bpred >= nCoef, arbitrarily using 0\n";
+ bpred = 0;
+ }
+ state[ch].iCoef[0] = iCoef[(int)bpred*2+0];
+ state[ch].iCoef[1] = iCoef[(int)bpred*2+1];
- for (ch = 0; ch < chans; ch++)
- lsbshortldi(state[ch].step, ip);
+ }
- /* sample1's directly into obuff */
- for (ch = 0; ch < chans; ch++)
- lsbshortldi(obuff[chans+ch], ip);
+ for (ch = 0; ch < chans; ch++)
+ lsbshortldi(state[ch].step, ip);
- /* sample2's directly into obuff */
- for (ch = 0; ch < chans; ch++)
- lsbshortldi(obuff[ch], ip);
+ /* sample1's directly into obuff */
+ for (ch = 0; ch < chans; ch++)
+ lsbshortldi(obuff[chans+ch], ip);
- {
- int ch;
- unsigned char b;
- short *op, *top;
+ /* sample2's directly into obuff */
+ for (ch = 0; ch < chans; ch++)
+ lsbshortldi(obuff[ch], ip);
- /* already have 1st 2 samples from block-header */
- op = obuff + 2*chans;
- top = obuff + n*chans;
+ {
+ int ch;
+ unsigned char b;
+ short *op, *top;
- ch = 0;
- while (op < top) {
- b = *ip++;
- *op++ = AdpcmDecode(b >> 4, state+ch, op[-chans], op[-2*chans]);
- if (++ch == chans) ch = 0;
- /* ch = ++ch % chans; */
- *op++ = AdpcmDecode(b&0x0f, state+ch, op[-chans], op[-2*chans]);
- if (++ch == chans) ch = 0;
- /* ch = ++ch % chans; */
- }
- }
- return errmsg;
-}
+ /* already have 1st 2 samples from block-header */
+ op = obuff + 2*chans;
+ top = obuff + n*chans;
+
+ ch = 0;
+ while (op < top) {
+ b = *ip++;
+ *op++ = AdpcmDecode(b >> 4, state+ch, op[-chans], op[-2*chans]);
+ if (++ch == chans) ch = 0;
+ /* ch = ++ch % chans; */
+ *op++ = AdpcmDecode(b&0x0f, state+ch, op[-chans], op[-2*chans]);
+ if (++ch == chans) ch = 0;
+ /* ch = ++ch % chans; */
+ }
+ }
+ return errmsg;
+}
static int AdpcmMashS(
- int ch, /* channel number to encode, REQUIRE 0 <= ch < chans */
- int chans, /* total channels */
- SAMPL v[2], /* values to use as starting 2 */
- const short iCoef[2],/* lin predictor coeffs */
- const SAMPL *ibuff, /* ibuff[] is interleaved input samples */
- int n, /* samples to encode PER channel */
- int *iostep, /* input/output step, REQUIRE 16 <= *st <= 0x7fff */
- unsigned char *obuff, /* output buffer[blockAlign], or NULL for no output */
- int sho /* nonzero for debug printout */
+ int ch, /* channel number to encode, REQUIRE 0 <= ch < chans */
+ int chans, /* total channels */
+ SAMPL v[2], /* values to use as starting 2 */
+ const short iCoef[2],/* lin predictor coeffs */
+ const SAMPL *ibuff, /* ibuff[] is interleaved input samples */
+ int n, /* samples to encode PER channel */
+ int *iostep, /* input/output step, REQUIRE 16 <= *st <= 0x7fff */
+ unsigned char *obuff, /* output buffer[blockAlign], or NULL for no output */
+ int sho /* nonzero for debug printout */
)
{
- const SAMPL *ip, *itop;
- unsigned char *op;
- int ox = 0; /* */
- int i, d, v0, v1, step;
- double d2; /* long long is okay also, speed abt the same */
+ const SAMPL *ip, *itop;
+ unsigned char *op;
+ int ox = 0; /* */
+ int i, d, v0, v1, step;
+ double d2; /* long long is okay also, speed abt the same */
- ip = ibuff + ch; /* point ip to 1st input sample for this channel */
- itop = ibuff + n*chans;
- v0 = v[0];
- v1 = v[1];
- d = *ip - v1; ip += chans; /* 1st input sample for this channel */
- d2 = d*d; /* d2 will be sum of squares of errors, given input v0 and *st */
- d = *ip - v0; ip += chans; /* 2nd input sample for this channel */
- d2 += d*d;
+ ip = ibuff + ch; /* point ip to 1st input sample for this channel */
+ itop = ibuff + n*chans;
+ v0 = v[0];
+ v1 = v[1];
+ d = *ip - v1; ip += chans; /* 1st input sample for this channel */
+ d2 = d*d; /* d2 will be sum of squares of errors, given input v0 and *st */
+ d = *ip - v0; ip += chans; /* 2nd input sample for this channel */
+ d2 += d*d;
- step = *iostep;
+ step = *iostep;
- op = obuff; /* output pointer (or NULL) */
- if (op) { /* NULL means don't output, just compute the rms error */
- op += chans; /* skip bpred indices */
- op += 2*ch; /* channel's stepsize */
- op[0] = step; op[1] = step>>8;
- op += 2*chans; /* skip to v0 */
- op[0] = v0; op[1] = v0>>8;
- op += 2*chans; /* skip to v1 */
- op[0] = v1; op[1] = v1>>8;
- op = obuff+7*chans; /* point to base of output nibbles */
- ox = 4*ch;
- }
- for (i = 0; ip < itop; ip+=chans) {
- int vlin,d,dp,c;
+ op = obuff; /* output pointer (or NULL) */
+ if (op) { /* NULL means don't output, just compute the rms error */
+ op += chans; /* skip bpred indices */
+ op += 2*ch; /* channel's stepsize */
+ op[0] = step; op[1] = step>>8;
+ op += 2*chans; /* skip to v0 */
+ op[0] = v0; op[1] = v0>>8;
+ op += 2*chans; /* skip to v1 */
+ op[0] = v1; op[1] = v1>>8;
+ op = obuff+7*chans; /* point to base of output nibbles */
+ ox = 4*ch;
+ }
+ for (i = 0; ip < itop; ip+=chans) {
+ int vlin,d,dp,c;
- /* make linear prediction for next sample */
- vlin = (v0 * iCoef[0] + v1 * iCoef[1]) >> 8;
- d = *ip - vlin; /* difference between linear prediction and current sample */
- dp = d + (step<<3) + (step>>1);
- c = 0;
- if (dp>0) {
- c = dp/step;
- if (c>15) c = 15;
- }
- c -= 8;
- dp = c * step; /* quantized estimate of samp - vlin */
- c &= 0x0f; /* mask to 4 bits */
+ /* make linear prediction for next sample */
+ vlin = (v0 * iCoef[0] + v1 * iCoef[1]) >> 8;
+ d = *ip - vlin; /* difference between linear prediction and current sample */
+ dp = d + (step<<3) + (step>>1);
+ c = 0;
+ if (dp>0) {
+ c = dp/step;
+ if (c>15) c = 15;
+ }
+ c -= 8;
+ dp = c * step; /* quantized estimate of samp - vlin */
+ c &= 0x0f; /* mask to 4 bits */
- v1 = v0; /* shift history */
- v0 = vlin + dp;
- if (v0<-0x8000) v0 = -0x8000;
- else if (v0>0x7fff) v0 = 0x7fff;
+ v1 = v0; /* shift history */
+ v0 = vlin + dp;
+ if (v0<-0x8000) v0 = -0x8000;
+ else if (v0>0x7fff) v0 = 0x7fff;
- d = *ip - v0;
- d2 += d*d; /* update square-error */
+ d = *ip - v0;
+ d2 += d*d; /* update square-error */
- if (op) { /* if we want output, put it in proper place */
- /* FIXME: does c<<0 work properly? */
- op[ox>>3] |= (ox&4)? c:(c<<4);
- ox += 4*chans;
- /* if (sho) fprintf(stderr,"%.1x",c); */
+ if (op) { /* if we want output, put it in proper place */
+ /* FIXME: does c<<0 work properly? */
+ op[ox>>3] |= (ox&4)? c:(c<<4);
+ ox += 4*chans;
+ /* if (sho) fprintf(stderr,"%.1x",c); */
- }
+ }
- /* Update the step for the next sample */
- step = (stepAdjustTable[c] * step) >> 8;
- if (step < 16) step = 16;
+ /* Update the step for the next sample */
+ step = (stepAdjustTable[c] * step) >> 8;
+ if (step < 16) step = 16;
- }
- /* if (sho && op) fprintf(stderr,"\n");*/
- d2 /= n; /* be sure it's non-negative */
+ }
+ /* if (sho && op) fprintf(stderr,"\n");*/
+ d2 /= n; /* be sure it's non-negative */
#ifdef DEBUG
- if (sho) {
- fprintf(stderr, "ch%d: st %d->%d, d %.1f\n", ch, *iostep, step, sqrt(d2));
- fflush(stderr);
- }
+ if (sho) {
+ fprintf(stderr, "ch%d: st %d->%d, d %.1f\n", ch, *iostep, step, sqrt(d2));
+ fflush(stderr);
+ }
#endif
- *iostep = step;
- return (int) sqrt(d2);
+ *iostep = step;
+ return (int) sqrt(d2);
}
#if 0
@@ -256,134 +256,131 @@
static long AvgDelta(int ch, int chans, const SAMPL *ibuff, int n)
{
- const SAMPL *ip, *itop;
- long v0;
- long d1;
-
- ip = ibuff + ch;
- itop = ip + n*chans;
- d1 = 0;
- v0 = *ip;
- ip += chans;
- for ( ; ip < itop; ip+=chans) {
- long v1;
+ const SAMPL *ip, *itop;
+ long v0;
+ long d1;
- v1 = *ip;
- d1 = abs(v1-v0);
- v0 = v1;
- }
- return (d1/(n-1));
+ ip = ibuff + ch;
+ itop = ip + n*chans;
+ d1 = 0;
+ v0 = *ip;
+ ip += chans;
+ for ( ; ip < itop; ip+=chans) {
+ long v1;
+
+ v1 = *ip;
+ d1 = abs(v1-v0);
+ v0 = v1;
+ }
+ return (d1/(n-1));
}
static long ReAvgDelta(int ch, int chans, const SAMPL *ibuff, int n, int step)
{
- const SAMPL *ip, *itop;
- long v0;
- long d1;
-
- ip = ibuff + ch;
- itop = ip + n*chans;
- d1 = 0;
- v0 = *ip;
- ip += chans;
- for ( ; ip < itop; ip+=chans) {
- long v1, c;
+ const SAMPL *ip, *itop;
+ long v0;
+ long d1;
- v1 = *ip;
- c = abs(v1-v0);
- if (step && c>2*step) c=2*step;
- d1 += c;
- v0 = v1;
- }
- return (d1/(n-1));
+ ip = ibuff + ch;
+ itop = ip + n*chans;
+ d1 = 0;
+ v0 = *ip;
+ ip += chans;
+ for ( ; ip < itop; ip+=chans) {
+ long v1, c;
+
+ v1 = *ip;
+ c = abs(v1-v0);
+ if (step && c>2*step) c=2*step;
+ d1 += c;
+ v0 = v1;
+ }
+ return (d1/(n-1));
}
#endif
-#ifdef __GNUC__
-inline
-#endif
-static void AdpcmMashChannel(
- int ch, /* channel number to encode, REQUIRE 0 <= ch < chans */
- int chans, /* total channels */
- const SAMPL *ip, /* ip[] is interleaved input samples */
- int n, /* samples to encode PER channel, REQUIRE */
- int *st, /* input/output steps, 16<=st[i] */
- unsigned char *obuff, /* output buffer[blockAlign] */
- int opt /* non-zero allows some cpu-intensive code to improve output */
+inline static void AdpcmMashChannel(
+ int ch, /* channel number to encode, REQUIRE 0 <= ch < chans */
+ int chans, /* total channels */
+ const SAMPL *ip, /* ip[] is interleaved input samples */
+ int n, /* samples to encode PER channel, REQUIRE */
+ int *st, /* input/output steps, 16<=st[i] */
+ unsigned char *obuff, /* output buffer[blockAlign] */
+ int opt /* non-zero allows some cpu-intensive code to improve output */
)
{
- SAMPL v[2];
- int n0,s0,s1,ss,smin;
- int d,dmin,k,kmin;
-
- n0 = n/2; if (n0>32) n0=32;
+ SAMPL v[2];
+ int n0,s0,s1,ss,smin;
+ int d,dmin,k,kmin;
+
+ n0 = n/2; if (n0>32) n0=32;
#if 0
- s0=ReAvgDelta(ch, chans, ip, n, 0);
- s1=ReAvgDelta(ch, chans, ip, n, s0);
- fprintf(stderr, "ReAvg%d: %d->%d (%d)\n", ch, s0,s1,*st);
- fflush(stderr);
+ s0=ReAvgDelta(ch, chans, ip, n, 0);
+ s1=ReAvgDelta(ch, chans, ip, n, s0);
+ fprintf(stderr, "ReAvg%d: %d->%d (%d)\n", ch, s0,s1,*st);
+ fflush(stderr);
#endif
- if (*st<16) *st = 16;
- v[1] = ip[ch];
- v[0] = ip[ch+chans];
+ if (*st<16) *st = 16;
+ v[1] = ip[ch];
+ v[0] = ip[ch+chans];
- dmin = 0; kmin = 0; smin = 0;
- /* for each of 7 standard coeff sets, we try compression
- * beginning with last step-value, and with slightly
- * forward-adjusted step-value, taking best of the 14
- */
- for (k=0; k<7; k++) {
- int d0,d1;
- ss = s0 = *st;
- d0=AdpcmMashS(ch, chans, v, iCoef[k], ip, n, &ss, NULL, 0); /* with step s0 */
+ dmin = 0; kmin = 0; smin = 0;
+ /* for each of 7 standard coeff sets, we try compression
+ * beginning with last step-value, and with slightly
+ * forward-adjusted step-value, taking best of the 14
+ */
+ for (k=0; k<7; k++) {
+ int d0,d1;
+ ss = s0 = *st;
+ d0=AdpcmMashS(ch, chans, v, iCoef[k], ip, n, &ss, NULL, 0); /* with step s0 */
- s1 = s0;
- AdpcmMashS(ch, chans, v, iCoef[k], ip, n0, &s1, NULL, 0);
- /* fprintf(stderr," s32 %d\n",s1); */
- ss = s1 = (3*s0+s1)/4;
- d1=AdpcmMashS(ch, chans, v, iCoef[k], ip, n, &ss, NULL, 0); /* with step s1 */
- if (!k || d0<dmin || d1<dmin) {
- kmin = k;
- if (d0<=d1) {
- dmin = d0;
- smin = s0;
- }else{
- dmin = d1;
- smin = s1;
- }
- }
- }
- *st = smin;
+ s1 = s0;
+ AdpcmMashS(ch, chans, v, iCoef[k], ip, n0, &s1, NULL, 0);
+ /* fprintf(stderr," s32 %d\n",s1); */
+ ss = s1 = (3*s0+s1)/4;
+ d1=AdpcmMashS(ch, chans, v, iCoef[k], ip, n, &ss, NULL, 0); /* with step s1 */
+ if (!k || d0<dmin || d1<dmin) {
+ kmin = k;
+ if (d0<=d1) {
+ dmin = d0;
+ smin = s0;
+ }else{
+ dmin = d1;
+ smin = s1;
+ }
+ }
+ }
+ *st = smin;
#ifdef DEBUG
- fprintf(stderr,"kmin %d, smin %5d, ",kmin,smin);
- d=AdpcmMashS(ch, chans, v, iCoef[kmin], ip, n, st, obuff, 1);
+ fprintf(stderr,"kmin %d, smin %5d, ",kmin,smin);
+ d=AdpcmMashS(ch, chans, v, iCoef[kmin], ip, n, st, obuff, 1);
#else
- d=AdpcmMashS(ch, chans, v, iCoef[kmin], ip, n, st, obuff, 0);
+ d=AdpcmMashS(ch, chans, v, iCoef[kmin], ip, n, st, obuff, 0);
#endif
- obuff[ch] = kmin;
+ obuff[ch] = kmin;
}
void AdpcmBlockMashI(
- int chans, /* total channels */
- const SAMPL *ip, /* ip[n*chans] is interleaved input samples */
- int n, /* samples to encode PER channel */
- int *st, /* input/output steps, 16<=st[i] */
- unsigned char *obuff, /* output buffer[blockAlign] */
- int blockAlign, /* >= 7*chans + chans*(n-2)/2.0 */
- int opt /* non-zero allows some cpu-intensive code to improve output */
+ int chans, /* total channels */
+ const SAMPL *ip, /* ip[n*chans] is interleaved input samples */
+ int n, /* samples to encode PER channel */
+ int *st, /* input/output steps, 16<=st[i] */
+ unsigned char *obuff, /* output buffer[blockAlign] */
+ int blockAlign, /* >= 7*chans + chans*(n-2)/2.0 */
+ int opt /* non-zero allows some cpu-intensive code to improve output */
)
{
- int ch;
- unsigned char *p;
+ int ch;
+ unsigned char *p;
- /*fprintf(stderr,"AdpcmMashI(chans %d, ip %p, n %d, st %p, obuff %p, bA %d)\n",
- chans, ip, n, st, obuff, blockAlign);*/
+ /*fprintf(stderr,"AdpcmMashI(chans %d, ip %p, n %d, st %p, obuff %p, bA %d)\n",
+ chans, ip, n, st, obuff, blockAlign);*/
- for (p=obuff+7*chans; p<obuff+blockAlign; p++) *p=0;
+ for (p=obuff+7*chans; p<obuff+blockAlign; p++) *p=0;
- for (ch=0; ch<chans; ch++)
- AdpcmMashChannel(ch, chans, ip, n, st+ch, obuff, opt);
+ for (ch=0; ch<chans; ch++)
+ AdpcmMashChannel(ch, chans, ip, n, st+ch, obuff, opt);
}
/*
@@ -395,40 +392,40 @@
* Yes, it is confusing usage.
*/
st_size_t AdpcmSamplesIn(
- st_size_t dataLen,
- unsigned short chans,
- unsigned short blockAlign,
- unsigned short samplesPerBlock
+ st_size_t dataLen,
+ unsigned short chans,
+ unsigned short blockAlign,
+ unsigned short samplesPerBlock
)
{
- st_size_t m, n;
+ st_size_t m, n;
- if (samplesPerBlock) {
- n = (dataLen / blockAlign) * samplesPerBlock;
- m = (dataLen % blockAlign);
- } else {
- n = 0;
- m = blockAlign;
- }
- if (m >= 7*chans) {
- m -= 7*chans; /* bytes beyond block-header */
- m = (2*m)/chans + 2; /* nibbles/chans + 2 in header */
- if (samplesPerBlock && m > samplesPerBlock) m = samplesPerBlock;
- n += m;
- }
- return n;
- /* wSamplesPerBlock = 2*(wBlockAlign - 7*wChannels)/wChannels + 2; */
+ if (samplesPerBlock) {
+ n = (dataLen / blockAlign) * samplesPerBlock;
+ m = (dataLen % blockAlign);
+ } else {
+ n = 0;
+ m = blockAlign;
+ }
+ if (m >= 7*chans) {
+ m -= 7*chans; /* bytes beyond block-header */
+ m = (2*m)/chans + 2; /* nibbles/chans + 2 in header */
+ if (samplesPerBlock && m > samplesPerBlock) m = samplesPerBlock;
+ n += m;
+ }
+ return n;
+ /* wSamplesPerBlock = 2*(wBlockAlign - 7*wChannels)/wChannels + 2; */
}
st_size_t AdpcmBytesPerBlock(
- unsigned short chans,
- unsigned short samplesPerBlock
+ unsigned short chans,
+ unsigned short samplesPerBlock
)
{
- st_size_t n;
- n = 7*chans; /* header */
- if (samplesPerBlock > 2)
- n += (((st_size_t)samplesPerBlock-2)*chans + 1)/2;
- return n;
+ st_size_t n;
+ n = 7*chans; /* header */
+ if (samplesPerBlock > 2)
+ n += (((st_size_t)samplesPerBlock-2)*chans + 1)/2;
+ return n;
}
--- a/src/handlers.c
+++ b/src/handlers.c
@@ -2,8 +2,8 @@
* Originally created: July 5, 1991
* Copyright 1991 Lance Norskog And Sundry Contributors
* This source code is freely redistributable and may be used for
- * any purpose. This copyright notice must be maintained.
- * Lance Norskog And Sundry Contributors are not responsible for
+ * any purpose. This copyright notice must be maintained.
+ * Lance Norskog And Sundry Contributors are not responsible for
* the consequences of using this software.
*/
@@ -18,65 +18,65 @@
/* SGI/Apple AIFF */
static char *aiffnames[] = {
- "aiff",
- "aif",
- (char *) 0
+ "aiff",
+ "aif",
+ (char *) 0
};
/* a-law byte raw */
static char *alnames[] = {
- "al",
- (char *) 0
+ "al",
+ (char *) 0
};
-#if defined(ALSA_PLAYER)
+#if defined(ALSA_PLAYER)
/* /dev/snd/pcmXX */
static char *alsanames[] = {
- "alsa",
- (char *) 0
+ "alsa",
+ (char *) 0
};
#endif
/* SPARC .au w/header */
static char *aunames[] = {
- "au",
- "snd",
- (char *) 0
+ "au",
+ "snd",
+ (char *) 0
};
static char *autonames[] = {
- "auto",
- (char *) 0
+ "auto",
+ (char *) 0
};
static char *avrnames[] = {
- "avr",
- (char *) 0
+ "avr",
+ (char *) 0
};
static char *cdrnames[] = {
- "cdr",
- (char *) 0
+ "cdr",
+ (char *) 0
};
/* Cont. Variable Slope Delta */
static char *cvsdnames[] = {
"cvs",
- "cvsd",
- (char *)0
+ "cvsd",
+ (char *)0
};
/* Text data samples */
static char *datnames[] = {
- "dat",
- (char *) 0
+ "dat",
+ (char *) 0
};
/* Cont. Variable Solot Delta */
static char *dvmsnames[] = {
"vms",
- "dvms",
- (char *)0
+ "dvms",
+ (char *)0
};
#ifdef ENABLE_GSM
@@ -83,26 +83,26 @@
/* GSM 06.10 */
static char *gsmnames[] = {
"gsm",
- (char *) 0
+ (char *) 0
};
#endif
/* Mac FSSD/HCOM */
static char *hcomnames[] = {
- "hcom",
- (char *) 0
+ "hcom",
+ (char *) 0
};
/* inverse a-law byte raw */
static char *lanames[] = {
- "la",
- (char *) 0
+ "la",
+ (char *) 0
};
/* inverse u-law byte raw */
static char *lunames[] = {
- "lu",
- (char *) 0
+ "lu",
+ (char *) 0
};
/* Amiga MAUD */
@@ -111,11 +111,13 @@
(char *) 0,
};
+#if defined(HAVE_LIBMAD) || defined(HAVE_LAME)
/* MP3 */
static char *mp3names[] = {
"mp3",
(char *) 0,
};
+#endif
static char *nulnames[] = {
"nul",
@@ -122,72 +124,72 @@
(char *) 0,
};
-#if defined(OSS_PLAYER)
+#if defined(OSS_PLAYER)
/* OSS /dev/dsp player */
static char *ossdspnames[] = {
- "ossdsp",
- (char *) 0
+ "ossdsp",
+ (char *) 0
};
#endif
static char *rawnames[] = {
- "raw",
- (char *) 0
+ "raw",
+ (char *) 0
};
/* raw prototypes are defined in st.h since they are used globally. */
static char *sbnames[] = {
- "sb",
- (char *) 0
+ "sb",
+ (char *) 0
};
/* IRCAM Sound File */
static char *sfnames[] = {
- "sf",
- (char *) 0
+ "sf",
+ (char *) 0
};
static char *slnames[] = {
- "sl",
- (char *) 0,
+ "sl",
+ (char *) 0,
};
/* SampleVision sound */
static char *smpnames[] = {
- "smp",
- (char *) 0,
+ "smp",
+ (char *) 0,
};
/* Sndtool Sound File */
static char *sndtnames[] = {
- "sndt",
- (char *) 0
-};
+ "sndt",
+ (char *) 0
+};
/* NIST Sphere File */
static char *spherenames[] = {
- "sph",
- (char *) 0
+ "sph",
+ (char *) 0
};
-#if defined(SUNAUDIO_PLAYER)
+#if defined(SUNAUDIO_PLAYER)
/* Sun /dev/audio player */
static char *sunnames[] = {
- "sunau",
- (char *) 0
+ "sunau",
+ (char *) 0
};
#endif
/* Amiga 8SVX */
static char *svxnames[] = {
- "8svx",
- (char *) 0
+ "8svx",
+ (char *) 0
};
static char *swnames[] = {
- "sw",
- (char *) 0
+ "sw",
+ (char *) 0
};
/* Yamaha TX16W and SY99 waves */
@@ -197,41 +199,41 @@
};
static char *ubnames[] = {
- "ub",
- "sou",
- "fssd",
- (char *) 0
+ "ub",
+ "sou",
+ "fssd",
+ (char *) 0
};
static char *ulnames[] = {
- "ul",
- (char *) 0
+ "ul",
+ (char *) 0
};
static char *uwnames[] = {
- "uw",
- (char *) 0
+ "uw",
+ (char *) 0
};
/* Sound Blaster .VOC */
static char *vocnames[] = {
- "voc",
- (char *) 0
+ "voc",
+ (char *) 0
};
#ifdef HAVE_LIBVORBIS
/* Ogg Vorbis */
static char *vorbisnames[] = {
- "vorbis",
- "ogg",
- (char *) 0
+ "vorbis",
+ "ogg",
+ (char *) 0
};
#endif
/* Microsoftt RIFF */
static char *wavnames[] = {
- "wav",
- (char *) 0
+ "wav",
+ (char *) 0
};
/* Psion .wve */
@@ -243,135 +245,137 @@
st_format_t st_formats[] = {
{aiffnames,
- ST_FILE_STEREO | ST_FILE_LOOPS | ST_FILE_SEEK,
- st_aiffstartread, st_aiffread, st_aiffstopread,
- st_aiffstartwrite, st_aiffwrite, st_aiffstopwrite, st_aiffseek},
+ ST_FILE_STEREO | ST_FILE_LOOPS | ST_FILE_SEEK,
+ st_aiffstartread, st_aiffread, st_aiffstopread,
+ st_aiffstartwrite, st_aiffwrite, st_aiffstopwrite, st_aiffseek},
{alnames, ST_FILE_STEREO,
- st_alstartread, st_rawread, st_rawstopread,
- st_alstartwrite, st_rawwrite, st_rawstopwrite, st_format_nothing_seek},
+ st_alstartread, st_rawread, st_rawstopread,
+ st_alstartwrite, st_rawwrite, st_rawstopwrite, st_format_nothing_seek},
#ifdef ALSA_PLAYER
{alsanames, ST_FILE_STEREO,
- st_alsastartread, st_rawread, st_rawstopread,
- st_alsastartwrite, st_rawwrite, st_rawstopwrite,
- st_format_nothing_seek},
+ st_alsastartread, st_rawread, st_rawstopread,
+ st_alsastartwrite, st_rawwrite, st_rawstopwrite,
+ st_format_nothing_seek},
#endif
{aunames, ST_FILE_STEREO | ST_FILE_SEEK,
- st_austartread, st_auread, st_rawstopread,
- st_austartwrite, st_auwrite, st_austopwrite,
- st_auseek},
+ st_austartread, st_auread, st_rawstopread,
+ st_austartwrite, st_auwrite, st_austopwrite,
+ st_auseek},
{autonames, ST_FILE_STEREO,
- st_autostartread, st_format_nothing_io, st_format_nothing,
- st_autostartwrite, st_format_nothing_io, st_format_nothing,
- st_format_nothing_seek},
+ st_autostartread, st_format_nothing_io, st_format_nothing,
+ st_autostartwrite, st_format_nothing_io, st_format_nothing,
+ st_format_nothing_seek},
{avrnames, ST_FILE_STEREO,
- st_avrstartread, st_rawread, st_format_nothing,
- st_avrstartwrite, st_avrwrite, st_avrstopwrite,
- st_format_nothing_seek},
+ st_avrstartread, st_rawread, st_format_nothing,
+ st_avrstartwrite, st_avrwrite, st_avrstopwrite,
+ st_format_nothing_seek},
{cdrnames, ST_FILE_STEREO | ST_FILE_SEEK,
- st_cdrstartread, st_cdrread, st_cdrstopread,
- st_cdrstartwrite, st_cdrwrite, st_cdrstopwrite,
- st_rawseek},
+ st_cdrstartread, st_cdrread, st_cdrstopread,
+ st_cdrstartwrite, st_cdrwrite, st_cdrstopwrite,
+ st_rawseek},
{cvsdnames, 0,
- st_cvsdstartread, st_cvsdread, st_cvsdstopread,
- st_cvsdstartwrite, st_cvsdwrite, st_cvsdstopwrite,
- st_format_nothing_seek},
+ st_cvsdstartread, st_cvsdread, st_cvsdstopread,
+ st_cvsdstartwrite, st_cvsdwrite, st_cvsdstopwrite,
+ st_format_nothing_seek},
{datnames, 0,
- st_datstartread, st_datread, st_format_nothing,
- st_datstartwrite, st_datwrite, st_format_nothing,
- st_format_nothing_seek},
+ st_datstartread, st_datread, st_format_nothing,
+ st_datstartwrite, st_datwrite, st_format_nothing,
+ st_format_nothing_seek},
{dvmsnames, 0,
- st_dvmsstartread, st_cvsdread, st_cvsdstopread,
- st_dvmsstartwrite, st_cvsdwrite, st_dvmsstopwrite, st_format_nothing_seek},
+ st_dvmsstartread, st_cvsdread, st_cvsdstopread,
+ st_dvmsstartwrite, st_cvsdwrite, st_dvmsstopwrite, st_format_nothing_seek},
#ifdef ENABLE_GSM
{gsmnames, 0,
- st_gsmstartread, st_gsmread, st_gsmstopread,
- st_gsmstartwrite, st_gsmwrite, st_gsmstopwrite, st_format_nothing_seek},
+ st_gsmstartread, st_gsmread, st_gsmstopread,
+ st_gsmstartwrite, st_gsmwrite, st_gsmstopwrite, st_format_nothing_seek},
#endif
{hcomnames, 0,
- st_hcomstartread, st_hcomread, st_hcomstopread,
- st_hcomstartwrite, st_hcomwrite, st_hcomstopwrite, st_format_nothing_seek},
+ st_hcomstartread, st_hcomread, st_hcomstopread,
+ st_hcomstartwrite, st_hcomwrite, st_hcomstopwrite, st_format_nothing_seek},
{lanames, ST_FILE_STEREO,
- st_lastartread, st_rawread, st_rawstopread,
- st_lastartwrite, st_rawwrite, st_rawstopwrite, st_format_nothing_seek},
+ st_lastartread, st_rawread, st_rawstopread,
+ st_lastartwrite, st_rawwrite, st_rawstopwrite, st_format_nothing_seek},
{lunames, ST_FILE_STEREO,
- st_lustartread, st_rawread, st_rawstopread,
- st_lustartwrite, st_rawwrite, st_rawstopwrite, st_format_nothing_seek},
+ st_lustartread, st_rawread, st_rawstopread,
+ st_lustartwrite, st_rawwrite, st_rawstopwrite, st_format_nothing_seek},
{maudnames, ST_FILE_STEREO,
- st_maudstartread, st_maudread, st_maudstopread,
- st_maudstartwrite, st_maudwrite, st_maudstopwrite, st_format_nothing_seek},
+ st_maudstartread, st_maudread, st_maudstopread,
+ st_maudstartwrite, st_maudwrite, st_maudstopwrite, st_format_nothing_seek},
+#if defined(HAVE_LIBMAD) || defined(HAVE_LAME)
{mp3names, ST_FILE_STEREO,
- st_mp3startread, st_mp3read, st_mp3stopread,
- st_mp3startwrite, st_mp3write, st_mp3stopwrite, st_format_nothing_seek},
+ st_mp3startread, st_mp3read, st_mp3stopread,
+ st_mp3startwrite, st_mp3write, st_mp3stopwrite, st_format_nothing_seek},
+#endif
{nulnames, ST_FILE_STEREO,
- st_nulstartread, st_nulread, st_nulstopread,
- st_nulstartwrite, st_nulwrite, st_nulstopwrite, st_format_nothing_seek},
+ st_nulstartread, st_nulread, st_nulstopread,
+ st_nulstartwrite, st_nulwrite, st_nulstopwrite, st_format_nothing_seek},
#ifdef OSS_PLAYER
{ossdspnames, ST_FILE_STEREO,
- st_ossdspstartread, st_rawread, st_rawstopread,
- st_ossdspstartwrite, st_rawwrite, st_rawstopwrite, st_format_nothing_seek},
+ st_ossdspstartread, st_rawread, st_rawstopread,
+ st_ossdspstartwrite, st_rawwrite, st_rawstopwrite, st_format_nothing_seek},
#endif
{rawnames, ST_FILE_STEREO | ST_FILE_SEEK,
- st_rawstartread, st_rawread, st_rawstopread,
- st_rawstartwrite, st_rawwrite, st_rawstopwrite, st_rawseek},
+ st_rawstartread, st_rawread, st_rawstopread,
+ st_rawstartwrite, st_rawwrite, st_rawstopwrite, st_rawseek},
{sbnames, ST_FILE_STEREO,
- st_sbstartread, st_rawread, st_rawstopread,
- st_sbstartwrite, st_rawwrite, st_rawstopwrite, st_format_nothing_seek},
+ st_sbstartread, st_rawread, st_rawstopread,
+ st_sbstartwrite, st_rawwrite, st_rawstopwrite, st_format_nothing_seek},
{sfnames, ST_FILE_STEREO | ST_FILE_SEEK,
- st_sfstartread, st_rawread, st_rawstopread,
- st_sfstartwrite, st_rawwrite, st_rawstopwrite, st_sfseek},
+ st_sfstartread, st_rawread, st_rawstopread,
+ st_sfstartwrite, st_rawwrite, st_rawstopwrite, st_sfseek},
{ slnames, ST_FILE_STEREO,
- st_slstartread, st_rawread, st_rawstopread,
- st_slstartwrite, st_rawwrite, st_rawstopwrite, st_format_nothing_seek},
+ st_slstartread, st_rawread, st_rawstopread,
+ st_slstartwrite, st_rawwrite, st_rawstopwrite, st_format_nothing_seek},
{smpnames, ST_FILE_STEREO | ST_FILE_LOOPS | ST_FILE_SEEK,
- st_smpstartread, st_smpread, st_format_nothing,
- st_smpstartwrite, st_smpwrite, st_smpstopwrite, st_smpseek},
+ st_smpstartread, st_smpread, st_format_nothing,
+ st_smpstartwrite, st_smpwrite, st_smpstopwrite, st_smpseek},
{sndtnames, ST_FILE_STEREO | ST_FILE_SEEK,
- st_sndtstartread, st_rawread, st_rawstopread,
- st_sndtstartwrite, st_sndtwrite, st_sndtstopwrite, st_sndseek},
+ st_sndtstartread, st_rawread, st_rawstopread,
+ st_sndtstartwrite, st_sndtwrite, st_sndtstopwrite, st_sndseek},
{spherenames, ST_FILE_STEREO,
- st_spherestartread, st_sphereread, st_rawstopread,
- st_spherestartwrite, st_spherewrite, st_spherestopwrite,
- st_format_nothing_seek},
+ st_spherestartread, st_sphereread, st_rawstopread,
+ st_spherestartwrite, st_spherewrite, st_spherestopwrite,
+ st_format_nothing_seek},
#ifdef SUNAUDIO_PLAYER
{sunnames, ST_FILE_STEREO,
- st_sunstartread, st_rawread, st_rawstopread,
- st_sunstartwrite, st_rawwrite, st_rawstopwrite, st_format_nothing_seek},
+ st_sunstartread, st_rawread, st_rawstopread,
+ st_sunstartwrite, st_rawwrite, st_rawstopwrite, st_format_nothing_seek},
#endif
{svxnames, ST_FILE_STEREO,
- st_svxstartread, st_svxread, st_svxstopread,
- st_svxstartwrite, st_svxwrite, st_svxstopwrite, st_format_nothing_seek},
+ st_svxstartread, st_svxread, st_svxstopread,
+ st_svxstartwrite, st_svxwrite, st_svxstopwrite, st_format_nothing_seek},
{swnames, ST_FILE_STEREO,
- st_swstartread, st_rawread, st_rawstopread,
- st_swstartwrite, st_rawwrite, st_rawstopwrite, st_format_nothing_seek},
+ st_swstartread, st_rawread, st_rawstopread,
+ st_swstartwrite, st_rawwrite, st_rawstopwrite, st_format_nothing_seek},
{txwnames, 0,
- st_txwstartread, st_txwread, st_txwstopread,
- st_txwstartwrite, st_txwwrite, st_txwstopwrite, st_format_nothing_seek},
+ st_txwstartread, st_txwread, st_txwstopread,
+ st_txwstartwrite, st_txwwrite, st_txwstopwrite, st_format_nothing_seek},
{ubnames, ST_FILE_STEREO,
- st_ubstartread, st_rawread, st_rawstopread,
- st_ubstartwrite, st_rawwrite, st_rawstopwrite, st_format_nothing_seek},
+ st_ubstartread, st_rawread, st_rawstopread,
+ st_ubstartwrite, st_rawwrite, st_rawstopwrite, st_format_nothing_seek},
{ulnames, ST_FILE_STEREO,
- st_ulstartread, st_rawread, st_rawstopread,
- st_ulstartwrite, st_rawwrite, st_rawstopwrite, st_format_nothing_seek},
+ st_ulstartread, st_rawread, st_rawstopread,
+ st_ulstartwrite, st_rawwrite, st_rawstopwrite, st_format_nothing_seek},
{uwnames, ST_FILE_STEREO,
- st_uwstartread, st_rawread, st_rawstopread,
- st_uwstartwrite, st_rawwrite, st_rawstopwrite, st_format_nothing_seek},
+ st_uwstartread, st_rawread, st_rawstopread,
+ st_uwstartwrite, st_rawwrite, st_rawstopwrite, st_format_nothing_seek},
{vocnames, ST_FILE_STEREO,
- st_vocstartread, st_vocread, st_vocstopread,
- st_vocstartwrite, st_vocwrite, st_vocstopwrite, st_format_nothing_seek},
+ st_vocstartread, st_vocread, st_vocstopread,
+ st_vocstartwrite, st_vocwrite, st_vocstopwrite, st_format_nothing_seek},
#ifdef HAVE_LIBVORBIS
{vorbisnames, ST_FILE_STEREO,
- st_vorbisstartread, st_vorbisread, st_vorbisstopread,
- st_vorbisstartwrite, st_vorbiswrite, st_vorbisstopwrite,
+ st_vorbisstartread, st_vorbisread, st_vorbisstopread,
+ st_vorbisstartwrite, st_vorbiswrite, st_vorbisstopwrite,
st_format_nothing_seek},
#endif
{wavnames, ST_FILE_STEREO | ST_FILE_SEEK,
- st_wavstartread, st_wavread, st_format_nothing,
- st_wavstartwrite, st_wavwrite, st_wavstopwrite, st_wavseek},
+ st_wavstartread, st_wavread, st_format_nothing,
+ st_wavstartwrite, st_wavwrite, st_wavstopwrite, st_wavseek},
{wvenames, ST_FILE_SEEK,
- st_wvestartread, st_wveread, st_rawstopread,
- st_wvestartwrite, st_wvewrite, st_wvestopwrite, st_wveseek},
+ st_wvestartread, st_wveread, st_rawstopread,
+ st_wvestartwrite, st_wvewrite, st_wvestopwrite, st_wveseek},
{0, 0,
- 0, 0, 0, 0, 0, 0}
+ 0, 0, 0, 0, 0, 0}
};
/* Effects handlers. */
@@ -384,121 +388,121 @@
*/
st_effect_t st_effects[] = {
- {"avg", ST_EFF_MCHAN | ST_EFF_CHAN,
- st_avg_getopts, st_avg_start, st_avg_flow,
- st_effect_nothing_drain, st_avg_stop},
- {"band", 0,
- st_band_getopts, st_band_start, st_band_flow,
- st_effect_nothing_drain, st_band_stop},
- {"bandpass", 0,
- st_bandpass_getopts, st_bandpass_start, st_butterworth_flow,
- st_effect_nothing_drain, st_effect_nothing},
- {"bandreject", 0,
- st_bandreject_getopts, st_bandreject_start, st_butterworth_flow,
- st_effect_nothing_drain, st_effect_nothing},
- {"chorus", 0,
- st_chorus_getopts, st_chorus_start, st_chorus_flow,
- st_chorus_drain, st_chorus_stop},
- {"compand", ST_EFF_MCHAN,
- st_compand_getopts, st_compand_start, st_compand_flow,
- st_compand_drain, st_compand_stop},
- {"copy", ST_EFF_MCHAN,
- st_copy_getopts, st_copy_start, st_copy_flow,
- st_effect_nothing_drain, st_effect_nothing},
- {"dcshift", ST_EFF_MCHAN,
- st_dcshift_getopts, st_dcshift_start, st_dcshift_flow,
- st_effect_nothing_drain, st_dcshift_stop},
- {"deemph", ST_EFF_MCHAN,
- st_deemph_getopts, st_deemph_start, st_deemph_flow,
- st_effect_nothing_drain, st_deemph_stop},
- {"earwax", ST_EFF_MCHAN,
- st_earwax_getopts, st_earwax_start, st_earwax_flow,
- st_earwax_drain, st_earwax_stop},
- {"echo", 0,
- st_echo_getopts, st_echo_start, st_echo_flow,
- st_echo_drain, st_echo_stop},
- {"echos", 0,
- st_echos_getopts, st_echos_start, st_echos_flow,
- st_echos_drain, st_echos_stop},
- {"fade", ST_EFF_MCHAN,
- st_fade_getopts, st_fade_start, st_fade_flow,
- st_fade_drain, st_fade_stop},
- { "filter", 0,
- st_filter_getopts, st_filter_start, st_filter_flow,
- st_filter_drain, st_filter_stop},
- {"flanger", 0,
- st_flanger_getopts, st_flanger_start, st_flanger_flow,
- st_flanger_drain, st_flanger_stop},
- {"highp", 0,
- st_highp_getopts, st_highp_start, st_highp_flow,
- st_effect_nothing_drain, st_highp_stop},
- {"highpass", 0,
- st_highpass_getopts, st_highpass_start, st_butterworth_flow,
- st_effect_nothing_drain, st_effect_nothing},
- {"lowp", 0,
- st_lowp_getopts, st_lowp_start, st_lowp_flow,
- st_effect_nothing_drain, st_lowp_stop},
- {"lowpass", 0,
- st_lowpass_getopts, st_lowpass_start, st_butterworth_flow,
- st_effect_nothing_drain, st_effect_nothing},
- {"map", ST_EFF_REPORT,
- st_map_getopts, st_map_start, st_map_flow,
- st_effect_nothing_drain, st_effect_nothing},
- {"mask", ST_EFF_MCHAN,
- st_mask_getopts, st_effect_nothing, st_mask_flow,
- st_effect_nothing_drain, st_effect_nothing},
- {"pan", ST_EFF_MCHAN | ST_EFF_CHAN,
- st_pan_getopts, st_pan_start, st_pan_flow,
- st_effect_nothing_drain, st_pan_stop},
- {"phaser", 0,
- st_phaser_getopts, st_phaser_start, st_phaser_flow,
- st_phaser_drain, st_phaser_stop},
- {"pitch", 0,
- st_pitch_getopts, st_pitch_start, st_pitch_flow,
- st_pitch_drain, st_pitch_stop},
- {"polyphase", ST_EFF_RATE,
- st_poly_getopts, st_poly_start, st_poly_flow,
- st_poly_drain, st_poly_stop},
- {"rate", ST_EFF_RATE,
- st_rate_getopts, st_rate_start, st_rate_flow,
- st_effect_nothing_drain, st_effect_nothing},
- {"resample", ST_EFF_RATE,
- st_resample_getopts, st_resample_start, st_resample_flow,
- st_resample_drain, st_resample_stop},
- {"reverb", 0,
- st_reverb_getopts, st_reverb_start, st_reverb_flow,
- st_reverb_drain, st_reverb_stop},
- {"reverse", 0,
- st_reverse_getopts, st_reverse_start,
- st_reverse_flow, st_reverse_drain, st_reverse_stop},
- {"silence", ST_EFF_MCHAN,
- st_silence_getopts, st_silence_start,
- st_silence_flow, st_silence_drain, st_silence_stop},
- {"speed", 0,
- st_speed_getopts, st_speed_start,
- st_speed_flow, st_speed_drain, st_speed_stop},
- {"stat", ST_EFF_MCHAN | ST_EFF_REPORT,
- st_stat_getopts, st_stat_start, st_stat_flow,
- st_stat_drain, st_stat_stop},
- {"stretch", 0,
- st_stretch_getopts, st_stretch_start, st_stretch_flow,
- st_stretch_drain, st_stretch_stop},
- {"swap", ST_EFF_MCHAN,
- st_swap_getopts, st_swap_start, st_swap_flow,
- st_swap_drain, st_swap_stop},
- {"synth", ST_EFF_MCHAN,
- st_synth_getopts, st_synth_start, st_synth_flow,
+ {"avg", ST_EFF_MCHAN | ST_EFF_CHAN,
+ st_avg_getopts, st_avg_start, st_avg_flow,
+ st_effect_nothing_drain, st_avg_stop},
+ {"band", 0,
+ st_band_getopts, st_band_start, st_band_flow,
+ st_effect_nothing_drain, st_band_stop},
+ {"bandpass", 0,
+ st_bandpass_getopts, st_bandpass_start, st_butterworth_flow,
+ st_effect_nothing_drain, st_effect_nothing},
+ {"bandreject", 0,
+ st_bandreject_getopts, st_bandreject_start, st_butterworth_flow,
+ st_effect_nothing_drain, st_effect_nothing},
+ {"chorus", 0,
+ st_chorus_getopts, st_chorus_start, st_chorus_flow,
+ st_chorus_drain, st_chorus_stop},
+ {"compand", ST_EFF_MCHAN,
+ st_compand_getopts, st_compand_start, st_compand_flow,
+ st_compand_drain, st_compand_stop},
+ {"copy", ST_EFF_MCHAN,
+ st_copy_getopts, st_copy_start, st_copy_flow,
+ st_effect_nothing_drain, st_effect_nothing},
+ {"dcshift", ST_EFF_MCHAN,
+ st_dcshift_getopts, st_dcshift_start, st_dcshift_flow,
+ st_effect_nothing_drain, st_dcshift_stop},
+ {"deemph", ST_EFF_MCHAN,
+ st_deemph_getopts, st_deemph_start, st_deemph_flow,
+ st_effect_nothing_drain, st_deemph_stop},
+ {"earwax", ST_EFF_MCHAN,
+ st_earwax_getopts, st_earwax_start, st_earwax_flow,
+ st_earwax_drain, st_earwax_stop},
+ {"echo", 0,
+ st_echo_getopts, st_echo_start, st_echo_flow,
+ st_echo_drain, st_echo_stop},
+ {"echos", 0,
+ st_echos_getopts, st_echos_start, st_echos_flow,
+ st_echos_drain, st_echos_stop},
+ {"fade", ST_EFF_MCHAN,
+ st_fade_getopts, st_fade_start, st_fade_flow,
+ st_fade_drain, st_fade_stop},
+ { "filter", 0,
+ st_filter_getopts, st_filter_start, st_filter_flow,
+ st_filter_drain, st_filter_stop},
+ {"flanger", 0,
+ st_flanger_getopts, st_flanger_start, st_flanger_flow,
+ st_flanger_drain, st_flanger_stop},
+ {"highp", 0,
+ st_highp_getopts, st_highp_start, st_highp_flow,
+ st_effect_nothing_drain, st_highp_stop},
+ {"highpass", 0,
+ st_highpass_getopts, st_highpass_start, st_butterworth_flow,
+ st_effect_nothing_drain, st_effect_nothing},
+ {"lowp", 0,
+ st_lowp_getopts, st_lowp_start, st_lowp_flow,
+ st_effect_nothing_drain, st_lowp_stop},
+ {"lowpass", 0,
+ st_lowpass_getopts, st_lowpass_start, st_butterworth_flow,
+ st_effect_nothing_drain, st_effect_nothing},
+ {"map", ST_EFF_REPORT,
+ st_map_getopts, st_map_start, st_map_flow,
+ st_effect_nothing_drain, st_effect_nothing},
+ {"mask", ST_EFF_MCHAN,
+ st_mask_getopts, st_effect_nothing, st_mask_flow,
+ st_effect_nothing_drain, st_effect_nothing},
+ {"pan", ST_EFF_MCHAN | ST_EFF_CHAN,
+ st_pan_getopts, st_pan_start, st_pan_flow,
+ st_effect_nothing_drain, st_pan_stop},
+ {"phaser", 0,
+ st_phaser_getopts, st_phaser_start, st_phaser_flow,
+ st_phaser_drain, st_phaser_stop},
+ {"pitch", 0,
+ st_pitch_getopts, st_pitch_start, st_pitch_flow,
+ st_pitch_drain, st_pitch_stop},
+ {"polyphase", ST_EFF_RATE,
+ st_poly_getopts, st_poly_start, st_poly_flow,
+ st_poly_drain, st_poly_stop},
+ {"rate", ST_EFF_RATE,
+ st_rate_getopts, st_rate_start, st_rate_flow,
+ st_effect_nothing_drain, st_effect_nothing},
+ {"resample", ST_EFF_RATE,
+ st_resample_getopts, st_resample_start, st_resample_flow,
+ st_resample_drain, st_resample_stop},
+ {"reverb", 0,
+ st_reverb_getopts, st_reverb_start, st_reverb_flow,
+ st_reverb_drain, st_reverb_stop},
+ {"reverse", 0,
+ st_reverse_getopts, st_reverse_start,
+ st_reverse_flow, st_reverse_drain, st_reverse_stop},
+ {"silence", ST_EFF_MCHAN,
+ st_silence_getopts, st_silence_start,
+ st_silence_flow, st_silence_drain, st_silence_stop},
+ {"speed", 0,
+ st_speed_getopts, st_speed_start,
+ st_speed_flow, st_speed_drain, st_speed_stop},
+ {"stat", ST_EFF_MCHAN | ST_EFF_REPORT,
+ st_stat_getopts, st_stat_start, st_stat_flow,
+ st_stat_drain, st_stat_stop},
+ {"stretch", 0,
+ st_stretch_getopts, st_stretch_start, st_stretch_flow,
+ st_stretch_drain, st_stretch_stop},
+ {"swap", ST_EFF_MCHAN,
+ st_swap_getopts, st_swap_start, st_swap_flow,
+ st_swap_drain, st_swap_stop},
+ {"synth", ST_EFF_MCHAN,
+ st_synth_getopts, st_synth_start, st_synth_flow,
st_synth_drain, st_synth_stop},
- {"trim", ST_EFF_MCHAN,
- st_trim_getopts, st_trim_start, st_trim_flow,
+ {"trim", ST_EFF_MCHAN,
+ st_trim_getopts, st_trim_start, st_trim_flow,
st_effect_nothing_drain, st_effect_nothing},
- {"vibro", 0,
- st_vibro_getopts, st_vibro_start, st_vibro_flow,
- st_effect_nothing_drain, st_effect_nothing},
- {"vol", ST_EFF_MCHAN,
- st_vol_getopts, st_vol_start, st_vol_flow,
- st_effect_nothing_drain, st_vol_stop},
- {0, 0, 0, 0, 0, 0, 0}
+ {"vibro", 0,
+ st_vibro_getopts, st_vibro_start, st_vibro_flow,
+ st_effect_nothing_drain, st_effect_nothing},
+ {"vol", ST_EFF_MCHAN,
+ st_vol_getopts, st_vol_start, st_vol_flow,
+ st_effect_nothing_drain, st_vol_stop},
+ {0, 0, 0, 0, 0, 0, 0}
};
--- a/src/hcom.c
+++ b/src/hcom.c
@@ -8,8 +8,8 @@
* September 25, 1991
* Copyright 1991 Guido van Rossum And Sundry Contributors
* This source code is freely redistributable and may be used for
- * any purpose. This copyright notice must be maintained.
- * Guido van Rossum And Sundry Contributors are not responsible for
+ * any purpose. This copyright notice must be maintained.
+ * Guido van Rossum And Sundry Contributors are not responsible for
* the consequences of using this software.
*
* April 28, 1998 - Chris Bagwell (cbagwell@sprynet.com)
@@ -30,24 +30,24 @@
/* Dictionary entry for Huffman (de)compression */
typedef struct {
- long frequ;
- short dict_leftson;
- short dict_rightson;
+ long frequ;
+ short dict_leftson;
+ short dict_rightson;
} dictent;
/* Private data used by reader */
struct readpriv {
- /* Static data from the header */
- dictent *dictionary;
- int32_t checksum;
- int deltacompression;
- /* Engine state */
- long huffcount;
- long cksum;
- int dictentry;
- int nrbits;
- uint32_t current;
- short sample;
+ /* Static data from the header */
+ dictent *dictionary;
+ int32_t checksum;
+ int deltacompression;
+ /* Engine state */
+ long huffcount;
+ long cksum;
+ int dictentry;
+ int nrbits;
+ uint32_t current;
+ short sample;
};
static int skipbytes(ft_t, int);
@@ -54,112 +54,112 @@
int st_hcomstartread(ft_t ft)
{
- struct readpriv *p = (struct readpriv *) ft->priv;
- int i;
- char buf[5];
- uint32_t datasize, rsrcsize;
- uint32_t huffcount, checksum, compresstype, divisor;
- unsigned short dictsize;
- int rc;
+ struct readpriv *p = (struct readpriv *) ft->priv;
+ int i;
+ char buf[5];
+ uint32_t datasize, rsrcsize;
+ uint32_t huffcount, checksum, compresstype, divisor;
+ unsigned short dictsize;
+ int rc;
- /* hcom is in big endian format. Swap whats
- * read in on little machine
- */
- if (ST_IS_LITTLEENDIAN)
- {
- ft->swap = ft->swap ? 0 : 1;
- }
+ /* hcom is in big endian format. Swap whats
+ * read in on little machine
+ */
+ if (ST_IS_LITTLEENDIAN)
+ {
+ ft->swap = ft->swap ? 0 : 1;
+ }
- /* Skip first 65 bytes of header */
- rc = skipbytes(ft, 65);
- if (rc)
- return rc;
+ /* Skip first 65 bytes of header */
+ rc = skipbytes(ft, 65);
+ if (rc)
+ return rc;
- /* Check the file type (bytes 65-68) */
- if (st_reads(ft, buf, 4) == ST_EOF || strncmp(buf, "FSSD", 4) != 0)
- {
- st_fail_errno(ft,ST_EHDR,"Mac header type is not FSSD");
- return (ST_EOF);
- }
+ /* Check the file type (bytes 65-68) */
+ if (st_reads(ft, buf, 4) == ST_EOF || strncmp(buf, "FSSD", 4) != 0)
+ {
+ st_fail_errno(ft,ST_EHDR,"Mac header type is not FSSD");
+ return (ST_EOF);
+ }
- /* Skip to byte 83 */
- rc = skipbytes(ft, 83-69);
- if (rc)
- return rc;
+ /* Skip to byte 83 */
+ rc = skipbytes(ft, 83-69);
+ if (rc)
+ return rc;
- /* Get essential numbers from the header */
- st_readdw(ft, &datasize); /* bytes 83-86 */
- st_readdw(ft, &rsrcsize); /* bytes 87-90 */
+ /* Get essential numbers from the header */
+ st_readdw(ft, &datasize); /* bytes 83-86 */
+ st_readdw(ft, &rsrcsize); /* bytes 87-90 */
- /* Skip the rest of the header (total 128 bytes) */
- rc = skipbytes(ft, 128-91);
- if (rc != 0)
- return rc;
+ /* Skip the rest of the header (total 128 bytes) */
+ rc = skipbytes(ft, 128-91);
+ if (rc != 0)
+ return rc;
- /* The data fork must contain a "HCOM" header */
- if (st_reads(ft, buf, 4) == ST_EOF || strncmp(buf, "HCOM", 4) != 0)
- {
- st_fail_errno(ft,ST_EHDR,"Mac data fork is not HCOM");
- return (ST_EOF);
- }
+ /* The data fork must contain a "HCOM" header */
+ if (st_reads(ft, buf, 4) == ST_EOF || strncmp(buf, "HCOM", 4) != 0)
+ {
+ st_fail_errno(ft,ST_EHDR,"Mac data fork is not HCOM");
+ return (ST_EOF);
+ }
- /* Then follow various parameters */
- st_readdw(ft, &huffcount);
- st_readdw(ft, &checksum);
- st_readdw(ft, &compresstype);
- if (compresstype > 1)
- {
- st_fail_errno(ft,ST_EHDR,"Bad compression type in HCOM header");
- return (ST_EOF);
- }
- st_readdw(ft, &divisor);
- if (divisor == 0 || divisor > 4)
- {
- st_fail_errno(ft,ST_EHDR,"Bad sampling rate divisor in HCOM header");
- return (ST_EOF);
- }
- st_readw(ft, &dictsize);
+ /* Then follow various parameters */
+ st_readdw(ft, &huffcount);
+ st_readdw(ft, &checksum);
+ st_readdw(ft, &compresstype);
+ if (compresstype > 1)
+ {
+ st_fail_errno(ft,ST_EHDR,"Bad compression type in HCOM header");
+ return (ST_EOF);
+ }
+ st_readdw(ft, &divisor);
+ if (divisor == 0 || divisor > 4)
+ {
+ st_fail_errno(ft,ST_EHDR,"Bad sampling rate divisor in HCOM header");
+ return (ST_EOF);
+ }
+ st_readw(ft, &dictsize);
- /* Translate to sox parameters */
- ft->info.encoding = ST_ENCODING_UNSIGNED;
- ft->info.size = ST_SIZE_BYTE;
- ft->info.rate = 22050 / divisor;
- ft->info.channels = 1;
+ /* Translate to sox parameters */
+ ft->info.encoding = ST_ENCODING_UNSIGNED;
+ ft->info.size = ST_SIZE_BYTE;
+ ft->info.rate = 22050 / divisor;
+ ft->info.channels = 1;
- /* Allocate memory for the dictionary */
- p->dictionary = (dictent *) malloc(511 * sizeof(dictent));
- if (p->dictionary == NULL)
- {
- st_fail_errno(ft,ST_ENOMEM,"can't malloc memory for Huffman dictionary");
- return (ST_EOF);
- }
+ /* Allocate memory for the dictionary */
+ p->dictionary = (dictent *) malloc(511 * sizeof(dictent));
+ if (p->dictionary == NULL)
+ {
+ st_fail_errno(ft,ST_ENOMEM,"can't malloc memory for Huffman dictionary");
+ return (ST_EOF);
+ }
- /* Read dictionary */
- for(i = 0; i < dictsize; i++) {
- st_readw(ft, (unsigned short *)&(p->dictionary[i].dict_leftson));
- st_readw(ft, (unsigned short *)&(p->dictionary[i].dict_rightson));
- /*
- st_report("%d %d",
- p->dictionary[i].dict_leftson,
- p->dictionary[i].dict_rightson);
- */
- }
- rc = skipbytes(ft, 1); /* skip pad byte */
- if (rc)
- return rc;
+ /* Read dictionary */
+ for(i = 0; i < dictsize; i++) {
+ st_readw(ft, (unsigned short *)&(p->dictionary[i].dict_leftson));
+ st_readw(ft, (unsigned short *)&(p->dictionary[i].dict_rightson));
+ /*
+ st_report("%d %d",
+ p->dictionary[i].dict_leftson,
+ p->dictionary[i].dict_rightson);
+ */
+ }
+ rc = skipbytes(ft, 1); /* skip pad byte */
+ if (rc)
+ return rc;
- /* Initialized the decompression engine */
- p->checksum = checksum;
- p->deltacompression = compresstype;
- if (!p->deltacompression)
- st_report("HCOM data using value compression");
- p->huffcount = huffcount;
- p->cksum = 0;
- p->dictentry = 0;
- p->nrbits = -1; /* Special case to get first byte */
+ /* Initialized the decompression engine */
+ p->checksum = checksum;
+ p->deltacompression = compresstype;
+ if (!p->deltacompression)
+ st_report("HCOM data using value compression");
+ p->huffcount = huffcount;
+ p->cksum = 0;
+ p->dictentry = 0;
+ p->nrbits = -1; /* Special case to get first byte */
- return (ST_SUCCESS);
+ return (ST_SUCCESS);
}
/* FIXME: Move to misc.c */
@@ -166,174 +166,174 @@
static int skipbytes(ft_t ft, int n)
{
unsigned char trash;
- while (--n >= 0) {
- if (st_readb(ft, &trash) == ST_EOF)
- {
- st_fail_errno(ft,ST_EOF,"unexpected EOF in Mac header");
- return(ST_EOF);
- }
- }
- return(ST_SUCCESS);
-}
+ while (--n >= 0) {
+ if (st_readb(ft, &trash) == ST_EOF)
+ {
+ st_fail_errno(ft,ST_EOF,"unexpected EOF in Mac header");
+ return(ST_EOF);
+ }
+ }
+ return(ST_SUCCESS);
+}
st_ssize_t st_hcomread(ft_t ft, st_sample_t *buf, st_ssize_t len)
{
- register struct readpriv *p = (struct readpriv *) ft->priv;
- int done = 0;
- unsigned char sample_rate;
+ register struct readpriv *p = (struct readpriv *) ft->priv;
+ int done = 0;
+ unsigned char sample_rate;
- if (p->nrbits < 0) {
- /* The first byte is special */
- if (p->huffcount == 0)
- return 0; /* Don't know if this can happen... */
- if (st_readb(ft, &sample_rate) == ST_EOF)
- {
- st_fail_errno(ft,ST_EOF,"unexpected EOF at start of HCOM data");
- return (0);
- }
- p->sample = sample_rate;
- *buf++ = (p->sample - 128) * 0x1000000L;
- p->huffcount--;
- p->nrbits = 0;
- done++;
- len--;
- if (len == 0)
- return done;
- }
+ if (p->nrbits < 0) {
+ /* The first byte is special */
+ if (p->huffcount == 0)
+ return 0; /* Don't know if this can happen... */
+ if (st_readb(ft, &sample_rate) == ST_EOF)
+ {
+ st_fail_errno(ft,ST_EOF,"unexpected EOF at start of HCOM data");
+ return (0);
+ }
+ p->sample = sample_rate;
+ *buf++ = (p->sample - 128) * 0x1000000L;
+ p->huffcount--;
+ p->nrbits = 0;
+ done++;
+ len--;
+ if (len == 0)
+ return done;
+ }
- while (p->huffcount > 0) {
- if(p->nrbits == 0) {
- st_readdw(ft, &(p->current));
- if (feof(ft->fp))
- {
- st_fail_errno(ft,ST_EOF,"unexpected EOF in HCOM data");
- return (0);
- }
- p->cksum += p->current;
- p->nrbits = 32;
- }
- if(p->current & 0x80000000L) {
- p->dictentry =
- p->dictionary[p->dictentry].dict_rightson;
- } else {
- p->dictentry =
- p->dictionary[p->dictentry].dict_leftson;
- }
- p->current = p->current << 1;
- p->nrbits--;
- if(p->dictionary[p->dictentry].dict_leftson < 0) {
- short datum;
- datum = p->dictionary[p->dictentry].dict_rightson;
- if (!p->deltacompression)
- p->sample = 0;
- p->sample = (p->sample + datum) & 0xff;
- p->huffcount--;
- if (p->sample == 0)
- *buf++ = -127 * 0x1000000L;
- else
- *buf++ = (p->sample - 128) * 0x1000000L;
- p->dictentry = 0;
- done++;
- len--;
- if (len == 0)
- break;
- }
- }
+ while (p->huffcount > 0) {
+ if(p->nrbits == 0) {
+ st_readdw(ft, &(p->current));
+ if (feof(ft->fp))
+ {
+ st_fail_errno(ft,ST_EOF,"unexpected EOF in HCOM data");
+ return (0);
+ }
+ p->cksum += p->current;
+ p->nrbits = 32;
+ }
+ if(p->current & 0x80000000L) {
+ p->dictentry =
+ p->dictionary[p->dictentry].dict_rightson;
+ } else {
+ p->dictentry =
+ p->dictionary[p->dictentry].dict_leftson;
+ }
+ p->current = p->current << 1;
+ p->nrbits--;
+ if(p->dictionary[p->dictentry].dict_leftson < 0) {
+ short datum;
+ datum = p->dictionary[p->dictentry].dict_rightson;
+ if (!p->deltacompression)
+ p->sample = 0;
+ p->sample = (p->sample + datum) & 0xff;
+ p->huffcount--;
+ if (p->sample == 0)
+ *buf++ = -127 * 0x1000000L;
+ else
+ *buf++ = (p->sample - 128) * 0x1000000L;
+ p->dictentry = 0;
+ done++;
+ len--;
+ if (len == 0)
+ break;
+ }
+ }
- return done;
+ return done;
}
-int st_hcomstopread(ft_t ft)
+int st_hcomstopread(ft_t ft)
{
- register struct readpriv *p = (struct readpriv *) ft->priv;
+ register struct readpriv *p = (struct readpriv *) ft->priv;
- if (p->huffcount != 0)
- {
- st_fail_errno(ft,ST_EFMT,"not all HCOM data read");
- return (ST_EOF);
- }
- if(p->cksum != p->checksum)
- {
- st_fail_errno(ft,ST_EFMT,"checksum error in HCOM data");
- return (ST_EOF);
- }
- free((char *)p->dictionary);
- p->dictionary = NULL;
- return (ST_SUCCESS);
+ if (p->huffcount != 0)
+ {
+ st_fail_errno(ft,ST_EFMT,"not all HCOM data read");
+ return (ST_EOF);
+ }
+ if(p->cksum != p->checksum)
+ {
+ st_fail_errno(ft,ST_EFMT,"checksum error in HCOM data");
+ return (ST_EOF);
+ }
+ free((char *)p->dictionary);
+ p->dictionary = NULL;
+ return (ST_SUCCESS);
}
struct writepriv {
- unsigned char *data; /* Buffer allocated with malloc */
- unsigned int size; /* Size of allocated buffer */
- unsigned int pos; /* Where next byte goes */
+ unsigned char *data; /* Buffer allocated with malloc */
+ unsigned int size; /* Size of allocated buffer */
+ unsigned int pos; /* Where next byte goes */
};
#define BUFINCR (10*BUFSIZ)
-int st_hcomstartwrite(ft_t ft)
+int st_hcomstartwrite(ft_t ft)
{
- register struct writepriv *p = (struct writepriv *) ft->priv;
+ register struct writepriv *p = (struct writepriv *) ft->priv;
- /* hcom is inbigendian format. Swap whats
- * read in on little endian machines.
- */
- if (ST_IS_LITTLEENDIAN)
- {
- ft->swap = ft->swap ? 0 : 1;
- }
+ /* hcom is inbigendian format. Swap whats
+ * read in on little endian machines.
+ */
+ if (ST_IS_LITTLEENDIAN)
+ {
+ ft->swap = ft->swap ? 0 : 1;
+ }
- switch (ft->info.rate) {
- case 22050:
- case 22050/2:
- case 22050/3:
- case 22050/4:
- break;
- default:
- st_fail_errno(ft,ST_EFMT,"unacceptable output rate for HCOM: try 5512, 7350, 11025 or 22050 hertz");
- return (ST_EOF);
- }
- ft->info.size = ST_SIZE_BYTE;
- ft->info.encoding = ST_ENCODING_UNSIGNED;
- ft->info.channels = 1;
+ switch (ft->info.rate) {
+ case 22050:
+ case 22050/2:
+ case 22050/3:
+ case 22050/4:
+ break;
+ default:
+ st_fail_errno(ft,ST_EFMT,"unacceptable output rate for HCOM: try 5512, 7350, 11025 or 22050 hertz");
+ return (ST_EOF);
+ }
+ ft->info.size = ST_SIZE_BYTE;
+ ft->info.encoding = ST_ENCODING_UNSIGNED;
+ ft->info.channels = 1;
- p->size = BUFINCR;
- p->pos = 0;
- p->data = (unsigned char *) malloc(p->size);
- if (p->data == NULL)
- {
- st_fail_errno(ft,ST_ENOMEM,"can't malloc buffer for uncompressed HCOM data");
- return (ST_EOF);
- }
- return (ST_SUCCESS);
+ p->size = BUFINCR;
+ p->pos = 0;
+ p->data = (unsigned char *) malloc(p->size);
+ if (p->data == NULL)
+ {
+ st_fail_errno(ft,ST_ENOMEM,"can't malloc buffer for uncompressed HCOM data");
+ return (ST_EOF);
+ }
+ return (ST_SUCCESS);
}
st_ssize_t st_hcomwrite(ft_t ft, st_sample_t *buf, st_ssize_t len)
{
- register struct writepriv *p = (struct writepriv *) ft->priv;
- st_sample_t datum;
- st_ssize_t save_len = len;
+ register struct writepriv *p = (struct writepriv *) ft->priv;
+ st_sample_t datum;
+ st_ssize_t save_len = len;
- if (len == 0)
- return (0);
+ if (len == 0)
+ return (0);
- if (p->pos + len > p->size) {
- p->size = ((p->pos + len) / BUFINCR + 1) * BUFINCR;
- p->data = (unsigned char *) realloc(p->data, p->size);
- if (p->data == NULL)
- {
- st_fail_errno(ft,ST_ENOMEM,"can't realloc buffer for uncompressed HCOM data");
- return (0);
- }
- }
+ if (p->pos + len > p->size) {
+ p->size = ((p->pos + len) / BUFINCR + 1) * BUFINCR;
+ p->data = (unsigned char *) realloc(p->data, p->size);
+ if (p->data == NULL)
+ {
+ st_fail_errno(ft,ST_ENOMEM,"can't realloc buffer for uncompressed HCOM data");
+ return (0);
+ }
+ }
- while (--len >= 0) {
- datum = *buf++;
- datum >>= 24;
- datum ^= 128;
- p->data[p->pos++] = datum;
- }
+ while (--len >= 0) {
+ datum = *buf++;
+ datum >>= 24;
+ datum ^= 128;
+ p->data[p->pos++] = datum;
+ }
- return (save_len - len);
+ return (save_len - len);
}
/* Some global compression stuff hcom uses. hcom currently has problems */
@@ -419,7 +419,7 @@
d = (datafork[i] - (sample & 0xff)) & 0xff; /* creates absolute entries LMS */
sample = datafork[i];
datafork[i] = d;
-#if 0 /* checking our table is accessed correctly */
+#if 0 /* checking our table is accessed correctly */
if(d < 0 || d > 255)
printf("d is outside array bounds %d\n", d);
#endif
@@ -473,7 +473,7 @@
makecodes(0, 0, 0, 1);
l = 0;
for(i = 0; i < 256; i++) {
- l += frequtable[i] * codesize[i];
+ l += frequtable[i] * codesize[i];
}
l = (((l + 31) >> 5) << 2) + 24 + dictsize * 4;
st_report(" Original size: %6d bytes", *dl);
@@ -507,8 +507,8 @@
samplerate = 22050 / (int32_t)fr;
putlong(datafork + 16, samplerate);
putshort(datafork + 20, dictsize);
- *df = datafork; /* reassign passed pointer to new datafork */
- *dl = l; /* and its compressed length */
+ *df = datafork; /* reassign passed pointer to new datafork */
+ *dl = l; /* and its compressed length */
return (ST_SUCCESS);
}
@@ -516,58 +516,58 @@
/* FIXME: Place in misc.c */
static void padbytes(ft_t ft, int n)
{
- while (--n >= 0)
- st_writeb(ft, '\0');
+ while (--n >= 0)
+ st_writeb(ft, '\0');
}
/* End of hcom utility routines */
-int st_hcomstopwrite(ft_t ft)
+int st_hcomstopwrite(ft_t ft)
{
- register struct writepriv *p = (struct writepriv *) ft->priv;
- unsigned char *compressed_data = p->data;
- uint32_t compressed_len = p->pos;
- int rc;
+ register struct writepriv *p = (struct writepriv *) ft->priv;
+ unsigned char *compressed_data = p->data;
+ uint32_t compressed_len = p->pos;
+ int rc;
- /* Compress it all at once */
- rc = compress(&compressed_data, (long *)&compressed_len, (double) ft->info.rate);
- free((char *) p->data);
+ /* Compress it all at once */
+ rc = compress(&compressed_data, (uint32_t *)&compressed_len, (double) ft->info.rate);
+ free((char *) p->data);
- if (rc){
- st_fail_errno(ft, rc,"can't malloc buffer for compressed HCOM data");
- return 0;
- }
+ if (rc){
+ st_fail_errno(ft, rc,"can't malloc buffer for compressed HCOM data");
+ return 0;
+ }
- /* Write the header */
- fwrite("\000\001A", 1, 3, ft->fp); /* Dummy file name "A" */
- padbytes(ft, 65-3);
- st_writes(ft, "FSSD");
- padbytes(ft, 83-69);
- st_writedw(ft, (uint32_t) compressed_len); /* compressed_data size */
- st_writedw(ft, (uint32_t) 0); /* rsrc size */
- padbytes(ft, 128 - 91);
- if (ferror(ft->fp))
- {
- st_fail_errno(ft,errno,"write error in HCOM header");
- return (ST_EOF);
- }
+ /* Write the header */
+ fwrite("\000\001A", 1, 3, ft->fp); /* Dummy file name "A" */
+ padbytes(ft, 65-3);
+ st_writes(ft, "FSSD");
+ padbytes(ft, 83-69);
+ st_writedw(ft, (uint32_t) compressed_len); /* compressed_data size */
+ st_writedw(ft, (uint32_t) 0); /* rsrc size */
+ padbytes(ft, 128 - 91);
+ if (ferror(ft->fp))
+ {
+ st_fail_errno(ft,errno,"write error in HCOM header");
+ return (ST_EOF);
+ }
- /* Write the compressed_data fork */
- if (fwrite((char *) compressed_data, 1, (int)compressed_len, ft->fp) != compressed_len)
- {
- st_fail_errno(ft,errno,"can't write compressed HCOM data");
- rc = ST_EOF;
- }
- else
- rc = ST_SUCCESS;
- free((char *) compressed_data);
+ /* Write the compressed_data fork */
+ if (fwrite((char *) compressed_data, 1, (int)compressed_len, ft->fp) != compressed_len)
+ {
+ st_fail_errno(ft,errno,"can't write compressed HCOM data");
+ rc = ST_EOF;
+ }
+ else
+ rc = ST_SUCCESS;
+ free((char *) compressed_data);
- if (rc)
- return rc;
+ if (rc)
+ return rc;
- /* Pad the compressed_data fork to a multiple of 128 bytes */
- padbytes(ft, 128 - (int) (compressed_len%128));
+ /* Pad the compressed_data fork to a multiple of 128 bytes */
+ padbytes(ft, 128 - (int) (compressed_len%128));
- return (ST_SUCCESS);
+ return (ST_SUCCESS);
}