ref: 5dd3781ba19781048609e3ce684d8cc4558eabc5
parent: 41faaddc652a01d3b1a79c5279b9dd05c3d47959
author: robs <robs>
date: Wed Apr 2 04:00:31 EDT 2008
eliminate as many pointer casts as possible
--- a/src/8svx.c
+++ b/src/8svx.c
@@ -85,7 +85,7 @@
lsx_readdw(ft, &chunksize);
if (chunksize & 1)
chunksize++;
- chunk_buf = (char *) lsx_malloc(chunksize + 2);
+ chunk_buf = lsx_malloc(chunksize + 2);
if (lsx_readbuf(ft, chunk_buf,(size_t)chunksize)
!= chunksize)
{
@@ -103,7 +103,7 @@
lsx_readdw(ft, &chunksize);
if (chunksize & 1)
chunksize++;
- chunk_buf = (char *) lsx_malloc(chunksize + 1);
+ chunk_buf = lsx_malloc(chunksize + 1);
if (lsx_readbuf(ft, chunk_buf,(size_t)chunksize)
!= chunksize)
{
--- a/src/FFT.c
+++ b/src/FFT.c
@@ -121,7 +121,7 @@
int BlockEnd;
double angle_numerator = 2.0 * M_PI;
- float tr, ti; /* temp real, temp imaginary */
+ double tr, ti; /* temp real, temp imaginary */
if (!IsPowerOfTwo(NumSamples)) {
sox_fail("%d is not a power of two", NumSamples);
@@ -155,12 +155,12 @@
double delta_angle = angle_numerator / (double) BlockSize;
- float sm2 = sin(-2 * delta_angle);
- float sm1 = sin(-delta_angle);
- float cm2 = cos(-2 * delta_angle);
- float cm1 = cos(-delta_angle);
- float w = 2 * cm1;
- float ar0, ar1, ar2, ai0, ai1, ai2;
+ double sm2 = sin(-2 * delta_angle);
+ double sm1 = sin(-delta_angle);
+ double cm2 = cos(-2 * delta_angle);
+ double cm1 = cos(-delta_angle);
+ double w = 2 * cm1;
+ double ar0, ar1, ar2, ai0, ai1, ai2;
for (i = 0; i < NumSamples; i += BlockSize) {
ar2 = cm2;
@@ -234,7 +234,7 @@
float h1r, h1i, h2r, h2i;
float *tmpReal, *tmpImag;
- tmpReal = (float*)lsx_calloc(NumSamples, sizeof(float));
+ tmpReal = lsx_calloc(NumSamples, sizeof(float));
tmpImag = tmpReal + Half;
for (i = 0; i < Half; i++) {
@@ -295,7 +295,7 @@
theta = M_PI / Half;
- tmpReal = (float*)lsx_calloc(Half * 4, sizeof(float));
+ tmpReal = lsx_calloc(Half * 4, sizeof(float));
tmpImag = tmpReal + Half;
RealOut = tmpImag + Half;
ImagOut = RealOut + Half;
--- a/src/adpcms.c
+++ b/src/adpcms.c
@@ -149,7 +149,7 @@
static int adpcm_start(sox_format_t * ft, adpcm_io_t * state, sox_encoding_t type)
{
/* setup file info */
- state->file.buf = (char *) lsx_malloc(sox_globals.bufsiz);
+ state->file.buf = lsx_malloc(sox_globals.bufsiz);
state->file.size = sox_globals.bufsiz;
ft->signal.channels = 1;
--- a/src/aiff.c
+++ b/src/aiff.c
@@ -160,7 +160,7 @@
}
}
while(chunksize-- > 0)
- lsx_readb(ft, (unsigned char *)&trash8);
+ lsx_readb(ft, &trash8);
foundcomm = 1;
}
else if (strncmp(buf, "SSND", 4) == 0) {
@@ -233,7 +233,7 @@
marks[i].name[read_len] = 0;
if ((len & 1) == 0 && chunksize) {
chunksize--;
- lsx_readb(ft, (unsigned char *)&trash8);
+ lsx_readb(ft, &trash8);
}
}
/* HA HA! Sound Designer (and others) makes */
@@ -240,20 +240,20 @@
/* bogus files. It spits out bogus chunksize */
/* for MARK field */
while(chunksize-- > 0)
- lsx_readb(ft, (unsigned char *)&trash8);
+ lsx_readb(ft, &trash8);
}
else if (strncmp(buf, "INST", 4) == 0) {
/* INST chunk */
lsx_readdw(ft, &chunksize);
- lsx_readb(ft, (unsigned char *)&(ft->oob.instr.MIDInote));
- lsx_readb(ft, (unsigned char *)&trash8);
- lsx_readb(ft, (unsigned char *)&(ft->oob.instr.MIDIlow));
- lsx_readb(ft, (unsigned char *)&(ft->oob.instr.MIDIhi));
+ lsx_readsb(ft, &(ft->oob.instr.MIDInote));
+ lsx_readb(ft, &trash8);
+ lsx_readsb(ft, &(ft->oob.instr.MIDIlow));
+ lsx_readsb(ft, &(ft->oob.instr.MIDIhi));
/* Low velocity */
- lsx_readb(ft, (unsigned char *)&trash8);
+ lsx_readb(ft, &trash8);
/* Hi velocity */
- lsx_readb(ft, (unsigned char *)&trash8);
- lsx_readw(ft, (unsigned short *)&trash16);/* gain */
+ lsx_readb(ft, &trash8);
+ lsx_readw(ft, &trash16);/* gain */
lsx_readw(ft, &looptype); /* sustain loop */
ft->oob.loops[0].type = looptype;
lsx_readw(ft, &sustainLoopBegin); /* begin marker */
@@ -272,7 +272,7 @@
*/
chunksize += (chunksize % 2);
while(chunksize-- > 0)
- lsx_readb(ft, (unsigned char *)&trash8);
+ lsx_readb(ft, &trash8);
}
else if (strncmp(buf, "ALCH", 4) == 0) {
/* I think this is bogus and gets grabbed by APPL */
@@ -280,7 +280,7 @@
lsx_readdw(ft, &trash32); /* ENVS - jeez! */
lsx_readdw(ft, &chunksize);
while(chunksize-- > 0)
- lsx_readb(ft, (unsigned char *)&trash8);
+ lsx_readb(ft, &trash8);
}
else if (strncmp(buf, "ANNO", 4) == 0) {
rc = textChunk(&annotation, "Annotation:", ft);
@@ -344,7 +344,7 @@
/* Skip the chunk using lsx_readb() so we may read
from a pipe */
while (chunksize-- > 0) {
- if (lsx_readb(ft, (unsigned char *)&trash8) == SOX_EOF)
+ if (lsx_readb(ft, &trash8) == SOX_EOF)
break;
}
}
@@ -371,7 +371,7 @@
sox_warn("AIFF header has invalid blocksize. Ignoring but expect a premature EOF");
while (offset-- > 0) {
- if (lsx_readb(ft, (unsigned char *)&trash8) == SOX_EOF)
+ if (lsx_readb(ft, &trash8) == SOX_EOF)
{
lsx_fail_errno(ft,errno,"unexpected EOF while skipping AIFF offset");
return(SOX_EOF);
@@ -511,7 +511,7 @@
uint32_t chunksize;
lsx_readdw(ft, &chunksize);
/* allocate enough memory to hold the text including a terminating \0 */
- *text = (char *) lsx_malloc((size_t) chunksize + 1);
+ *text = lsx_malloc((size_t) chunksize + 1);
if (lsx_readbuf(ft, *text, chunksize) != chunksize)
{
lsx_fail_errno(ft,SOX_EOF,"AIFF: Unexpected EOF in %s header", chunkDescription);
@@ -561,7 +561,7 @@
totalCommentLength += commentLength;
/* allocate enough memory to hold the text including a terminating \0 */
if(commentIndex == 0) {
- *text = (char *) lsx_malloc((size_t) totalCommentLength + 1);
+ *text = lsx_malloc((size_t) totalCommentLength + 1);
}
else {
*text = lsx_realloc(*text, (size_t) totalCommentLength + 1);
@@ -611,7 +611,7 @@
{
char buf[5];
uint32_t chunksize;
- uint32_t trash;
+ uint8_t trash;
if (!ft->seekable)
{
@@ -624,13 +624,13 @@
if (lsx_eof(ft))
break;
buf[4] = '\0';
- sox_warn("Ignoring AIFF tail chunk: '%s', %d bytes long",
+ sox_warn("Ignoring AIFF tail chunk: '%s', %u bytes long",
buf, chunksize);
if (! strcmp(buf, "MARK") || ! strcmp(buf, "INST"))
sox_warn(" You're stripping MIDI/loop info!");
while (chunksize-- > 0)
{
- if (lsx_readb(ft, (unsigned char *)&trash) == SOX_EOF)
+ if (lsx_readb(ft, &trash) == SOX_EOF)
break;
}
}
@@ -952,13 +952,13 @@
static double read_ieee_extended(sox_format_t * ft)
{
- char buf[10];
+ unsigned char buf[10];
if (lsx_readbuf(ft, buf, 10) != 10)
{
lsx_fail_errno(ft,SOX_EOF,"EOF while reading IEEE extended number");
return(SOX_EOF);
}
- return ConvertFromIeeeExtended((unsigned char *)buf);
+ return ConvertFromIeeeExtended(buf);
}
static void write_ieee_extended(sox_format_t * ft, double x)
--- a/src/ao.c
+++ b/src/ao.c
@@ -97,7 +97,7 @@
aobuf_size = (ft->encoding.bits_per_sample >> 3) * len;
- sox_sw_write_buf((char *)ao->buf, buf, len, ft->encoding.reverse_bytes,
+ sox_sw_write_buf(ao->buf, buf, len, ft->encoding.reverse_bytes,
&(ft->clips));
if (ao_play(ao->device, (void *)ao->buf, aobuf_size) == 0)
return 0;
--- a/src/avr.c
+++ b/src/avr.c
@@ -231,11 +231,11 @@
lsx_writew (ft, 0);
/* ext */
- lsx_writebuf(ft, (void *)"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", sizeof(avr->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,
- (void *)"\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\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
"\0\0\0\0", sizeof (avr->user));
--- a/src/chorus.c
+++ b/src/chorus.c
@@ -197,7 +197,7 @@
return (SOX_EOF);
}
chorus->length[i] = effp->in_signal.rate / chorus->speed[i];
- chorus->lookup_tab[i] = (int *) lsx_malloc(sizeof (int) * chorus->length[i]);
+ chorus->lookup_tab[i] = lsx_malloc(sizeof (int) * chorus->length[i]);
if (chorus->modulation[i] == MOD_SINE)
lsx_generate_wave_table(SOX_WAVE_SINE, SOX_INT, chorus->lookup_tab[i],
@@ -221,7 +221,7 @@
sox_warn("chorus: warning >>> gain-out can cause saturation or clipping of output <<<");
- chorus->chorusbuf = (float *) lsx_malloc(sizeof (float) * chorus->maxsamples);
+ chorus->chorusbuf = lsx_malloc(sizeof (float) * chorus->maxsamples);
for ( i = 0; i < chorus->maxsamples; i++ )
chorus->chorusbuf[i] = 0.0;
@@ -320,11 +320,11 @@
priv_t * chorus = (priv_t *) effp->priv;
int i;
- free((char *) chorus->chorusbuf);
- chorus->chorusbuf = (float *) -1; /* guaranteed core dump */
+ free(chorus->chorusbuf);
+ chorus->chorusbuf = NULL;
for ( i = 0; i < chorus->num_chorus; i++ ) {
- free((char *) chorus->lookup_tab[i]);
- chorus->lookup_tab[i] = (int *) -1; /* guaranteed core dump */
+ free(chorus->lookup_tab[i]);
+ chorus->lookup_tab[i] = NULL;
}
return (SOX_SUCCESS);
}
--- a/src/echo.c
+++ b/src/echo.c
@@ -144,7 +144,7 @@
if ( echo->samples[i] > echo->maxsamples )
echo->maxsamples = echo->samples[i];
}
- echo->delay_buf = (double *) lsx_malloc(sizeof (double) * echo->maxsamples);
+ echo->delay_buf = lsx_malloc(sizeof (double) * echo->maxsamples);
for ( j = 0; j < echo->maxsamples; ++j )
echo->delay_buf[j] = 0.0;
/* Be nice and check the hint with warning, if... */
@@ -242,8 +242,8 @@
{
priv_t * echo = (priv_t *) effp->priv;
- free((char *) echo->delay_buf);
- echo->delay_buf = (double *) -1; /* guaranteed core dump */
+ free(echo->delay_buf);
+ echo->delay_buf = NULL;
return (SOX_SUCCESS);
}
--- a/src/echos.c
+++ b/src/echos.c
@@ -143,7 +143,7 @@
echos->pointer[i] = echos->sumsamples;
echos->sumsamples += echos->samples[i];
}
- echos->delay_buf = (double *) lsx_malloc(sizeof (double) * echos->sumsamples);
+ echos->delay_buf = lsx_malloc(sizeof (double) * echos->sumsamples);
for ( j = 0; j < echos->sumsamples; ++j )
echos->delay_buf[j] = 0.0;
/* Be nice and check the hint with warning, if... */
@@ -251,8 +251,8 @@
{
priv_t * echos = (priv_t *) effp->priv;
- free((char *) echos->delay_buf);
- echos->delay_buf = (double *) -1; /* guaranteed core dump */
+ free(echos->delay_buf);
+ echos->delay_buf = NULL;
return (SOX_SUCCESS);
}
--- a/src/fade.c
+++ b/src/fade.c
@@ -70,7 +70,7 @@
fade->out_fadetype = 'l';
}
- fade->in_stop_str = (char *)lsx_malloc(strlen(argv[0])+1);
+ fade->in_stop_str = lsx_malloc(strlen(argv[0])+1);
strcpy(fade->in_stop_str,argv[0]);
/* Do a dummy parse to see if it will fail */
if (lsx_parsesamples(0., fade->in_stop_str, &fade->in_stop, 't') == NULL)
@@ -83,7 +83,7 @@
/* See if there is fade-in/fade-out times/curves specified. */
if(t_argno == 1)
{
- fade->out_stop_str = (char *)lsx_malloc(strlen(argv[t_argno])+1);
+ fade->out_stop_str = lsx_malloc(strlen(argv[t_argno])+1);
strcpy(fade->out_stop_str,argv[t_argno]);
/* Do a dummy parse to see if it will fail */
@@ -93,7 +93,7 @@
}
else
{
- fade->out_start_str = (char *)lsx_malloc(strlen(argv[t_argno])+1);
+ fade->out_start_str = lsx_malloc(strlen(argv[t_argno])+1);
strcpy(fade->out_start_str,argv[t_argno]);
/* Do a dummy parse to see if it will fail */
--- a/src/fifo.h
+++ b/src/fifo.h
@@ -44,7 +44,7 @@
while (1) {
if (f->end + n <= f->allocation) {
- void *p = (char *) f->data + f->end;
+ void *p = f->data + f->end;
f->end += n;
return p;
--- a/src/filter.c
+++ b/src/filter.c
@@ -21,7 +21,7 @@
* REMARKS: (Stan Brooks speaking)
* This code is heavily based on the resample.c code which was
* apparently itself a rewrite (by Lance Norskog?) of code originally
- * by Julius O. Smith, and distributed under the LGPL.
+ * by Julius O. Smith, now distributed under the LGPL.
*/
#include "sox_i.h"
@@ -116,7 +116,8 @@
}
Xh = f->Nwin/2;
- Fp0 = (double *) lsx_malloc(sizeof(double) * (Xh + 2)) + 1;
+ Fp0 = lsx_malloc(sizeof(double) * (Xh + 2));
+ ++Fp0;
if (f->freq0 > (sox_sample_t)f->rate/200) {
Xh0 = lsx_makeFilter(Fp0, Xh, 2.0*(double)f->freq0/f->rate, f->beta, 1, 0);
if (Xh0 <= 1)
@@ -127,7 +128,8 @@
} else {
Xh0 = 0;
}
- Fp1 = (double *) lsx_malloc(sizeof(double) * (Xh + 2)) + 1;
+ Fp1 = lsx_malloc(sizeof(double) * (Xh + 2));
+ ++Fp1;
/* need Fp[-1] and Fp[Xh] for lsx_makeFilter */
if (f->freq1 < (sox_sample_t)f->rate/2) {
Xh1 = lsx_makeFilter(Fp1, Xh, 2.0*(double)f->freq1/f->rate, f->beta, 1, 0);
@@ -160,7 +162,7 @@
f->Xh = Xh;
f->Xt = Xh;
- f->X = (double *) lsx_malloc(sizeof(double) * (2*BUFFSIZE + 2*Xh));
+ f->X = lsx_malloc(sizeof(double) * (2*BUFFSIZE + 2*Xh));
f->Y = f->X + BUFFSIZE + 2*Xh;
/* Need Xh zeros at beginning of X */
@@ -239,10 +241,10 @@
osamp_res = *osamp;
Obuf = obuf;
while (isamp_res>0 && osamp_res>0) {
- sox_sample_t Isamp, Osamp;
+ sox_size_t Isamp, Osamp;
Isamp = isamp_res;
Osamp = osamp_res;
- sox_filter_flow(effp, NULL, Obuf, (sox_size_t *)&Isamp, (sox_size_t *)&Osamp);
+ sox_filter_flow(effp, NULL, Obuf, &Isamp, &Osamp);
/* sox_debug("DRAIN isamp,osamp (%d,%d) -> (%d,%d)",
* isamp_res,osamp_res,Isamp,Osamp); */
Obuf += Osamp;
--- a/src/getopt.c
+++ b/src/getopt.c
@@ -437,7 +437,7 @@
if (nonoption_flags_max_len < argc)
nonoption_flags_max_len = argc;
__getopt_nonoption_flags =
- (char *) lsx_malloc (nonoption_flags_max_len);
+ lsx_malloc (nonoption_flags_max_len);
if (__getopt_nonoption_flags == NULL)
nonoption_flags_max_len = -1;
else
--- a/src/gsm.c
+++ b/src/gsm.c
@@ -79,8 +79,8 @@
return (SOX_EOF);
}
}
- p->frames = (gsm_byte*) lsx_malloc(p->channels*FRAMESIZE);
- p->samples = (gsm_signal*) lsx_malloc(BLOCKSIZE * (p->channels+1) * sizeof(gsm_signal));
+ p->frames = lsx_malloc(p->channels*FRAMESIZE);
+ p->samples = lsx_malloc(BLOCKSIZE * (p->channels+1) * sizeof(gsm_signal));
p->sampleTop = p->samples + BLOCKSIZE*p->channels;
p->samplePtr = (w)? p->samples : p->sampleTop;
return (SOX_SUCCESS);
--- a/src/hcom.c
+++ b/src/hcom.c
@@ -141,12 +141,12 @@
ft->signal.channels = 1;
/* Allocate memory for the dictionary */
- p->dictionary = (dictent *)lsx_malloc(511 * sizeof(dictent));
+ p->dictionary = lsx_malloc(511 * sizeof(dictent));
/* Read dictionary */
for(i = 0; i < dictsize; i++) {
- lsx_readw(ft, (unsigned short *)&(p->dictionary[i].dict_leftson));
- lsx_readw(ft, (unsigned short *)&(p->dictionary[i].dict_rightson));
+ lsx_readsw(ft, &(p->dictionary[i].dict_leftson));
+ lsx_readsw(ft, &(p->dictionary[i].dict_rightson));
sox_debug("%d %d",
p->dictionary[i].dict_leftson,
p->dictionary[i].dict_rightson);
@@ -245,7 +245,7 @@
lsx_fail_errno(ft,SOX_EFMT,"checksum error in HCOM data");
return (SOX_EOF);
}
- free((char *)p->dictionary);
+ free(p->dictionary);
p->dictionary = NULL;
return (SOX_SUCCESS);
}
@@ -273,7 +273,7 @@
if (p->pos + len > p->size) {
p->size = ((p->pos + len) / BUFINCR + 1) * BUFINCR;
- p->data = (unsigned char *)lsx_realloc(p->data, p->size);
+ p->data = lsx_realloc(p->data, p->size);
}
for (i = 0; i < len; i++) {
@@ -391,7 +391,7 @@
l = (((l + 31) >> 5) << 2) + 24 + dictsize * 4;
sox_debug(" Original size: %6d bytes", *dl);
sox_debug("Compressed size: %6d bytes", l);
- datafork = (unsigned char *)lsx_malloc((unsigned)l);
+ datafork = lsx_malloc((unsigned)l);
ddf = datafork + 22;
for(i = 0; i < dictsize; i++) {
put16_be(&ddf, newdict[i].dict_leftson);
@@ -409,7 +409,7 @@
codesize[0] = 32 - p->nbits;
putcode(ft, codes, codesize, 0, &ddf);
}
- strncpy((char *)datafork, "HCOM", 4);
+ memcpy(datafork, "HCOM", 4);
dfp = datafork + 4;
put32_be(&dfp, *dl);
put32_be(&dfp, p->new_checksum);
@@ -433,10 +433,10 @@
/* Compress it all at once */
if (compressed_len)
compress(ft, &compressed_data, (int32_t *)&compressed_len);
- free((char *)p->data);
+ free(p->data);
/* Write the header */
- lsx_writebuf(ft, (void *)"\000\001A", 3); /* Dummy file name "A" */
+ lsx_writebuf(ft, "\000\001A", 3); /* Dummy file name "A" */
lsx_padbytes(ft, 65-3);
lsx_writes(ft, "FSSD");
lsx_padbytes(ft, 83-69);
@@ -451,7 +451,7 @@
lsx_fail_errno(ft, errno, "can't write compressed HCOM data");
rc = SOX_EOF;
}
- free((char *)compressed_data);
+ free(compressed_data);
if (rc == SOX_SUCCESS)
/* Pad the compressed_data fork to a multiple of 128 bytes */
--- a/src/maud.c
+++ b/src/maud.c
@@ -93,7 +93,7 @@
lsx_readw(ft, &bitpersam);
/* number of bits per sample after decompression */
- lsx_readw(ft, (unsigned short *)&trash16);
+ lsx_readw(ft, &trash16);
lsx_readdw(ft, &nom); /* clock source frequency */
lsx_readw(ft, &denom); /* clock devide */
@@ -160,7 +160,7 @@
lsx_readdw(ft, &chunksize);
if (chunksize & 1)
chunksize++;
- chunk_buf = (char *) lsx_malloc(chunksize + 1);
+ chunk_buf = lsx_malloc(chunksize + 1);
if (lsx_readbuf(ft, chunk_buf, chunksize)
!= chunksize)
{
--- a/src/mcompand.c
+++ b/src/mcompand.c
@@ -94,8 +94,8 @@
static int lowpass_setup (butterworth_crossover_t * butterworth, double frequency, sox_rate_t rate, sox_size_t nchan) {
double c;
- butterworth->xy_low = (struct xy *)lsx_calloc(nchan, sizeof(struct xy));
- butterworth->xy_high = (struct xy *)lsx_calloc(nchan, sizeof(struct xy));
+ butterworth->xy_low = lsx_calloc(nchan, sizeof(struct xy));
+ butterworth->xy_high = lsx_calloc(nchan, sizeof(struct xy));
/* lowpass setup */
butterworth->frequency_low = frequency/1.3;
@@ -239,9 +239,9 @@
}
rates = 1 + commas/2;
- l->attackRate = (double *)lsx_malloc(sizeof(double) * rates);
- l->decayRate = (double *)lsx_malloc(sizeof(double) * rates);
- l->volume = (double *)lsx_malloc(sizeof(double) * rates);
+ l->attackRate = lsx_malloc(sizeof(double) * rates);
+ l->decayRate = lsx_malloc(sizeof(double) * rates);
+ l->volume = lsx_malloc(sizeof(double) * rates);
l->expectedChannels = rates;
l->delay_buf = NULL;
@@ -319,7 +319,7 @@
}
c->nBands = (n+1)>>1;
- c->bands = (comp_band_t *)lsx_calloc(c->nBands, sizeof(comp_band_t));
+ c->bands = lsx_calloc(c->nBands, sizeof(comp_band_t));
for (i=0;i<c->nBands;++i) {
len = strlen(argv[i<<1]);
@@ -382,7 +382,7 @@
/* Allocate the delay buffer */
if (c->delay_buf_size > 0)
- l->delay_buf = (sox_sample_t *)lsx_calloc(sizeof(long), c->delay_buf_size);
+ l->delay_buf = lsx_calloc(sizeof(long), c->delay_buf_size);
l->delay_buf_ptr = 0;
l->delay_buf_cnt = 0;
@@ -488,13 +488,13 @@
double out;
if (c->band_buf_len < len) {
- c->band_buf1 = (sox_sample_t *)lsx_realloc(c->band_buf1,len*sizeof(sox_sample_t));
- c->band_buf2 = (sox_sample_t *)lsx_realloc(c->band_buf2,len*sizeof(sox_sample_t));
- c->band_buf3 = (sox_sample_t *)lsx_realloc(c->band_buf3,len*sizeof(sox_sample_t));
+ c->band_buf1 = lsx_realloc(c->band_buf1,len*sizeof(sox_sample_t));
+ c->band_buf2 = lsx_realloc(c->band_buf2,len*sizeof(sox_sample_t));
+ c->band_buf3 = lsx_realloc(c->band_buf3,len*sizeof(sox_sample_t));
c->band_buf_len = len;
}
- ibuf_copy = (sox_sample_t *)lsx_malloc(*isamp * sizeof(sox_sample_t));
+ ibuf_copy = lsx_malloc(*isamp * sizeof(sox_sample_t));
memcpy(ibuf_copy, ibuf, *isamp * sizeof(sox_sample_t));
/* split ibuf into bands using butterworths, pipe each band through sox_mcompand_flow_1, then add back together and write to obuf */
--- a/src/mp3.c
+++ b/src/mp3.c
@@ -33,13 +33,13 @@
/* Private data */
typedef struct {
#ifdef HAVE_MAD_H
- struct mad_stream *Stream;
- struct mad_frame *Frame;
- struct mad_synth *Synth;
- mad_timer_t *Timer;
+ struct mad_stream Stream;
+ struct mad_frame Frame;
+ struct mad_synth Synth;
+ mad_timer_t Timer;
unsigned char *InputBuffer;
- sox_ssize_t cursamp;
- sox_size_t FrameCount;
+ sox_ssize_t cursamp;
+ sox_size_t FrameCount;
#endif /*HAVE_MAD_H*/
#ifdef HAVE_LAME_LAME_H
lame_global_flags *gfp;
@@ -90,7 +90,7 @@
size_t bytes_read;
size_t remaining;
- remaining = p->Stream->bufend - p->Stream->next_frame;
+ remaining = p->Stream.bufend - p->Stream.next_frame;
/* libmad does not consume all the buffer it's given. Some
* data, part of a truncated frame, is left unused at the
@@ -102,7 +102,7 @@
* TODO: Is 2016 bytes the size of the largest frame?
* (448000*(1152/32000))/8
*/
- memmove(p->InputBuffer, p->Stream->next_frame, remaining);
+ memmove(p->InputBuffer, p->Stream.next_frame, remaining);
bytes_read = lsx_readbuf(ft, p->InputBuffer+remaining,
INPUT_BUFFER_SIZE-remaining);
@@ -111,8 +111,8 @@
return SOX_EOF;
}
- mad_stream_buffer(p->Stream, p->InputBuffer, bytes_read+remaining);
- p->Stream->error = 0;
+ mad_stream_buffer(&p->Stream, p->InputBuffer, bytes_read+remaining);
+ p->Stream.error = 0;
return SOX_SUCCESS;
}
@@ -140,10 +140,10 @@
* consumed as well as letting additional data to be
* read in.
*/
- remaining = p->Stream->bufend - p->Stream->next_frame;
- if ((tagsize = tagtype(p->Stream->this_frame, remaining)))
+ remaining = p->Stream.bufend - p->Stream.next_frame;
+ if ((tagsize = tagtype(p->Stream.this_frame, remaining)))
{
- mad_stream_skip(p->Stream, tagsize);
+ mad_stream_skip(&p->Stream, tagsize);
rc = SOX_SUCCESS;
}
@@ -151,7 +151,7 @@
* so help libmad out and go back into frame seek mode.
* This is true whether an ID3 tag was found or not.
*/
- mad_stream_sync(p->Stream);
+ mad_stream_sync(&p->Stream);
return rc;
}
@@ -161,17 +161,9 @@
priv_t *p = (priv_t *) ft->priv;
size_t ReadSize;
- p->Stream = NULL;
- p->Frame = NULL;
- p->Synth = NULL;
- p->Timer = NULL;
p->InputBuffer = NULL;
- p->Stream=(struct mad_stream *)lsx_malloc(sizeof(struct mad_stream));
- p->Frame=(struct mad_frame *)lsx_malloc(sizeof(struct mad_frame));
- p->Synth=(struct mad_synth *)lsx_malloc(sizeof(struct mad_synth));
- p->Timer=(mad_timer_t *)lsx_malloc(sizeof(mad_timer_t));
- p->InputBuffer=(unsigned char *)lsx_malloc(INPUT_BUFFER_SIZE);
+ p->InputBuffer=lsx_malloc(INPUT_BUFFER_SIZE);
if (ft->seekable) {
#if HAVE_ID3TAG && HAVE_UNISTD_H
@@ -181,10 +173,10 @@
ft->signal.length = mp3_duration_ms(ft->fp, p->InputBuffer);
}
- mad_stream_init(p->Stream);
- mad_frame_init(p->Frame);
- mad_synth_init(p->Synth);
- mad_timer_reset(p->Timer);
+ mad_stream_init(&p->Stream);
+ mad_frame_init(&p->Frame);
+ mad_synth_init(&p->Synth);
+ mad_timer_reset(&p->Timer);
ft->encoding.encoding = SOX_ENCODING_MP3;
@@ -199,17 +191,17 @@
return SOX_EOF;
}
- mad_stream_buffer(p->Stream, p->InputBuffer, ReadSize);
+ mad_stream_buffer(&p->Stream, p->InputBuffer, ReadSize);
/* Find a valid frame before starting up. This makes sure
* that we have a valid MP3 and also skips past ID3v2 tags
* at the beginning of the audio file.
*/
- p->Stream->error = 0;
- while (mad_frame_decode(p->Frame,p->Stream))
+ p->Stream.error = 0;
+ while (mad_frame_decode(&p->Frame,&p->Stream))
{
/* check whether input buffer needs a refill */
- if (p->Stream->error == MAD_ERROR_BUFLEN)
+ if (p->Stream.error == MAD_ERROR_BUFLEN)
{
if (sox_mp3_input(ft) == SOX_EOF)
return SOX_EOF;
@@ -225,22 +217,22 @@
* frame. In that case we can abort early without
* scanning the whole file.
*/
- p->Stream->error = 0;
+ p->Stream.error = 0;
}
- if (p->Stream->error)
+ if (p->Stream.error)
{
lsx_fail_errno(ft,SOX_EOF,"No valid MP3 frame found");
return SOX_EOF;
}
- switch(p->Frame->header.mode)
+ switch(p->Frame.header.mode)
{
case MAD_MODE_SINGLE_CHANNEL:
case MAD_MODE_DUAL_CHANNEL:
case MAD_MODE_JOINT_STEREO:
case MAD_MODE_STEREO:
- ft->signal.channels = MAD_NCHANNELS(&p->Frame->header);
+ ft->signal.channels = MAD_NCHANNELS(&p->Frame.header);
break;
default:
lsx_fail_errno(ft, SOX_EFMT, "Cannot determine number of channels");
@@ -249,9 +241,9 @@
p->FrameCount=1;
- mad_timer_add(p->Timer,p->Frame->header.duration);
- mad_synth_frame(p->Synth,p->Frame);
- ft->signal.rate=p->Synth->pcm.samplerate;
+ mad_timer_add(&p->Timer,p->Frame.header.duration);
+ mad_synth_frame(&p->Synth,&p->Frame);
+ ft->signal.rate=p->Synth.pcm.samplerate;
ft->signal.length = ft->signal.length * .001 * ft->signal.rate + .5;
ft->signal.length *= ft->signal.channels; /* Keep separate from line above! */
@@ -274,11 +266,11 @@
size_t chan;
do {
- donow=min(len,(p->Synth->pcm.length - p->cursamp)*ft->signal.channels);
+ donow=min(len,(p->Synth.pcm.length - p->cursamp)*ft->signal.channels);
i=0;
while(i<donow){
for(chan=0;chan<ft->signal.channels;chan++){
- sample=p->Synth->pcm.samples[chan][p->cursamp];
+ sample=p->Synth.pcm.samples[chan][p->cursamp];
if (sample < -MAD_F_ONE)
sample=-MAD_F_ONE;
else if (sample >= MAD_F_ONE)
@@ -295,15 +287,15 @@
if (len==0) break;
/* check whether input buffer needs a refill */
- if (p->Stream->error == MAD_ERROR_BUFLEN)
+ if (p->Stream.error == MAD_ERROR_BUFLEN)
{
if (sox_mp3_input(ft) == SOX_EOF)
return 0;
}
- if (mad_frame_decode(p->Frame,p->Stream))
+ if (mad_frame_decode(&p->Frame,&p->Stream))
{
- if(MAD_RECOVERABLE(p->Stream->error))
+ if(MAD_RECOVERABLE(p->Stream.error))
{
sox_mp3_inputtag(ft);
continue;
@@ -310,19 +302,19 @@
}
else
{
- if (p->Stream->error == MAD_ERROR_BUFLEN)
+ if (p->Stream.error == MAD_ERROR_BUFLEN)
continue;
else
{
sox_report("unrecoverable frame level error (%s).",
- mad_stream_errorstr(p->Stream));
+ mad_stream_errorstr(&p->Stream));
return done;
}
}
}
p->FrameCount++;
- mad_timer_add(p->Timer,p->Frame->header.duration);
- mad_synth_frame(p->Synth,p->Frame);
+ mad_timer_add(&p->Timer,p->Frame.header.duration);
+ mad_synth_frame(&p->Synth,&p->Frame);
p->cursamp=0;
} while(1);
@@ -333,14 +325,10 @@
{
priv_t *p=(priv_t*) ft->priv;
- mad_synth_finish(p->Synth);
- mad_frame_finish(p->Frame);
- mad_stream_finish(p->Stream);
+ mad_synth_finish(&p->Synth);
+ mad_frame_finish(&p->Frame);
+ mad_stream_finish(&p->Stream);
- free(p->Stream);
- free(p->Frame);
- free(p->Synth);
- free(p->Timer);
free(p->InputBuffer);
return SOX_SUCCESS;
@@ -412,7 +400,7 @@
static sox_size_t sox_mp3write(sox_format_t * ft, const sox_sample_t *buf, sox_size_t samp)
{
priv_t *p = (priv_t *)ft->priv;
- char *mp3buffer;
+ unsigned char *mp3buffer;
sox_size_t mp3buffer_size;
short signed int *buffer_l, *buffer_r = NULL;
int nsamples = samp/ft->signal.channels;
@@ -436,7 +424,7 @@
* lsx_malloc()'ing a smaller buffer and call a consistent
* interface.
*/
- buffer_l = (short signed int *)lsx_malloc(nsamples * sizeof(short signed int));
+ buffer_l = lsx_malloc(nsamples * sizeof(short signed int));
if (ft->signal.channels == 2)
{
@@ -443,14 +431,7 @@
/* lame doesn't support iterleaved samples so we must break
* them out into seperate buffers.
*/
- if ((buffer_r =
- (short signed int *)lsx_malloc(nsamples*
- sizeof(short signed int))) == NULL)
- {
- lsx_fail_errno(ft,SOX_ENOMEM,"Memory allocation failed");
- goto end3;
- }
-
+ buffer_r = lsx_malloc(nsamples* sizeof(short signed int));
j=0;
for (i=0; i<nsamples; i++)
{
@@ -468,14 +449,10 @@
}
mp3buffer_size = 1.25 * nsamples + 7200;
- if ((mp3buffer=(char *)lsx_malloc(mp3buffer_size)) == NULL)
- {
- lsx_fail_errno(ft,SOX_ENOMEM,"Memory allocation failed");
- goto end2;
- }
+ mp3buffer = lsx_malloc(mp3buffer_size);
if ((written = lame_encode_buffer(p->gfp,buffer_l, buffer_r,
- nsamples, (unsigned char *)mp3buffer,
+ nsamples, mp3buffer,
(int)mp3buffer_size)) > mp3buffer_size){
lsx_fail_errno(ft,SOX_EOF,"Encoding failed");
goto end;
@@ -491,10 +468,8 @@
end:
free(mp3buffer);
-end2:
if (ft->signal.channels == 2)
free(buffer_r);
-end3:
free(buffer_l);
return done;
@@ -503,11 +478,11 @@
static int stopwrite(sox_format_t * ft)
{
priv_t *p = (priv_t *) ft->priv;
- char mp3buffer[7200];
+ unsigned char mp3buffer[7200];
int written;
size_t written2;
- if ((written=lame_encode_flush(p->gfp, (unsigned char *)mp3buffer, 7200)) <0){
+ if ((written=lame_encode_flush(p->gfp, mp3buffer, 7200)) <0){
lsx_fail_errno(ft,SOX_EOF,"Encoding failed");
}
else if (lsx_writebuf(ft, mp3buffer, written2 = written) < written2){
--- a/src/noiseprof.c
+++ b/src/noiseprof.c
@@ -79,12 +79,12 @@
return SOX_EOF;
}
- data->chandata = (chandata_t*)lsx_calloc(channels, sizeof(*(data->chandata)));
+ data->chandata = lsx_calloc(channels, sizeof(*(data->chandata)));
data->bufdata = 0;
for (i = 0; i < channels; i ++) {
- data->chandata[i].sum = (float*)lsx_calloc(FREQCOUNT, sizeof(float));
- data->chandata[i].profilecount = (int*)lsx_calloc(FREQCOUNT, sizeof(int));
- data->chandata[i].window = (float*)lsx_calloc(WINDOWSIZE, sizeof(float));
+ data->chandata[i].sum = lsx_calloc(FREQCOUNT, sizeof(float));
+ data->chandata[i].profilecount = lsx_calloc(FREQCOUNT, sizeof(int));
+ data->chandata[i].window = lsx_calloc(WINDOWSIZE, sizeof(float));
}
return SOX_SUCCESS;
@@ -92,7 +92,7 @@
/* Collect statistics from the complete window on channel chan. */
static void collect_data(chandata_t* chan) {
- float *out = (float*)lsx_calloc(FREQCOUNT, sizeof(float));
+ float *out = lsx_calloc(FREQCOUNT, sizeof(float));
int i;
PowerSpectrum(WINDOWSIZE, chan->window, out);
--- a/src/noisered.c
+++ b/src/noisered.c
@@ -65,11 +65,11 @@
sox_size_t i;
FILE* ifp;
- data->chandata = (chandata_t*)lsx_calloc(channels, sizeof(*(data->chandata)));
+ data->chandata = lsx_calloc(channels, sizeof(*(data->chandata)));
data->bufdata = 0;
for (i = 0; i < channels; i ++) {
- data->chandata[i].noisegate = (float*)lsx_calloc(FREQCOUNT, sizeof(float));
- data->chandata[i].smoothing = (float*)lsx_calloc(FREQCOUNT, sizeof(float));
+ data->chandata[i].noisegate = lsx_calloc(FREQCOUNT, sizeof(float));
+ data->chandata[i].smoothing = lsx_calloc(FREQCOUNT, sizeof(float));
data->chandata[i].lastwindow = NULL;
}
@@ -130,7 +130,7 @@
float *smoothing = chan->smoothing;
int i;
- inr = (float*)lsx_calloc(WINDOWSIZE * 5, sizeof(float));
+ inr = lsx_calloc(WINDOWSIZE * 5, sizeof(float));
ini = inr + WINDOWSIZE;
outr = ini + WINDOWSIZE;
outi = outr + WINDOWSIZE;
@@ -207,7 +207,7 @@
chandata_t *chan = &(data->chandata[chan_num]);
int first = (chan->lastwindow == NULL);
- if ((nextwindow = (float*)lsx_calloc(WINDOWSIZE, sizeof(float))) == NULL)
+ if ((nextwindow = lsx_calloc(WINDOWSIZE, sizeof(float))) == NULL)
return SOX_EOF;
memcpy(nextwindow, chan->window+WINDOWSIZE/2,
@@ -263,7 +263,7 @@
sox_size_t j;
if (chan->window == NULL)
- chan->window = (float*)lsx_calloc(WINDOWSIZE, sizeof(float));
+ chan->window = lsx_calloc(WINDOWSIZE, sizeof(float));
for (j = 0; j < ncopy; j ++)
chan->window[oldbuf + j] =
--- a/src/oss.c
+++ b/src/oss.c
@@ -194,7 +194,7 @@
}
file->count = 0;
file->pos = 0;
- file->buf = (char *)lsx_malloc(file->size);
+ file->buf = lsx_malloc(file->size);
if (ioctl(fileno(ft->fp), SNDCTL_DSP_SYNC, NULL) < 0) {
lsx_fail_errno(ft,SOX_EOF,"Unable to sync dsp");
--- a/src/pan.c
+++ b/src/pan.c
@@ -78,7 +78,7 @@
char ich, och;
double left, right, direction, hdir;
- ibuf_copy = (sox_sample_t *)lsx_malloc(*isamp * sizeof(sox_sample_t));
+ ibuf_copy = lsx_malloc(*isamp * sizeof(sox_sample_t));
memcpy(ibuf_copy, ibuf, *isamp * sizeof(sox_sample_t));
direction = pan->direction; /* -1 <= direction <= 1 */
--- a/src/phaser.c
+++ b/src/phaser.c
@@ -149,10 +149,10 @@
sox_warn("phaser: warning >>> gain-out can cause saturation or clipping of output <<<");
phaser->length = effp->in_signal.rate / phaser->speed;
- phaser->phaserbuf = (double *) lsx_malloc(sizeof (double) * phaser->maxsamples);
+ phaser->phaserbuf = lsx_malloc(sizeof (double) * phaser->maxsamples);
for ( i = 0; i < phaser->maxsamples; i++ )
phaser->phaserbuf[i] = 0.0;
- phaser->lookup_tab = (int *) lsx_malloc(sizeof (int) * phaser->length);
+ phaser->lookup_tab = lsx_malloc(sizeof (int) * phaser->length);
if (phaser->modulation == MOD_SINE)
lsx_generate_wave_table(SOX_WAVE_SINE, SOX_INT, phaser->lookup_tab,
--- a/src/pitch.c
+++ b/src/pitch.c
@@ -357,10 +357,10 @@
pitch->size = pitch->step + 2*pitch->overlap;
- pitch->fade = (double *) lsx_malloc(pitch->step*sizeof(double));
- pitch->tmp = (double *) lsx_malloc(pitch->step*sizeof(double));
- pitch->acc = (double *) lsx_malloc(pitch->step*sizeof(double));
- pitch->buf = (sox_sample_t *) lsx_malloc(pitch->size*sizeof(sox_sample_t));
+ pitch->fade = lsx_malloc(pitch->step*sizeof(double));
+ pitch->tmp = lsx_malloc(pitch->step*sizeof(double));
+ pitch->acc = lsx_malloc(pitch->step*sizeof(double));
+ pitch->buf = lsx_malloc(pitch->size*sizeof(sox_sample_t));
pitch->index = pitch->overlap;
/* default initial signal */
--- a/src/polyphas.c
+++ b/src/polyphas.c
@@ -383,7 +383,7 @@
int j, prod, f_cutoff, f_len;
polystage *s;
- rate->stage[k] = s = (polystage*) lsx_malloc(sizeof(polystage));
+ rate->stage[k] = s = lsx_malloc(sizeof(polystage));
s->up = l1[k];
s->down = l2[k];
f_cutoff = max(s->up, s->down);
@@ -397,8 +397,8 @@
sox_debug("Poly: stage %d: Up by %d, down by %d, i_samps %d, hsize %d",
k+1,s->up,s->down,size, s->hsize);
s->filt_len = f_len;
- s->filt_array = (Float *) lsx_malloc(sizeof(Float) * f_len);
- s->window = (Float *) lsx_malloc(sizeof(Float) * (s->hsize+size));
+ s->filt_array = lsx_malloc(sizeof(Float) * f_len);
+ s->window = lsx_malloc(sizeof(Float) * (s->hsize+size));
/* zero past_history section of window */
for(j = 0; j < s->hsize; j++)
s->window[j] = 0.0;
@@ -418,7 +418,7 @@
rate->oskip = skip/2;
{ /* bogus last stage is for output buffering */
polystage *s;
- rate->stage[k] = s = (polystage*) lsx_malloc(sizeof(polystage));
+ rate->stage[k] = s = lsx_malloc(sizeof(polystage));
s->up = s->down = 0;
s->size = size;
s->hsize = 0;
@@ -425,7 +425,7 @@
s->held = 0;
s->filt_len = 0;
s->filt_array = NULL;
- s->window = (Float *) lsx_malloc(sizeof(Float) * size);
+ s->window = lsx_malloc(sizeof(Float) * size);
}
sox_debug("Poly: output samples %d, oskip %d",size, rate->oskip);
return (SOX_SUCCESS);
--- a/src/rabbit.c
+++ b/src/rabbit.c
@@ -88,7 +88,7 @@
effp->out_signal.channels = effp->in_signal.channels;
effp->out_signal.rate = out_rate;
- r->data = (SRC_DATA *)lsx_calloc(1, sizeof(SRC_DATA));
+ r->data = lsx_calloc(1, sizeof(SRC_DATA));
r->data->src_ratio = out_rate / effp->in_signal.rate;
r->i_alloc = r->o_alloc = 0;
r->state = src_new(r->converter_type, (int)effp->in_signal.channels, &err);
--- a/src/raw.c
+++ b/src/raw.c
@@ -25,8 +25,10 @@
}
/* Works nicely for starting read and write; lsx_rawstart{read,write}
- are #defined in sox_i.h */
-int lsx_rawstart(sox_format_t * ft, sox_bool default_rate, sox_bool default_channels, sox_bool default_length, sox_encoding_t encoding, unsigned size)
+ * are #defined in sox_i.h */
+int lsx_rawstart(sox_format_t * ft, sox_bool default_rate,
+ sox_bool default_channels, sox_bool default_length,
+ sox_encoding_t encoding, unsigned size)
{
if (default_rate && ft->signal.rate == 0) {
sox_warn("'%s': sample rate not specified; trying 8kHz", ft->filename);
@@ -39,21 +41,27 @@
}
if (encoding != SOX_ENCODING_UNKNOWN) {
- if (ft->mode == 'r' &&
- ft->encoding.encoding != SOX_ENCODING_UNKNOWN &&
+ if (ft->mode == 'r' && ft->encoding.encoding != SOX_ENCODING_UNKNOWN &&
ft->encoding.encoding != encoding)
- sox_report("'%s': Format options overriding file-type encoding", ft->filename);
- else ft->encoding.encoding = encoding;
+ sox_report("'%s': Format options overriding file-type encoding",
+ ft->filename);
+ else
+ ft->encoding.encoding = encoding;
}
if (size != 0) {
- if (ft->mode == 'r' && ft->encoding.bits_per_sample != 0 && ft->encoding.bits_per_sample != size)
- sox_report("'%s': Format options overriding file-type sample-size", ft->filename);
- else ft->encoding.bits_per_sample = size;
+ if (ft->mode == 'r' && ft->encoding.bits_per_sample != 0 &&
+ ft->encoding.bits_per_sample != size)
+ sox_report("'%s': Format options overriding file-type sample-size",
+ ft->filename);
+ else
+ ft->encoding.bits_per_sample = size;
}
- if (!ft->signal.length && ft->mode == 'r' && default_length && ft->encoding.bits_per_sample)
- ft->signal.length = div_bits(lsx_filelength(ft), ft->encoding.bits_per_sample);
+ if (!ft->signal.length && ft->mode == 'r' && default_length &&
+ ft->encoding.bits_per_sample)
+ ft->signal.length =
+ div_bits(lsx_filelength(ft), ft->encoding.bits_per_sample);
return SOX_SUCCESS;
}
@@ -86,7 +94,7 @@
#define WRITE_SAMPLES_FUNC(type, size, sign, ctype, uctype, cast) \
static sox_size_t sox_write_ ## sign ## type ## _samples( \
- sox_format_t * ft, sox_sample_t *buf, sox_size_t len) \
+ sox_format_t * ft, sox_sample_t const * buf, sox_size_t len) \
{ \
sox_size_t n, nwritten; \
ctype *data = lsx_malloc(sizeof(ctype) * len); \
@@ -97,110 +105,88 @@
return nwritten; \
}
-WRITE_SAMPLES_FUNC(b, 1, u, uint8_t, uint8_t, SOX_SAMPLE_TO_UNSIGNED_8BIT)
+
+WRITE_SAMPLES_FUNC(b, 1, u, uint8_t, uint8_t, SOX_SAMPLE_TO_UNSIGNED_8BIT)
WRITE_SAMPLES_FUNC(b, 1, s, int8_t, uint8_t, SOX_SAMPLE_TO_SIGNED_8BIT)
-WRITE_SAMPLES_FUNC(b, 1, ulaw, uint8_t, uint8_t, SOX_SAMPLE_TO_ULAW_BYTE)
+WRITE_SAMPLES_FUNC(b, 1, ulaw, uint8_t, uint8_t, SOX_SAMPLE_TO_ULAW_BYTE)
WRITE_SAMPLES_FUNC(b, 1, alaw, uint8_t, uint8_t, SOX_SAMPLE_TO_ALAW_BYTE)
-WRITE_SAMPLES_FUNC(w, 2, u, uint16_t, uint16_t, SOX_SAMPLE_TO_UNSIGNED_16BIT)
+WRITE_SAMPLES_FUNC(w, 2, u, uint16_t, uint16_t, SOX_SAMPLE_TO_UNSIGNED_16BIT)
WRITE_SAMPLES_FUNC(w, 2, s, int16_t, uint16_t, SOX_SAMPLE_TO_SIGNED_16BIT)
-WRITE_SAMPLES_FUNC(3, 3, u, uint24_t, uint24_t, SOX_SAMPLE_TO_UNSIGNED_24BIT)
+WRITE_SAMPLES_FUNC(3, 3, u, uint24_t, uint24_t, SOX_SAMPLE_TO_UNSIGNED_24BIT)
WRITE_SAMPLES_FUNC(3, 3, s, int24_t, uint24_t, SOX_SAMPLE_TO_SIGNED_24BIT)
-WRITE_SAMPLES_FUNC(dw, 4, u, uint32_t, uint32_t, SOX_SAMPLE_TO_UNSIGNED_32BIT)
+WRITE_SAMPLES_FUNC(dw, 4, u, uint32_t, uint32_t, SOX_SAMPLE_TO_UNSIGNED_32BIT)
WRITE_SAMPLES_FUNC(dw, 4, s, int32_t, uint32_t, SOX_SAMPLE_TO_SIGNED_32BIT)
-WRITE_SAMPLES_FUNC(f, sizeof(float), su, float, float, SOX_SAMPLE_TO_FLOAT_32BIT)
-WRITE_SAMPLES_FUNC(df, sizeof(double), su, double, double, SOX_SAMPLE_TO_FLOAT_64BIT)
+WRITE_SAMPLES_FUNC(f, sizeof(float), su, float, float, SOX_SAMPLE_TO_FLOAT_32BIT)
+WRITE_SAMPLES_FUNC(df, sizeof (double), su, double, double, SOX_SAMPLE_TO_FLOAT_64BIT)
-typedef sox_size_t (ft_io_fun)(sox_format_t * ft, sox_sample_t *buf, sox_size_t len);
+#define GET_FORMAT(type) \
+static ft_##type##_fn * type##_fn(sox_format_t * ft) { \
+ switch (ft->encoding.bits_per_sample) { \
+ case 8: \
+ switch (ft->encoding.encoding) { \
+ case SOX_ENCODING_SIGN2: return sox_##type##_sb_samples; \
+ case SOX_ENCODING_UNSIGNED: return sox_##type##_ub_samples; \
+ case SOX_ENCODING_ULAW: return sox_##type##_ulawb_samples; \
+ case SOX_ENCODING_ALAW: return sox_##type##_alawb_samples; \
+ default: break; } \
+ break; \
+ case 16: \
+ switch (ft->encoding.encoding) { \
+ case SOX_ENCODING_SIGN2: return sox_##type##_sw_samples; \
+ case SOX_ENCODING_UNSIGNED: return sox_##type##_uw_samples; \
+ default: break; } \
+ break; \
+ case 24: \
+ switch (ft->encoding.encoding) { \
+ case SOX_ENCODING_SIGN2: return sox_##type##_s3_samples; \
+ case SOX_ENCODING_UNSIGNED: return sox_##type##_u3_samples; \
+ default: break; } \
+ break; \
+ case 32: \
+ switch (ft->encoding.encoding) { \
+ case SOX_ENCODING_SIGN2: return sox_##type##_sdw_samples; \
+ case SOX_ENCODING_UNSIGNED: return sox_##type##_udw_samples; \
+ case SOX_ENCODING_FLOAT: return sox_##type##_suf_samples; \
+ default: break; } \
+ break; \
+ case 64: \
+ switch (ft->encoding.encoding) { \
+ case SOX_ENCODING_FLOAT: return sox_##type##_sudf_samples; \
+ default: break; } \
+ break; \
+ default: \
+ lsx_fail_errno(ft, SOX_EFMT, "this handler does not support this data size"); \
+ return NULL; } \
+ lsx_fail_errno(ft, SOX_EFMT, "this encoding is not supported for this data size"); \
+ return NULL; }
-static ft_io_fun *check_format(sox_format_t * ft, sox_bool write)
-{
- switch (ft->encoding.bits_per_sample) {
- case 8:
- switch (ft->encoding.encoding) {
- case SOX_ENCODING_SIGN2:
- return write ? sox_write_sb_samples : sox_read_sb_samples;
- case SOX_ENCODING_UNSIGNED:
- return write ? sox_write_ub_samples : sox_read_ub_samples;
- case SOX_ENCODING_ULAW:
- return write ? sox_write_ulawb_samples : sox_read_ulawb_samples;
- case SOX_ENCODING_ALAW:
- return write ? sox_write_alawb_samples : sox_read_alawb_samples;
- default:
- break;
- }
- break;
+typedef sox_size_t(ft_read_fn)
+ (sox_format_t * ft, sox_sample_t * buf, sox_size_t len);
- case 16:
- switch (ft->encoding.encoding) {
- case SOX_ENCODING_SIGN2:
- return write ? sox_write_sw_samples : sox_read_sw_samples;
- case SOX_ENCODING_UNSIGNED:
- return write ? sox_write_uw_samples : sox_read_uw_samples;
- default:
- break;
- }
- break;
+GET_FORMAT(read)
- case 24:
- switch (ft->encoding.encoding) {
- case SOX_ENCODING_SIGN2:
- return write ? sox_write_s3_samples : sox_read_s3_samples;
- case SOX_ENCODING_UNSIGNED:
- return write ? sox_write_u3_samples: sox_read_u3_samples;
- default:
- break;
- }
- break;
-
- case 32:
- switch (ft->encoding.encoding) {
- case SOX_ENCODING_SIGN2:
- return write ? sox_write_sdw_samples : sox_read_sdw_samples;
- case SOX_ENCODING_UNSIGNED:
- return write ? sox_write_udw_samples : sox_read_udw_samples;
- case SOX_ENCODING_FLOAT:
- return write ? sox_write_suf_samples : sox_read_suf_samples;
- default:
- break;
- }
- break;
-
- case 64:
- switch (ft->encoding.encoding) {
- case SOX_ENCODING_FLOAT:
- return write ? sox_write_sudf_samples : sox_read_sudf_samples;
- default:
- break;
- }
- break;
-
- default:
- lsx_fail_errno(ft,SOX_EFMT,"this handler does not support this data size");
- return NULL;
- }
-
- lsx_fail_errno(ft,SOX_EFMT,"this encoding is not supported for this data size");
- return NULL;
-}
-
/* Read a stream of some type into SoX's internal buffer format. */
-sox_size_t lsx_rawread(sox_format_t * ft, sox_sample_t *buf, sox_size_t nsamp)
+sox_size_t lsx_rawread(sox_format_t * ft, sox_sample_t * buf, sox_size_t nsamp)
{
- ft_io_fun * read_buf = check_format(ft, sox_false);
+ ft_read_fn * read_buf = read_fn(ft);
- if (read_buf && nsamp)
- return read_buf(ft, buf, nsamp);
-
- return 0;
+ if (read_buf && nsamp)
+ return read_buf(ft, buf, nsamp);
+ return 0;
}
+typedef sox_size_t(ft_write_fn)
+ (sox_format_t * ft, sox_sample_t const * buf, sox_size_t len);
+
+GET_FORMAT(write)
+
/* Writes SoX's internal buffer format to buffer of various data types. */
-sox_size_t lsx_rawwrite(sox_format_t * ft, const sox_sample_t *buf, sox_size_t nsamp)
+sox_size_t lsx_rawwrite(
+ sox_format_t * ft, sox_sample_t const * buf, sox_size_t nsamp)
{
- ft_io_fun *write_buf = check_format(ft, sox_true);
+ ft_write_fn * write_buf = write_fn(ft);
- if (write_buf && nsamp)
- return write_buf(ft, (sox_sample_t *)buf, nsamp);
-
- return 0;
+ if (write_buf && nsamp)
+ return write_buf(ft, buf, nsamp);
+ return 0;
}
--- a/src/repeat.c
+++ b/src/repeat.c
@@ -101,7 +101,7 @@
buf = obuf;
samp = p->remaining;
- read = fread((char *) buf, sizeof(sox_sample_t), samp, p->tmp_file);
+ read = fread(buf, sizeof(sox_sample_t), samp, p->tmp_file);
if (read != samp) {
perror(strerror(errno));
sox_fail("read error on temporary file");
@@ -126,7 +126,7 @@
p->remaining = p->total - samp;
- read = fread((char *) buf, sizeof(sox_sample_t), samp, p->tmp_file);
+ read = fread(buf, sizeof(sox_sample_t), samp, p->tmp_file);
if (read != samp) {
perror(strerror(errno));
sox_fail("repeat2: read error on temporary " "file\n");
@@ -139,7 +139,7 @@
}
*osamp = done;
} else {
- read = fread((char *) obuf, sizeof(sox_sample_t), *osamp, p->tmp_file);
+ read = fread(obuf, sizeof(sox_sample_t), *osamp, p->tmp_file);
if (read != *osamp) {
perror(strerror(errno));
sox_fail("repeat3: read error on temporary file");
--- a/src/resample.c
+++ b/src/resample.c
@@ -213,7 +213,8 @@
/* Nwing: # of filter coeffs in right wing */
r->Nwing = r->Nq * (r->Nmult / 2 + 1) + 1;
- r->Imp = (double *) lsx_malloc(sizeof(double) * (r->Nwing + 2)) + 1;
+ r->Imp = lsx_malloc(sizeof(double) * (r->Nwing + 2));
+ ++r->Imp;
/* need Imp[-1] and Imp[Nwing] for quadratic interpolation */
/* returns error # <=0, or adjusted wing-len > 0 */
i = lsx_makeFilter(r->Imp, r->Nwing, r->rolloff, r->beta, r->Nq, 1);
@@ -258,7 +259,7 @@
r->Ysize = BUFFSIZE - r->Xsize;
sox_debug("Xsize %li, Ysize %li, Xoff %li", r->Xsize, r->Ysize, r->Xoff);
- r->X = (double *) lsx_malloc(sizeof(double) * (BUFFSIZE));
+ r->X = lsx_malloc(sizeof(double) * (BUFFSIZE));
r->Y = r->X + r->Xsize;
/* Need Xoff zeros at beginning of sample */
@@ -390,10 +391,10 @@
osamp_res = *osamp;
Obuf = obuf;
while (isamp_res>0 && osamp_res>0) {
- sox_sample_t Isamp, Osamp;
+ sox_size_t Isamp, Osamp;
Isamp = isamp_res;
Osamp = osamp_res;
- rc = flow(effp, NULL, Obuf, (sox_size_t *)&Isamp, (sox_size_t *)&Osamp);
+ rc = flow(effp, NULL, Obuf, &Isamp, &Osamp);
if (rc)
return rc;
sox_debug("DRAIN isamp,osamp (%li,%li) -> (%d,%d)",
@@ -601,7 +602,7 @@
if (Mwing==0)
return(-4);
- ImpR = (double *) lsx_malloc(sizeof(double) * Mwing);
+ ImpR = lsx_malloc(sizeof(double) * Mwing);
/* Design a Nuttall or Kaiser windowed Sinc low-pass filter */
LpFilter(ImpR, Mwing, Froll, Beta, Num);
--- a/src/silence.c
+++ b/src/silence.c
@@ -116,7 +116,7 @@
* parse the duration info yet. So save argument off
* for future processing.
*/
- silence->start_duration_str = (char *)lsx_malloc(strlen(argv[0])+1);
+ silence->start_duration_str = lsx_malloc(strlen(argv[0])+1);
strcpy(silence->start_duration_str,argv[0]);
/* Perform a fake parse to do error checking */
if (lsx_parsesamples(0.,silence->start_duration_str,
@@ -157,7 +157,7 @@
* parse the duration info yet. So save argument off
* for future processing.
*/
- silence->stop_duration_str = (char *)lsx_malloc(strlen(argv[0])+1);
+ silence->stop_duration_str = lsx_malloc(strlen(argv[0])+1);
strcpy(silence->stop_duration_str,argv[0]);
/* Perform a fake parse to do error checking */
if (lsx_parsesamples(0.,silence->stop_duration_str,
@@ -228,8 +228,7 @@
*/
silence->window_size = (effp->in_signal.rate / 50) *
effp->in_signal.channels;
- silence->window = (double *)lsx_malloc(silence->window_size *
- sizeof(double));
+ silence->window = lsx_malloc(silence->window_size * sizeof(double));
clear_rms(effp);
@@ -252,12 +251,12 @@
else
silence->mode = SILENCE_COPY;
- silence->start_holdoff = (sox_sample_t *)lsx_malloc(sizeof(sox_sample_t)*silence->start_duration);
+ silence->start_holdoff = lsx_malloc(sizeof(sox_sample_t)*silence->start_duration);
silence->start_holdoff_offset = 0;
silence->start_holdoff_end = 0;
silence->start_found_periods = 0;
- silence->stop_holdoff = (sox_sample_t *)lsx_malloc(sizeof(sox_sample_t)*silence->stop_duration);
+ silence->stop_holdoff = lsx_malloc(sizeof(sox_sample_t)*silence->stop_duration);
silence->stop_holdoff_offset = 0;
silence->stop_holdoff_end = 0;
silence->stop_found_periods = 0;
--- a/src/smp.c
+++ b/src/smp.c
@@ -51,7 +51,7 @@
struct smptrailer {
struct loop loops[8]; /* loops */
struct marker markers[8]; /* markers */
- char MIDInote; /* for unity pitch playback */
+ int8_t MIDInote; /* for unity pitch playback */
uint32_t rate; /* in hertz */
uint32_t SMPTEoffset; /* in subframes - huh? */
uint32_t CycleSize; /* sample count in one cycle of the */
@@ -75,9 +75,9 @@
static int readtrailer(sox_format_t * ft, struct smptrailer *trailer)
{
int i;
- int16_t trash16;
+ uint16_t trash16;
- lsx_readw(ft, (unsigned short *)&trash16); /* read reserved word */
+ lsx_readw(ft, &trash16); /* read reserved word */
for(i = 0; i < 8; i++) { /* read the 8 loops */
lsx_readdw(ft, &(trailer->loops[i].start));
ft->oob.loops[i].start = trailer->loops[i].start;
@@ -84,9 +84,9 @@
lsx_readdw(ft, &(trailer->loops[i].end));
ft->oob.loops[i].length =
trailer->loops[i].end - trailer->loops[i].start;
- lsx_readb(ft, (unsigned char *)&(trailer->loops[i].type));
+ lsx_readb(ft, &(trailer->loops[i].type));
ft->oob.loops[i].type = trailer->loops[i].type;
- lsx_readw(ft, (unsigned short *)&(trailer->loops[i].count));
+ lsx_readw(ft, &(trailer->loops[i].count));
ft->oob.loops[i].count = trailer->loops[i].count;
}
for(i = 0; i < 8; i++) { /* read the 8 markers */
@@ -98,7 +98,7 @@
trailer->markers[i].name[MARKERLEN] = 0;
lsx_readdw(ft, &(trailer->markers[i].position));
}
- lsx_readb(ft, (unsigned char *)&(trailer->MIDInote));
+ lsx_readsb(ft, &(trailer->MIDInote));
lsx_readdw(ft, &(trailer->rate));
lsx_readdw(ft, &(trailer->SMPTEoffset));
lsx_readdw(ft, &(trailer->CycleSize));
@@ -215,7 +215,7 @@
}
/* Read SampleVision header */
- if (lsx_readbuf(ft, (char *)&header, HEADERSIZE) != HEADERSIZE)
+ if (lsx_readbuf(ft, &header, HEADERSIZE) != HEADERSIZE)
{
lsx_fail_errno(ft,SOX_EHDR,"unexpected EOF in SMP header");
return(SOX_EOF);
--- a/src/sndfile.c
+++ b/src/sndfile.c
@@ -210,7 +210,7 @@
priv_t * sf = (priv_t *)ft->priv;
int subtype = ft_enc(ft->encoding.bits_per_sample? ft->encoding.bits_per_sample : ft->signal.precision, ft->encoding.encoding);
sf->log_buffer_ptr = sf->log_buffer = lsx_malloc(LOG_MAX);
- sf->sf_info = (SF_INFO *)lsx_calloc(1, sizeof(SF_INFO));
+ sf->sf_info = lsx_calloc(1, sizeof(SF_INFO));
/* Copy format info */
if (subtype) {
--- a/src/sox.h
+++ b/src/sox.h
@@ -1,6 +1,6 @@
/* libSoX Library Public Interface
*
- * Copyright 1999-2007 Chris Bagwell and SoX Contributors.
+ * Copyright 1999-2008 Chris Bagwell and SoX Contributors.
*
* This source code is freely redistributable and may be used for
* any purpose. This copyright notice must be maintained.
@@ -166,9 +166,9 @@
#include <stddef.h>
-typedef size_t sox_size_t;
-#define SOX_SIZE_MAX (sox_size_t)(-1)
-typedef ptrdiff_t sox_ssize_t;
+#define sox_size_t size_t
+#define SOX_SIZE_MAX (sox_size_t)(-sizeof(char))
+#define sox_ssize_t ptrdiff_t
typedef void (*sox_output_message_handler_t)(unsigned level, const char *filename, const char *fmt, va_list ap);
@@ -284,8 +284,8 @@
/* vague attempt at generic information for sampler-specific info */
typedef struct {
- char MIDInote; /* for unity pitch playback */
- char MIDIlow, MIDIhi;/* MIDI pitch-bend range */
+ int8_t MIDInote; /* for unity pitch playback */
+ int8_t MIDIlow, MIDIhi;/* MIDI pitch-bend range */
char loopmode; /* semantics of loop data */
unsigned nloops; /* number of active loops (max SOX_MAX_NLOOPS) */
} sox_instrinfo_t;
--- a/src/sox_i.h
+++ b/src/sox_i.h
@@ -100,14 +100,20 @@
int lsx_readf(sox_format_t * ft, float * f);
int lsx_readw(sox_format_t * ft, uint16_t * uw);
+UNUSED static int lsx_readsb(sox_format_t * ft, int8_t * sb)
+ {return lsx_readb(ft, (uint8_t *)sb);}
+UNUSED static int lsx_readsw(sox_format_t * ft, int16_t * sw)
+ {return lsx_readw(ft, (uint16_t *)sw);}
+
int lsx_write3(sox_format_t * ft, unsigned u3);
int lsx_writeb(sox_format_t * ft, unsigned ub);
int lsx_writedf(sox_format_t * ft, double d);
int lsx_writedw(sox_format_t * ft, unsigned udw);
int lsx_writef(sox_format_t * ft, double f);
+int lsx_writew(sox_format_t * ft, unsigned uw);
+
int lsx_writesb(sox_format_t * ft, signed);
int lsx_writesw(sox_format_t * ft, signed);
-int lsx_writew(sox_format_t * ft, unsigned uw);
int lsx_eof(sox_format_t * ft);
int lsx_error(sox_format_t * ft);
--- a/src/stat.c
+++ b/src/stat.c
@@ -104,8 +104,8 @@
if (stat->fft) {
stat->fft_offset = 0;
- stat->re_in = (float *)lsx_malloc(sizeof(float) * stat->fft_size);
- stat->re_out = (float *)lsx_malloc(sizeof(float) * (stat->fft_size / 2));
+ stat->re_in = lsx_malloc(sizeof(float) * stat->fft_size);
+ stat->re_out = lsx_malloc(sizeof(float) * (stat->fft_size / 2));
}
return SOX_SUCCESS;
--- a/src/stretch.c
+++ b/src/stretch.c
@@ -151,7 +151,7 @@
stretch->size = (int)(effp->out_signal.rate * 0.001 * stretch->window);
/* start in the middle of an input to avoid initial fading... */
stretch->index = stretch->size / 2;
- stretch->ibuf = (sox_sample_t *)lsx_malloc(stretch->size * sizeof(sox_sample_t));
+ stretch->ibuf = lsx_malloc(stretch->size * sizeof(sox_sample_t));
/* the shift ratio deal with the longest of ishift/oshift
hence ishift<=size and oshift<=size. */
@@ -166,9 +166,9 @@
assert(stretch->oshift <= stretch->size);
stretch->oindex = stretch->index; /* start as synchronized */
- stretch->obuf = (double *)lsx_malloc(stretch->size * sizeof(double));
+ stretch->obuf = lsx_malloc(stretch->size * sizeof(double));
stretch->fsize = (int)(stretch->fading * stretch->size);
- stretch->fbuf = (double *)lsx_malloc(stretch->fsize * sizeof(double));
+ stretch->fbuf = lsx_malloc(stretch->fsize * sizeof(double));
/* initialize buffers */
for (i = 0; i<stretch->size; i++)
--- a/src/trim.c
+++ b/src/trim.c
@@ -35,13 +35,13 @@
*/
switch (n) {
case 2:
- trim->length_str = (char *)lsx_malloc(strlen(argv[1])+1);
+ trim->length_str = lsx_malloc(strlen(argv[1])+1);
strcpy(trim->length_str,argv[1]);
/* Do a dummy parse to see if it will fail */
if (lsx_parsesamples(0., trim->length_str, &trim->length, 't') == NULL)
return lsx_usage(effp);
case 1:
- trim->start_str = (char *)lsx_malloc(strlen(argv[0])+1);
+ trim->start_str = lsx_malloc(strlen(argv[0])+1);
strcpy(trim->start_str,argv[0]);
/* Do a dummy parse to see if it will fail */
if (lsx_parsesamples(0., trim->start_str, &trim->start, 't') == NULL)
--- a/src/tx16w.c
+++ b/src/tx16w.c
@@ -74,12 +74,12 @@
{
int c;
char filetype[7];
- char format;
- char sample_rate;
+ int8_t format;
+ unsigned char sample_rate;
sox_size_t num_samp_bytes = 0;
- char gunk[8];
+ unsigned char gunk[8];
int blewIt;
- uint32_t trash;
+ uint8_t trash;
priv_t * sk = (priv_t *) ft->priv;
/* If you need to seek around the input file. */
@@ -90,7 +90,7 @@
}
/* This is dumb but portable, just count the bytes til EOF */
- while (lsx_read_b_buf(ft, (unsigned char *)&trash, 1) == 1)
+ while (lsx_read_b_buf(ft, &trash, 1) == 1)
num_samp_bytes++;
num_samp_bytes -= 32; /* calculate num samples by sub header size */
lsx_seeki(ft, 0, 0); /* rewind file */
@@ -97,23 +97,18 @@
sk->rest = num_samp_bytes; /* set how many sample bytes to read */
/* first 6 bytes are file type ID LM8953 */
- lsx_readb(ft, (unsigned char *)&filetype[0]);
- lsx_readb(ft, (unsigned char *)&filetype[1]);
- lsx_readb(ft, (unsigned char *)&filetype[2]);
- lsx_readb(ft, (unsigned char *)&filetype[3]);
- lsx_readb(ft, (unsigned char *)&filetype[4]);
- lsx_readb(ft, (unsigned char *)&filetype[5]);
+ lsx_readchars(ft, filetype, sizeof(filetype) - 1);
filetype[6] = '\0';
for( c = 16; c > 0 ; c-- ) /* Discard next 16 bytes */
- lsx_readb(ft, (unsigned char *)&trash);
- lsx_readb(ft, (unsigned char *)&format);
- lsx_readb(ft, (unsigned char *)&sample_rate);
+ lsx_readb(ft, &trash);
+ lsx_readsb(ft, &format);
+ lsx_readb(ft, &sample_rate);
/*
* save next 8 bytes - if sample rate is 0, then we need
* to look at gunk[2] and gunk[5] to get real rate
*/
for( c = 0; c < 8; c++ )
- lsx_readb(ft, (unsigned char *)&(gunk[c]));
+ lsx_readb(ft, &(gunk[c]));
/*
* We should now be pointing at start of raw sample data in file
*/
@@ -162,7 +157,7 @@
break;
}
if ( blewIt ) {
- sox_debug("Invalid sample rate identifier found %d", (int)sample_rate);
+ sox_debug("Invalid sample rate identifier found %d", sample_rate);
ft->signal.rate = 1e5 / 3;
}
}
--- a/src/voc.c
+++ b/src/voc.c
@@ -418,7 +418,7 @@
}
break;
case 16:
- lsx_readw(ft, (unsigned short *) &sw);
+ lsx_readsw(ft, &sw);
if (lsx_eof(ft)) {
sox_warn("VOC input: short file");
v->block_remaining = 0;
@@ -555,8 +555,6 @@
uint24_t sblen;
uint16_t new_rate_16;
uint32_t new_rate_32;
- uint32_t i;
- uint32_t trash;
v->silent = 0;
/* DO while we have no audio to read */
@@ -619,10 +617,7 @@
v->size = uc;
lsx_readb(ft, &(v->channels));
lsx_readw(ft, &(v->format)); /* ANN: added format */
- lsx_readb(ft, (unsigned char *) &trash); /* notused */
- lsx_readb(ft, (unsigned char *) &trash); /* notused */
- lsx_readb(ft, (unsigned char *) &trash); /* notused */
- lsx_readb(ft, (unsigned char *) &trash); /* notused */
+ lsx_skipbytes(ft, 4);
v->block_remaining = sblen - 12;
return (SOX_SUCCESS);
case VOC_CONT:
@@ -658,12 +653,12 @@
case VOC_TEXT:
{
uint32_t i = sblen;
- char c /*, line_buf[80];
+ int8_t c /*, line_buf[80];
* int len = 0 */ ;
sox_warn("VOC TEXT");
while (i--) {
- lsx_readb(ft, (unsigned char *) &c);
+ lsx_readsb(ft, &c);
/* FIXME: this needs to be tested but I couldn't
* find a voc file with a VOC_TEXT chunk :(
if (c != '\0' && c != '\r')
@@ -682,8 +677,7 @@
case VOC_LOOP:
case VOC_LOOPEND:
sox_debug("skipping repeat loop");
- for (i = 0; i < sblen; i++)
- lsx_readb(ft, (unsigned char *) &trash);
+ lsx_skipbytes(ft, sblen);
break;
case VOC_EXTENDED:
/* An Extended block is followed by a data block */
@@ -714,8 +708,7 @@
continue;
default:
sox_debug("skipping unknown block code %d", block);
- for (i = 0; i < sblen; i++)
- lsx_readb(ft, (unsigned char *) &trash);
+ lsx_skipbytes(ft, sblen);
}
}
return SOX_SUCCESS;
--- a/src/vorbis.c
+++ b/src/vorbis.c
@@ -101,10 +101,10 @@
};
/* Allocate space for decoding structure */
- vb->vf = (OggVorbis_File *) lsx_malloc(sizeof(OggVorbis_File));
+ vb->vf = lsx_malloc(sizeof(OggVorbis_File));
/* Init the decoder */
- if (ov_open_callbacks((void *) ft->fp, vb->vf, NULL, 0, callbacks) < 0) {
+ if (ov_open_callbacks(ft->fp, vb->vf, NULL, 0, callbacks) < 0) {
lsx_fail_errno(ft, SOX_EHDR, "Input not an Ogg Vorbis audio stream");
return (SOX_EOF);
}
@@ -281,7 +281,7 @@
ft->encoding.encoding = SOX_ENCODING_VORBIS;
/* Allocate memory for all of the structures */
- ve = vb->vorbis_enc_data = (vorbis_enc_t *) lsx_malloc(sizeof(vorbis_enc_t));
+ ve = vb->vorbis_enc_data = lsx_malloc(sizeof(vorbis_enc_t));
vorbis_info_init(&ve->vi);
--- a/src/wav.c
+++ b/src/wav.c
@@ -165,7 +165,7 @@
errmsg = lsx_ms_adpcm_block_expand_i(ft->signal.channels, wav->nCoefs, wav->lsx_ms_adpcm_i_coefs, wav->packet, wav->samples, samplesThisBlock);
if (errmsg)
- sox_warn((char*)errmsg);
+ sox_warn(errmsg);
return samplesThisBlock;
}
@@ -230,7 +230,7 @@
return (SOX_EOF);
}
- wav->gsmsample=(gsm_signal*)lsx_malloc(sizeof(gsm_signal)*160*2);
+ wav->gsmsample=lsx_malloc(sizeof(gsm_signal)*160*2);
wav->gsmindex=0;
return (SOX_SUCCESS);
}
@@ -657,7 +657,7 @@
lsx_fail_errno(ft,SOX_EOF,"ADPCM file nCoefs (%.4hx) makes no sense", wav->nCoefs);
return SOX_EOF;
}
- wav->packet = (unsigned char *)lsx_malloc(wav->blockAlign);
+ wav->packet = lsx_malloc(wav->blockAlign);
len -= 4;
@@ -667,14 +667,14 @@
return SOX_EOF;
}
- wav->samples = (short *)lsx_malloc(wChannels*wav->samplesPerBlock*sizeof(short));
+ wav->samples = lsx_malloc(wChannels*wav->samplesPerBlock*sizeof(short));
/* nCoefs, lsx_ms_adpcm_i_coefs used by adpcm.c */
- wav->lsx_ms_adpcm_i_coefs = (short *)lsx_malloc(wav->nCoefs * 2 * sizeof(short));
+ wav->lsx_ms_adpcm_i_coefs = lsx_malloc(wav->nCoefs * 2 * sizeof(short));
{
int i, errct=0;
for (i=0; len>=2 && i < 2*wav->nCoefs; i++) {
- lsx_readw(ft, (unsigned short *)&(wav->lsx_ms_adpcm_i_coefs[i]));
+ lsx_readsw(ft, &(wav->lsx_ms_adpcm_i_coefs[i]));
len -= 2;
if (i<14) errct += (wav->lsx_ms_adpcm_i_coefs[i] != lsx_ms_adpcm_i_coef[i/2][i%2]);
/* sox_debug("lsx_ms_adpcm_i_coefs[%2d] %4d",i,wav->lsx_ms_adpcm_i_coefs[i]); */
@@ -708,10 +708,10 @@
return SOX_EOF;
}
- wav->packet = (unsigned char *)lsx_malloc(wav->blockAlign);
+ wav->packet = lsx_malloc(wav->blockAlign);
len -= 2;
- wav->samples = (short *)lsx_malloc(wChannels*wav->samplesPerBlock*sizeof(short));
+ wav->samples = lsx_malloc(wChannels*wav->samplesPerBlock*sizeof(short));
bytespersample = 2; /* AFTER de-compression */
break;
@@ -863,7 +863,7 @@
if (lsx_seeki(ft, (sox_ssize_t)len, SEEK_CUR) == SOX_SUCCESS &&
findChunk(ft, "LIST", &len) != SOX_EOF)
{
- wav->comment = (char*)lsx_malloc(256);
+ wav->comment = lsx_malloc(256);
/* Initialize comment to a NULL string */
wav->comment[0] = 0;
while(!lsx_eof(ft))
@@ -1128,8 +1128,8 @@
for (ch=0; ch<ft->signal.channels; ch++)
wav->state[ch] = 0;
sbsize = ft->signal.channels * wav->samplesPerBlock;
- wav->packet = (unsigned char *)lsx_malloc(wav->blockAlign);
- wav->samples = (short *)lsx_malloc(sbsize*sizeof(short));
+ wav->packet = lsx_malloc(wav->blockAlign);
+ wav->samples = lsx_malloc(sbsize*sizeof(short));
wav->sampleTop = wav->samples + sbsize;
wav->samplePtr = wav->samples;
break;
--- a/src/xa.c
+++ b/src/xa.c
@@ -172,10 +172,10 @@
xa->bufPos = xa->blockSize;
/* Allocate memory for the block buffer */
- xa->buf = (unsigned char *)lsx_calloc(1, xa->blockSize);
+ xa->buf = lsx_calloc(1, xa->blockSize);
/* Allocate memory for the state */
- xa->state = (xa_state_t *)lsx_calloc(sizeof(xa_state_t), ft->signal.channels);
+ xa->state = lsx_calloc(sizeof(xa_state_t), ft->signal.channels);
/* Final initialization */
xa->bytesDecoded = 0;
--- a/src/xmalloc.h
+++ b/src/xmalloc.h
@@ -23,7 +23,7 @@
#include <stddef.h>
#include <string.h>
-void * lsx_realloc(void *ptr, size_t newsize);
+void * lsx_realloc(void * ptr, size_t newsize);
#define lsx_malloc(size) lsx_realloc(NULL, (size))
#define lsx_calloc(n,s) ((n)*(s)? memset(lsx_malloc((n)*(s)),0,(n)*(s)) : NULL)
#define lsx_strdup(p) ((p)? strcpy((char *)lsx_malloc(strlen(p) + 1), p) : NULL)