mirror of
https://gitee.com/openharmony/third_party_libsnd
synced 2024-11-27 03:50:29 +00:00
Remove the buffer union from SF_PRIVATE.
This commit is contained in:
parent
7588ad5a55
commit
b5c45de7bc
@ -1,4 +1,10 @@
|
||||
2012-01-26 Erik de Castro Lopo <erikd AT mega-nerd DOT com>
|
||||
2012-02-01 Erik de Castro Lopo <erikd AT mega-nerd DOT com>
|
||||
|
||||
* src/common.h src*.c
|
||||
Remove the buffer union from SF_PRIVATE. Most uses of this have been
|
||||
replaced with a BUF_UNION that is allocated on the stack.
|
||||
|
||||
2012-01-31 Erik de Castro Lopo <erikd AT mega-nerd DOT com>
|
||||
|
||||
* src/common.h src*.c
|
||||
Rename logbuffer field of SF_PRIVATE to parselog and reduce its size.
|
||||
|
64
src/aiff.c
64
src/aiff.c
@ -381,6 +381,7 @@ static int
|
||||
aiff_read_header (SF_PRIVATE *psf, COMM_CHUNK *comm_fmt)
|
||||
{ SSND_CHUNK ssnd_fmt ;
|
||||
AIFF_PRIVATE *paiff ;
|
||||
BUF_UNION ubuf ;
|
||||
unsigned marker, chunk_size, dword, FORMsize, SSNDsize, bytesread ;
|
||||
int k, found_chunk = 0, done = 0, error = 0 ;
|
||||
char *cptr ;
|
||||
@ -489,7 +490,7 @@ aiff_read_header (SF_PRIVATE *psf, COMM_CHUNK *comm_fmt)
|
||||
psf_log_printf (psf, " time stamp : %d\n", psf->peak_info->timestamp) ;
|
||||
psf_log_printf (psf, " Ch Position Value\n") ;
|
||||
|
||||
cptr = psf->u.cbuf ;
|
||||
cptr = ubuf.cbuf ;
|
||||
for (dword = 0 ; dword < (unsigned) psf->sf.channels ; dword++)
|
||||
{ float value ;
|
||||
unsigned int position ;
|
||||
@ -498,9 +499,9 @@ aiff_read_header (SF_PRIVATE *psf, COMM_CHUNK *comm_fmt)
|
||||
psf->peak_info->peaks [dword].value = value ;
|
||||
psf->peak_info->peaks [dword].position = position ;
|
||||
|
||||
snprintf (cptr, sizeof (psf->u.scbuf), " %2d %-12" PRId64 " %g\n",
|
||||
snprintf (cptr, sizeof (ubuf.scbuf), " %2d %-12" PRId64 " %g\n",
|
||||
dword, psf->peak_info->peaks [dword].position, psf->peak_info->peaks [dword].value) ;
|
||||
cptr [sizeof (psf->u.scbuf) - 1] = 0 ;
|
||||
cptr [sizeof (ubuf.scbuf) - 1] = 0 ;
|
||||
psf_log_printf (psf, "%s", cptr) ;
|
||||
} ;
|
||||
|
||||
@ -556,12 +557,12 @@ aiff_read_header (SF_PRIVATE *psf, COMM_CHUNK *comm_fmt)
|
||||
dword = chunk_size ;
|
||||
if (dword == 0)
|
||||
break ;
|
||||
if (dword >= SIGNED_SIZEOF (psf->u.scbuf))
|
||||
if (dword >= SIGNED_SIZEOF (ubuf.scbuf))
|
||||
{ psf_log_printf (psf, " %M : %d (too big)\n", marker, dword) ;
|
||||
return SFE_INTERNAL ;
|
||||
} ;
|
||||
|
||||
cptr = psf->u.cbuf ;
|
||||
cptr = ubuf.cbuf ;
|
||||
psf_binheader_readf (psf, "b", cptr, dword + (dword & 1)) ;
|
||||
cptr [dword] = 0 ;
|
||||
|
||||
@ -575,12 +576,12 @@ aiff_read_header (SF_PRIVATE *psf, COMM_CHUNK *comm_fmt)
|
||||
dword = chunk_size ;
|
||||
if (dword == 0)
|
||||
break ;
|
||||
if (dword >= SIGNED_SIZEOF (psf->u.scbuf) - 1)
|
||||
if (dword >= SIGNED_SIZEOF (ubuf.scbuf) - 1)
|
||||
{ psf_log_printf (psf, " %M : %d (too big)\n", marker, dword) ;
|
||||
return SFE_INTERNAL ;
|
||||
} ;
|
||||
|
||||
cptr = psf->u.cbuf ;
|
||||
cptr = ubuf.cbuf ;
|
||||
psf_binheader_readf (psf, "b", cptr, dword + (dword & 1)) ;
|
||||
cptr [dword] = 0 ;
|
||||
psf_log_printf (psf, " %M : %s\n", marker, cptr) ;
|
||||
@ -603,12 +604,12 @@ aiff_read_header (SF_PRIVATE *psf, COMM_CHUNK *comm_fmt)
|
||||
{ dword -= psf_binheader_readf (psf, "E422", ×tamp, &id, &len) ;
|
||||
psf_log_printf (psf, " time : 0x%x\n marker : %x\n length : %d\n", timestamp, id, len) ;
|
||||
|
||||
if (len + 1 > SIGNED_SIZEOF (psf->u.scbuf))
|
||||
if (len + 1 > SIGNED_SIZEOF (ubuf.scbuf))
|
||||
{ psf_log_printf (psf, "\nError : string length (%d) too big.\n", len) ;
|
||||
return SFE_INTERNAL ;
|
||||
} ;
|
||||
|
||||
cptr = psf->u.cbuf ;
|
||||
cptr = ubuf.cbuf ;
|
||||
dword -= psf_binheader_readf (psf, "b", cptr, len) ;
|
||||
cptr [len] = 0 ;
|
||||
psf_log_printf (psf, " string : %s\n", cptr) ;
|
||||
@ -625,7 +626,7 @@ aiff_read_header (SF_PRIVATE *psf, COMM_CHUNK *comm_fmt)
|
||||
dword = chunk_size ;
|
||||
if (dword == 0)
|
||||
break ;
|
||||
if (dword >= SIGNED_SIZEOF (psf->u.scbuf) - 1)
|
||||
if (dword >= SIGNED_SIZEOF (ubuf.scbuf) - 1)
|
||||
{ psf_log_printf (psf, " %M : %d (too big, skipping)\n", marker, dword) ;
|
||||
psf_binheader_readf (psf, "j", dword + (dword & 1)) ;
|
||||
break ;
|
||||
@ -637,7 +638,7 @@ aiff_read_header (SF_PRIVATE *psf, COMM_CHUNK *comm_fmt)
|
||||
break ;
|
||||
} ;
|
||||
|
||||
cptr = psf->u.cbuf ;
|
||||
cptr = ubuf.cbuf ;
|
||||
psf_binheader_readf (psf, "mb", &appl_marker, cptr, dword + (dword & 1) - 4) ;
|
||||
cptr [dword] = 0 ;
|
||||
|
||||
@ -656,12 +657,12 @@ aiff_read_header (SF_PRIVATE *psf, COMM_CHUNK *comm_fmt)
|
||||
dword = chunk_size ;
|
||||
if (dword == 0)
|
||||
break ;
|
||||
if (dword >= SIGNED_SIZEOF (psf->u.scbuf) - 2)
|
||||
if (dword >= SIGNED_SIZEOF (ubuf.scbuf) - 2)
|
||||
{ psf_log_printf (psf, " %M : %d (too big)\n", marker, dword) ;
|
||||
return SFE_INTERNAL ;
|
||||
} ;
|
||||
|
||||
cptr = psf->u.cbuf ;
|
||||
cptr = ubuf.cbuf ;
|
||||
psf_binheader_readf (psf, "b", cptr, dword + (dword & 1)) ;
|
||||
cptr [dword] = 0 ;
|
||||
psf_log_printf (psf, " %M : %s\n", marker, cptr) ;
|
||||
@ -672,12 +673,12 @@ aiff_read_header (SF_PRIVATE *psf, COMM_CHUNK *comm_fmt)
|
||||
dword = chunk_size ;
|
||||
if (dword == 0)
|
||||
break ;
|
||||
if (dword >= SIGNED_SIZEOF (psf->u.scbuf) - 2)
|
||||
if (dword >= SIGNED_SIZEOF (ubuf.scbuf) - 2)
|
||||
{ psf_log_printf (psf, " %M : %d (too big)\n", marker, dword) ;
|
||||
return SFE_INTERNAL ;
|
||||
} ;
|
||||
|
||||
cptr = psf->u.cbuf ;
|
||||
cptr = ubuf.cbuf ;
|
||||
psf_binheader_readf (psf, "b", cptr, dword + (dword & 1)) ;
|
||||
cptr [dword] = 0 ;
|
||||
psf_log_printf (psf, " %M : %s\n", marker, cptr) ;
|
||||
@ -785,22 +786,22 @@ aiff_read_header (SF_PRIVATE *psf, COMM_CHUNK *comm_fmt)
|
||||
|
||||
pstr_len = (ch & 1) ? ch : ch + 1 ;
|
||||
|
||||
if (pstr_len < sizeof (psf->u.scbuf) - 1)
|
||||
{ bytesread += psf_binheader_readf (psf, "b", psf->u.scbuf, pstr_len) ;
|
||||
psf->u.scbuf [pstr_len] = 0 ;
|
||||
if (pstr_len < sizeof (ubuf.scbuf) - 1)
|
||||
{ bytesread += psf_binheader_readf (psf, "b", ubuf.scbuf, pstr_len) ;
|
||||
ubuf.scbuf [pstr_len] = 0 ;
|
||||
}
|
||||
else
|
||||
{ unsigned int read_len = pstr_len - (sizeof (psf->u.scbuf) - 1) ;
|
||||
bytesread += psf_binheader_readf (psf, "bj", psf->u.scbuf, read_len, pstr_len - read_len) ;
|
||||
psf->u.scbuf [sizeof (psf->u.scbuf) - 1] = 0 ;
|
||||
{ unsigned int read_len = pstr_len - (sizeof (ubuf.scbuf) - 1) ;
|
||||
bytesread += psf_binheader_readf (psf, "bj", ubuf.scbuf, read_len, pstr_len - read_len) ;
|
||||
ubuf.scbuf [sizeof (ubuf.scbuf) - 1] = 0 ;
|
||||
}
|
||||
|
||||
psf_log_printf (psf, " Name : %s\n", psf->u.scbuf) ;
|
||||
psf_log_printf (psf, " Name : %s\n", ubuf.scbuf) ;
|
||||
|
||||
paiff->markstr [n].markerID = mark_id ;
|
||||
paiff->markstr [n].position = position ;
|
||||
/*
|
||||
** TODO if psf->u.scbuf is equal to
|
||||
** TODO if ubuf.scbuf is equal to
|
||||
** either Beg_loop, Beg loop or beg loop and spam
|
||||
** if (psf->instrument == NULL && (psf->instrument = psf_instrument_alloc ()) == NULL)
|
||||
** return SFE_MALLOC_FAILED ;
|
||||
@ -919,9 +920,10 @@ aiff_close (SF_PRIVATE *psf)
|
||||
|
||||
static int
|
||||
aiff_read_comm_chunk (SF_PRIVATE *psf, COMM_CHUNK *comm_fmt)
|
||||
{ int error = 0, subformat ;
|
||||
{ BUF_UNION ubuf ;
|
||||
int error = 0, subformat ;
|
||||
|
||||
psf->u.scbuf [0] = 0 ;
|
||||
ubuf.scbuf [0] = 0 ;
|
||||
|
||||
/* The COMM chunk has an int aligned to an odd word boundary. Some
|
||||
** procesors are not able to deal with this (ie bus fault) so we have
|
||||
@ -950,11 +952,11 @@ aiff_read_comm_chunk (SF_PRIVATE *psf, COMM_CHUNK *comm_fmt)
|
||||
|
||||
psf_binheader_readf (psf, "Em1", &(comm_fmt->encoding), &encoding_len) ;
|
||||
|
||||
comm_fmt->size = SF_MIN (sizeof (psf->u.scbuf), make_size_t (comm_fmt->size)) ;
|
||||
memset (psf->u.scbuf, 0, comm_fmt->size) ;
|
||||
comm_fmt->size = SF_MIN (sizeof (ubuf.scbuf), make_size_t (comm_fmt->size)) ;
|
||||
memset (ubuf.scbuf, 0, comm_fmt->size) ;
|
||||
read_len = comm_fmt->size - SIZEOF_AIFC_COMM + 1 ;
|
||||
psf_binheader_readf (psf, "b", psf->u.scbuf, read_len) ;
|
||||
psf->u.scbuf [read_len + 1] = 0 ;
|
||||
psf_binheader_readf (psf, "b", ubuf.scbuf, read_len) ;
|
||||
ubuf.scbuf [read_len + 1] = 0 ;
|
||||
} ;
|
||||
|
||||
psf_log_printf (psf, " Sample Rate : %d\n", tenbytefloat2int (comm_fmt->sampleRate)) ;
|
||||
@ -1054,10 +1056,10 @@ aiff_read_comm_chunk (SF_PRIVATE *psf, COMM_CHUNK *comm_fmt)
|
||||
error = SFE_UNIMPLEMENTED ;
|
||||
} ;
|
||||
|
||||
if (! psf->u.scbuf [0])
|
||||
if (! ubuf.scbuf [0])
|
||||
psf_log_printf (psf, " Encoding : %M\n", comm_fmt->encoding) ;
|
||||
else
|
||||
psf_log_printf (psf, " Encoding : %M => %s\n", comm_fmt->encoding, psf->u.scbuf) ;
|
||||
psf_log_printf (psf, " Encoding : %M => %s\n", comm_fmt->encoding, ubuf.scbuf) ;
|
||||
|
||||
return error ;
|
||||
} /* aiff_read_comm_chunk */
|
||||
|
74
src/alaw.c
74
src/alaw.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** Copyright (C) 1999-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
|
||||
** Copyright (C) 1999-2012 Erik de Castro Lopo <erikd@mega-nerd.com>
|
||||
**
|
||||
** This program is free software; you can redistribute it and/or modify
|
||||
** it under the terms of the GNU Lesser General Public License as published by
|
||||
@ -358,16 +358,17 @@ d2alaw_array (const double *ptr, int count, unsigned char *buffer, double normfa
|
||||
|
||||
static sf_count_t
|
||||
alaw_read_alaw2s (SF_PRIVATE *psf, short *ptr, sf_count_t len)
|
||||
{ int bufferlen, readcount ;
|
||||
{ BUF_UNION ubuf ;
|
||||
int bufferlen, readcount ;
|
||||
sf_count_t total = 0 ;
|
||||
|
||||
bufferlen = ARRAY_LEN (psf->u.ucbuf) ;
|
||||
bufferlen = ARRAY_LEN (ubuf.ucbuf) ;
|
||||
|
||||
while (len > 0)
|
||||
{ if (len < bufferlen)
|
||||
bufferlen = (int) len ;
|
||||
readcount = psf_fread (psf->u.ucbuf, 1, bufferlen, psf) ;
|
||||
alaw2s_array (psf->u.ucbuf, readcount, ptr + total) ;
|
||||
readcount = psf_fread (ubuf.ucbuf, 1, bufferlen, psf) ;
|
||||
alaw2s_array (ubuf.ucbuf, readcount, ptr + total) ;
|
||||
total += readcount ;
|
||||
if (readcount < bufferlen)
|
||||
break ;
|
||||
@ -379,16 +380,17 @@ alaw_read_alaw2s (SF_PRIVATE *psf, short *ptr, sf_count_t len)
|
||||
|
||||
static sf_count_t
|
||||
alaw_read_alaw2i (SF_PRIVATE *psf, int *ptr, sf_count_t len)
|
||||
{ int bufferlen, readcount ;
|
||||
{ BUF_UNION ubuf ;
|
||||
int bufferlen, readcount ;
|
||||
sf_count_t total = 0 ;
|
||||
|
||||
bufferlen = ARRAY_LEN (psf->u.ucbuf) ;
|
||||
bufferlen = ARRAY_LEN (ubuf.ucbuf) ;
|
||||
|
||||
while (len > 0)
|
||||
{ if (len < bufferlen)
|
||||
bufferlen = (int) len ;
|
||||
readcount = psf_fread (psf->u.ucbuf, 1, bufferlen, psf) ;
|
||||
alaw2i_array (psf->u.ucbuf, readcount, ptr + total) ;
|
||||
readcount = psf_fread (ubuf.ucbuf, 1, bufferlen, psf) ;
|
||||
alaw2i_array (ubuf.ucbuf, readcount, ptr + total) ;
|
||||
total += readcount ;
|
||||
if (readcount < bufferlen)
|
||||
break ;
|
||||
@ -400,19 +402,20 @@ alaw_read_alaw2i (SF_PRIVATE *psf, int *ptr, sf_count_t len)
|
||||
|
||||
static sf_count_t
|
||||
alaw_read_alaw2f (SF_PRIVATE *psf, float *ptr, sf_count_t len)
|
||||
{ int bufferlen, readcount ;
|
||||
{ BUF_UNION ubuf ;
|
||||
int bufferlen, readcount ;
|
||||
sf_count_t total = 0 ;
|
||||
float normfact ;
|
||||
|
||||
normfact = (psf->norm_float == SF_TRUE) ? 1.0 / ((float) 0x8000) : 1.0 ;
|
||||
|
||||
bufferlen = ARRAY_LEN (psf->u.ucbuf) ;
|
||||
bufferlen = ARRAY_LEN (ubuf.ucbuf) ;
|
||||
|
||||
while (len > 0)
|
||||
{ if (len < bufferlen)
|
||||
bufferlen = (int) len ;
|
||||
readcount = psf_fread (psf->u.ucbuf, 1, bufferlen, psf) ;
|
||||
alaw2f_array (psf->u.ucbuf, readcount, ptr + total, normfact) ;
|
||||
readcount = psf_fread (ubuf.ucbuf, 1, bufferlen, psf) ;
|
||||
alaw2f_array (ubuf.ucbuf, readcount, ptr + total, normfact) ;
|
||||
total += readcount ;
|
||||
if (readcount < bufferlen)
|
||||
break ;
|
||||
@ -424,18 +427,19 @@ alaw_read_alaw2f (SF_PRIVATE *psf, float *ptr, sf_count_t len)
|
||||
|
||||
static sf_count_t
|
||||
alaw_read_alaw2d (SF_PRIVATE *psf, double *ptr, sf_count_t len)
|
||||
{ int bufferlen, readcount ;
|
||||
{ BUF_UNION ubuf ;
|
||||
int bufferlen, readcount ;
|
||||
sf_count_t total = 0 ;
|
||||
double normfact ;
|
||||
|
||||
normfact = (psf->norm_double) ? 1.0 / ((double) 0x8000) : 1.0 ;
|
||||
bufferlen = ARRAY_LEN (psf->u.ucbuf) ;
|
||||
bufferlen = ARRAY_LEN (ubuf.ucbuf) ;
|
||||
|
||||
while (len > 0)
|
||||
{ if (len < bufferlen)
|
||||
bufferlen = (int) len ;
|
||||
readcount = psf_fread (psf->u.ucbuf, 1, bufferlen, psf) ;
|
||||
alaw2d_array (psf->u.ucbuf, readcount, ptr + total, normfact) ;
|
||||
readcount = psf_fread (ubuf.ucbuf, 1, bufferlen, psf) ;
|
||||
alaw2d_array (ubuf.ucbuf, readcount, ptr + total, normfact) ;
|
||||
total += readcount ;
|
||||
if (readcount < bufferlen)
|
||||
break ;
|
||||
@ -450,16 +454,17 @@ alaw_read_alaw2d (SF_PRIVATE *psf, double *ptr, sf_count_t len)
|
||||
|
||||
static sf_count_t
|
||||
alaw_write_s2alaw (SF_PRIVATE *psf, const short *ptr, sf_count_t len)
|
||||
{ int bufferlen, writecount ;
|
||||
{ BUF_UNION ubuf ;
|
||||
int bufferlen, writecount ;
|
||||
sf_count_t total = 0 ;
|
||||
|
||||
bufferlen = ARRAY_LEN (psf->u.ucbuf) ;
|
||||
bufferlen = ARRAY_LEN (ubuf.ucbuf) ;
|
||||
|
||||
while (len > 0)
|
||||
{ if (len < bufferlen)
|
||||
bufferlen = (int) len ;
|
||||
s2alaw_array (ptr + total, bufferlen, psf->u.ucbuf) ;
|
||||
writecount = psf_fwrite (psf->u.ucbuf, 1, bufferlen, psf) ;
|
||||
s2alaw_array (ptr + total, bufferlen, ubuf.ucbuf) ;
|
||||
writecount = psf_fwrite (ubuf.ucbuf, 1, bufferlen, psf) ;
|
||||
total += writecount ;
|
||||
if (writecount < bufferlen)
|
||||
break ;
|
||||
@ -471,16 +476,17 @@ alaw_write_s2alaw (SF_PRIVATE *psf, const short *ptr, sf_count_t len)
|
||||
|
||||
static sf_count_t
|
||||
alaw_write_i2alaw (SF_PRIVATE *psf, const int *ptr, sf_count_t len)
|
||||
{ int bufferlen, writecount ;
|
||||
{ BUF_UNION ubuf ;
|
||||
int bufferlen, writecount ;
|
||||
sf_count_t total = 0 ;
|
||||
|
||||
bufferlen = ARRAY_LEN (psf->u.ucbuf) ;
|
||||
bufferlen = ARRAY_LEN (ubuf.ucbuf) ;
|
||||
|
||||
while (len > 0)
|
||||
{ if (len < bufferlen)
|
||||
bufferlen = (int) len ;
|
||||
i2alaw_array (ptr + total, bufferlen, psf->u.ucbuf) ;
|
||||
writecount = psf_fwrite (psf->u.ucbuf, 1, bufferlen, psf) ;
|
||||
i2alaw_array (ptr + total, bufferlen, ubuf.ucbuf) ;
|
||||
writecount = psf_fwrite (ubuf.ucbuf, 1, bufferlen, psf) ;
|
||||
total += writecount ;
|
||||
if (writecount < bufferlen)
|
||||
break ;
|
||||
@ -492,19 +498,20 @@ alaw_write_i2alaw (SF_PRIVATE *psf, const int *ptr, sf_count_t len)
|
||||
|
||||
static sf_count_t
|
||||
alaw_write_f2alaw (SF_PRIVATE *psf, const float *ptr, sf_count_t len)
|
||||
{ int bufferlen, writecount ;
|
||||
{ BUF_UNION ubuf ;
|
||||
int bufferlen, writecount ;
|
||||
sf_count_t total = 0 ;
|
||||
float normfact ;
|
||||
|
||||
normfact = (psf->norm_float == SF_TRUE) ? (1.0 * 0x7FFF) / 16.0 : 1.0 / 16 ;
|
||||
|
||||
bufferlen = ARRAY_LEN (psf->u.ucbuf) ;
|
||||
bufferlen = ARRAY_LEN (ubuf.ucbuf) ;
|
||||
|
||||
while (len > 0)
|
||||
{ if (len < bufferlen)
|
||||
bufferlen = (int) len ;
|
||||
f2alaw_array (ptr + total, bufferlen, psf->u.ucbuf, normfact) ;
|
||||
writecount = psf_fwrite (psf->u.ucbuf, 1, bufferlen, psf) ;
|
||||
f2alaw_array (ptr + total, bufferlen, ubuf.ucbuf, normfact) ;
|
||||
writecount = psf_fwrite (ubuf.ucbuf, 1, bufferlen, psf) ;
|
||||
total += writecount ;
|
||||
if (writecount < bufferlen)
|
||||
break ;
|
||||
@ -516,19 +523,20 @@ alaw_write_f2alaw (SF_PRIVATE *psf, const float *ptr, sf_count_t len)
|
||||
|
||||
static sf_count_t
|
||||
alaw_write_d2alaw (SF_PRIVATE *psf, const double *ptr, sf_count_t len)
|
||||
{ int bufferlen, writecount ;
|
||||
{ BUF_UNION ubuf ;
|
||||
int bufferlen, writecount ;
|
||||
sf_count_t total = 0 ;
|
||||
double normfact ;
|
||||
|
||||
normfact = (psf->norm_double) ? (1.0 * 0x7FFF) / 16.0 : 1.0 / 16.0 ;
|
||||
|
||||
bufferlen = ARRAY_LEN (psf->u.ucbuf) ;
|
||||
bufferlen = ARRAY_LEN (ubuf.ucbuf) ;
|
||||
|
||||
while (len > 0)
|
||||
{ if (len < bufferlen)
|
||||
bufferlen = (int) len ;
|
||||
d2alaw_array (ptr + total, bufferlen, psf->u.ucbuf, normfact) ;
|
||||
writecount = psf_fwrite (psf->u.ucbuf, 1, bufferlen, psf) ;
|
||||
d2alaw_array (ptr + total, bufferlen, ubuf.ucbuf, normfact) ;
|
||||
writecount = psf_fwrite (ubuf.ucbuf, 1, bufferlen, psf) ;
|
||||
total += writecount ;
|
||||
if (writecount < bufferlen)
|
||||
break ;
|
||||
|
22
src/caf.c
22
src/caf.c
@ -286,7 +286,8 @@ decode_desc_chunk (SF_PRIVATE *psf, const DESC_CHUNK *desc)
|
||||
|
||||
static int
|
||||
caf_read_header (SF_PRIVATE *psf)
|
||||
{ DESC_CHUNK desc ;
|
||||
{ BUF_UNION ubuf ;
|
||||
DESC_CHUNK desc ;
|
||||
sf_count_t chunk_size ;
|
||||
double srate ;
|
||||
short version, flags ;
|
||||
@ -300,10 +301,10 @@ caf_read_header (SF_PRIVATE *psf)
|
||||
if (marker != caff_MARKER)
|
||||
return SFE_CAF_NOT_CAF ;
|
||||
|
||||
psf_binheader_readf (psf, "mE8b", &marker, &chunk_size, psf->u.ucbuf, 8) ;
|
||||
srate = double64_be_read (psf->u.ucbuf) ;
|
||||
snprintf (psf->u.cbuf, sizeof (psf->u.cbuf), "%5.3f", srate) ;
|
||||
psf_log_printf (psf, "%M : %D\n Sample rate : %s\n", marker, chunk_size, psf->u.cbuf) ;
|
||||
psf_binheader_readf (psf, "mE8b", &marker, &chunk_size, ubuf.ucbuf, 8) ;
|
||||
srate = double64_be_read (ubuf.ucbuf) ;
|
||||
snprintf (ubuf.cbuf, sizeof (ubuf.cbuf), "%5.3f", srate) ;
|
||||
psf_log_printf (psf, "%M : %D\n Sample rate : %s\n", marker, chunk_size, ubuf.cbuf) ;
|
||||
if (marker != desc_MARKER)
|
||||
return SFE_CAF_NO_DESC ;
|
||||
|
||||
@ -360,8 +361,8 @@ caf_read_header (SF_PRIVATE *psf)
|
||||
psf->peak_info->peaks [k].value = value ;
|
||||
psf->peak_info->peaks [k].position = position ;
|
||||
|
||||
snprintf (psf->u.cbuf, sizeof (psf->u.cbuf), " %2d %-12" PRId64 " %g\n", k, position, value) ;
|
||||
psf_log_printf (psf, psf->u.cbuf) ;
|
||||
snprintf (ubuf.cbuf, sizeof (ubuf.cbuf), " %2d %-12" PRId64 " %g\n", k, position, value) ;
|
||||
psf_log_printf (psf, ubuf.cbuf) ;
|
||||
} ;
|
||||
|
||||
psf->peak_info->peak_loc = SF_PEAK_START ;
|
||||
@ -427,7 +428,8 @@ caf_read_header (SF_PRIVATE *psf)
|
||||
|
||||
static int
|
||||
caf_write_header (SF_PRIVATE *psf, int calc_length)
|
||||
{ CAF_PRIVATE *pcaf ;
|
||||
{ BUF_UNION ubuf ;
|
||||
CAF_PRIVATE *pcaf ;
|
||||
DESC_CHUNK desc ;
|
||||
sf_count_t current, free_len ;
|
||||
uint32_t uk ;
|
||||
@ -463,8 +465,8 @@ caf_write_header (SF_PRIVATE *psf, int calc_length)
|
||||
/* 'desc' marker and chunk size. */
|
||||
psf_binheader_writef (psf, "Em8", desc_MARKER, (sf_count_t) (sizeof (DESC_CHUNK))) ;
|
||||
|
||||
double64_be_write (1.0 * psf->sf.samplerate, psf->u.ucbuf) ;
|
||||
psf_binheader_writef (psf, "b", psf->u.ucbuf, make_size_t (8)) ;
|
||||
double64_be_write (1.0 * psf->sf.samplerate, ubuf.ucbuf) ;
|
||||
psf_binheader_writef (psf, "b", ubuf.ucbuf, make_size_t (8)) ;
|
||||
|
||||
subformat = SF_CODEC (psf->sf.format) ;
|
||||
|
||||
|
@ -258,7 +258,8 @@ psf_get_format_info (SF_FORMAT_INFO *data)
|
||||
|
||||
double
|
||||
psf_calc_signal_max (SF_PRIVATE *psf, int normalize)
|
||||
{ sf_count_t position ;
|
||||
{ BUF_UNION ubuf ;
|
||||
sf_count_t position ;
|
||||
double max_val, temp, *data ;
|
||||
int k, len, readcount, save_state ;
|
||||
|
||||
@ -282,8 +283,8 @@ psf_calc_signal_max (SF_PRIVATE *psf, int normalize)
|
||||
/* Go to start of file. */
|
||||
sf_seek ((SNDFILE*) psf, 0, SEEK_SET) ;
|
||||
|
||||
data = psf->u.dbuf ;
|
||||
len = ARRAY_LEN (psf->u.dbuf) ;
|
||||
data = ubuf.dbuf ;
|
||||
len = ARRAY_LEN (ubuf.dbuf) ;
|
||||
|
||||
for (readcount = 1, max_val = 0.0 ; readcount > 0 ; /* nothing */)
|
||||
{ readcount = sf_read_double ((SNDFILE*) psf, data, len) ;
|
||||
@ -302,7 +303,8 @@ psf_calc_signal_max (SF_PRIVATE *psf, int normalize)
|
||||
|
||||
int
|
||||
psf_calc_max_all_channels (SF_PRIVATE *psf, double *peaks, int normalize)
|
||||
{ sf_count_t position ;
|
||||
{ BUF_UNION ubuf ;
|
||||
sf_count_t position ;
|
||||
double temp, *data ;
|
||||
int k, len, readcount, save_state ;
|
||||
int chan ;
|
||||
@ -323,9 +325,9 @@ psf_calc_max_all_channels (SF_PRIVATE *psf, double *peaks, int normalize)
|
||||
position = sf_seek ((SNDFILE*) psf, 0, SEEK_CUR) ; /* Get current position in file */
|
||||
sf_seek ((SNDFILE*) psf, 0, SEEK_SET) ; /* Go to start of file. */
|
||||
|
||||
len = ARRAY_LEN (psf->u.dbuf) ;
|
||||
len = ARRAY_LEN (ubuf.dbuf) ;
|
||||
|
||||
data = psf->u.dbuf ;
|
||||
data = ubuf.dbuf ;
|
||||
|
||||
chan = 0 ;
|
||||
readcount = len ;
|
||||
|
37
src/common.h
37
src/common.h
@ -70,7 +70,7 @@
|
||||
# define WARN_UNUSED
|
||||
#endif
|
||||
|
||||
#define SF_BUFFER_LEN (8192*2)
|
||||
#define SF_BUFFER_LEN (8192)
|
||||
#define SF_FILENAME_LEN (512)
|
||||
#define SF_SYSERR_LEN (256)
|
||||
#define SF_MAX_STRINGS (32)
|
||||
@ -314,6 +314,24 @@ typedef struct
|
||||
} PSF_FILE ;
|
||||
|
||||
|
||||
|
||||
typedef union
|
||||
{ double dbuf [SF_BUFFER_LEN / sizeof (double)] ;
|
||||
#if (defined (SIZEOF_INT64_T) && (SIZEOF_INT64_T == 8))
|
||||
int64_t lbuf [SF_BUFFER_LEN / sizeof (int64_t)] ;
|
||||
#else
|
||||
long lbuf [SF_BUFFER_LEN / sizeof (double)] ;
|
||||
#endif
|
||||
float fbuf [SF_BUFFER_LEN / sizeof (float)] ;
|
||||
int ibuf [SF_BUFFER_LEN / sizeof (int)] ;
|
||||
short sbuf [SF_BUFFER_LEN / sizeof (short)] ;
|
||||
char cbuf [SF_BUFFER_LEN / sizeof (char)] ;
|
||||
signed char scbuf [SF_BUFFER_LEN / sizeof (signed char)] ;
|
||||
unsigned char ucbuf [SF_BUFFER_LEN / sizeof (signed char)] ;
|
||||
} BUF_UNION ;
|
||||
|
||||
|
||||
|
||||
typedef struct sf_private_tag
|
||||
{
|
||||
/* Canary in a coal mine. */
|
||||
@ -323,22 +341,7 @@ typedef struct sf_private_tag
|
||||
char c [16] ;
|
||||
} canary ;
|
||||
|
||||
/* Force the compiler to double align the start of buffer. */
|
||||
union
|
||||
{ double dbuf [SF_BUFFER_LEN / sizeof (double)] ;
|
||||
#if (defined (SIZEOF_INT64_T) && (SIZEOF_INT64_T == 8))
|
||||
int64_t lbuf [SF_BUFFER_LEN / sizeof (int64_t)] ;
|
||||
#else
|
||||
long lbuf [SF_BUFFER_LEN / sizeof (double)] ;
|
||||
#endif
|
||||
float fbuf [SF_BUFFER_LEN / sizeof (float)] ;
|
||||
int ibuf [SF_BUFFER_LEN / sizeof (int)] ;
|
||||
short sbuf [SF_BUFFER_LEN / sizeof (short)] ;
|
||||
char cbuf [SF_BUFFER_LEN / sizeof (char)] ;
|
||||
signed char scbuf [SF_BUFFER_LEN / sizeof (signed char)] ;
|
||||
unsigned char ucbuf [SF_BUFFER_LEN / sizeof (signed char)] ;
|
||||
} u ;
|
||||
|
||||
// BUF_UNION u ;
|
||||
|
||||
PSF_FILE file, rsrc ;
|
||||
|
||||
|
191
src/double64.c
191
src/double64.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** Copyright (C) 1999-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
|
||||
** Copyright (C) 1999-2012 Erik de Castro Lopo <erikd@mega-nerd.com>
|
||||
**
|
||||
** This program is free software; you can redistribute it and/or modify
|
||||
** it under the terms of the GNU Lesser General Public License as published by
|
||||
@ -554,24 +554,25 @@ f2d_array (const float *src, double *dest, int count)
|
||||
|
||||
static sf_count_t
|
||||
host_read_d2s (SF_PRIVATE *psf, short *ptr, sf_count_t len)
|
||||
{ void (*convert) (const double *, int, short *, double) ;
|
||||
{ BUF_UNION ubuf ;
|
||||
void (*convert) (const double *, int, short *, double) ;
|
||||
int bufferlen, readcount ;
|
||||
sf_count_t total = 0 ;
|
||||
double scale ;
|
||||
|
||||
convert = (psf->add_clipping) ? d2s_clip_array : d2s_array ;
|
||||
bufferlen = ARRAY_LEN (psf->u.dbuf) ;
|
||||
bufferlen = ARRAY_LEN (ubuf.dbuf) ;
|
||||
scale = (psf->float_int_mult == 0) ? 1.0 : 0x7FFF / psf->float_max ;
|
||||
|
||||
while (len > 0)
|
||||
{ if (len < bufferlen)
|
||||
bufferlen = (int) len ;
|
||||
readcount = psf_fread (psf->u.dbuf, sizeof (double), bufferlen, psf) ;
|
||||
readcount = psf_fread (ubuf.dbuf, sizeof (double), bufferlen, psf) ;
|
||||
|
||||
if (psf->data_endswap == SF_TRUE)
|
||||
endswap_double_array (psf->u.dbuf, readcount) ;
|
||||
endswap_double_array (ubuf.dbuf, readcount) ;
|
||||
|
||||
convert (psf->u.dbuf, readcount, ptr + total, scale) ;
|
||||
convert (ubuf.dbuf, readcount, ptr + total, scale) ;
|
||||
total += readcount ;
|
||||
len -= readcount ;
|
||||
if (readcount < bufferlen)
|
||||
@ -583,24 +584,25 @@ host_read_d2s (SF_PRIVATE *psf, short *ptr, sf_count_t len)
|
||||
|
||||
static sf_count_t
|
||||
host_read_d2i (SF_PRIVATE *psf, int *ptr, sf_count_t len)
|
||||
{ void (*convert) (const double *, int, int *, double) ;
|
||||
{ BUF_UNION ubuf ;
|
||||
void (*convert) (const double *, int, int *, double) ;
|
||||
int bufferlen, readcount ;
|
||||
sf_count_t total = 0 ;
|
||||
double scale ;
|
||||
|
||||
convert = (psf->add_clipping) ? d2i_clip_array : d2i_array ;
|
||||
bufferlen = ARRAY_LEN (psf->u.dbuf) ;
|
||||
bufferlen = ARRAY_LEN (ubuf.dbuf) ;
|
||||
scale = (psf->float_int_mult == 0) ? 1.0 : 0x7FFFFFFF / psf->float_max ;
|
||||
|
||||
while (len > 0)
|
||||
{ if (len < bufferlen)
|
||||
bufferlen = (int) len ;
|
||||
readcount = psf_fread (psf->u.dbuf, sizeof (double), bufferlen, psf) ;
|
||||
readcount = psf_fread (ubuf.dbuf, sizeof (double), bufferlen, psf) ;
|
||||
|
||||
if (psf->data_endswap == SF_TRUE)
|
||||
endswap_double_array (psf->u.dbuf, bufferlen) ;
|
||||
endswap_double_array (ubuf.dbuf, bufferlen) ;
|
||||
|
||||
convert (psf->u.dbuf, readcount, ptr + total, scale) ;
|
||||
convert (ubuf.dbuf, readcount, ptr + total, scale) ;
|
||||
total += readcount ;
|
||||
len -= readcount ;
|
||||
if (readcount < bufferlen)
|
||||
@ -612,20 +614,21 @@ host_read_d2i (SF_PRIVATE *psf, int *ptr, sf_count_t len)
|
||||
|
||||
static sf_count_t
|
||||
host_read_d2f (SF_PRIVATE *psf, float *ptr, sf_count_t len)
|
||||
{ int bufferlen, readcount ;
|
||||
{ BUF_UNION ubuf ;
|
||||
int bufferlen, readcount ;
|
||||
sf_count_t total = 0 ;
|
||||
|
||||
bufferlen = ARRAY_LEN (psf->u.dbuf) ;
|
||||
bufferlen = ARRAY_LEN (ubuf.dbuf) ;
|
||||
|
||||
while (len > 0)
|
||||
{ if (len < bufferlen)
|
||||
bufferlen = (int) len ;
|
||||
readcount = psf_fread (psf->u.dbuf, sizeof (double), bufferlen, psf) ;
|
||||
readcount = psf_fread (ubuf.dbuf, sizeof (double), bufferlen, psf) ;
|
||||
|
||||
if (psf->data_endswap == SF_TRUE)
|
||||
endswap_double_array (psf->u.dbuf, bufferlen) ;
|
||||
endswap_double_array (ubuf.dbuf, bufferlen) ;
|
||||
|
||||
d2f_array (psf->u.dbuf, readcount, ptr + total) ;
|
||||
d2f_array (ubuf.dbuf, readcount, ptr + total) ;
|
||||
total += readcount ;
|
||||
len -= readcount ;
|
||||
if (readcount < bufferlen)
|
||||
@ -667,26 +670,27 @@ host_read_d (SF_PRIVATE *psf, double *ptr, sf_count_t len)
|
||||
|
||||
static sf_count_t
|
||||
host_write_s2d (SF_PRIVATE *psf, const short *ptr, sf_count_t len)
|
||||
{ int bufferlen, writecount ;
|
||||
{ BUF_UNION ubuf ;
|
||||
int bufferlen, writecount ;
|
||||
sf_count_t total = 0 ;
|
||||
double scale ;
|
||||
|
||||
scale = (psf->scale_int_float == 0) ? 1.0 : 1.0 / 0x8000 ;
|
||||
bufferlen = ARRAY_LEN (psf->u.dbuf) ;
|
||||
bufferlen = ARRAY_LEN (ubuf.dbuf) ;
|
||||
|
||||
while (len > 0)
|
||||
{ if (len < bufferlen)
|
||||
bufferlen = (int) len ;
|
||||
|
||||
s2d_array (ptr + total, psf->u.dbuf, bufferlen, scale) ;
|
||||
s2d_array (ptr + total, ubuf.dbuf, bufferlen, scale) ;
|
||||
|
||||
if (psf->peak_info)
|
||||
double64_peak_update (psf, psf->u.dbuf, bufferlen, total / psf->sf.channels) ;
|
||||
double64_peak_update (psf, ubuf.dbuf, bufferlen, total / psf->sf.channels) ;
|
||||
|
||||
if (psf->data_endswap == SF_TRUE)
|
||||
endswap_double_array (psf->u.dbuf, bufferlen) ;
|
||||
endswap_double_array (ubuf.dbuf, bufferlen) ;
|
||||
|
||||
writecount = psf_fwrite (psf->u.dbuf, sizeof (double), bufferlen, psf) ;
|
||||
writecount = psf_fwrite (ubuf.dbuf, sizeof (double), bufferlen, psf) ;
|
||||
total += writecount ;
|
||||
if (writecount < bufferlen)
|
||||
break ;
|
||||
@ -698,25 +702,26 @@ host_write_s2d (SF_PRIVATE *psf, const short *ptr, sf_count_t len)
|
||||
|
||||
static sf_count_t
|
||||
host_write_i2d (SF_PRIVATE *psf, const int *ptr, sf_count_t len)
|
||||
{ int bufferlen, writecount ;
|
||||
{ BUF_UNION ubuf ;
|
||||
int bufferlen, writecount ;
|
||||
sf_count_t total = 0 ;
|
||||
double scale ;
|
||||
|
||||
scale = (psf->scale_int_float == 0) ? 1.0 : 1.0 / (8.0 * 0x10000000) ;
|
||||
bufferlen = ARRAY_LEN (psf->u.dbuf) ;
|
||||
bufferlen = ARRAY_LEN (ubuf.dbuf) ;
|
||||
|
||||
while (len > 0)
|
||||
{ if (len < bufferlen)
|
||||
bufferlen = (int) len ;
|
||||
i2d_array (ptr + total, psf->u.dbuf, bufferlen, scale) ;
|
||||
i2d_array (ptr + total, ubuf.dbuf, bufferlen, scale) ;
|
||||
|
||||
if (psf->peak_info)
|
||||
double64_peak_update (psf, psf->u.dbuf, bufferlen, total / psf->sf.channels) ;
|
||||
double64_peak_update (psf, ubuf.dbuf, bufferlen, total / psf->sf.channels) ;
|
||||
|
||||
if (psf->data_endswap == SF_TRUE)
|
||||
endswap_double_array (psf->u.dbuf, bufferlen) ;
|
||||
endswap_double_array (ubuf.dbuf, bufferlen) ;
|
||||
|
||||
writecount = psf_fwrite (psf->u.dbuf, sizeof (double), bufferlen, psf) ;
|
||||
writecount = psf_fwrite (ubuf.dbuf, sizeof (double), bufferlen, psf) ;
|
||||
total += writecount ;
|
||||
if (writecount < bufferlen)
|
||||
break ;
|
||||
@ -728,23 +733,24 @@ host_write_i2d (SF_PRIVATE *psf, const int *ptr, sf_count_t len)
|
||||
|
||||
static sf_count_t
|
||||
host_write_f2d (SF_PRIVATE *psf, const float *ptr, sf_count_t len)
|
||||
{ int bufferlen, writecount ;
|
||||
{ BUF_UNION ubuf ;
|
||||
int bufferlen, writecount ;
|
||||
sf_count_t total = 0 ;
|
||||
|
||||
bufferlen = ARRAY_LEN (psf->u.dbuf) ;
|
||||
bufferlen = ARRAY_LEN (ubuf.dbuf) ;
|
||||
|
||||
while (len > 0)
|
||||
{ if (len < bufferlen)
|
||||
bufferlen = (int) len ;
|
||||
f2d_array (ptr + total, psf->u.dbuf, bufferlen) ;
|
||||
f2d_array (ptr + total, ubuf.dbuf, bufferlen) ;
|
||||
|
||||
if (psf->peak_info)
|
||||
double64_peak_update (psf, psf->u.dbuf, bufferlen, total / psf->sf.channels) ;
|
||||
double64_peak_update (psf, ubuf.dbuf, bufferlen, total / psf->sf.channels) ;
|
||||
|
||||
if (psf->data_endswap == SF_TRUE)
|
||||
endswap_double_array (psf->u.dbuf, bufferlen) ;
|
||||
endswap_double_array (ubuf.dbuf, bufferlen) ;
|
||||
|
||||
writecount = psf_fwrite (psf->u.dbuf, sizeof (double), bufferlen, psf) ;
|
||||
writecount = psf_fwrite (ubuf.dbuf, sizeof (double), bufferlen, psf) ;
|
||||
total += writecount ;
|
||||
if (writecount < bufferlen)
|
||||
break ;
|
||||
@ -756,7 +762,8 @@ host_write_f2d (SF_PRIVATE *psf, const float *ptr, sf_count_t len)
|
||||
|
||||
static sf_count_t
|
||||
host_write_d (SF_PRIVATE *psf, const double *ptr, sf_count_t len)
|
||||
{ int bufferlen, writecount ;
|
||||
{ BUF_UNION ubuf ;
|
||||
int bufferlen, writecount ;
|
||||
sf_count_t total = 0 ;
|
||||
|
||||
if (psf->peak_info)
|
||||
@ -765,15 +772,15 @@ host_write_d (SF_PRIVATE *psf, const double *ptr, sf_count_t len)
|
||||
if (psf->data_endswap != SF_TRUE)
|
||||
return psf_fwrite (ptr, sizeof (double), len, psf) ;
|
||||
|
||||
bufferlen = ARRAY_LEN (psf->u.dbuf) ;
|
||||
bufferlen = ARRAY_LEN (ubuf.dbuf) ;
|
||||
|
||||
while (len > 0)
|
||||
{ if (len < bufferlen)
|
||||
bufferlen = (int) len ;
|
||||
|
||||
endswap_double_copy (psf->u.dbuf, ptr + total, bufferlen) ;
|
||||
endswap_double_copy (ubuf.dbuf, ptr + total, bufferlen) ;
|
||||
|
||||
writecount = psf_fwrite (psf->u.dbuf, sizeof (double), bufferlen, psf) ;
|
||||
writecount = psf_fwrite (ubuf.dbuf, sizeof (double), bufferlen, psf) ;
|
||||
total += writecount ;
|
||||
if (writecount < bufferlen)
|
||||
break ;
|
||||
@ -788,24 +795,25 @@ host_write_d (SF_PRIVATE *psf, const double *ptr, sf_count_t len)
|
||||
|
||||
static sf_count_t
|
||||
replace_read_d2s (SF_PRIVATE *psf, short *ptr, sf_count_t len)
|
||||
{ int bufferlen, readcount ;
|
||||
{ BUF_UNION ubuf ;
|
||||
int bufferlen, readcount ;
|
||||
sf_count_t total = 0 ;
|
||||
double scale ;
|
||||
|
||||
bufferlen = ARRAY_LEN (psf->u.dbuf) ;
|
||||
bufferlen = ARRAY_LEN (ubuf.dbuf) ;
|
||||
scale = (psf->float_int_mult == 0) ? 1.0 : 0x7FFF / psf->float_max ;
|
||||
|
||||
while (len > 0)
|
||||
{ if (len < bufferlen)
|
||||
bufferlen = (int) len ;
|
||||
readcount = psf_fread (psf->u.dbuf, sizeof (double), bufferlen, psf) ;
|
||||
readcount = psf_fread (ubuf.dbuf, sizeof (double), bufferlen, psf) ;
|
||||
|
||||
if (psf->data_endswap == SF_TRUE)
|
||||
endswap_double_array (psf->u.dbuf, bufferlen) ;
|
||||
endswap_double_array (ubuf.dbuf, bufferlen) ;
|
||||
|
||||
d2bd_read (psf->u.dbuf, bufferlen) ;
|
||||
d2bd_read (ubuf.dbuf, bufferlen) ;
|
||||
|
||||
d2s_array (psf->u.dbuf, readcount, ptr + total, scale) ;
|
||||
d2s_array (ubuf.dbuf, readcount, ptr + total, scale) ;
|
||||
total += readcount ;
|
||||
if (readcount < bufferlen)
|
||||
break ;
|
||||
@ -817,24 +825,25 @@ replace_read_d2s (SF_PRIVATE *psf, short *ptr, sf_count_t len)
|
||||
|
||||
static sf_count_t
|
||||
replace_read_d2i (SF_PRIVATE *psf, int *ptr, sf_count_t len)
|
||||
{ int bufferlen, readcount ;
|
||||
{ BUF_UNION ubuf ;
|
||||
int bufferlen, readcount ;
|
||||
sf_count_t total = 0 ;
|
||||
double scale ;
|
||||
|
||||
bufferlen = ARRAY_LEN (psf->u.dbuf) ;
|
||||
bufferlen = ARRAY_LEN (ubuf.dbuf) ;
|
||||
scale = (psf->float_int_mult == 0) ? 1.0 : 0x7FFFFFFF / psf->float_max ;
|
||||
|
||||
while (len > 0)
|
||||
{ if (len < bufferlen)
|
||||
bufferlen = (int) len ;
|
||||
readcount = psf_fread (psf->u.dbuf, sizeof (double), bufferlen, psf) ;
|
||||
readcount = psf_fread (ubuf.dbuf, sizeof (double), bufferlen, psf) ;
|
||||
|
||||
if (psf->data_endswap == SF_TRUE)
|
||||
endswap_double_array (psf->u.dbuf, bufferlen) ;
|
||||
endswap_double_array (ubuf.dbuf, bufferlen) ;
|
||||
|
||||
d2bd_read (psf->u.dbuf, bufferlen) ;
|
||||
d2bd_read (ubuf.dbuf, bufferlen) ;
|
||||
|
||||
d2i_array (psf->u.dbuf, readcount, ptr + total, scale) ;
|
||||
d2i_array (ubuf.dbuf, readcount, ptr + total, scale) ;
|
||||
total += readcount ;
|
||||
if (readcount < bufferlen)
|
||||
break ;
|
||||
@ -846,22 +855,23 @@ replace_read_d2i (SF_PRIVATE *psf, int *ptr, sf_count_t len)
|
||||
|
||||
static sf_count_t
|
||||
replace_read_d2f (SF_PRIVATE *psf, float *ptr, sf_count_t len)
|
||||
{ int bufferlen, readcount ;
|
||||
{ BUF_UNION ubuf ;
|
||||
int bufferlen, readcount ;
|
||||
sf_count_t total = 0 ;
|
||||
|
||||
bufferlen = ARRAY_LEN (psf->u.dbuf) ;
|
||||
bufferlen = ARRAY_LEN (ubuf.dbuf) ;
|
||||
|
||||
while (len > 0)
|
||||
{ if (len < bufferlen)
|
||||
bufferlen = (int) len ;
|
||||
readcount = psf_fread (psf->u.dbuf, sizeof (double), bufferlen, psf) ;
|
||||
readcount = psf_fread (ubuf.dbuf, sizeof (double), bufferlen, psf) ;
|
||||
|
||||
if (psf->data_endswap == SF_TRUE)
|
||||
endswap_double_array (psf->u.dbuf, bufferlen) ;
|
||||
endswap_double_array (ubuf.dbuf, bufferlen) ;
|
||||
|
||||
d2bd_read (psf->u.dbuf, bufferlen) ;
|
||||
d2bd_read (ubuf.dbuf, bufferlen) ;
|
||||
|
||||
memcpy (ptr + total, psf->u.dbuf, bufferlen * sizeof (double)) ;
|
||||
memcpy (ptr + total, ubuf.dbuf, bufferlen * sizeof (double)) ;
|
||||
|
||||
total += readcount ;
|
||||
if (readcount < bufferlen)
|
||||
@ -874,23 +884,24 @@ replace_read_d2f (SF_PRIVATE *psf, float *ptr, sf_count_t len)
|
||||
|
||||
static sf_count_t
|
||||
replace_read_d (SF_PRIVATE *psf, double *ptr, sf_count_t len)
|
||||
{ int bufferlen, readcount ;
|
||||
{ BUF_UNION ubuf ;
|
||||
int bufferlen, readcount ;
|
||||
sf_count_t total = 0 ;
|
||||
|
||||
/* FIXME : This is probably nowhere near optimal. */
|
||||
bufferlen = ARRAY_LEN (psf->u.dbuf) ;
|
||||
bufferlen = ARRAY_LEN (ubuf.dbuf) ;
|
||||
|
||||
while (len > 0)
|
||||
{ if (len < bufferlen)
|
||||
bufferlen = (int) len ;
|
||||
readcount = psf_fread (psf->u.dbuf, sizeof (double), bufferlen, psf) ;
|
||||
readcount = psf_fread (ubuf.dbuf, sizeof (double), bufferlen, psf) ;
|
||||
|
||||
if (psf->data_endswap == SF_TRUE)
|
||||
endswap_double_array (psf->u.dbuf, readcount) ;
|
||||
endswap_double_array (ubuf.dbuf, readcount) ;
|
||||
|
||||
d2bd_read (psf->u.dbuf, readcount) ;
|
||||
d2bd_read (ubuf.dbuf, readcount) ;
|
||||
|
||||
memcpy (ptr + total, psf->u.dbuf, readcount * sizeof (double)) ;
|
||||
memcpy (ptr + total, ubuf.dbuf, readcount * sizeof (double)) ;
|
||||
|
||||
total += readcount ;
|
||||
if (readcount < bufferlen)
|
||||
@ -903,27 +914,28 @@ replace_read_d (SF_PRIVATE *psf, double *ptr, sf_count_t len)
|
||||
|
||||
static sf_count_t
|
||||
replace_write_s2d (SF_PRIVATE *psf, const short *ptr, sf_count_t len)
|
||||
{ int bufferlen, writecount ;
|
||||
{ BUF_UNION ubuf ;
|
||||
int bufferlen, writecount ;
|
||||
sf_count_t total = 0 ;
|
||||
double scale ;
|
||||
|
||||
scale = (psf->scale_int_float == 0) ? 1.0 : 1.0 / 0x8000 ;
|
||||
bufferlen = ARRAY_LEN (psf->u.dbuf) ;
|
||||
bufferlen = ARRAY_LEN (ubuf.dbuf) ;
|
||||
|
||||
while (len > 0)
|
||||
{ if (len < bufferlen)
|
||||
bufferlen = (int) len ;
|
||||
s2d_array (ptr + total, psf->u.dbuf, bufferlen, scale) ;
|
||||
s2d_array (ptr + total, ubuf.dbuf, bufferlen, scale) ;
|
||||
|
||||
if (psf->peak_info)
|
||||
double64_peak_update (psf, psf->u.dbuf, bufferlen, total / psf->sf.channels) ;
|
||||
double64_peak_update (psf, ubuf.dbuf, bufferlen, total / psf->sf.channels) ;
|
||||
|
||||
bd2d_write (psf->u.dbuf, bufferlen) ;
|
||||
bd2d_write (ubuf.dbuf, bufferlen) ;
|
||||
|
||||
if (psf->data_endswap == SF_TRUE)
|
||||
endswap_double_array (psf->u.dbuf, bufferlen) ;
|
||||
endswap_double_array (ubuf.dbuf, bufferlen) ;
|
||||
|
||||
writecount = psf_fwrite (psf->u.dbuf, sizeof (double), bufferlen, psf) ;
|
||||
writecount = psf_fwrite (ubuf.dbuf, sizeof (double), bufferlen, psf) ;
|
||||
total += writecount ;
|
||||
if (writecount < bufferlen)
|
||||
break ;
|
||||
@ -935,27 +947,28 @@ replace_write_s2d (SF_PRIVATE *psf, const short *ptr, sf_count_t len)
|
||||
|
||||
static sf_count_t
|
||||
replace_write_i2d (SF_PRIVATE *psf, const int *ptr, sf_count_t len)
|
||||
{ int bufferlen, writecount ;
|
||||
{ BUF_UNION ubuf ;
|
||||
int bufferlen, writecount ;
|
||||
sf_count_t total = 0 ;
|
||||
double scale ;
|
||||
|
||||
scale = (psf->scale_int_float == 0) ? 1.0 : 1.0 / (8.0 * 0x10000000) ;
|
||||
bufferlen = ARRAY_LEN (psf->u.dbuf) ;
|
||||
bufferlen = ARRAY_LEN (ubuf.dbuf) ;
|
||||
|
||||
while (len > 0)
|
||||
{ if (len < bufferlen)
|
||||
bufferlen = (int) len ;
|
||||
i2d_array (ptr + total, psf->u.dbuf, bufferlen, scale) ;
|
||||
i2d_array (ptr + total, ubuf.dbuf, bufferlen, scale) ;
|
||||
|
||||
if (psf->peak_info)
|
||||
double64_peak_update (psf, psf->u.dbuf, bufferlen, total / psf->sf.channels) ;
|
||||
double64_peak_update (psf, ubuf.dbuf, bufferlen, total / psf->sf.channels) ;
|
||||
|
||||
bd2d_write (psf->u.dbuf, bufferlen) ;
|
||||
bd2d_write (ubuf.dbuf, bufferlen) ;
|
||||
|
||||
if (psf->data_endswap == SF_TRUE)
|
||||
endswap_double_array (psf->u.dbuf, bufferlen) ;
|
||||
endswap_double_array (ubuf.dbuf, bufferlen) ;
|
||||
|
||||
writecount = psf_fwrite (psf->u.dbuf, sizeof (double), bufferlen, psf) ;
|
||||
writecount = psf_fwrite (ubuf.dbuf, sizeof (double), bufferlen, psf) ;
|
||||
total += writecount ;
|
||||
if (writecount < bufferlen)
|
||||
break ;
|
||||
@ -967,22 +980,23 @@ replace_write_i2d (SF_PRIVATE *psf, const int *ptr, sf_count_t len)
|
||||
|
||||
static sf_count_t
|
||||
replace_write_f2d (SF_PRIVATE *psf, const float *ptr, sf_count_t len)
|
||||
{ int bufferlen, writecount ;
|
||||
{ BUF_UNION ubuf ;
|
||||
int bufferlen, writecount ;
|
||||
sf_count_t total = 0 ;
|
||||
|
||||
bufferlen = ARRAY_LEN (psf->u.dbuf) ;
|
||||
bufferlen = ARRAY_LEN (ubuf.dbuf) ;
|
||||
|
||||
while (len > 0)
|
||||
{ if (len < bufferlen)
|
||||
bufferlen = (int) len ;
|
||||
f2d_array (ptr + total, psf->u.dbuf, bufferlen) ;
|
||||
f2d_array (ptr + total, ubuf.dbuf, bufferlen) ;
|
||||
|
||||
bd2d_write (psf->u.dbuf, bufferlen) ;
|
||||
bd2d_write (ubuf.dbuf, bufferlen) ;
|
||||
|
||||
if (psf->data_endswap == SF_TRUE)
|
||||
endswap_double_array (psf->u.dbuf, bufferlen) ;
|
||||
endswap_double_array (ubuf.dbuf, bufferlen) ;
|
||||
|
||||
writecount = psf_fwrite (psf->u.dbuf, sizeof (double), bufferlen, psf) ;
|
||||
writecount = psf_fwrite (ubuf.dbuf, sizeof (double), bufferlen, psf) ;
|
||||
total += writecount ;
|
||||
if (writecount < bufferlen)
|
||||
break ;
|
||||
@ -994,27 +1008,28 @@ replace_write_f2d (SF_PRIVATE *psf, const float *ptr, sf_count_t len)
|
||||
|
||||
static sf_count_t
|
||||
replace_write_d (SF_PRIVATE *psf, const double *ptr, sf_count_t len)
|
||||
{ int bufferlen, writecount ;
|
||||
{ BUF_UNION ubuf ;
|
||||
int bufferlen, writecount ;
|
||||
sf_count_t total = 0 ;
|
||||
|
||||
/* FIXME : This is probably nowhere near optimal. */
|
||||
if (psf->peak_info)
|
||||
double64_peak_update (psf, ptr, len, 0) ;
|
||||
|
||||
bufferlen = ARRAY_LEN (psf->u.dbuf) ;
|
||||
bufferlen = ARRAY_LEN (ubuf.dbuf) ;
|
||||
|
||||
while (len > 0)
|
||||
{ if (len < bufferlen)
|
||||
bufferlen = (int) len ;
|
||||
|
||||
memcpy (psf->u.dbuf, ptr + total, bufferlen * sizeof (double)) ;
|
||||
memcpy (ubuf.dbuf, ptr + total, bufferlen * sizeof (double)) ;
|
||||
|
||||
bd2d_write (psf->u.dbuf, bufferlen) ;
|
||||
bd2d_write (ubuf.dbuf, bufferlen) ;
|
||||
|
||||
if (psf->data_endswap == SF_TRUE)
|
||||
endswap_double_array (psf->u.dbuf, bufferlen) ;
|
||||
endswap_double_array (ubuf.dbuf, bufferlen) ;
|
||||
|
||||
writecount = psf_fwrite (psf->u.dbuf, sizeof (double), bufferlen, psf) ;
|
||||
writecount = psf_fwrite (ubuf.dbuf, sizeof (double), bufferlen, psf) ;
|
||||
total += writecount ;
|
||||
if (writecount < bufferlen)
|
||||
break ;
|
||||
|
38
src/dwvw.c
38
src/dwvw.c
@ -181,6 +181,7 @@ dwvw_seek (SF_PRIVATE *psf, int UNUSED (mode), sf_count_t offset)
|
||||
static sf_count_t
|
||||
dwvw_read_s (SF_PRIVATE *psf, short *ptr, sf_count_t len)
|
||||
{ DWVW_PRIVATE *pdwvw ;
|
||||
BUF_UNION ubuf ;
|
||||
int *iptr ;
|
||||
int k, bufferlen, readcount = 0, count ;
|
||||
sf_count_t total = 0 ;
|
||||
@ -189,8 +190,8 @@ dwvw_read_s (SF_PRIVATE *psf, short *ptr, sf_count_t len)
|
||||
return 0 ;
|
||||
pdwvw = (DWVW_PRIVATE*) psf->codec_data ;
|
||||
|
||||
iptr = psf->u.ibuf ;
|
||||
bufferlen = ARRAY_LEN (psf->u.ibuf) ;
|
||||
iptr = ubuf.ibuf ;
|
||||
bufferlen = ARRAY_LEN (ubuf.ibuf) ;
|
||||
while (len > 0)
|
||||
{ readcount = (len >= bufferlen) ? bufferlen : len ;
|
||||
count = dwvw_decode_data (psf, pdwvw, iptr, readcount) ;
|
||||
@ -234,8 +235,9 @@ dwvw_read_i (SF_PRIVATE *psf, int *ptr, sf_count_t len)
|
||||
static sf_count_t
|
||||
dwvw_read_f (SF_PRIVATE *psf, float *ptr, sf_count_t len)
|
||||
{ DWVW_PRIVATE *pdwvw ;
|
||||
int *iptr ;
|
||||
int k, bufferlen, readcount = 0, count ;
|
||||
BUF_UNION ubuf ;
|
||||
int *iptr ;
|
||||
int k, bufferlen, readcount = 0, count ;
|
||||
sf_count_t total = 0 ;
|
||||
float normfact ;
|
||||
|
||||
@ -245,8 +247,8 @@ dwvw_read_f (SF_PRIVATE *psf, float *ptr, sf_count_t len)
|
||||
|
||||
normfact = (psf->norm_float == SF_TRUE) ? 1.0 / ((float) 0x80000000) : 1.0 ;
|
||||
|
||||
iptr = psf->u.ibuf ;
|
||||
bufferlen = ARRAY_LEN (psf->u.ibuf) ;
|
||||
iptr = ubuf.ibuf ;
|
||||
bufferlen = ARRAY_LEN (ubuf.ibuf) ;
|
||||
while (len > 0)
|
||||
{ readcount = (len >= bufferlen) ? bufferlen : len ;
|
||||
count = dwvw_decode_data (psf, pdwvw, iptr, readcount) ;
|
||||
@ -265,8 +267,9 @@ dwvw_read_f (SF_PRIVATE *psf, float *ptr, sf_count_t len)
|
||||
static sf_count_t
|
||||
dwvw_read_d (SF_PRIVATE *psf, double *ptr, sf_count_t len)
|
||||
{ DWVW_PRIVATE *pdwvw ;
|
||||
int *iptr ;
|
||||
int k, bufferlen, readcount = 0, count ;
|
||||
BUF_UNION ubuf ;
|
||||
int *iptr ;
|
||||
int k, bufferlen, readcount = 0, count ;
|
||||
sf_count_t total = 0 ;
|
||||
double normfact ;
|
||||
|
||||
@ -276,8 +279,8 @@ dwvw_read_d (SF_PRIVATE *psf, double *ptr, sf_count_t len)
|
||||
|
||||
normfact = (psf->norm_double == SF_TRUE) ? 1.0 / ((double) 0x80000000) : 1.0 ;
|
||||
|
||||
iptr = psf->u.ibuf ;
|
||||
bufferlen = ARRAY_LEN (psf->u.ibuf) ;
|
||||
iptr = ubuf.ibuf ;
|
||||
bufferlen = ARRAY_LEN (ubuf.ibuf) ;
|
||||
while (len > 0)
|
||||
{ readcount = (len >= bufferlen) ? bufferlen : len ;
|
||||
count = dwvw_decode_data (psf, pdwvw, iptr, readcount) ;
|
||||
@ -548,6 +551,7 @@ dwvw_encode_data (SF_PRIVATE *psf, DWVW_PRIVATE *pdwvw, const int *ptr, int len)
|
||||
static sf_count_t
|
||||
dwvw_write_s (SF_PRIVATE *psf, const short *ptr, sf_count_t len)
|
||||
{ DWVW_PRIVATE *pdwvw ;
|
||||
BUF_UNION ubuf ;
|
||||
int *iptr ;
|
||||
int k, bufferlen, writecount = 0, count ;
|
||||
sf_count_t total = 0 ;
|
||||
@ -556,8 +560,8 @@ dwvw_write_s (SF_PRIVATE *psf, const short *ptr, sf_count_t len)
|
||||
return 0 ;
|
||||
pdwvw = (DWVW_PRIVATE*) psf->codec_data ;
|
||||
|
||||
iptr = psf->u.ibuf ;
|
||||
bufferlen = ARRAY_LEN (psf->u.ibuf) ;
|
||||
iptr = ubuf.ibuf ;
|
||||
bufferlen = ARRAY_LEN (ubuf.ibuf) ;
|
||||
while (len > 0)
|
||||
{ writecount = (len >= bufferlen) ? bufferlen : len ;
|
||||
for (k = 0 ; k < writecount ; k++)
|
||||
@ -601,6 +605,7 @@ dwvw_write_i (SF_PRIVATE *psf, const int *ptr, sf_count_t len)
|
||||
static sf_count_t
|
||||
dwvw_write_f (SF_PRIVATE *psf, const float *ptr, sf_count_t len)
|
||||
{ DWVW_PRIVATE *pdwvw ;
|
||||
BUF_UNION ubuf ;
|
||||
int *iptr ;
|
||||
int k, bufferlen, writecount = 0, count ;
|
||||
sf_count_t total = 0 ;
|
||||
@ -612,8 +617,8 @@ dwvw_write_f (SF_PRIVATE *psf, const float *ptr, sf_count_t len)
|
||||
|
||||
normfact = (psf->norm_float == SF_TRUE) ? (1.0 * 0x7FFFFFFF) : 1.0 ;
|
||||
|
||||
iptr = psf->u.ibuf ;
|
||||
bufferlen = ARRAY_LEN (psf->u.ibuf) ;
|
||||
iptr = ubuf.ibuf ;
|
||||
bufferlen = ARRAY_LEN (ubuf.ibuf) ;
|
||||
while (len > 0)
|
||||
{ writecount = (len >= bufferlen) ? bufferlen : len ;
|
||||
for (k = 0 ; k < writecount ; k++)
|
||||
@ -632,6 +637,7 @@ dwvw_write_f (SF_PRIVATE *psf, const float *ptr, sf_count_t len)
|
||||
static sf_count_t
|
||||
dwvw_write_d (SF_PRIVATE *psf, const double *ptr, sf_count_t len)
|
||||
{ DWVW_PRIVATE *pdwvw ;
|
||||
BUF_UNION ubuf ;
|
||||
int *iptr ;
|
||||
int k, bufferlen, writecount = 0, count ;
|
||||
sf_count_t total = 0 ;
|
||||
@ -643,8 +649,8 @@ dwvw_write_d (SF_PRIVATE *psf, const double *ptr, sf_count_t len)
|
||||
|
||||
normfact = (psf->norm_double == SF_TRUE) ? (1.0 * 0x7FFFFFFF) : 1.0 ;
|
||||
|
||||
iptr = psf->u.ibuf ;
|
||||
bufferlen = ARRAY_LEN (psf->u.ibuf) ;
|
||||
iptr = ubuf.ibuf ;
|
||||
bufferlen = ARRAY_LEN (ubuf.ibuf) ;
|
||||
while (len > 0)
|
||||
{ writecount = (len >= bufferlen) ? bufferlen : len ;
|
||||
for (k = 0 ; k < writecount ; k++)
|
||||
|
202
src/float32.c
202
src/float32.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** Copyright (C) 1999-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
|
||||
** Copyright (C) 1999-2012 Erik de Castro Lopo <erikd@mega-nerd.com>
|
||||
**
|
||||
** This program is free software; you can redistribute it and/or modify
|
||||
** it under the terms of the GNU Lesser General Public License as published by
|
||||
@ -505,25 +505,26 @@ d2f_array (const double *src, float *dest, int count)
|
||||
|
||||
static sf_count_t
|
||||
host_read_f2s (SF_PRIVATE *psf, short *ptr, sf_count_t len)
|
||||
{ void (*convert) (const float *, int, short *, float) ;
|
||||
{ BUF_UNION ubuf ;
|
||||
void (*convert) (const float *, int, short *, float) ;
|
||||
int bufferlen, readcount ;
|
||||
sf_count_t total = 0 ;
|
||||
float scale ;
|
||||
|
||||
convert = (psf->add_clipping) ? f2s_clip_array : f2s_array ;
|
||||
bufferlen = ARRAY_LEN (psf->u.fbuf) ;
|
||||
bufferlen = ARRAY_LEN (ubuf.fbuf) ;
|
||||
scale = (psf->float_int_mult == 0) ? 1.0 : 0x7FFF / psf->float_max ;
|
||||
|
||||
while (len > 0)
|
||||
{ if (len < bufferlen)
|
||||
bufferlen = (int) len ;
|
||||
readcount = psf_fread (psf->u.fbuf, sizeof (float), bufferlen, psf) ;
|
||||
readcount = psf_fread (ubuf.fbuf, sizeof (float), bufferlen, psf) ;
|
||||
|
||||
/* Fix me : Need lef2s_array */
|
||||
if (psf->data_endswap == SF_TRUE)
|
||||
endswap_int_array (psf->u.ibuf, bufferlen) ;
|
||||
endswap_int_array (ubuf.ibuf, bufferlen) ;
|
||||
|
||||
convert (psf->u.fbuf, readcount, ptr + total, scale) ;
|
||||
convert (ubuf.fbuf, readcount, ptr + total, scale) ;
|
||||
total += readcount ;
|
||||
if (readcount < bufferlen)
|
||||
break ;
|
||||
@ -535,24 +536,25 @@ host_read_f2s (SF_PRIVATE *psf, short *ptr, sf_count_t len)
|
||||
|
||||
static sf_count_t
|
||||
host_read_f2i (SF_PRIVATE *psf, int *ptr, sf_count_t len)
|
||||
{ void (*convert) (const float *, int, int *, float) ;
|
||||
{ BUF_UNION ubuf ;
|
||||
void (*convert) (const float *, int, int *, float) ;
|
||||
int bufferlen, readcount ;
|
||||
sf_count_t total = 0 ;
|
||||
float scale ;
|
||||
|
||||
convert = (psf->add_clipping) ? f2i_clip_array : f2i_array ;
|
||||
bufferlen = ARRAY_LEN (psf->u.fbuf) ;
|
||||
bufferlen = ARRAY_LEN (ubuf.fbuf) ;
|
||||
scale = (psf->float_int_mult == 0) ? 1.0 : 0x7FFFFFFF / psf->float_max ;
|
||||
|
||||
while (len > 0)
|
||||
{ if (len < bufferlen)
|
||||
bufferlen = (int) len ;
|
||||
readcount = psf_fread (psf->u.fbuf, sizeof (float), bufferlen, psf) ;
|
||||
readcount = psf_fread (ubuf.fbuf, sizeof (float), bufferlen, psf) ;
|
||||
|
||||
if (psf->data_endswap == SF_TRUE)
|
||||
endswap_int_array (psf->u.ibuf, bufferlen) ;
|
||||
endswap_int_array (ubuf.ibuf, bufferlen) ;
|
||||
|
||||
convert (psf->u.fbuf, readcount, ptr + total, scale) ;
|
||||
convert (ubuf.fbuf, readcount, ptr + total, scale) ;
|
||||
total += readcount ;
|
||||
if (readcount < bufferlen)
|
||||
break ;
|
||||
@ -564,20 +566,21 @@ host_read_f2i (SF_PRIVATE *psf, int *ptr, sf_count_t len)
|
||||
|
||||
static sf_count_t
|
||||
host_read_f (SF_PRIVATE *psf, float *ptr, sf_count_t len)
|
||||
{ int bufferlen, readcount ;
|
||||
{ BUF_UNION ubuf ;
|
||||
int bufferlen, readcount ;
|
||||
sf_count_t total = 0 ;
|
||||
|
||||
if (psf->data_endswap != SF_TRUE)
|
||||
return psf_fread (ptr, sizeof (float), len, psf) ;
|
||||
|
||||
bufferlen = ARRAY_LEN (psf->u.fbuf) ;
|
||||
bufferlen = ARRAY_LEN (ubuf.fbuf) ;
|
||||
|
||||
while (len > 0)
|
||||
{ if (len < bufferlen)
|
||||
bufferlen = (int) len ;
|
||||
readcount = psf_fread (psf->u.fbuf, sizeof (float), bufferlen, psf) ;
|
||||
readcount = psf_fread (ubuf.fbuf, sizeof (float), bufferlen, psf) ;
|
||||
|
||||
endswap_int_copy ((int*) (ptr + total), psf->u.ibuf, readcount) ;
|
||||
endswap_int_copy ((int*) (ptr + total), ubuf.ibuf, readcount) ;
|
||||
|
||||
total += readcount ;
|
||||
if (readcount < bufferlen)
|
||||
@ -590,21 +593,22 @@ host_read_f (SF_PRIVATE *psf, float *ptr, sf_count_t len)
|
||||
|
||||
static sf_count_t
|
||||
host_read_f2d (SF_PRIVATE *psf, double *ptr, sf_count_t len)
|
||||
{ int bufferlen, readcount ;
|
||||
{ BUF_UNION ubuf ;
|
||||
int bufferlen, readcount ;
|
||||
sf_count_t total = 0 ;
|
||||
|
||||
bufferlen = ARRAY_LEN (psf->u.fbuf) ;
|
||||
bufferlen = ARRAY_LEN (ubuf.fbuf) ;
|
||||
|
||||
while (len > 0)
|
||||
{ if (len < bufferlen)
|
||||
bufferlen = (int) len ;
|
||||
readcount = psf_fread (psf->u.fbuf, sizeof (float), bufferlen, psf) ;
|
||||
readcount = psf_fread (ubuf.fbuf, sizeof (float), bufferlen, psf) ;
|
||||
|
||||
if (psf->data_endswap == SF_TRUE)
|
||||
endswap_int_array (psf->u.ibuf, bufferlen) ;
|
||||
endswap_int_array (ubuf.ibuf, bufferlen) ;
|
||||
|
||||
/* Fix me : Need lef2d_array */
|
||||
f2d_array (psf->u.fbuf, readcount, ptr + total) ;
|
||||
f2d_array (ubuf.fbuf, readcount, ptr + total) ;
|
||||
total += readcount ;
|
||||
if (readcount < bufferlen)
|
||||
break ;
|
||||
@ -616,26 +620,27 @@ host_read_f2d (SF_PRIVATE *psf, double *ptr, sf_count_t len)
|
||||
|
||||
static sf_count_t
|
||||
host_write_s2f (SF_PRIVATE *psf, const short *ptr, sf_count_t len)
|
||||
{ int bufferlen, writecount ;
|
||||
{ BUF_UNION ubuf ;
|
||||
int bufferlen, writecount ;
|
||||
sf_count_t total = 0 ;
|
||||
float scale ;
|
||||
|
||||
/* Erik */
|
||||
scale = (psf->scale_int_float == 0) ? 1.0 : 1.0 / 0x8000 ;
|
||||
bufferlen = ARRAY_LEN (psf->u.fbuf) ;
|
||||
bufferlen = ARRAY_LEN (ubuf.fbuf) ;
|
||||
|
||||
while (len > 0)
|
||||
{ if (len < bufferlen)
|
||||
bufferlen = (int) len ;
|
||||
s2f_array (ptr + total, psf->u.fbuf, bufferlen, scale) ;
|
||||
s2f_array (ptr + total, ubuf.fbuf, bufferlen, scale) ;
|
||||
|
||||
if (psf->peak_info)
|
||||
float32_peak_update (psf, psf->u.fbuf, bufferlen, total / psf->sf.channels) ;
|
||||
float32_peak_update (psf, ubuf.fbuf, bufferlen, total / psf->sf.channels) ;
|
||||
|
||||
if (psf->data_endswap == SF_TRUE)
|
||||
endswap_int_array (psf->u.ibuf, bufferlen) ;
|
||||
endswap_int_array (ubuf.ibuf, bufferlen) ;
|
||||
|
||||
writecount = psf_fwrite (psf->u.fbuf, sizeof (float), bufferlen, psf) ;
|
||||
writecount = psf_fwrite (ubuf.fbuf, sizeof (float), bufferlen, psf) ;
|
||||
total += writecount ;
|
||||
if (writecount < bufferlen)
|
||||
break ;
|
||||
@ -647,25 +652,26 @@ host_write_s2f (SF_PRIVATE *psf, const short *ptr, sf_count_t len)
|
||||
|
||||
static sf_count_t
|
||||
host_write_i2f (SF_PRIVATE *psf, const int *ptr, sf_count_t len)
|
||||
{ int bufferlen, writecount ;
|
||||
{ BUF_UNION ubuf ;
|
||||
int bufferlen, writecount ;
|
||||
sf_count_t total = 0 ;
|
||||
float scale ;
|
||||
|
||||
scale = (psf->scale_int_float == 0) ? 1.0 : 1.0 / (8.0 * 0x10000000) ;
|
||||
bufferlen = ARRAY_LEN (psf->u.fbuf) ;
|
||||
bufferlen = ARRAY_LEN (ubuf.fbuf) ;
|
||||
|
||||
while (len > 0)
|
||||
{ if (len < bufferlen)
|
||||
bufferlen = (int) len ;
|
||||
i2f_array (ptr + total, psf->u.fbuf, bufferlen, scale) ;
|
||||
i2f_array (ptr + total, ubuf.fbuf, bufferlen, scale) ;
|
||||
|
||||
if (psf->peak_info)
|
||||
float32_peak_update (psf, psf->u.fbuf, bufferlen, total / psf->sf.channels) ;
|
||||
float32_peak_update (psf, ubuf.fbuf, bufferlen, total / psf->sf.channels) ;
|
||||
|
||||
if (psf->data_endswap == SF_TRUE)
|
||||
endswap_int_array (psf->u.ibuf, bufferlen) ;
|
||||
endswap_int_array (ubuf.ibuf, bufferlen) ;
|
||||
|
||||
writecount = psf_fwrite (psf->u.fbuf, sizeof (float) , bufferlen, psf) ;
|
||||
writecount = psf_fwrite (ubuf.fbuf, sizeof (float) , bufferlen, psf) ;
|
||||
total += writecount ;
|
||||
if (writecount < bufferlen)
|
||||
break ;
|
||||
@ -677,7 +683,8 @@ host_write_i2f (SF_PRIVATE *psf, const int *ptr, sf_count_t len)
|
||||
|
||||
static sf_count_t
|
||||
host_write_f (SF_PRIVATE *psf, const float *ptr, sf_count_t len)
|
||||
{ int bufferlen, writecount ;
|
||||
{ BUF_UNION ubuf ;
|
||||
int bufferlen, writecount ;
|
||||
sf_count_t total = 0 ;
|
||||
|
||||
if (psf->peak_info)
|
||||
@ -686,15 +693,15 @@ host_write_f (SF_PRIVATE *psf, const float *ptr, sf_count_t len)
|
||||
if (psf->data_endswap != SF_TRUE)
|
||||
return psf_fwrite (ptr, sizeof (float), len, psf) ;
|
||||
|
||||
bufferlen = ARRAY_LEN (psf->u.fbuf) ;
|
||||
bufferlen = ARRAY_LEN (ubuf.fbuf) ;
|
||||
|
||||
while (len > 0)
|
||||
{ if (len < bufferlen)
|
||||
bufferlen = (int) len ;
|
||||
|
||||
endswap_int_copy (psf->u.ibuf, (const int*) (ptr + total), bufferlen) ;
|
||||
endswap_int_copy (ubuf.ibuf, (const int*) (ptr + total), bufferlen) ;
|
||||
|
||||
writecount = psf_fwrite (psf->u.fbuf, sizeof (float), bufferlen, psf) ;
|
||||
writecount = psf_fwrite (ubuf.fbuf, sizeof (float), bufferlen, psf) ;
|
||||
total += writecount ;
|
||||
if (writecount < bufferlen)
|
||||
break ;
|
||||
@ -706,24 +713,25 @@ host_write_f (SF_PRIVATE *psf, const float *ptr, sf_count_t len)
|
||||
|
||||
static sf_count_t
|
||||
host_write_d2f (SF_PRIVATE *psf, const double *ptr, sf_count_t len)
|
||||
{ int bufferlen, writecount ;
|
||||
{ BUF_UNION ubuf ;
|
||||
int bufferlen, writecount ;
|
||||
sf_count_t total = 0 ;
|
||||
|
||||
bufferlen = ARRAY_LEN (psf->u.fbuf) ;
|
||||
bufferlen = ARRAY_LEN (ubuf.fbuf) ;
|
||||
|
||||
while (len > 0)
|
||||
{ if (len < bufferlen)
|
||||
bufferlen = (int) len ;
|
||||
|
||||
d2f_array (ptr + total, psf->u.fbuf, bufferlen) ;
|
||||
d2f_array (ptr + total, ubuf.fbuf, bufferlen) ;
|
||||
|
||||
if (psf->peak_info)
|
||||
float32_peak_update (psf, psf->u.fbuf, bufferlen, total / psf->sf.channels) ;
|
||||
float32_peak_update (psf, ubuf.fbuf, bufferlen, total / psf->sf.channels) ;
|
||||
|
||||
if (psf->data_endswap == SF_TRUE)
|
||||
endswap_int_array (psf->u.ibuf, bufferlen) ;
|
||||
endswap_int_array (ubuf.ibuf, bufferlen) ;
|
||||
|
||||
writecount = psf_fwrite (psf->u.fbuf, sizeof (float), bufferlen, psf) ;
|
||||
writecount = psf_fwrite (ubuf.fbuf, sizeof (float), bufferlen, psf) ;
|
||||
total += writecount ;
|
||||
if (writecount < bufferlen)
|
||||
break ;
|
||||
@ -738,24 +746,25 @@ host_write_d2f (SF_PRIVATE *psf, const double *ptr, sf_count_t len)
|
||||
|
||||
static sf_count_t
|
||||
replace_read_f2s (SF_PRIVATE *psf, short *ptr, sf_count_t len)
|
||||
{ int bufferlen, readcount ;
|
||||
{ BUF_UNION ubuf ;
|
||||
int bufferlen, readcount ;
|
||||
sf_count_t total = 0 ;
|
||||
float scale ;
|
||||
|
||||
bufferlen = ARRAY_LEN (psf->u.fbuf) ;
|
||||
bufferlen = ARRAY_LEN (ubuf.fbuf) ;
|
||||
scale = (psf->float_int_mult == 0) ? 1.0 : 0x7FFF / psf->float_max ;
|
||||
|
||||
while (len > 0)
|
||||
{ if (len < bufferlen)
|
||||
bufferlen = (int) len ;
|
||||
readcount = psf_fread (psf->u.fbuf, sizeof (float), bufferlen, psf) ;
|
||||
readcount = psf_fread (ubuf.fbuf, sizeof (float), bufferlen, psf) ;
|
||||
|
||||
if (psf->data_endswap == SF_TRUE)
|
||||
endswap_int_array (psf->u.ibuf, bufferlen) ;
|
||||
endswap_int_array (ubuf.ibuf, bufferlen) ;
|
||||
|
||||
bf2f_array (psf->u.fbuf, bufferlen) ;
|
||||
bf2f_array (ubuf.fbuf, bufferlen) ;
|
||||
|
||||
f2s_array (psf->u.fbuf, readcount, ptr + total, scale) ;
|
||||
f2s_array (ubuf.fbuf, readcount, ptr + total, scale) ;
|
||||
total += readcount ;
|
||||
if (readcount < bufferlen)
|
||||
break ;
|
||||
@ -767,24 +776,25 @@ replace_read_f2s (SF_PRIVATE *psf, short *ptr, sf_count_t len)
|
||||
|
||||
static sf_count_t
|
||||
replace_read_f2i (SF_PRIVATE *psf, int *ptr, sf_count_t len)
|
||||
{ int bufferlen, readcount ;
|
||||
{ BUF_UNION ubuf ;
|
||||
int bufferlen, readcount ;
|
||||
sf_count_t total = 0 ;
|
||||
float scale ;
|
||||
|
||||
bufferlen = ARRAY_LEN (psf->u.fbuf) ;
|
||||
bufferlen = ARRAY_LEN (ubuf.fbuf) ;
|
||||
scale = (psf->float_int_mult == 0) ? 1.0 : 0x7FFF / psf->float_max ;
|
||||
|
||||
while (len > 0)
|
||||
{ if (len < bufferlen)
|
||||
bufferlen = (int) len ;
|
||||
readcount = psf_fread (psf->u.fbuf, sizeof (float), bufferlen, psf) ;
|
||||
readcount = psf_fread (ubuf.fbuf, sizeof (float), bufferlen, psf) ;
|
||||
|
||||
if (psf->data_endswap == SF_TRUE)
|
||||
endswap_int_array (psf->u.ibuf, bufferlen) ;
|
||||
endswap_int_array (ubuf.ibuf, bufferlen) ;
|
||||
|
||||
bf2f_array (psf->u.fbuf, bufferlen) ;
|
||||
bf2f_array (ubuf.fbuf, bufferlen) ;
|
||||
|
||||
f2i_array (psf->u.fbuf, readcount, ptr + total, scale) ;
|
||||
f2i_array (ubuf.fbuf, readcount, ptr + total, scale) ;
|
||||
total += readcount ;
|
||||
if (readcount < bufferlen)
|
||||
break ;
|
||||
@ -796,24 +806,25 @@ replace_read_f2i (SF_PRIVATE *psf, int *ptr, sf_count_t len)
|
||||
|
||||
static sf_count_t
|
||||
replace_read_f (SF_PRIVATE *psf, float *ptr, sf_count_t len)
|
||||
{ int bufferlen, readcount ;
|
||||
{ BUF_UNION ubuf ;
|
||||
int bufferlen, readcount ;
|
||||
sf_count_t total = 0 ;
|
||||
|
||||
/* FIX THIS */
|
||||
|
||||
bufferlen = ARRAY_LEN (psf->u.fbuf) ;
|
||||
bufferlen = ARRAY_LEN (ubuf.fbuf) ;
|
||||
|
||||
while (len > 0)
|
||||
{ if (len < bufferlen)
|
||||
bufferlen = (int) len ;
|
||||
readcount = psf_fread (psf->u.fbuf, sizeof (float), bufferlen, psf) ;
|
||||
readcount = psf_fread (ubuf.fbuf, sizeof (float), bufferlen, psf) ;
|
||||
|
||||
if (psf->data_endswap == SF_TRUE)
|
||||
endswap_int_array (psf->u.ibuf, bufferlen) ;
|
||||
endswap_int_array (ubuf.ibuf, bufferlen) ;
|
||||
|
||||
bf2f_array (psf->u.fbuf, bufferlen) ;
|
||||
bf2f_array (ubuf.fbuf, bufferlen) ;
|
||||
|
||||
memcpy (ptr + total, psf->u.fbuf, bufferlen * sizeof (float)) ;
|
||||
memcpy (ptr + total, ubuf.fbuf, bufferlen * sizeof (float)) ;
|
||||
|
||||
total += readcount ;
|
||||
if (readcount < bufferlen)
|
||||
@ -826,22 +837,23 @@ replace_read_f (SF_PRIVATE *psf, float *ptr, sf_count_t len)
|
||||
|
||||
static sf_count_t
|
||||
replace_read_f2d (SF_PRIVATE *psf, double *ptr, sf_count_t len)
|
||||
{ int bufferlen, readcount ;
|
||||
{ BUF_UNION ubuf ;
|
||||
int bufferlen, readcount ;
|
||||
sf_count_t total = 0 ;
|
||||
|
||||
bufferlen = ARRAY_LEN (psf->u.fbuf) ;
|
||||
bufferlen = ARRAY_LEN (ubuf.fbuf) ;
|
||||
|
||||
while (len > 0)
|
||||
{ if (len < bufferlen)
|
||||
bufferlen = (int) len ;
|
||||
readcount = psf_fread (psf->u.fbuf, sizeof (float), bufferlen, psf) ;
|
||||
readcount = psf_fread (ubuf.fbuf, sizeof (float), bufferlen, psf) ;
|
||||
|
||||
if (psf->data_endswap == SF_TRUE)
|
||||
endswap_int_array (psf->u.ibuf, bufferlen) ;
|
||||
endswap_int_array (ubuf.ibuf, bufferlen) ;
|
||||
|
||||
bf2f_array (psf->u.fbuf, bufferlen) ;
|
||||
bf2f_array (ubuf.fbuf, bufferlen) ;
|
||||
|
||||
f2d_array (psf->u.fbuf, readcount, ptr + total) ;
|
||||
f2d_array (ubuf.fbuf, readcount, ptr + total) ;
|
||||
total += readcount ;
|
||||
if (readcount < bufferlen)
|
||||
break ;
|
||||
@ -853,27 +865,28 @@ replace_read_f2d (SF_PRIVATE *psf, double *ptr, sf_count_t len)
|
||||
|
||||
static sf_count_t
|
||||
replace_write_s2f (SF_PRIVATE *psf, const short *ptr, sf_count_t len)
|
||||
{ int bufferlen, writecount ;
|
||||
{ BUF_UNION ubuf ;
|
||||
int bufferlen, writecount ;
|
||||
sf_count_t total = 0 ;
|
||||
float scale ;
|
||||
|
||||
scale = (psf->scale_int_float == 0) ? 1.0 : 1.0 / 0x8000 ;
|
||||
bufferlen = ARRAY_LEN (psf->u.fbuf) ;
|
||||
bufferlen = ARRAY_LEN (ubuf.fbuf) ;
|
||||
|
||||
while (len > 0)
|
||||
{ if (len < bufferlen)
|
||||
bufferlen = (int) len ;
|
||||
s2f_array (ptr + total, psf->u.fbuf, bufferlen, scale) ;
|
||||
s2f_array (ptr + total, ubuf.fbuf, bufferlen, scale) ;
|
||||
|
||||
if (psf->peak_info)
|
||||
float32_peak_update (psf, psf->u.fbuf, bufferlen, total / psf->sf.channels) ;
|
||||
float32_peak_update (psf, ubuf.fbuf, bufferlen, total / psf->sf.channels) ;
|
||||
|
||||
f2bf_array (psf->u.fbuf, bufferlen) ;
|
||||
f2bf_array (ubuf.fbuf, bufferlen) ;
|
||||
|
||||
if (psf->data_endswap == SF_TRUE)
|
||||
endswap_int_array (psf->u.ibuf, bufferlen) ;
|
||||
endswap_int_array (ubuf.ibuf, bufferlen) ;
|
||||
|
||||
writecount = psf_fwrite (psf->u.fbuf, sizeof (float), bufferlen, psf) ;
|
||||
writecount = psf_fwrite (ubuf.fbuf, sizeof (float), bufferlen, psf) ;
|
||||
total += writecount ;
|
||||
if (writecount < bufferlen)
|
||||
break ;
|
||||
@ -885,27 +898,28 @@ replace_write_s2f (SF_PRIVATE *psf, const short *ptr, sf_count_t len)
|
||||
|
||||
static sf_count_t
|
||||
replace_write_i2f (SF_PRIVATE *psf, const int *ptr, sf_count_t len)
|
||||
{ int bufferlen, writecount ;
|
||||
{ BUF_UNION ubuf ;
|
||||
int bufferlen, writecount ;
|
||||
sf_count_t total = 0 ;
|
||||
float scale ;
|
||||
|
||||
scale = (psf->scale_int_float == 0) ? 1.0 : 1.0 / (8.0 * 0x10000000) ;
|
||||
bufferlen = ARRAY_LEN (psf->u.fbuf) ;
|
||||
bufferlen = ARRAY_LEN (ubuf.fbuf) ;
|
||||
|
||||
while (len > 0)
|
||||
{ if (len < bufferlen)
|
||||
bufferlen = (int) len ;
|
||||
i2f_array (ptr + total, psf->u.fbuf, bufferlen, scale) ;
|
||||
i2f_array (ptr + total, ubuf.fbuf, bufferlen, scale) ;
|
||||
|
||||
if (psf->peak_info)
|
||||
float32_peak_update (psf, psf->u.fbuf, bufferlen, total / psf->sf.channels) ;
|
||||
float32_peak_update (psf, ubuf.fbuf, bufferlen, total / psf->sf.channels) ;
|
||||
|
||||
f2bf_array (psf->u.fbuf, bufferlen) ;
|
||||
f2bf_array (ubuf.fbuf, bufferlen) ;
|
||||
|
||||
if (psf->data_endswap == SF_TRUE)
|
||||
endswap_int_array (psf->u.ibuf, bufferlen) ;
|
||||
endswap_int_array (ubuf.ibuf, bufferlen) ;
|
||||
|
||||
writecount = psf_fwrite (psf->u.fbuf, sizeof (float), bufferlen, psf) ;
|
||||
writecount = psf_fwrite (ubuf.fbuf, sizeof (float), bufferlen, psf) ;
|
||||
total += writecount ;
|
||||
if (writecount < bufferlen)
|
||||
break ;
|
||||
@ -917,27 +931,28 @@ replace_write_i2f (SF_PRIVATE *psf, const int *ptr, sf_count_t len)
|
||||
|
||||
static sf_count_t
|
||||
replace_write_f (SF_PRIVATE *psf, const float *ptr, sf_count_t len)
|
||||
{ int bufferlen, writecount ;
|
||||
{ BUF_UNION ubuf ;
|
||||
int bufferlen, writecount ;
|
||||
sf_count_t total = 0 ;
|
||||
|
||||
/* FIX THIS */
|
||||
if (psf->peak_info)
|
||||
float32_peak_update (psf, ptr, len, 0) ;
|
||||
|
||||
bufferlen = ARRAY_LEN (psf->u.fbuf) ;
|
||||
bufferlen = ARRAY_LEN (ubuf.fbuf) ;
|
||||
|
||||
while (len > 0)
|
||||
{ if (len < bufferlen)
|
||||
bufferlen = (int) len ;
|
||||
|
||||
memcpy (psf->u.fbuf, ptr + total, bufferlen * sizeof (float)) ;
|
||||
memcpy (ubuf.fbuf, ptr + total, bufferlen * sizeof (float)) ;
|
||||
|
||||
f2bf_array (psf->u.fbuf, bufferlen) ;
|
||||
f2bf_array (ubuf.fbuf, bufferlen) ;
|
||||
|
||||
if (psf->data_endswap == SF_TRUE)
|
||||
endswap_int_array (psf->u.ibuf, bufferlen) ;
|
||||
endswap_int_array (ubuf.ibuf, bufferlen) ;
|
||||
|
||||
writecount = psf_fwrite (psf->u.fbuf, sizeof (float) , bufferlen, psf) ;
|
||||
writecount = psf_fwrite (ubuf.fbuf, sizeof (float) , bufferlen, psf) ;
|
||||
total += writecount ;
|
||||
if (writecount < bufferlen)
|
||||
break ;
|
||||
@ -949,25 +964,26 @@ replace_write_f (SF_PRIVATE *psf, const float *ptr, sf_count_t len)
|
||||
|
||||
static sf_count_t
|
||||
replace_write_d2f (SF_PRIVATE *psf, const double *ptr, sf_count_t len)
|
||||
{ int bufferlen, writecount ;
|
||||
{ BUF_UNION ubuf ;
|
||||
int bufferlen, writecount ;
|
||||
sf_count_t total = 0 ;
|
||||
|
||||
bufferlen = ARRAY_LEN (psf->u.fbuf) ;
|
||||
bufferlen = ARRAY_LEN (ubuf.fbuf) ;
|
||||
|
||||
while (len > 0)
|
||||
{ if (len < bufferlen)
|
||||
bufferlen = (int) len ;
|
||||
d2f_array (ptr + total, psf->u.fbuf, bufferlen) ;
|
||||
d2f_array (ptr + total, ubuf.fbuf, bufferlen) ;
|
||||
|
||||
if (psf->peak_info)
|
||||
float32_peak_update (psf, psf->u.fbuf, bufferlen, total / psf->sf.channels) ;
|
||||
float32_peak_update (psf, ubuf.fbuf, bufferlen, total / psf->sf.channels) ;
|
||||
|
||||
f2bf_array (psf->u.fbuf, bufferlen) ;
|
||||
f2bf_array (ubuf.fbuf, bufferlen) ;
|
||||
|
||||
if (psf->data_endswap == SF_TRUE)
|
||||
endswap_int_array (psf->u.ibuf, bufferlen) ;
|
||||
endswap_int_array (ubuf.ibuf, bufferlen) ;
|
||||
|
||||
writecount = psf_fwrite (psf->u.fbuf, sizeof (float), bufferlen, psf) ;
|
||||
writecount = psf_fwrite (ubuf.fbuf, sizeof (float), bufferlen, psf) ;
|
||||
total += writecount ;
|
||||
if (writecount < bufferlen)
|
||||
break ;
|
||||
|
30
src/g72x.c
30
src/g72x.c
@ -253,7 +253,8 @@ g72x_read_s (SF_PRIVATE *psf, short *ptr, sf_count_t len)
|
||||
|
||||
static sf_count_t
|
||||
g72x_read_i (SF_PRIVATE *psf, int *ptr, sf_count_t len)
|
||||
{ G72x_PRIVATE *pg72x ;
|
||||
{ BUF_UNION ubuf ;
|
||||
G72x_PRIVATE *pg72x ;
|
||||
short *sptr ;
|
||||
int k, bufferlen, readcount = 0, count ;
|
||||
sf_count_t total = 0 ;
|
||||
@ -262,7 +263,7 @@ g72x_read_i (SF_PRIVATE *psf, int *ptr, sf_count_t len)
|
||||
return 0 ;
|
||||
pg72x = (G72x_PRIVATE*) psf->codec_data ;
|
||||
|
||||
sptr = psf->u.sbuf ;
|
||||
sptr = ubuf.sbuf ;
|
||||
bufferlen = SF_BUFFER_LEN / sizeof (short) ;
|
||||
while (len > 0)
|
||||
{ readcount = (len >= bufferlen) ? bufferlen : len ;
|
||||
@ -282,7 +283,8 @@ g72x_read_i (SF_PRIVATE *psf, int *ptr, sf_count_t len)
|
||||
|
||||
static sf_count_t
|
||||
g72x_read_f (SF_PRIVATE *psf, float *ptr, sf_count_t len)
|
||||
{ G72x_PRIVATE *pg72x ;
|
||||
{ BUF_UNION ubuf ;
|
||||
G72x_PRIVATE *pg72x ;
|
||||
short *sptr ;
|
||||
int k, bufferlen, readcount = 0, count ;
|
||||
sf_count_t total = 0 ;
|
||||
@ -294,7 +296,7 @@ g72x_read_f (SF_PRIVATE *psf, float *ptr, sf_count_t len)
|
||||
|
||||
normfact = (psf->norm_float == SF_TRUE) ? 1.0 / ((float) 0x8000) : 1.0 ;
|
||||
|
||||
sptr = psf->u.sbuf ;
|
||||
sptr = ubuf.sbuf ;
|
||||
bufferlen = SF_BUFFER_LEN / sizeof (short) ;
|
||||
while (len > 0)
|
||||
{ readcount = (len >= bufferlen) ? bufferlen : len ;
|
||||
@ -313,7 +315,8 @@ g72x_read_f (SF_PRIVATE *psf, float *ptr, sf_count_t len)
|
||||
|
||||
static sf_count_t
|
||||
g72x_read_d (SF_PRIVATE *psf, double *ptr, sf_count_t len)
|
||||
{ G72x_PRIVATE *pg72x ;
|
||||
{ BUF_UNION ubuf ;
|
||||
G72x_PRIVATE *pg72x ;
|
||||
short *sptr ;
|
||||
int k, bufferlen, readcount = 0, count ;
|
||||
sf_count_t total = 0 ;
|
||||
@ -325,7 +328,7 @@ g72x_read_d (SF_PRIVATE *psf, double *ptr, sf_count_t len)
|
||||
|
||||
normfact = (psf->norm_double == SF_TRUE) ? 1.0 / ((double) 0x8000) : 1.0 ;
|
||||
|
||||
sptr = psf->u.sbuf ;
|
||||
sptr = ubuf.sbuf ;
|
||||
bufferlen = SF_BUFFER_LEN / sizeof (short) ;
|
||||
while (len > 0)
|
||||
{ readcount = (len >= bufferlen) ? bufferlen : len ;
|
||||
@ -491,7 +494,8 @@ g72x_write_s (SF_PRIVATE *psf, const short *ptr, sf_count_t len)
|
||||
|
||||
static sf_count_t
|
||||
g72x_write_i (SF_PRIVATE *psf, const int *ptr, sf_count_t len)
|
||||
{ G72x_PRIVATE *pg72x ;
|
||||
{ BUF_UNION ubuf ;
|
||||
G72x_PRIVATE *pg72x ;
|
||||
short *sptr ;
|
||||
int k, bufferlen, writecount = 0, count ;
|
||||
sf_count_t total = 0 ;
|
||||
@ -500,7 +504,7 @@ g72x_write_i (SF_PRIVATE *psf, const int *ptr, sf_count_t len)
|
||||
return 0 ;
|
||||
pg72x = (G72x_PRIVATE*) psf->codec_data ;
|
||||
|
||||
sptr = psf->u.sbuf ;
|
||||
sptr = ubuf.sbuf ;
|
||||
bufferlen = ((SF_BUFFER_LEN / psf->blockwidth) * psf->blockwidth) / sizeof (short) ;
|
||||
while (len > 0)
|
||||
{ writecount = (len >= bufferlen) ? bufferlen : len ;
|
||||
@ -518,7 +522,8 @@ g72x_write_i (SF_PRIVATE *psf, const int *ptr, sf_count_t len)
|
||||
|
||||
static sf_count_t
|
||||
g72x_write_f (SF_PRIVATE *psf, const float *ptr, sf_count_t len)
|
||||
{ G72x_PRIVATE *pg72x ;
|
||||
{ BUF_UNION ubuf ;
|
||||
G72x_PRIVATE *pg72x ;
|
||||
short *sptr ;
|
||||
int k, bufferlen, writecount = 0, count ;
|
||||
sf_count_t total = 0 ;
|
||||
@ -530,7 +535,7 @@ g72x_write_f (SF_PRIVATE *psf, const float *ptr, sf_count_t len)
|
||||
|
||||
normfact = (psf->norm_float == SF_TRUE) ? (1.0 * 0x8000) : 1.0 ;
|
||||
|
||||
sptr = psf->u.sbuf ;
|
||||
sptr = ubuf.sbuf ;
|
||||
bufferlen = ((SF_BUFFER_LEN / psf->blockwidth) * psf->blockwidth) / sizeof (short) ;
|
||||
while (len > 0)
|
||||
{ writecount = (len >= bufferlen) ? bufferlen : len ;
|
||||
@ -549,7 +554,8 @@ g72x_write_f (SF_PRIVATE *psf, const float *ptr, sf_count_t len)
|
||||
|
||||
static sf_count_t
|
||||
g72x_write_d (SF_PRIVATE *psf, const double *ptr, sf_count_t len)
|
||||
{ G72x_PRIVATE *pg72x ;
|
||||
{ BUF_UNION ubuf ;
|
||||
G72x_PRIVATE *pg72x ;
|
||||
short *sptr ;
|
||||
int k, bufferlen, writecount = 0, count ;
|
||||
sf_count_t total = 0 ;
|
||||
@ -561,7 +567,7 @@ g72x_write_d (SF_PRIVATE *psf, const double *ptr, sf_count_t len)
|
||||
|
||||
normfact = (psf->norm_double == SF_TRUE) ? (1.0 * 0x8000) : 1.0 ;
|
||||
|
||||
sptr = psf->u.sbuf ;
|
||||
sptr = ubuf.sbuf ;
|
||||
bufferlen = ((SF_BUFFER_LEN / psf->blockwidth) * psf->blockwidth) / sizeof (short) ;
|
||||
while (len > 0)
|
||||
{ writecount = (len >= bufferlen) ? bufferlen : len ;
|
||||
|
30
src/gsm610.c
30
src/gsm610.c
@ -290,6 +290,7 @@ gsm610_read_s (SF_PRIVATE *psf, short *ptr, sf_count_t len)
|
||||
static sf_count_t
|
||||
gsm610_read_i (SF_PRIVATE *psf, int *ptr, sf_count_t len)
|
||||
{ GSM610_PRIVATE *pgsm610 ;
|
||||
BUF_UNION ubuf ;
|
||||
short *sptr ;
|
||||
int k, bufferlen, readcount = 0, count ;
|
||||
sf_count_t total = 0 ;
|
||||
@ -298,8 +299,8 @@ gsm610_read_i (SF_PRIVATE *psf, int *ptr, sf_count_t len)
|
||||
return 0 ;
|
||||
pgsm610 = (GSM610_PRIVATE*) psf->codec_data ;
|
||||
|
||||
sptr = psf->u.sbuf ;
|
||||
bufferlen = ARRAY_LEN (psf->u.sbuf) ;
|
||||
sptr = ubuf.sbuf ;
|
||||
bufferlen = ARRAY_LEN (ubuf.sbuf) ;
|
||||
while (len > 0)
|
||||
{ readcount = (len >= bufferlen) ? bufferlen : len ;
|
||||
count = gsm610_read_block (psf, pgsm610, sptr, readcount) ;
|
||||
@ -315,6 +316,7 @@ gsm610_read_i (SF_PRIVATE *psf, int *ptr, sf_count_t len)
|
||||
static sf_count_t
|
||||
gsm610_read_f (SF_PRIVATE *psf, float *ptr, sf_count_t len)
|
||||
{ GSM610_PRIVATE *pgsm610 ;
|
||||
BUF_UNION ubuf ;
|
||||
short *sptr ;
|
||||
int k, bufferlen, readcount = 0, count ;
|
||||
sf_count_t total = 0 ;
|
||||
@ -326,8 +328,8 @@ gsm610_read_f (SF_PRIVATE *psf, float *ptr, sf_count_t len)
|
||||
|
||||
normfact = (psf->norm_float == SF_TRUE) ? 1.0 / ((float) 0x8000) : 1.0 ;
|
||||
|
||||
sptr = psf->u.sbuf ;
|
||||
bufferlen = ARRAY_LEN (psf->u.sbuf) ;
|
||||
sptr = ubuf.sbuf ;
|
||||
bufferlen = ARRAY_LEN (ubuf.sbuf) ;
|
||||
while (len > 0)
|
||||
{ readcount = (len >= bufferlen) ? bufferlen : len ;
|
||||
count = gsm610_read_block (psf, pgsm610, sptr, readcount) ;
|
||||
@ -343,6 +345,7 @@ gsm610_read_f (SF_PRIVATE *psf, float *ptr, sf_count_t len)
|
||||
static sf_count_t
|
||||
gsm610_read_d (SF_PRIVATE *psf, double *ptr, sf_count_t len)
|
||||
{ GSM610_PRIVATE *pgsm610 ;
|
||||
BUF_UNION ubuf ;
|
||||
short *sptr ;
|
||||
int k, bufferlen, readcount = 0, count ;
|
||||
sf_count_t total = 0 ;
|
||||
@ -354,8 +357,8 @@ gsm610_read_d (SF_PRIVATE *psf, double *ptr, sf_count_t len)
|
||||
return 0 ;
|
||||
pgsm610 = (GSM610_PRIVATE*) psf->codec_data ;
|
||||
|
||||
sptr = psf->u.sbuf ;
|
||||
bufferlen = ARRAY_LEN (psf->u.sbuf) ;
|
||||
sptr = ubuf.sbuf ;
|
||||
bufferlen = ARRAY_LEN (ubuf.sbuf) ;
|
||||
while (len > 0)
|
||||
{ readcount = (len >= bufferlen) ? bufferlen : len ;
|
||||
count = gsm610_read_block (psf, pgsm610, sptr, readcount) ;
|
||||
@ -517,6 +520,7 @@ gsm610_write_s (SF_PRIVATE *psf, const short *ptr, sf_count_t len)
|
||||
static sf_count_t
|
||||
gsm610_write_i (SF_PRIVATE *psf, const int *ptr, sf_count_t len)
|
||||
{ GSM610_PRIVATE *pgsm610 ;
|
||||
BUF_UNION ubuf ;
|
||||
short *sptr ;
|
||||
int k, bufferlen, writecount = 0, count ;
|
||||
sf_count_t total = 0 ;
|
||||
@ -525,8 +529,8 @@ gsm610_write_i (SF_PRIVATE *psf, const int *ptr, sf_count_t len)
|
||||
return 0 ;
|
||||
pgsm610 = (GSM610_PRIVATE*) psf->codec_data ;
|
||||
|
||||
sptr = psf->u.sbuf ;
|
||||
bufferlen = ARRAY_LEN (psf->u.sbuf) ;
|
||||
sptr = ubuf.sbuf ;
|
||||
bufferlen = ARRAY_LEN (ubuf.sbuf) ;
|
||||
while (len > 0)
|
||||
{ writecount = (len >= bufferlen) ? bufferlen : len ;
|
||||
for (k = 0 ; k < writecount ; k++)
|
||||
@ -542,6 +546,7 @@ gsm610_write_i (SF_PRIVATE *psf, const int *ptr, sf_count_t len)
|
||||
static sf_count_t
|
||||
gsm610_write_f (SF_PRIVATE *psf, const float *ptr, sf_count_t len)
|
||||
{ GSM610_PRIVATE *pgsm610 ;
|
||||
BUF_UNION ubuf ;
|
||||
short *sptr ;
|
||||
int k, bufferlen, writecount = 0, count ;
|
||||
sf_count_t total = 0 ;
|
||||
@ -553,8 +558,8 @@ gsm610_write_f (SF_PRIVATE *psf, const float *ptr, sf_count_t len)
|
||||
|
||||
normfact = (psf->norm_float == SF_TRUE) ? (1.0 * 0x7FFF) : 1.0 ;
|
||||
|
||||
sptr = psf->u.sbuf ;
|
||||
bufferlen = ARRAY_LEN (psf->u.sbuf) ;
|
||||
sptr = ubuf.sbuf ;
|
||||
bufferlen = ARRAY_LEN (ubuf.sbuf) ;
|
||||
while (len > 0)
|
||||
{ writecount = (len >= bufferlen) ? bufferlen : len ;
|
||||
for (k = 0 ; k < writecount ; k++)
|
||||
@ -570,6 +575,7 @@ gsm610_write_f (SF_PRIVATE *psf, const float *ptr, sf_count_t len)
|
||||
static sf_count_t
|
||||
gsm610_write_d (SF_PRIVATE *psf, const double *ptr, sf_count_t len)
|
||||
{ GSM610_PRIVATE *pgsm610 ;
|
||||
BUF_UNION ubuf ;
|
||||
short *sptr ;
|
||||
int k, bufferlen, writecount = 0, count ;
|
||||
sf_count_t total = 0 ;
|
||||
@ -581,8 +587,8 @@ gsm610_write_d (SF_PRIVATE *psf, const double *ptr, sf_count_t len)
|
||||
|
||||
normfact = (psf->norm_double == SF_TRUE) ? (1.0 * 0x7FFF) : 1.0 ;
|
||||
|
||||
sptr = psf->u.sbuf ;
|
||||
bufferlen = ARRAY_LEN (psf->u.sbuf) ;
|
||||
sptr = ubuf.sbuf ;
|
||||
bufferlen = ARRAY_LEN (ubuf.sbuf) ;
|
||||
while (len > 0)
|
||||
{ writecount = (len >= bufferlen) ? bufferlen : len ;
|
||||
for (k = 0 ; k < writecount ; k++)
|
||||
|
@ -625,6 +625,7 @@ ima_read_s (SF_PRIVATE *psf, short *ptr, sf_count_t len)
|
||||
static sf_count_t
|
||||
ima_read_i (SF_PRIVATE *psf, int *ptr, sf_count_t len)
|
||||
{ IMA_ADPCM_PRIVATE *pima ;
|
||||
BUF_UNION ubuf ;
|
||||
short *sptr ;
|
||||
int k, bufferlen, readcount, count ;
|
||||
sf_count_t total = 0 ;
|
||||
@ -633,8 +634,8 @@ ima_read_i (SF_PRIVATE *psf, int *ptr, sf_count_t len)
|
||||
return 0 ;
|
||||
pima = (IMA_ADPCM_PRIVATE*) psf->codec_data ;
|
||||
|
||||
sptr = psf->u.sbuf ;
|
||||
bufferlen = ARRAY_LEN (psf->u.sbuf) ;
|
||||
sptr = ubuf.sbuf ;
|
||||
bufferlen = ARRAY_LEN (ubuf.sbuf) ;
|
||||
while (len > 0)
|
||||
{ readcount = (len >= bufferlen) ? bufferlen : (int) len ;
|
||||
count = ima_read_block (psf, pima, sptr, readcount) ;
|
||||
@ -652,6 +653,7 @@ ima_read_i (SF_PRIVATE *psf, int *ptr, sf_count_t len)
|
||||
static sf_count_t
|
||||
ima_read_f (SF_PRIVATE *psf, float *ptr, sf_count_t len)
|
||||
{ IMA_ADPCM_PRIVATE *pima ;
|
||||
BUF_UNION ubuf ;
|
||||
short *sptr ;
|
||||
int k, bufferlen, readcount, count ;
|
||||
sf_count_t total = 0 ;
|
||||
@ -663,8 +665,8 @@ ima_read_f (SF_PRIVATE *psf, float *ptr, sf_count_t len)
|
||||
|
||||
normfact = (psf->norm_float == SF_TRUE) ? 1.0 / ((float) 0x8000) : 1.0 ;
|
||||
|
||||
sptr = psf->u.sbuf ;
|
||||
bufferlen = ARRAY_LEN (psf->u.sbuf) ;
|
||||
sptr = ubuf.sbuf ;
|
||||
bufferlen = ARRAY_LEN (ubuf.sbuf) ;
|
||||
while (len > 0)
|
||||
{ readcount = (len >= bufferlen) ? bufferlen : (int) len ;
|
||||
count = ima_read_block (psf, pima, sptr, readcount) ;
|
||||
@ -682,6 +684,7 @@ ima_read_f (SF_PRIVATE *psf, float *ptr, sf_count_t len)
|
||||
static sf_count_t
|
||||
ima_read_d (SF_PRIVATE *psf, double *ptr, sf_count_t len)
|
||||
{ IMA_ADPCM_PRIVATE *pima ;
|
||||
BUF_UNION ubuf ;
|
||||
short *sptr ;
|
||||
int k, bufferlen, readcount, count ;
|
||||
sf_count_t total = 0 ;
|
||||
@ -693,8 +696,8 @@ ima_read_d (SF_PRIVATE *psf, double *ptr, sf_count_t len)
|
||||
|
||||
normfact = (psf->norm_double == SF_TRUE) ? 1.0 / ((double) 0x8000) : 1.0 ;
|
||||
|
||||
sptr = psf->u.sbuf ;
|
||||
bufferlen = ARRAY_LEN (psf->u.sbuf) ;
|
||||
sptr = ubuf.sbuf ;
|
||||
bufferlen = ARRAY_LEN (ubuf.sbuf) ;
|
||||
while (len > 0)
|
||||
{ readcount = (len >= bufferlen) ? bufferlen : (int) len ;
|
||||
count = ima_read_block (psf, pima, sptr, readcount) ;
|
||||
@ -860,6 +863,7 @@ ima_write_s (SF_PRIVATE *psf, const short *ptr, sf_count_t len)
|
||||
static sf_count_t
|
||||
ima_write_i (SF_PRIVATE *psf, const int *ptr, sf_count_t len)
|
||||
{ IMA_ADPCM_PRIVATE *pima ;
|
||||
BUF_UNION ubuf ;
|
||||
short *sptr ;
|
||||
int k, bufferlen, writecount, count ;
|
||||
sf_count_t total = 0 ;
|
||||
@ -868,8 +872,8 @@ ima_write_i (SF_PRIVATE *psf, const int *ptr, sf_count_t len)
|
||||
return 0 ;
|
||||
pima = (IMA_ADPCM_PRIVATE*) psf->codec_data ;
|
||||
|
||||
sptr = psf->u.sbuf ;
|
||||
bufferlen = ARRAY_LEN (psf->u.sbuf) ;
|
||||
sptr = ubuf.sbuf ;
|
||||
bufferlen = ARRAY_LEN (ubuf.sbuf) ;
|
||||
while (len > 0)
|
||||
{ writecount = (len >= bufferlen) ? bufferlen : (int) len ;
|
||||
for (k = 0 ; k < writecount ; k++)
|
||||
@ -887,6 +891,7 @@ ima_write_i (SF_PRIVATE *psf, const int *ptr, sf_count_t len)
|
||||
static sf_count_t
|
||||
ima_write_f (SF_PRIVATE *psf, const float *ptr, sf_count_t len)
|
||||
{ IMA_ADPCM_PRIVATE *pima ;
|
||||
BUF_UNION ubuf ;
|
||||
short *sptr ;
|
||||
int k, bufferlen, writecount, count ;
|
||||
sf_count_t total = 0 ;
|
||||
@ -898,8 +903,8 @@ ima_write_f (SF_PRIVATE *psf, const float *ptr, sf_count_t len)
|
||||
|
||||
normfact = (psf->norm_float == SF_TRUE) ? (1.0 * 0x7FFF) : 1.0 ;
|
||||
|
||||
sptr = psf->u.sbuf ;
|
||||
bufferlen = ARRAY_LEN (psf->u.sbuf) ;
|
||||
sptr = ubuf.sbuf ;
|
||||
bufferlen = ARRAY_LEN (ubuf.sbuf) ;
|
||||
while (len > 0)
|
||||
{ writecount = (len >= bufferlen) ? bufferlen : (int) len ;
|
||||
for (k = 0 ; k < writecount ; k++)
|
||||
@ -917,6 +922,7 @@ ima_write_f (SF_PRIVATE *psf, const float *ptr, sf_count_t len)
|
||||
static sf_count_t
|
||||
ima_write_d (SF_PRIVATE *psf, const double *ptr, sf_count_t len)
|
||||
{ IMA_ADPCM_PRIVATE *pima ;
|
||||
BUF_UNION ubuf ;
|
||||
short *sptr ;
|
||||
int k, bufferlen, writecount, count ;
|
||||
sf_count_t total = 0 ;
|
||||
@ -928,8 +934,8 @@ ima_write_d (SF_PRIVATE *psf, const double *ptr, sf_count_t len)
|
||||
|
||||
normfact = (psf->norm_double == SF_TRUE) ? (1.0 * 0x7FFF) : 1.0 ;
|
||||
|
||||
sptr = psf->u.sbuf ;
|
||||
bufferlen = ARRAY_LEN (psf->u.sbuf) ;
|
||||
sptr = ubuf.sbuf ;
|
||||
bufferlen = ARRAY_LEN (ubuf.sbuf) ;
|
||||
while (len > 0)
|
||||
{ writecount = (len >= bufferlen) ? bufferlen : (int) len ;
|
||||
for (k = 0 ; k < writecount ; k++)
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** Copyright (C) 2002-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
|
||||
** Copyright (C) 2002-2012 Erik de Castro Lopo <erikd@mega-nerd.com>
|
||||
**
|
||||
** This program is free software; you can redistribute it and/or modify
|
||||
** it under the terms of the GNU Lesser General Public License as published by
|
||||
@ -206,7 +206,8 @@ mat4_write_header (SF_PRIVATE *psf, int calc_length)
|
||||
|
||||
static int
|
||||
mat4_read_header (SF_PRIVATE *psf)
|
||||
{ int marker, rows, cols, imag ;
|
||||
{ char buffer [256] ;
|
||||
int marker, rows, cols, imag ;
|
||||
unsigned namesize ;
|
||||
double value ;
|
||||
const char *marker_str ;
|
||||
@ -244,8 +245,8 @@ mat4_read_header (SF_PRIVATE *psf)
|
||||
|
||||
psf_binheader_readf (psf, "d", &value) ;
|
||||
|
||||
snprintf (psf->u.cbuf, sizeof (psf->u.cbuf), " Value : %f\n", value) ;
|
||||
psf_log_printf (psf, psf->u.cbuf) ;
|
||||
snprintf (buffer, sizeof (buffer), " Value : %f\n", value) ;
|
||||
psf_log_printf (psf, buffer) ;
|
||||
|
||||
if ((rows != 1) || (cols != 1))
|
||||
return SFE_MAT4_NO_SAMPLERATE ;
|
||||
|
23
src/mat5.c
23
src/mat5.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** Copyright (C) 2002-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
|
||||
** Copyright (C) 2002-2012 Erik de Castro Lopo <erikd@mega-nerd.com>
|
||||
**
|
||||
** This program is free software; you can redistribute it and/or modify
|
||||
** it under the terms of the GNU Lesser General Public License as published by
|
||||
@ -157,6 +157,7 @@ mat5_write_header (SF_PRIVATE *psf, int calc_length)
|
||||
{ static const char *filename = "MATLAB 5.0 MAT-file, written by " PACKAGE "-" VERSION ", " ;
|
||||
static const char *sr_name = "samplerate\0\0\0\0\0\0\0\0\0\0\0" ;
|
||||
static const char *wd_name = "wavedata\0" ;
|
||||
char buffer [256] ;
|
||||
sf_count_t current, datasize ;
|
||||
int encoding ;
|
||||
|
||||
@ -204,11 +205,11 @@ mat5_write_header (SF_PRIVATE *psf, int calc_length)
|
||||
psf->headindex = 0 ;
|
||||
psf_fseek (psf, 0, SEEK_SET) ;
|
||||
|
||||
psf_get_date_str (psf->u.cbuf, sizeof (psf->u.scbuf)) ;
|
||||
psf_binheader_writef (psf, "bb", filename, strlen (filename), psf->u.cbuf, strlen (psf->u.cbuf) + 1) ;
|
||||
psf_get_date_str (buffer, sizeof (buffer)) ;
|
||||
psf_binheader_writef (psf, "bb", filename, strlen (filename), buffer, strlen (buffer) + 1) ;
|
||||
|
||||
memset (psf->u.scbuf, ' ', 124 - psf->headindex) ;
|
||||
psf_binheader_writef (psf, "b", psf->u.scbuf, make_size_t (124 - psf->headindex)) ;
|
||||
memset (buffer, ' ', 124 - psf->headindex) ;
|
||||
psf_binheader_writef (psf, "b", buffer, make_size_t (124 - psf->headindex)) ;
|
||||
|
||||
psf->rwf_endian = psf->endian ;
|
||||
|
||||
@ -257,20 +258,20 @@ mat5_write_header (SF_PRIVATE *psf, int calc_length)
|
||||
|
||||
static int
|
||||
mat5_read_header (SF_PRIVATE *psf)
|
||||
{ char name [32] ;
|
||||
{ char buffer [256], name [32] ;
|
||||
short version, endian ;
|
||||
int type, flags1, flags2, rows, cols ;
|
||||
unsigned size ;
|
||||
|
||||
psf_binheader_readf (psf, "pb", 0, psf->u.cbuf, 124) ;
|
||||
psf_binheader_readf (psf, "pb", 0, buffer, 124) ;
|
||||
|
||||
psf->u.scbuf [125] = 0 ;
|
||||
buffer [125] = 0 ;
|
||||
|
||||
if (strlen (psf->u.cbuf) >= 124)
|
||||
if (strlen (buffer) >= 124)
|
||||
return SFE_UNIMPLEMENTED ;
|
||||
|
||||
if (strstr (psf->u.cbuf, "MATLAB 5.0 MAT-file") == psf->u.cbuf)
|
||||
psf_log_printf (psf, "%s\n", psf->u.scbuf) ;
|
||||
if (strstr (buffer, "MATLAB 5.0 MAT-file") == buffer)
|
||||
psf_log_printf (psf, "%s\n", buffer) ;
|
||||
|
||||
|
||||
psf_binheader_readf (psf, "E22", &version, &endian) ;
|
||||
|
@ -363,6 +363,7 @@ msadpcm_read_s (SF_PRIVATE *psf, short *ptr, sf_count_t len)
|
||||
static sf_count_t
|
||||
msadpcm_read_i (SF_PRIVATE *psf, int *ptr, sf_count_t len)
|
||||
{ MSADPCM_PRIVATE *pms ;
|
||||
BUF_UNION ubuf ;
|
||||
short *sptr ;
|
||||
int k, bufferlen, readcount = 0, count ;
|
||||
sf_count_t total = 0 ;
|
||||
@ -371,8 +372,8 @@ msadpcm_read_i (SF_PRIVATE *psf, int *ptr, sf_count_t len)
|
||||
return 0 ;
|
||||
pms = (MSADPCM_PRIVATE*) psf->codec_data ;
|
||||
|
||||
sptr = psf->u.sbuf ;
|
||||
bufferlen = ARRAY_LEN (psf->u.sbuf) ;
|
||||
sptr = ubuf.sbuf ;
|
||||
bufferlen = ARRAY_LEN (ubuf.sbuf) ;
|
||||
while (len > 0)
|
||||
{ readcount = (len >= bufferlen) ? bufferlen : len ;
|
||||
count = msadpcm_read_block (psf, pms, sptr, readcount) ;
|
||||
@ -389,6 +390,7 @@ msadpcm_read_i (SF_PRIVATE *psf, int *ptr, sf_count_t len)
|
||||
static sf_count_t
|
||||
msadpcm_read_f (SF_PRIVATE *psf, float *ptr, sf_count_t len)
|
||||
{ MSADPCM_PRIVATE *pms ;
|
||||
BUF_UNION ubuf ;
|
||||
short *sptr ;
|
||||
int k, bufferlen, readcount = 0, count ;
|
||||
sf_count_t total = 0 ;
|
||||
@ -399,8 +401,8 @@ msadpcm_read_f (SF_PRIVATE *psf, float *ptr, sf_count_t len)
|
||||
pms = (MSADPCM_PRIVATE*) psf->codec_data ;
|
||||
|
||||
normfact = (psf->norm_float == SF_TRUE) ? 1.0 / ((float) 0x8000) : 1.0 ;
|
||||
sptr = psf->u.sbuf ;
|
||||
bufferlen = ARRAY_LEN (psf->u.sbuf) ;
|
||||
sptr = ubuf.sbuf ;
|
||||
bufferlen = ARRAY_LEN (ubuf.sbuf) ;
|
||||
while (len > 0)
|
||||
{ readcount = (len >= bufferlen) ? bufferlen : len ;
|
||||
count = msadpcm_read_block (psf, pms, sptr, readcount) ;
|
||||
@ -417,6 +419,7 @@ msadpcm_read_f (SF_PRIVATE *psf, float *ptr, sf_count_t len)
|
||||
static sf_count_t
|
||||
msadpcm_read_d (SF_PRIVATE *psf, double *ptr, sf_count_t len)
|
||||
{ MSADPCM_PRIVATE *pms ;
|
||||
BUF_UNION ubuf ;
|
||||
short *sptr ;
|
||||
int k, bufferlen, readcount = 0, count ;
|
||||
sf_count_t total = 0 ;
|
||||
@ -428,8 +431,8 @@ msadpcm_read_d (SF_PRIVATE *psf, double *ptr, sf_count_t len)
|
||||
return 0 ;
|
||||
pms = (MSADPCM_PRIVATE*) psf->codec_data ;
|
||||
|
||||
sptr = psf->u.sbuf ;
|
||||
bufferlen = ARRAY_LEN (psf->u.sbuf) ;
|
||||
sptr = ubuf.sbuf ;
|
||||
bufferlen = ARRAY_LEN (ubuf.sbuf) ;
|
||||
while (len > 0)
|
||||
{ readcount = (len >= bufferlen) ? bufferlen : len ;
|
||||
count = msadpcm_read_block (psf, pms, sptr, readcount) ;
|
||||
@ -673,6 +676,7 @@ msadpcm_write_s (SF_PRIVATE *psf, const short *ptr, sf_count_t len)
|
||||
static sf_count_t
|
||||
msadpcm_write_i (SF_PRIVATE *psf, const int *ptr, sf_count_t len)
|
||||
{ MSADPCM_PRIVATE *pms ;
|
||||
BUF_UNION ubuf ;
|
||||
short *sptr ;
|
||||
int k, bufferlen, writecount, count ;
|
||||
sf_count_t total = 0 ;
|
||||
@ -681,8 +685,8 @@ msadpcm_write_i (SF_PRIVATE *psf, const int *ptr, sf_count_t len)
|
||||
return 0 ;
|
||||
pms = (MSADPCM_PRIVATE*) psf->codec_data ;
|
||||
|
||||
sptr = psf->u.sbuf ;
|
||||
bufferlen = ARRAY_LEN (psf->u.sbuf) ;
|
||||
sptr = ubuf.sbuf ;
|
||||
bufferlen = ARRAY_LEN (ubuf.sbuf) ;
|
||||
while (len > 0)
|
||||
{ writecount = (len >= bufferlen) ? bufferlen : len ;
|
||||
for (k = 0 ; k < writecount ; k++)
|
||||
@ -699,6 +703,7 @@ msadpcm_write_i (SF_PRIVATE *psf, const int *ptr, sf_count_t len)
|
||||
static sf_count_t
|
||||
msadpcm_write_f (SF_PRIVATE *psf, const float *ptr, sf_count_t len)
|
||||
{ MSADPCM_PRIVATE *pms ;
|
||||
BUF_UNION ubuf ;
|
||||
short *sptr ;
|
||||
int k, bufferlen, writecount, count ;
|
||||
sf_count_t total = 0 ;
|
||||
@ -710,8 +715,8 @@ msadpcm_write_f (SF_PRIVATE *psf, const float *ptr, sf_count_t len)
|
||||
|
||||
normfact = (psf->norm_float == SF_TRUE) ? (1.0 * 0x7FFF) : 1.0 ;
|
||||
|
||||
sptr = psf->u.sbuf ;
|
||||
bufferlen = ARRAY_LEN (psf->u.sbuf) ;
|
||||
sptr = ubuf.sbuf ;
|
||||
bufferlen = ARRAY_LEN (ubuf.sbuf) ;
|
||||
while (len > 0)
|
||||
{ writecount = (len >= bufferlen) ? bufferlen : len ;
|
||||
for (k = 0 ; k < writecount ; k++)
|
||||
@ -728,6 +733,7 @@ msadpcm_write_f (SF_PRIVATE *psf, const float *ptr, sf_count_t len)
|
||||
static sf_count_t
|
||||
msadpcm_write_d (SF_PRIVATE *psf, const double *ptr, sf_count_t len)
|
||||
{ MSADPCM_PRIVATE *pms ;
|
||||
BUF_UNION ubuf ;
|
||||
short *sptr ;
|
||||
int k, bufferlen, writecount, count ;
|
||||
sf_count_t total = 0 ;
|
||||
@ -739,8 +745,8 @@ msadpcm_write_d (SF_PRIVATE *psf, const double *ptr, sf_count_t len)
|
||||
return 0 ;
|
||||
pms = (MSADPCM_PRIVATE*) psf->codec_data ;
|
||||
|
||||
sptr = psf->u.sbuf ;
|
||||
bufferlen = ARRAY_LEN (psf->u.sbuf) ;
|
||||
sptr = ubuf.sbuf ;
|
||||
bufferlen = ARRAY_LEN (ubuf.sbuf) ;
|
||||
while (len > 0)
|
||||
{ writecount = (len >= bufferlen) ? bufferlen : len ;
|
||||
for (k = 0 ; k < writecount ; k++)
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** Copyright (C) 1999-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
|
||||
** Copyright (C) 1999-2012 Erik de Castro Lopo <erikd@mega-nerd.com>
|
||||
**
|
||||
** This program is free software; you can redistribute it and/or modify
|
||||
** it under the terms of the GNU Lesser General Public License as published by
|
||||
@ -118,14 +118,12 @@ static char bad_header [] =
|
||||
|
||||
static int
|
||||
nist_read_header (SF_PRIVATE *psf)
|
||||
{ char *psf_header ;
|
||||
{ char psf_header [NIST_HEADER_LENGTH + 2] ;
|
||||
int bitwidth = 0, count, encoding ;
|
||||
unsigned bytes = 0 ;
|
||||
char str [64], *cptr ;
|
||||
long samples ;
|
||||
|
||||
psf_header = psf->u.cbuf ;
|
||||
|
||||
if (sizeof (psf->header) <= NIST_HEADER_LENGTH)
|
||||
return SFE_INTERNAL ;
|
||||
|
||||
|
42
src/paf.c
42
src/paf.c
@ -555,7 +555,8 @@ paf24_read (SF_PRIVATE *psf, PAF24_PRIVATE *ppaf24, int *ptr, int len)
|
||||
|
||||
static sf_count_t
|
||||
paf24_read_s (SF_PRIVATE *psf, short *ptr, sf_count_t len)
|
||||
{ PAF24_PRIVATE *ppaf24 ;
|
||||
{ BUF_UNION ubuf ;
|
||||
PAF24_PRIVATE *ppaf24 ;
|
||||
int *iptr ;
|
||||
int k, bufferlen, readcount, count ;
|
||||
sf_count_t total = 0 ;
|
||||
@ -564,8 +565,8 @@ paf24_read_s (SF_PRIVATE *psf, short *ptr, sf_count_t len)
|
||||
return 0 ;
|
||||
ppaf24 = (PAF24_PRIVATE*) psf->codec_data ;
|
||||
|
||||
iptr = psf->u.ibuf ;
|
||||
bufferlen = ARRAY_LEN (psf->u.ibuf) ;
|
||||
iptr = ubuf.ibuf ;
|
||||
bufferlen = ARRAY_LEN (ubuf.ibuf) ;
|
||||
while (len > 0)
|
||||
{ readcount = (len >= bufferlen) ? bufferlen : len ;
|
||||
count = paf24_read (psf, ppaf24, iptr, readcount) ;
|
||||
@ -593,7 +594,8 @@ paf24_read_i (SF_PRIVATE *psf, int *ptr, sf_count_t len)
|
||||
|
||||
static sf_count_t
|
||||
paf24_read_f (SF_PRIVATE *psf, float *ptr, sf_count_t len)
|
||||
{ PAF24_PRIVATE *ppaf24 ;
|
||||
{ BUF_UNION ubuf ;
|
||||
PAF24_PRIVATE *ppaf24 ;
|
||||
int *iptr ;
|
||||
int k, bufferlen, readcount, count ;
|
||||
sf_count_t total = 0 ;
|
||||
@ -605,8 +607,8 @@ paf24_read_f (SF_PRIVATE *psf, float *ptr, sf_count_t len)
|
||||
|
||||
normfact = (psf->norm_float == SF_TRUE) ? (1.0 / 0x80000000) : (1.0 / 0x100) ;
|
||||
|
||||
iptr = psf->u.ibuf ;
|
||||
bufferlen = ARRAY_LEN (psf->u.ibuf) ;
|
||||
iptr = ubuf.ibuf ;
|
||||
bufferlen = ARRAY_LEN (ubuf.ibuf) ;
|
||||
while (len > 0)
|
||||
{ readcount = (len >= bufferlen) ? bufferlen : len ;
|
||||
count = paf24_read (psf, ppaf24, iptr, readcount) ;
|
||||
@ -620,7 +622,8 @@ paf24_read_f (SF_PRIVATE *psf, float *ptr, sf_count_t len)
|
||||
|
||||
static sf_count_t
|
||||
paf24_read_d (SF_PRIVATE *psf, double *ptr, sf_count_t len)
|
||||
{ PAF24_PRIVATE *ppaf24 ;
|
||||
{ BUF_UNION ubuf ;
|
||||
PAF24_PRIVATE *ppaf24 ;
|
||||
int *iptr ;
|
||||
int k, bufferlen, readcount, count ;
|
||||
sf_count_t total = 0 ;
|
||||
@ -632,8 +635,8 @@ paf24_read_d (SF_PRIVATE *psf, double *ptr, sf_count_t len)
|
||||
|
||||
normfact = (psf->norm_double == SF_TRUE) ? (1.0 / 0x80000000) : (1.0 / 0x100) ;
|
||||
|
||||
iptr = psf->u.ibuf ;
|
||||
bufferlen = ARRAY_LEN (psf->u.ibuf) ;
|
||||
iptr = ubuf.ibuf ;
|
||||
bufferlen = ARRAY_LEN (ubuf.ibuf) ;
|
||||
while (len > 0)
|
||||
{ readcount = (len >= bufferlen) ? bufferlen : len ;
|
||||
count = paf24_read (psf, ppaf24, iptr, readcount) ;
|
||||
@ -721,7 +724,8 @@ paf24_write (SF_PRIVATE *psf, PAF24_PRIVATE *ppaf24, const int *ptr, int len)
|
||||
|
||||
static sf_count_t
|
||||
paf24_write_s (SF_PRIVATE *psf, const short *ptr, sf_count_t len)
|
||||
{ PAF24_PRIVATE *ppaf24 ;
|
||||
{ BUF_UNION ubuf ;
|
||||
PAF24_PRIVATE *ppaf24 ;
|
||||
int *iptr ;
|
||||
int k, bufferlen, writecount = 0, count ;
|
||||
sf_count_t total = 0 ;
|
||||
@ -730,8 +734,8 @@ paf24_write_s (SF_PRIVATE *psf, const short *ptr, sf_count_t len)
|
||||
return 0 ;
|
||||
ppaf24 = (PAF24_PRIVATE*) psf->codec_data ;
|
||||
|
||||
iptr = psf->u.ibuf ;
|
||||
bufferlen = ARRAY_LEN (psf->u.ibuf) ;
|
||||
iptr = ubuf.ibuf ;
|
||||
bufferlen = ARRAY_LEN (ubuf.ibuf) ;
|
||||
while (len > 0)
|
||||
{ writecount = (len >= bufferlen) ? bufferlen : len ;
|
||||
for (k = 0 ; k < writecount ; k++)
|
||||
@ -771,7 +775,8 @@ paf24_write_i (SF_PRIVATE *psf, const int *ptr, sf_count_t len)
|
||||
|
||||
static sf_count_t
|
||||
paf24_write_f (SF_PRIVATE *psf, const float *ptr, sf_count_t len)
|
||||
{ PAF24_PRIVATE *ppaf24 ;
|
||||
{ BUF_UNION ubuf ;
|
||||
PAF24_PRIVATE *ppaf24 ;
|
||||
int *iptr ;
|
||||
int k, bufferlen, writecount = 0, count ;
|
||||
sf_count_t total = 0 ;
|
||||
@ -783,8 +788,8 @@ paf24_write_f (SF_PRIVATE *psf, const float *ptr, sf_count_t len)
|
||||
|
||||
normfact = (psf->norm_float == SF_TRUE) ? (1.0 * 0x7FFFFFFF) : (1.0 / 0x100) ;
|
||||
|
||||
iptr = psf->u.ibuf ;
|
||||
bufferlen = ARRAY_LEN (psf->u.ibuf) ;
|
||||
iptr = ubuf.ibuf ;
|
||||
bufferlen = ARRAY_LEN (ubuf.ibuf) ;
|
||||
while (len > 0)
|
||||
{ writecount = (len >= bufferlen) ? bufferlen : len ;
|
||||
for (k = 0 ; k < writecount ; k++)
|
||||
@ -801,7 +806,8 @@ paf24_write_f (SF_PRIVATE *psf, const float *ptr, sf_count_t len)
|
||||
|
||||
static sf_count_t
|
||||
paf24_write_d (SF_PRIVATE *psf, const double *ptr, sf_count_t len)
|
||||
{ PAF24_PRIVATE *ppaf24 ;
|
||||
{ BUF_UNION ubuf ;
|
||||
PAF24_PRIVATE *ppaf24 ;
|
||||
int *iptr ;
|
||||
int k, bufferlen, writecount = 0, count ;
|
||||
sf_count_t total = 0 ;
|
||||
@ -813,8 +819,8 @@ paf24_write_d (SF_PRIVATE *psf, const double *ptr, sf_count_t len)
|
||||
|
||||
normfact = (psf->norm_double == SF_TRUE) ? (1.0 * 0x7FFFFFFF) : (1.0 / 0x100) ;
|
||||
|
||||
iptr = psf->u.ibuf ;
|
||||
bufferlen = ARRAY_LEN (psf->u.ibuf) ;
|
||||
iptr = ubuf.ibuf ;
|
||||
bufferlen = ARRAY_LEN (ubuf.ibuf) ;
|
||||
while (len > 0)
|
||||
{ writecount = (len >= bufferlen) ? bufferlen : len ;
|
||||
for (k = 0 ; k < writecount ; k++)
|
||||
|
44
src/sds.c
44
src/sds.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** Copyright (C) 2002-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
|
||||
** Copyright (C) 2002-2012 Erik de Castro Lopo <erikd@mega-nerd.com>
|
||||
**
|
||||
** This program is free software; you can redistribute it and/or modify
|
||||
** it under the terms of the GNU Lesser General Public License as published by
|
||||
@ -550,7 +550,8 @@ sds_4byte_read (SF_PRIVATE *psf, SDS_PRIVATE *psds)
|
||||
|
||||
static sf_count_t
|
||||
sds_read_s (SF_PRIVATE *psf, short *ptr, sf_count_t len)
|
||||
{ SDS_PRIVATE *psds ;
|
||||
{ BUF_UNION ubuf ;
|
||||
SDS_PRIVATE *psds ;
|
||||
int *iptr ;
|
||||
int k, bufferlen, readcount, count ;
|
||||
sf_count_t total = 0 ;
|
||||
@ -559,8 +560,8 @@ sds_read_s (SF_PRIVATE *psf, short *ptr, sf_count_t len)
|
||||
return 0 ;
|
||||
psds = (SDS_PRIVATE*) psf->codec_data ;
|
||||
|
||||
iptr = psf->u.ibuf ;
|
||||
bufferlen = ARRAY_LEN (psf->u.ibuf) ;
|
||||
iptr = ubuf.ibuf ;
|
||||
bufferlen = ARRAY_LEN (ubuf.ibuf) ;
|
||||
while (len > 0)
|
||||
{ readcount = (len >= bufferlen) ? bufferlen : len ;
|
||||
count = sds_read (psf, psds, iptr, readcount) ;
|
||||
@ -589,7 +590,8 @@ sds_read_i (SF_PRIVATE *psf, int *ptr, sf_count_t len)
|
||||
|
||||
static sf_count_t
|
||||
sds_read_f (SF_PRIVATE *psf, float *ptr, sf_count_t len)
|
||||
{ SDS_PRIVATE *psds ;
|
||||
{ BUF_UNION ubuf ;
|
||||
SDS_PRIVATE *psds ;
|
||||
int *iptr ;
|
||||
int k, bufferlen, readcount, count ;
|
||||
sf_count_t total = 0 ;
|
||||
@ -604,8 +606,8 @@ sds_read_f (SF_PRIVATE *psf, float *ptr, sf_count_t len)
|
||||
else
|
||||
normfact = 1.0 / (1 << psds->bitwidth) ;
|
||||
|
||||
iptr = psf->u.ibuf ;
|
||||
bufferlen = ARRAY_LEN (psf->u.ibuf) ;
|
||||
iptr = ubuf.ibuf ;
|
||||
bufferlen = ARRAY_LEN (ubuf.ibuf) ;
|
||||
while (len > 0)
|
||||
{ readcount = (len >= bufferlen) ? bufferlen : len ;
|
||||
count = sds_read (psf, psds, iptr, readcount) ;
|
||||
@ -620,7 +622,8 @@ sds_read_f (SF_PRIVATE *psf, float *ptr, sf_count_t len)
|
||||
|
||||
static sf_count_t
|
||||
sds_read_d (SF_PRIVATE *psf, double *ptr, sf_count_t len)
|
||||
{ SDS_PRIVATE *psds ;
|
||||
{ BUF_UNION ubuf ;
|
||||
SDS_PRIVATE *psds ;
|
||||
int *iptr ;
|
||||
int k, bufferlen, readcount, count ;
|
||||
sf_count_t total = 0 ;
|
||||
@ -635,8 +638,8 @@ sds_read_d (SF_PRIVATE *psf, double *ptr, sf_count_t len)
|
||||
else
|
||||
normfact = 1.0 / (1 << psds->bitwidth) ;
|
||||
|
||||
iptr = psf->u.ibuf ;
|
||||
bufferlen = ARRAY_LEN (psf->u.ibuf) ;
|
||||
iptr = ubuf.ibuf ;
|
||||
bufferlen = ARRAY_LEN (ubuf.ibuf) ;
|
||||
while (len > 0)
|
||||
{ readcount = (len >= bufferlen) ? bufferlen : len ;
|
||||
count = sds_read (psf, psds, iptr, readcount) ;
|
||||
@ -880,7 +883,8 @@ sds_4byte_write (SF_PRIVATE *psf, SDS_PRIVATE *psds)
|
||||
|
||||
static sf_count_t
|
||||
sds_write_s (SF_PRIVATE *psf, const short *ptr, sf_count_t len)
|
||||
{ SDS_PRIVATE *psds ;
|
||||
{ BUF_UNION ubuf ;
|
||||
SDS_PRIVATE *psds ;
|
||||
int *iptr ;
|
||||
int k, bufferlen, writecount, count ;
|
||||
sf_count_t total = 0 ;
|
||||
@ -890,8 +894,8 @@ sds_write_s (SF_PRIVATE *psf, const short *ptr, sf_count_t len)
|
||||
psds = (SDS_PRIVATE*) psf->codec_data ;
|
||||
psds->total_written += len ;
|
||||
|
||||
iptr = psf->u.ibuf ;
|
||||
bufferlen = ARRAY_LEN (psf->u.ibuf) ;
|
||||
iptr = ubuf.ibuf ;
|
||||
bufferlen = ARRAY_LEN (ubuf.ibuf) ;
|
||||
while (len > 0)
|
||||
{ writecount = (len >= bufferlen) ? bufferlen : len ;
|
||||
for (k = 0 ; k < writecount ; k++)
|
||||
@ -921,7 +925,8 @@ sds_write_i (SF_PRIVATE *psf, const int *ptr, sf_count_t len)
|
||||
|
||||
static sf_count_t
|
||||
sds_write_f (SF_PRIVATE *psf, const float *ptr, sf_count_t len)
|
||||
{ SDS_PRIVATE *psds ;
|
||||
{ BUF_UNION ubuf ;
|
||||
SDS_PRIVATE *psds ;
|
||||
int *iptr ;
|
||||
int k, bufferlen, writecount, count ;
|
||||
sf_count_t total = 0 ;
|
||||
@ -937,8 +942,8 @@ sds_write_f (SF_PRIVATE *psf, const float *ptr, sf_count_t len)
|
||||
else
|
||||
normfact = 1.0 * (1 << psds->bitwidth) ;
|
||||
|
||||
iptr = psf->u.ibuf ;
|
||||
bufferlen = ARRAY_LEN (psf->u.ibuf) ;
|
||||
iptr = ubuf.ibuf ;
|
||||
bufferlen = ARRAY_LEN (ubuf.ibuf) ;
|
||||
while (len > 0)
|
||||
{ writecount = (len >= bufferlen) ? bufferlen : len ;
|
||||
for (k = 0 ; k < writecount ; k++)
|
||||
@ -953,7 +958,8 @@ sds_write_f (SF_PRIVATE *psf, const float *ptr, sf_count_t len)
|
||||
|
||||
static sf_count_t
|
||||
sds_write_d (SF_PRIVATE *psf, const double *ptr, sf_count_t len)
|
||||
{ SDS_PRIVATE *psds ;
|
||||
{ BUF_UNION ubuf ;
|
||||
SDS_PRIVATE *psds ;
|
||||
int *iptr ;
|
||||
int k, bufferlen, writecount, count ;
|
||||
sf_count_t total = 0 ;
|
||||
@ -969,8 +975,8 @@ sds_write_d (SF_PRIVATE *psf, const double *ptr, sf_count_t len)
|
||||
else
|
||||
normfact = 1.0 * (1 << psds->bitwidth) ;
|
||||
|
||||
iptr = psf->u.ibuf ;
|
||||
bufferlen = ARRAY_LEN (psf->u.ibuf) ;
|
||||
iptr = ubuf.ibuf ;
|
||||
bufferlen = ARRAY_LEN (ubuf.ibuf) ;
|
||||
while (len > 0)
|
||||
{ writecount = (len >= bufferlen) ? bufferlen : len ;
|
||||
for (k = 0 ; k < writecount ; k++)
|
||||
|
74
src/ulaw.c
74
src/ulaw.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** Copyright (C) 1999-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
|
||||
** Copyright (C) 1999-2012 Erik de Castro Lopo <erikd@mega-nerd.com>
|
||||
**
|
||||
** This program is free software; you can redistribute it and/or modify
|
||||
** it under the terms of the GNU Lesser General Public License as published by
|
||||
@ -859,16 +859,17 @@ d2ulaw_array (const double *ptr, int count, unsigned char *buffer, double normfa
|
||||
|
||||
static sf_count_t
|
||||
ulaw_read_ulaw2s (SF_PRIVATE *psf, short *ptr, sf_count_t len)
|
||||
{ int bufferlen, readcount ;
|
||||
{ BUF_UNION ubuf ;
|
||||
int bufferlen, readcount ;
|
||||
sf_count_t total = 0 ;
|
||||
|
||||
bufferlen = ARRAY_LEN (psf->u.ucbuf) ;
|
||||
bufferlen = ARRAY_LEN (ubuf.ucbuf) ;
|
||||
|
||||
while (len > 0)
|
||||
{ if (len < bufferlen)
|
||||
bufferlen = (int) len ;
|
||||
readcount = psf_fread (psf->u.ucbuf, 1, bufferlen, psf) ;
|
||||
ulaw2s_array (psf->u.ucbuf, readcount, ptr + total) ;
|
||||
readcount = psf_fread (ubuf.ucbuf, 1, bufferlen, psf) ;
|
||||
ulaw2s_array (ubuf.ucbuf, readcount, ptr + total) ;
|
||||
total += readcount ;
|
||||
if (readcount < bufferlen)
|
||||
break ;
|
||||
@ -880,16 +881,17 @@ ulaw_read_ulaw2s (SF_PRIVATE *psf, short *ptr, sf_count_t len)
|
||||
|
||||
static sf_count_t
|
||||
ulaw_read_ulaw2i (SF_PRIVATE *psf, int *ptr, sf_count_t len)
|
||||
{ int bufferlen, readcount ;
|
||||
{ BUF_UNION ubuf ;
|
||||
int bufferlen, readcount ;
|
||||
sf_count_t total = 0 ;
|
||||
|
||||
bufferlen = ARRAY_LEN (psf->u.ucbuf) ;
|
||||
bufferlen = ARRAY_LEN (ubuf.ucbuf) ;
|
||||
|
||||
while (len > 0)
|
||||
{ if (len < bufferlen)
|
||||
bufferlen = (int) len ;
|
||||
readcount = psf_fread (psf->u.ucbuf, 1, bufferlen, psf) ;
|
||||
ulaw2i_array (psf->u.ucbuf, readcount, ptr + total) ;
|
||||
readcount = psf_fread (ubuf.ucbuf, 1, bufferlen, psf) ;
|
||||
ulaw2i_array (ubuf.ucbuf, readcount, ptr + total) ;
|
||||
total += readcount ;
|
||||
if (readcount < bufferlen)
|
||||
break ;
|
||||
@ -901,19 +903,20 @@ ulaw_read_ulaw2i (SF_PRIVATE *psf, int *ptr, sf_count_t len)
|
||||
|
||||
static sf_count_t
|
||||
ulaw_read_ulaw2f (SF_PRIVATE *psf, float *ptr, sf_count_t len)
|
||||
{ int bufferlen, readcount ;
|
||||
{ BUF_UNION ubuf ;
|
||||
int bufferlen, readcount ;
|
||||
sf_count_t total = 0 ;
|
||||
float normfact ;
|
||||
|
||||
normfact = (psf->norm_float == SF_TRUE) ? 1.0 / ((float) 0x8000) : 1.0 ;
|
||||
|
||||
bufferlen = ARRAY_LEN (psf->u.ucbuf) ;
|
||||
bufferlen = ARRAY_LEN (ubuf.ucbuf) ;
|
||||
|
||||
while (len > 0)
|
||||
{ if (len < bufferlen)
|
||||
bufferlen = (int) len ;
|
||||
readcount = psf_fread (psf->u.ucbuf, 1, bufferlen, psf) ;
|
||||
ulaw2f_array (psf->u.ucbuf, readcount, ptr + total, normfact) ;
|
||||
readcount = psf_fread (ubuf.ucbuf, 1, bufferlen, psf) ;
|
||||
ulaw2f_array (ubuf.ucbuf, readcount, ptr + total, normfact) ;
|
||||
total += readcount ;
|
||||
if (readcount < bufferlen)
|
||||
break ;
|
||||
@ -925,18 +928,19 @@ ulaw_read_ulaw2f (SF_PRIVATE *psf, float *ptr, sf_count_t len)
|
||||
|
||||
static sf_count_t
|
||||
ulaw_read_ulaw2d (SF_PRIVATE *psf, double *ptr, sf_count_t len)
|
||||
{ int bufferlen, readcount ;
|
||||
{ BUF_UNION ubuf ;
|
||||
int bufferlen, readcount ;
|
||||
sf_count_t total = 0 ;
|
||||
double normfact ;
|
||||
|
||||
normfact = (psf->norm_double) ? 1.0 / ((double) 0x8000) : 1.0 ;
|
||||
bufferlen = ARRAY_LEN (psf->u.ucbuf) ;
|
||||
bufferlen = ARRAY_LEN (ubuf.ucbuf) ;
|
||||
|
||||
while (len > 0)
|
||||
{ if (len < bufferlen)
|
||||
bufferlen = (int) len ;
|
||||
readcount = psf_fread (psf->u.ucbuf, 1, bufferlen, psf) ;
|
||||
ulaw2d_array (psf->u.ucbuf, readcount, ptr + total, normfact) ;
|
||||
readcount = psf_fread (ubuf.ucbuf, 1, bufferlen, psf) ;
|
||||
ulaw2d_array (ubuf.ucbuf, readcount, ptr + total, normfact) ;
|
||||
total += readcount ;
|
||||
if (readcount < bufferlen)
|
||||
break ;
|
||||
@ -951,16 +955,17 @@ ulaw_read_ulaw2d (SF_PRIVATE *psf, double *ptr, sf_count_t len)
|
||||
|
||||
static sf_count_t
|
||||
ulaw_write_s2ulaw (SF_PRIVATE *psf, const short *ptr, sf_count_t len)
|
||||
{ int bufferlen, writecount ;
|
||||
{ BUF_UNION ubuf ;
|
||||
int bufferlen, writecount ;
|
||||
sf_count_t total = 0 ;
|
||||
|
||||
bufferlen = ARRAY_LEN (psf->u.ucbuf) ;
|
||||
bufferlen = ARRAY_LEN (ubuf.ucbuf) ;
|
||||
|
||||
while (len > 0)
|
||||
{ if (len < bufferlen)
|
||||
bufferlen = (int) len ;
|
||||
s2ulaw_array (ptr + total, bufferlen, psf->u.ucbuf) ;
|
||||
writecount = psf_fwrite (psf->u.ucbuf, 1, bufferlen, psf) ;
|
||||
s2ulaw_array (ptr + total, bufferlen, ubuf.ucbuf) ;
|
||||
writecount = psf_fwrite (ubuf.ucbuf, 1, bufferlen, psf) ;
|
||||
total += writecount ;
|
||||
if (writecount < bufferlen)
|
||||
break ;
|
||||
@ -972,16 +977,17 @@ ulaw_write_s2ulaw (SF_PRIVATE *psf, const short *ptr, sf_count_t len)
|
||||
|
||||
static sf_count_t
|
||||
ulaw_write_i2ulaw (SF_PRIVATE *psf, const int *ptr, sf_count_t len)
|
||||
{ int bufferlen, writecount ;
|
||||
{ BUF_UNION ubuf ;
|
||||
int bufferlen, writecount ;
|
||||
sf_count_t total = 0 ;
|
||||
|
||||
bufferlen = ARRAY_LEN (psf->u.ucbuf) ;
|
||||
bufferlen = ARRAY_LEN (ubuf.ucbuf) ;
|
||||
|
||||
while (len > 0)
|
||||
{ if (len < bufferlen)
|
||||
bufferlen = (int) len ;
|
||||
i2ulaw_array (ptr + total, bufferlen, psf->u.ucbuf) ;
|
||||
writecount = psf_fwrite (psf->u.ucbuf, 1, bufferlen, psf) ;
|
||||
i2ulaw_array (ptr + total, bufferlen, ubuf.ucbuf) ;
|
||||
writecount = psf_fwrite (ubuf.ucbuf, 1, bufferlen, psf) ;
|
||||
total += writecount ;
|
||||
if (writecount < bufferlen)
|
||||
break ;
|
||||
@ -993,20 +999,21 @@ ulaw_write_i2ulaw (SF_PRIVATE *psf, const int *ptr, sf_count_t len)
|
||||
|
||||
static sf_count_t
|
||||
ulaw_write_f2ulaw (SF_PRIVATE *psf, const float *ptr, sf_count_t len)
|
||||
{ int bufferlen, writecount ;
|
||||
{ BUF_UNION ubuf ;
|
||||
int bufferlen, writecount ;
|
||||
sf_count_t total = 0 ;
|
||||
float normfact ;
|
||||
|
||||
/* Factor in a divide by 4. */
|
||||
normfact = (psf->norm_float == SF_TRUE) ? (0.25 * 0x7FFF) : 0.25 ;
|
||||
|
||||
bufferlen = ARRAY_LEN (psf->u.ucbuf) ;
|
||||
bufferlen = ARRAY_LEN (ubuf.ucbuf) ;
|
||||
|
||||
while (len > 0)
|
||||
{ if (len < bufferlen)
|
||||
bufferlen = (int) len ;
|
||||
f2ulaw_array (ptr + total, bufferlen, psf->u.ucbuf, normfact) ;
|
||||
writecount = psf_fwrite (psf->u.ucbuf, 1, bufferlen, psf) ;
|
||||
f2ulaw_array (ptr + total, bufferlen, ubuf.ucbuf, normfact) ;
|
||||
writecount = psf_fwrite (ubuf.ucbuf, 1, bufferlen, psf) ;
|
||||
total += writecount ;
|
||||
if (writecount < bufferlen)
|
||||
break ;
|
||||
@ -1018,20 +1025,21 @@ ulaw_write_f2ulaw (SF_PRIVATE *psf, const float *ptr, sf_count_t len)
|
||||
|
||||
static sf_count_t
|
||||
ulaw_write_d2ulaw (SF_PRIVATE *psf, const double *ptr, sf_count_t len)
|
||||
{ int bufferlen, writecount ;
|
||||
{ BUF_UNION ubuf ;
|
||||
int bufferlen, writecount ;
|
||||
sf_count_t total = 0 ;
|
||||
double normfact ;
|
||||
|
||||
/* Factor in a divide by 4. */
|
||||
normfact = (psf->norm_double) ? (0.25 * 0x7FFF) : 0.25 ;
|
||||
|
||||
bufferlen = ARRAY_LEN (psf->u.ucbuf) ;
|
||||
bufferlen = ARRAY_LEN (ubuf.ucbuf) ;
|
||||
|
||||
while (len > 0)
|
||||
{ if (len < bufferlen)
|
||||
bufferlen = (int) len ;
|
||||
d2ulaw_array (ptr + total, bufferlen, psf->u.ucbuf, normfact) ;
|
||||
writecount = psf_fwrite (psf->u.ucbuf, 1, bufferlen, psf) ;
|
||||
d2ulaw_array (ptr + total, bufferlen, ubuf.ucbuf, normfact) ;
|
||||
writecount = psf_fwrite (ubuf.ucbuf, 1, bufferlen, psf) ;
|
||||
total += writecount ;
|
||||
if (writecount < bufferlen)
|
||||
break ;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** Copyright (C) 2002-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
|
||||
** Copyright (C) 2002-2012 Erik de Castro Lopo <erikd@mega-nerd.com>
|
||||
**
|
||||
** This program is free software; you can redistribute it and/or modify
|
||||
** it under the terms of the GNU Lesser General Public License as published by
|
||||
@ -174,6 +174,7 @@ vox_read_s (SF_PRIVATE *psf, short *ptr, sf_count_t len)
|
||||
static sf_count_t
|
||||
vox_read_i (SF_PRIVATE *psf, int *ptr, sf_count_t len)
|
||||
{ IMA_OKI_ADPCM *pvox ;
|
||||
BUF_UNION ubuf ;
|
||||
short *sptr ;
|
||||
int k, bufferlen, readcount, count ;
|
||||
sf_count_t total = 0 ;
|
||||
@ -182,8 +183,8 @@ vox_read_i (SF_PRIVATE *psf, int *ptr, sf_count_t len)
|
||||
return 0 ;
|
||||
pvox = (IMA_OKI_ADPCM*) psf->codec_data ;
|
||||
|
||||
sptr = psf->u.sbuf ;
|
||||
bufferlen = ARRAY_LEN (psf->u.sbuf) ;
|
||||
sptr = ubuf.sbuf ;
|
||||
bufferlen = ARRAY_LEN (ubuf.sbuf) ;
|
||||
while (len > 0)
|
||||
{ readcount = (len >= bufferlen) ? bufferlen : (int) len ;
|
||||
count = vox_read_block (psf, pvox, sptr, readcount) ;
|
||||
@ -201,6 +202,7 @@ vox_read_i (SF_PRIVATE *psf, int *ptr, sf_count_t len)
|
||||
static sf_count_t
|
||||
vox_read_f (SF_PRIVATE *psf, float *ptr, sf_count_t len)
|
||||
{ IMA_OKI_ADPCM *pvox ;
|
||||
BUF_UNION ubuf ;
|
||||
short *sptr ;
|
||||
int k, bufferlen, readcount, count ;
|
||||
sf_count_t total = 0 ;
|
||||
@ -212,8 +214,8 @@ vox_read_f (SF_PRIVATE *psf, float *ptr, sf_count_t len)
|
||||
|
||||
normfact = (psf->norm_float == SF_TRUE) ? 1.0 / ((float) 0x8000) : 1.0 ;
|
||||
|
||||
sptr = psf->u.sbuf ;
|
||||
bufferlen = ARRAY_LEN (psf->u.sbuf) ;
|
||||
sptr = ubuf.sbuf ;
|
||||
bufferlen = ARRAY_LEN (ubuf.sbuf) ;
|
||||
while (len > 0)
|
||||
{ readcount = (len >= bufferlen) ? bufferlen : (int) len ;
|
||||
count = vox_read_block (psf, pvox, sptr, readcount) ;
|
||||
@ -231,6 +233,7 @@ vox_read_f (SF_PRIVATE *psf, float *ptr, sf_count_t len)
|
||||
static sf_count_t
|
||||
vox_read_d (SF_PRIVATE *psf, double *ptr, sf_count_t len)
|
||||
{ IMA_OKI_ADPCM *pvox ;
|
||||
BUF_UNION ubuf ;
|
||||
short *sptr ;
|
||||
int k, bufferlen, readcount, count ;
|
||||
sf_count_t total = 0 ;
|
||||
@ -242,8 +245,8 @@ vox_read_d (SF_PRIVATE *psf, double *ptr, sf_count_t len)
|
||||
|
||||
normfact = (psf->norm_double == SF_TRUE) ? 1.0 / ((double) 0x8000) : 1.0 ;
|
||||
|
||||
sptr = psf->u.sbuf ;
|
||||
bufferlen = ARRAY_LEN (psf->u.sbuf) ;
|
||||
sptr = ubuf.sbuf ;
|
||||
bufferlen = ARRAY_LEN (ubuf.sbuf) ;
|
||||
while (len > 0)
|
||||
{ readcount = (len >= bufferlen) ? bufferlen : (int) len ;
|
||||
count = vox_read_block (psf, pvox, sptr, readcount) ;
|
||||
@ -308,6 +311,7 @@ vox_write_s (SF_PRIVATE *psf, const short *ptr, sf_count_t len)
|
||||
static sf_count_t
|
||||
vox_write_i (SF_PRIVATE *psf, const int *ptr, sf_count_t len)
|
||||
{ IMA_OKI_ADPCM *pvox ;
|
||||
BUF_UNION ubuf ;
|
||||
short *sptr ;
|
||||
int k, bufferlen, writecount, count ;
|
||||
sf_count_t total = 0 ;
|
||||
@ -316,8 +320,8 @@ vox_write_i (SF_PRIVATE *psf, const int *ptr, sf_count_t len)
|
||||
return 0 ;
|
||||
pvox = (IMA_OKI_ADPCM*) psf->codec_data ;
|
||||
|
||||
sptr = psf->u.sbuf ;
|
||||
bufferlen = ARRAY_LEN (psf->u.sbuf) ;
|
||||
sptr = ubuf.sbuf ;
|
||||
bufferlen = ARRAY_LEN (ubuf.sbuf) ;
|
||||
while (len > 0)
|
||||
{ writecount = (len >= bufferlen) ? bufferlen : (int) len ;
|
||||
for (k = 0 ; k < writecount ; k++)
|
||||
@ -335,6 +339,7 @@ vox_write_i (SF_PRIVATE *psf, const int *ptr, sf_count_t len)
|
||||
static sf_count_t
|
||||
vox_write_f (SF_PRIVATE *psf, const float *ptr, sf_count_t len)
|
||||
{ IMA_OKI_ADPCM *pvox ;
|
||||
BUF_UNION ubuf ;
|
||||
short *sptr ;
|
||||
int k, bufferlen, writecount, count ;
|
||||
sf_count_t total = 0 ;
|
||||
@ -346,8 +351,8 @@ vox_write_f (SF_PRIVATE *psf, const float *ptr, sf_count_t len)
|
||||
|
||||
normfact = (psf->norm_float == SF_TRUE) ? (1.0 * 0x7FFF) : 1.0 ;
|
||||
|
||||
sptr = psf->u.sbuf ;
|
||||
bufferlen = ARRAY_LEN (psf->u.sbuf) ;
|
||||
sptr = ubuf.sbuf ;
|
||||
bufferlen = ARRAY_LEN (ubuf.sbuf) ;
|
||||
while (len > 0)
|
||||
{ writecount = (len >= bufferlen) ? bufferlen : (int) len ;
|
||||
for (k = 0 ; k < writecount ; k++)
|
||||
@ -365,6 +370,7 @@ vox_write_f (SF_PRIVATE *psf, const float *ptr, sf_count_t len)
|
||||
static sf_count_t
|
||||
vox_write_d (SF_PRIVATE *psf, const double *ptr, sf_count_t len)
|
||||
{ IMA_OKI_ADPCM *pvox ;
|
||||
BUF_UNION ubuf ;
|
||||
short *sptr ;
|
||||
int k, bufferlen, writecount, count ;
|
||||
sf_count_t total = 0 ;
|
||||
@ -376,8 +382,8 @@ vox_write_d (SF_PRIVATE *psf, const double *ptr, sf_count_t len)
|
||||
|
||||
normfact = (psf->norm_double == SF_TRUE) ? (1.0 * 0x7FFF) : 1.0 ;
|
||||
|
||||
sptr = psf->u.sbuf ;
|
||||
bufferlen = ARRAY_LEN (psf->u.sbuf) ;
|
||||
sptr = ubuf.sbuf ;
|
||||
bufferlen = ARRAY_LEN (ubuf.sbuf) ;
|
||||
while (len > 0)
|
||||
{ writecount = (len >= bufferlen) ? bufferlen : (int) len ;
|
||||
for (k = 0 ; k < writecount ; k++)
|
||||
|
65
src/wav.c
65
src/wav.c
@ -310,7 +310,7 @@ wav_read_header (SF_PRIVATE *psf, int *blockalign, int *framesperblock)
|
||||
FACT_CHUNK fact_chunk ;
|
||||
unsigned marker, chunk_size, RIFFsize = 0, done = 0, uk ;
|
||||
int parsestage = 0, error, format = 0 ;
|
||||
char *cptr ;
|
||||
char buffer [256] ;
|
||||
|
||||
if (psf->filelength > SF_PLATFORM_S64 (0xffffffff))
|
||||
psf_log_printf (psf, "Warning : filelength > 0xffffffff. This is bad!!!!\n") ;
|
||||
@ -486,7 +486,6 @@ wav_read_header (SF_PRIVATE *psf, int *blockalign, int *framesperblock)
|
||||
psf_log_printf (psf, " time stamp : %d\n", psf->peak_info->timestamp) ;
|
||||
psf_log_printf (psf, " Ch Position Value\n") ;
|
||||
|
||||
cptr = psf->u.cbuf ;
|
||||
for (uk = 0 ; uk < (unsigned) psf->sf.channels ; uk++)
|
||||
{ float value ;
|
||||
unsigned int position ;
|
||||
@ -495,10 +494,10 @@ wav_read_header (SF_PRIVATE *psf, int *blockalign, int *framesperblock)
|
||||
psf->peak_info->peaks [uk].value = value ;
|
||||
psf->peak_info->peaks [uk].position = position ;
|
||||
|
||||
snprintf (cptr, sizeof (psf->u.cbuf), " %2d %-12" PRId64 " %g\n",
|
||||
snprintf (buffer, sizeof (buffer), " %2d %-12" PRId64 " %g\n",
|
||||
uk, psf->peak_info->peaks [uk].position, psf->peak_info->peaks [uk].value) ;
|
||||
cptr [sizeof (psf->u.cbuf) - 1] = 0 ;
|
||||
psf_log_printf (psf, "%s", cptr) ;
|
||||
buffer [sizeof (buffer) - 1] = 0 ;
|
||||
psf_log_printf (psf, "%s", buffer) ;
|
||||
} ;
|
||||
|
||||
psf->peak_info->peak_loc = ((parsestage & HAVE_data) == 0) ? SF_PEAK_START : SF_PEAK_END ;
|
||||
@ -1288,7 +1287,7 @@ wav_command (SF_PRIVATE *psf, int command, void * UNUSED (data), int datasize)
|
||||
static int
|
||||
wav_subchunk_parse (SF_PRIVATE *psf, int chunk, unsigned length)
|
||||
{ sf_count_t current_pos ;
|
||||
char *cptr ;
|
||||
char buffer [512] ;
|
||||
unsigned dword, bytesread ;
|
||||
|
||||
current_pos = psf_fseek (psf, 0, SEEK_CUR) - 4 ;
|
||||
@ -1346,17 +1345,16 @@ wav_subchunk_parse (SF_PRIVATE *psf, int chunk, unsigned length)
|
||||
case ISRC_MARKER :
|
||||
bytesread += psf_binheader_readf (psf, "4", &dword) ;
|
||||
dword += (dword & 1) ;
|
||||
if (dword >= SIGNED_SIZEOF (psf->u.cbuf))
|
||||
if (dword >= SIGNED_SIZEOF (buffer))
|
||||
{ psf_log_printf (psf, " *** %M : %d (too big)\n", chunk, dword) ;
|
||||
psf_binheader_readf (psf, "j", dword) ;
|
||||
break ;
|
||||
} ;
|
||||
|
||||
cptr = psf->u.cbuf ;
|
||||
psf_binheader_readf (psf, "b", cptr, dword) ;
|
||||
psf_binheader_readf (psf, "b", buffer, dword) ;
|
||||
bytesread += dword ;
|
||||
cptr [dword] = 0 ;
|
||||
psf_log_printf (psf, " %M : %s\n", chunk, cptr) ;
|
||||
buffer [dword] = 0 ;
|
||||
psf_log_printf (psf, " %M : %s\n", chunk, buffer) ;
|
||||
break ;
|
||||
|
||||
case labl_MARKER :
|
||||
@ -1365,17 +1363,16 @@ wav_subchunk_parse (SF_PRIVATE *psf, int chunk, unsigned length)
|
||||
bytesread += psf_binheader_readf (psf, "44", &dword, &mark_id) ;
|
||||
dword -= 4 ;
|
||||
dword += (dword & 1) ;
|
||||
if (dword < 1 || dword >= SIGNED_SIZEOF (psf->u.cbuf))
|
||||
if (dword < 1 || dword >= SIGNED_SIZEOF (buffer))
|
||||
{ psf_log_printf (psf, " *** %M : %d (too big)\n", chunk, dword) ;
|
||||
psf_binheader_readf (psf, "j", dword) ;
|
||||
break ;
|
||||
} ;
|
||||
|
||||
cptr = psf->u.cbuf ;
|
||||
psf_binheader_readf (psf, "b", cptr, dword) ;
|
||||
psf_binheader_readf (psf, "b", buffer, dword) ;
|
||||
bytesread += dword ;
|
||||
cptr [dword] = 0 ;
|
||||
psf_log_printf (psf, " %M : %d : %s\n", chunk, mark_id, cptr) ;
|
||||
buffer [dword] = 0 ;
|
||||
psf_log_printf (psf, " %M : %d : %s\n", chunk, mark_id, buffer) ;
|
||||
} ;
|
||||
break ;
|
||||
|
||||
@ -1420,25 +1417,25 @@ wav_subchunk_parse (SF_PRIVATE *psf, int chunk, unsigned length)
|
||||
|
||||
switch (chunk)
|
||||
{ case ISFT_MARKER :
|
||||
psf_store_string (psf, SF_STR_SOFTWARE, psf->u.cbuf) ;
|
||||
psf_store_string (psf, SF_STR_SOFTWARE, buffer) ;
|
||||
break ;
|
||||
case ICOP_MARKER :
|
||||
psf_store_string (psf, SF_STR_COPYRIGHT, psf->u.cbuf) ;
|
||||
psf_store_string (psf, SF_STR_COPYRIGHT, buffer) ;
|
||||
break ;
|
||||
case INAM_MARKER :
|
||||
psf_store_string (psf, SF_STR_TITLE, psf->u.cbuf) ;
|
||||
psf_store_string (psf, SF_STR_TITLE, buffer) ;
|
||||
break ;
|
||||
case IART_MARKER :
|
||||
psf_store_string (psf, SF_STR_ARTIST, psf->u.cbuf) ;
|
||||
psf_store_string (psf, SF_STR_ARTIST, buffer) ;
|
||||
break ;
|
||||
case ICMT_MARKER :
|
||||
psf_store_string (psf, SF_STR_COMMENT, psf->u.cbuf) ;
|
||||
psf_store_string (psf, SF_STR_COMMENT, buffer) ;
|
||||
break ;
|
||||
case ICRD_MARKER :
|
||||
psf_store_string (psf, SF_STR_DATE, psf->u.cbuf) ;
|
||||
psf_store_string (psf, SF_STR_DATE, buffer) ;
|
||||
break ;
|
||||
case IGNR_MARKER :
|
||||
psf_store_string (psf, SF_STR_GENRE, psf->u.cbuf) ;
|
||||
psf_store_string (psf, SF_STR_GENRE, buffer) ;
|
||||
break ;
|
||||
} ;
|
||||
} ;
|
||||
@ -1453,7 +1450,8 @@ wav_subchunk_parse (SF_PRIVATE *psf, int chunk, unsigned length)
|
||||
|
||||
static int
|
||||
wav_read_smpl_chunk (SF_PRIVATE *psf, unsigned int chunklen)
|
||||
{ unsigned int bytesread = 0, dword, sampler_data, loop_count ;
|
||||
{ char buffer [512] ;
|
||||
unsigned int bytesread = 0, dword, sampler_data, loop_count ;
|
||||
unsigned int note, start, end, type = -1, count ;
|
||||
int j, k ;
|
||||
|
||||
@ -1473,9 +1471,9 @@ wav_read_smpl_chunk (SF_PRIVATE *psf, unsigned int chunklen)
|
||||
|
||||
bytesread += psf_binheader_readf (psf, "4", &dword) ;
|
||||
if (dword != 0)
|
||||
{ snprintf (psf->u.cbuf, sizeof (psf->u.cbuf), "%f",
|
||||
{ snprintf (buffer, sizeof (buffer), "%f",
|
||||
(1.0 * 0x80000000) / ((unsigned int) dword)) ;
|
||||
psf_log_printf (psf, " Pitch Fract. : %s\n", psf->u.cbuf) ;
|
||||
psf_log_printf (psf, " Pitch Fract. : %s\n", buffer) ;
|
||||
}
|
||||
else
|
||||
psf_log_printf (psf, " Pitch Fract. : 0\n") ;
|
||||
@ -1484,9 +1482,9 @@ wav_read_smpl_chunk (SF_PRIVATE *psf, unsigned int chunklen)
|
||||
psf_log_printf (psf, " SMPTE Format : %u\n", dword) ;
|
||||
|
||||
bytesread += psf_binheader_readf (psf, "4", &dword) ;
|
||||
snprintf (psf->u.cbuf, sizeof (psf->u.cbuf), "%02d:%02d:%02d %02d",
|
||||
snprintf (buffer, sizeof (buffer), "%02d:%02d:%02d %02d",
|
||||
(dword >> 24) & 0x7F, (dword >> 16) & 0x7F, (dword >> 8) & 0x7F, dword & 0x7F) ;
|
||||
psf_log_printf (psf, " SMPTE Offset : %s\n", psf->u.cbuf) ;
|
||||
psf_log_printf (psf, " SMPTE Offset : %s\n", buffer) ;
|
||||
|
||||
bytesread += psf_binheader_readf (psf, "4", &loop_count) ;
|
||||
psf_log_printf (psf, " Loop Count : %u\n", loop_count) ;
|
||||
@ -1613,7 +1611,8 @@ wav_read_smpl_chunk (SF_PRIVATE *psf, unsigned int chunklen)
|
||||
|
||||
static int
|
||||
wav_read_acid_chunk (SF_PRIVATE *psf, unsigned int chunklen)
|
||||
{ unsigned int bytesread = 0 ;
|
||||
{ char buffer [512] ;
|
||||
unsigned int bytesread = 0 ;
|
||||
int beats, flags ;
|
||||
short rootnote, q1, meter_denom, meter_numer ;
|
||||
float q2, tempo ;
|
||||
@ -1622,7 +1621,7 @@ wav_read_acid_chunk (SF_PRIVATE *psf, unsigned int chunklen)
|
||||
|
||||
bytesread += psf_binheader_readf (psf, "422f", &flags, &rootnote, &q1, &q2) ;
|
||||
|
||||
snprintf (psf->u.cbuf, sizeof (psf->u.cbuf), "%f", q2) ;
|
||||
snprintf (buffer, sizeof (buffer), "%f", q2) ;
|
||||
|
||||
psf_log_printf (psf, " Flags : 0x%04x (%s,%s,%s,%s,%s)\n", flags,
|
||||
(flags & 0x01) ? "OneShot" : "Loop",
|
||||
@ -1632,12 +1631,12 @@ wav_read_acid_chunk (SF_PRIVATE *psf, unsigned int chunklen)
|
||||
(flags & 0x10) ? "??On" : "??Off") ;
|
||||
|
||||
psf_log_printf (psf, " Root note : 0x%x\n ???? : 0x%04x\n ???? : %s\n",
|
||||
rootnote, q1, psf->u.cbuf) ;
|
||||
rootnote, q1, buffer) ;
|
||||
|
||||
bytesread += psf_binheader_readf (psf, "422f", &beats, &meter_denom, &meter_numer, &tempo) ;
|
||||
snprintf (psf->u.cbuf, sizeof (psf->u.cbuf), "%f", tempo) ;
|
||||
snprintf (buffer, sizeof (buffer), "%f", tempo) ;
|
||||
psf_log_printf (psf, " Beats : %d\n Meter : %d/%d\n Tempo : %s\n",
|
||||
beats, meter_numer, meter_denom, psf->u.cbuf) ;
|
||||
beats, meter_numer, meter_denom, buffer) ;
|
||||
|
||||
psf_binheader_readf (psf, "j", chunklen - bytesread) ;
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** Copyright (C) 1999-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
|
||||
** Copyright (C) 1999-2012 Erik de Castro Lopo <erikd@mega-nerd.com>
|
||||
** Copyright (C) 2004-2005 David Viens <davidv@plogue.com>
|
||||
**
|
||||
** This program is free software; you can redistribute it and/or modify
|
||||
@ -259,10 +259,12 @@ wav_w64_read_fmt_chunk (SF_PRIVATE *psf, int fmtsize)
|
||||
|
||||
psf_log_printf (psf, " Index Coeffs1 Coeffs2\n") ;
|
||||
for (k = 0 ; k < wav_fmt->msadpcm.numcoeffs ; k++)
|
||||
{ bytesread +=
|
||||
psf_binheader_readf (psf, "22", &(wav_fmt->msadpcm.coeffs [k].coeff1), &(wav_fmt->msadpcm.coeffs [k].coeff2)) ;
|
||||
snprintf (psf->u.cbuf, sizeof (psf->u.cbuf), " %2d %7d %7d\n", k, wav_fmt->msadpcm.coeffs [k].coeff1, wav_fmt->msadpcm.coeffs [k].coeff2) ;
|
||||
psf_log_printf (psf, psf->u.cbuf) ;
|
||||
{ char buffer [128] ;
|
||||
|
||||
bytesread +=
|
||||
psf_binheader_readf (psf, "22", &(wav_fmt->msadpcm.coeffs [k].coeff1), &(wav_fmt->msadpcm.coeffs [k].coeff2)) ;
|
||||
snprintf (buffer, sizeof (buffer), " %2d %7d %7d\n", k, wav_fmt->msadpcm.coeffs [k].coeff1, wav_fmt->msadpcm.coeffs [k].coeff2) ;
|
||||
psf_log_printf (psf, buffer) ;
|
||||
} ;
|
||||
break ;
|
||||
|
||||
@ -302,7 +304,8 @@ wav_w64_read_fmt_chunk (SF_PRIVATE *psf, int fmtsize)
|
||||
if (wav_fmt->ext.channelmask == 0)
|
||||
psf_log_printf (psf, " Channel Mask : 0x0 (should not be zero)\n") ;
|
||||
else
|
||||
{ unsigned bit ;
|
||||
{ char buffer [512] ;
|
||||
unsigned bit ;
|
||||
|
||||
wpriv->wavex_channelmask = wav_fmt->ext.channelmask ;
|
||||
|
||||
@ -313,7 +316,7 @@ wav_w64_read_fmt_chunk (SF_PRIVATE *psf, int fmtsize)
|
||||
return SFE_MALLOC_FAILED ;
|
||||
|
||||
/* Terminate the buffer we're going to append_snprintf into. */
|
||||
psf->u.cbuf [0] = 0 ;
|
||||
buffer [0] = 0 ;
|
||||
|
||||
for (bit = k = 0 ; bit < ARRAY_LEN (channel_mask_bits) ; bit++)
|
||||
{
|
||||
@ -324,21 +327,21 @@ wav_w64_read_fmt_chunk (SF_PRIVATE *psf, int fmtsize)
|
||||
} ;
|
||||
|
||||
psf->channel_map [k++] = channel_mask_bits [bit].id ;
|
||||
append_snprintf (psf->u.cbuf, sizeof (psf->u.cbuf), "%s, ", channel_mask_bits [bit].name) ;
|
||||
append_snprintf (buffer, sizeof (buffer), "%s, ", channel_mask_bits [bit].name) ;
|
||||
} ;
|
||||
} ;
|
||||
|
||||
/* Remove trailing ", ". */
|
||||
bit = strlen (psf->u.cbuf) ;
|
||||
psf->u.cbuf [--bit] = 0 ;
|
||||
psf->u.cbuf [--bit] = 0 ;
|
||||
bit = strlen (buffer) ;
|
||||
buffer [--bit] = 0 ;
|
||||
buffer [--bit] = 0 ;
|
||||
|
||||
if (k != psf->sf.channels)
|
||||
{ psf_log_printf (psf, " Channel Mask : 0x%X\n", wav_fmt->ext.channelmask) ;
|
||||
psf_log_printf (psf, "*** Less channel map bits than there are channels.\n") ;
|
||||
}
|
||||
else
|
||||
psf_log_printf (psf, " Channel Mask : 0x%X (%s)\n", wav_fmt->ext.channelmask, psf->u.cbuf) ;
|
||||
psf_log_printf (psf, " Channel Mask : 0x%X (%s)\n", wav_fmt->ext.channelmask, buffer) ;
|
||||
} ;
|
||||
|
||||
bytesread += psf_binheader_readf (psf, "422", &(wav_fmt->ext.esf.esf_field1), &(wav_fmt->ext.esf.esf_field2), &(wav_fmt->ext.esf.esf_field3)) ;
|
||||
@ -465,7 +468,8 @@ wavex_gen_channel_mask (const int *chan_map, int channels)
|
||||
|
||||
void
|
||||
wav_w64_analyze (SF_PRIVATE *psf)
|
||||
{ AUDIO_DETECT ad ;
|
||||
{ unsigned char buffer [4096] ;
|
||||
AUDIO_DETECT ad ;
|
||||
int format = 0 ;
|
||||
|
||||
if (psf->is_pipe)
|
||||
@ -482,8 +486,8 @@ wav_w64_analyze (SF_PRIVATE *psf)
|
||||
|
||||
psf_fseek (psf, 3 * 4 * 50, SEEK_SET) ;
|
||||
|
||||
while (psf_fread (psf->u.ucbuf, 1, 4096, psf) == 4096)
|
||||
{ format = audio_detect (psf, &ad, psf->u.ucbuf, 4096) ;
|
||||
while (psf_fread (buffer, 1, sizeof (buffer), psf) == sizeof (buffer))
|
||||
{ format = audio_detect (psf, &ad, buffer, sizeof (buffer)) ;
|
||||
if (format != 0)
|
||||
break ;
|
||||
} ;
|
||||
|
157
src/xi.c
157
src/xi.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** Copyright (C) 2003-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
|
||||
** Copyright (C) 2003-2012 Erik de Castro Lopo <erikd@mega-nerd.com>
|
||||
**
|
||||
** This program is free software; you can redistribute it and/or modify
|
||||
** it under the terms of the GNU Lesser General Public License as published by
|
||||
@ -216,7 +216,8 @@ dpcm_init (SF_PRIVATE *psf)
|
||||
|
||||
static sf_count_t
|
||||
dpcm_seek (SF_PRIVATE *psf, int mode, sf_count_t offset)
|
||||
{ XI_PRIVATE *pxi ;
|
||||
{ BUF_UNION ubuf ;
|
||||
XI_PRIVATE *pxi ;
|
||||
int total, bufferlen, len ;
|
||||
|
||||
if ((pxi = psf->codec_data) == NULL)
|
||||
@ -248,18 +249,18 @@ dpcm_seek (SF_PRIVATE *psf, int mode, sf_count_t offset)
|
||||
|
||||
if ((SF_CODEC (psf->sf.format)) == SF_FORMAT_DPCM_16)
|
||||
{ total = offset ;
|
||||
bufferlen = ARRAY_LEN (psf->u.sbuf) ;
|
||||
bufferlen = ARRAY_LEN (ubuf.sbuf) ;
|
||||
while (total > 0)
|
||||
{ len = (total > bufferlen) ? bufferlen : total ;
|
||||
total -= dpcm_read_dles2s (psf, psf->u.sbuf, len) ;
|
||||
total -= dpcm_read_dles2s (psf, ubuf.sbuf, len) ;
|
||||
} ;
|
||||
}
|
||||
else
|
||||
{ total = offset ;
|
||||
bufferlen = ARRAY_LEN (psf->u.sbuf) ;
|
||||
bufferlen = ARRAY_LEN (ubuf.sbuf) ;
|
||||
while (total > 0)
|
||||
{ len = (total > bufferlen) ? bufferlen : total ;
|
||||
total -= dpcm_read_dsc2s (psf, psf->u.sbuf, len) ;
|
||||
total -= dpcm_read_dsc2s (psf, ubuf.sbuf, len) ;
|
||||
} ;
|
||||
} ;
|
||||
|
||||
@ -492,20 +493,21 @@ static void dles2d_array (XI_PRIVATE *pxi, short *src, int count, double *dest,
|
||||
|
||||
static sf_count_t
|
||||
dpcm_read_dsc2s (SF_PRIVATE *psf, short *ptr, sf_count_t len)
|
||||
{ XI_PRIVATE *pxi ;
|
||||
{ BUF_UNION ubuf ;
|
||||
XI_PRIVATE *pxi ;
|
||||
int bufferlen, readcount ;
|
||||
sf_count_t total = 0 ;
|
||||
|
||||
if ((pxi = psf->codec_data) == NULL)
|
||||
return 0 ;
|
||||
|
||||
bufferlen = ARRAY_LEN (psf->u.ucbuf) ;
|
||||
bufferlen = ARRAY_LEN (ubuf.ucbuf) ;
|
||||
|
||||
while (len > 0)
|
||||
{ if (len < bufferlen)
|
||||
bufferlen = (int) len ;
|
||||
readcount = psf_fread (psf->u.scbuf, sizeof (signed char), bufferlen, psf) ;
|
||||
dsc2s_array (pxi, psf->u.scbuf, readcount, ptr + total) ;
|
||||
readcount = psf_fread (ubuf.scbuf, sizeof (signed char), bufferlen, psf) ;
|
||||
dsc2s_array (pxi, ubuf.scbuf, readcount, ptr + total) ;
|
||||
total += readcount ;
|
||||
if (readcount < bufferlen)
|
||||
break ;
|
||||
@ -517,20 +519,21 @@ dpcm_read_dsc2s (SF_PRIVATE *psf, short *ptr, sf_count_t len)
|
||||
|
||||
static sf_count_t
|
||||
dpcm_read_dsc2i (SF_PRIVATE *psf, int *ptr, sf_count_t len)
|
||||
{ XI_PRIVATE *pxi ;
|
||||
{ BUF_UNION ubuf ;
|
||||
XI_PRIVATE *pxi ;
|
||||
int bufferlen, readcount ;
|
||||
sf_count_t total = 0 ;
|
||||
|
||||
if ((pxi = psf->codec_data) == NULL)
|
||||
return 0 ;
|
||||
|
||||
bufferlen = ARRAY_LEN (psf->u.ucbuf) ;
|
||||
bufferlen = ARRAY_LEN (ubuf.ucbuf) ;
|
||||
|
||||
while (len > 0)
|
||||
{ if (len < bufferlen)
|
||||
bufferlen = (int) len ;
|
||||
readcount = psf_fread (psf->u.scbuf, sizeof (signed char), bufferlen, psf) ;
|
||||
dsc2i_array (pxi, psf->u.scbuf, readcount, ptr + total) ;
|
||||
readcount = psf_fread (ubuf.scbuf, sizeof (signed char), bufferlen, psf) ;
|
||||
dsc2i_array (pxi, ubuf.scbuf, readcount, ptr + total) ;
|
||||
total += readcount ;
|
||||
if (readcount < bufferlen)
|
||||
break ;
|
||||
@ -542,7 +545,8 @@ dpcm_read_dsc2i (SF_PRIVATE *psf, int *ptr, sf_count_t len)
|
||||
|
||||
static sf_count_t
|
||||
dpcm_read_dsc2f (SF_PRIVATE *psf, float *ptr, sf_count_t len)
|
||||
{ XI_PRIVATE *pxi ;
|
||||
{ BUF_UNION ubuf ;
|
||||
XI_PRIVATE *pxi ;
|
||||
int bufferlen, readcount ;
|
||||
sf_count_t total = 0 ;
|
||||
float normfact ;
|
||||
@ -552,13 +556,13 @@ dpcm_read_dsc2f (SF_PRIVATE *psf, float *ptr, sf_count_t len)
|
||||
|
||||
normfact = (psf->norm_float == SF_TRUE) ? 1.0 / ((float) 0x80) : 1.0 ;
|
||||
|
||||
bufferlen = ARRAY_LEN (psf->u.ucbuf) ;
|
||||
bufferlen = ARRAY_LEN (ubuf.ucbuf) ;
|
||||
|
||||
while (len > 0)
|
||||
{ if (len < bufferlen)
|
||||
bufferlen = (int) len ;
|
||||
readcount = psf_fread (psf->u.scbuf, sizeof (signed char), bufferlen, psf) ;
|
||||
dsc2f_array (pxi, psf->u.scbuf, readcount, ptr + total, normfact) ;
|
||||
readcount = psf_fread (ubuf.scbuf, sizeof (signed char), bufferlen, psf) ;
|
||||
dsc2f_array (pxi, ubuf.scbuf, readcount, ptr + total, normfact) ;
|
||||
total += readcount ;
|
||||
if (readcount < bufferlen)
|
||||
break ;
|
||||
@ -570,7 +574,8 @@ dpcm_read_dsc2f (SF_PRIVATE *psf, float *ptr, sf_count_t len)
|
||||
|
||||
static sf_count_t
|
||||
dpcm_read_dsc2d (SF_PRIVATE *psf, double *ptr, sf_count_t len)
|
||||
{ XI_PRIVATE *pxi ;
|
||||
{ BUF_UNION ubuf ;
|
||||
XI_PRIVATE *pxi ;
|
||||
int bufferlen, readcount ;
|
||||
sf_count_t total = 0 ;
|
||||
double normfact ;
|
||||
@ -580,13 +585,13 @@ dpcm_read_dsc2d (SF_PRIVATE *psf, double *ptr, sf_count_t len)
|
||||
|
||||
normfact = (psf->norm_double == SF_TRUE) ? 1.0 / ((double) 0x80) : 1.0 ;
|
||||
|
||||
bufferlen = ARRAY_LEN (psf->u.ucbuf) ;
|
||||
bufferlen = ARRAY_LEN (ubuf.ucbuf) ;
|
||||
|
||||
while (len > 0)
|
||||
{ if (len < bufferlen)
|
||||
bufferlen = (int) len ;
|
||||
readcount = psf_fread (psf->u.scbuf, sizeof (signed char), bufferlen, psf) ;
|
||||
dsc2d_array (pxi, psf->u.scbuf, readcount, ptr + total, normfact) ;
|
||||
readcount = psf_fread (ubuf.scbuf, sizeof (signed char), bufferlen, psf) ;
|
||||
dsc2d_array (pxi, ubuf.scbuf, readcount, ptr + total, normfact) ;
|
||||
total += readcount ;
|
||||
if (readcount < bufferlen)
|
||||
break ;
|
||||
@ -601,20 +606,21 @@ dpcm_read_dsc2d (SF_PRIVATE *psf, double *ptr, sf_count_t len)
|
||||
|
||||
static sf_count_t
|
||||
dpcm_read_dles2s (SF_PRIVATE *psf, short *ptr, sf_count_t len)
|
||||
{ XI_PRIVATE *pxi ;
|
||||
{ BUF_UNION ubuf ;
|
||||
XI_PRIVATE *pxi ;
|
||||
int bufferlen, readcount ;
|
||||
sf_count_t total = 0 ;
|
||||
|
||||
if ((pxi = psf->codec_data) == NULL)
|
||||
return 0 ;
|
||||
|
||||
bufferlen = ARRAY_LEN (psf->u.sbuf) ;
|
||||
bufferlen = ARRAY_LEN (ubuf.sbuf) ;
|
||||
|
||||
while (len > 0)
|
||||
{ if (len < bufferlen)
|
||||
bufferlen = (int) len ;
|
||||
readcount = psf_fread (psf->u.sbuf, sizeof (short), bufferlen, psf) ;
|
||||
dles2s_array (pxi, psf->u.sbuf, readcount, ptr + total) ;
|
||||
readcount = psf_fread (ubuf.sbuf, sizeof (short), bufferlen, psf) ;
|
||||
dles2s_array (pxi, ubuf.sbuf, readcount, ptr + total) ;
|
||||
total += readcount ;
|
||||
if (readcount < bufferlen)
|
||||
break ;
|
||||
@ -626,20 +632,21 @@ dpcm_read_dles2s (SF_PRIVATE *psf, short *ptr, sf_count_t len)
|
||||
|
||||
static sf_count_t
|
||||
dpcm_read_dles2i (SF_PRIVATE *psf, int *ptr, sf_count_t len)
|
||||
{ XI_PRIVATE *pxi ;
|
||||
{ BUF_UNION ubuf ;
|
||||
XI_PRIVATE *pxi ;
|
||||
int bufferlen, readcount ;
|
||||
sf_count_t total = 0 ;
|
||||
|
||||
if ((pxi = psf->codec_data) == NULL)
|
||||
return 0 ;
|
||||
|
||||
bufferlen = ARRAY_LEN (psf->u.sbuf) ;
|
||||
bufferlen = ARRAY_LEN (ubuf.sbuf) ;
|
||||
|
||||
while (len > 0)
|
||||
{ if (len < bufferlen)
|
||||
bufferlen = (int) len ;
|
||||
readcount = psf_fread (psf->u.sbuf, sizeof (short), bufferlen, psf) ;
|
||||
dles2i_array (pxi, psf->u.sbuf, readcount, ptr + total) ;
|
||||
readcount = psf_fread (ubuf.sbuf, sizeof (short), bufferlen, psf) ;
|
||||
dles2i_array (pxi, ubuf.sbuf, readcount, ptr + total) ;
|
||||
total += readcount ;
|
||||
if (readcount < bufferlen)
|
||||
break ;
|
||||
@ -651,7 +658,8 @@ dpcm_read_dles2i (SF_PRIVATE *psf, int *ptr, sf_count_t len)
|
||||
|
||||
static sf_count_t
|
||||
dpcm_read_dles2f (SF_PRIVATE *psf, float *ptr, sf_count_t len)
|
||||
{ XI_PRIVATE *pxi ;
|
||||
{ BUF_UNION ubuf ;
|
||||
XI_PRIVATE *pxi ;
|
||||
int bufferlen, readcount ;
|
||||
sf_count_t total = 0 ;
|
||||
float normfact ;
|
||||
@ -661,13 +669,13 @@ dpcm_read_dles2f (SF_PRIVATE *psf, float *ptr, sf_count_t len)
|
||||
|
||||
normfact = (psf->norm_float == SF_TRUE) ? 1.0 / ((float) 0x8000) : 1.0 ;
|
||||
|
||||
bufferlen = ARRAY_LEN (psf->u.sbuf) ;
|
||||
bufferlen = ARRAY_LEN (ubuf.sbuf) ;
|
||||
|
||||
while (len > 0)
|
||||
{ if (len < bufferlen)
|
||||
bufferlen = (int) len ;
|
||||
readcount = psf_fread (psf->u.sbuf, sizeof (short), bufferlen, psf) ;
|
||||
dles2f_array (pxi, psf->u.sbuf, readcount, ptr + total, normfact) ;
|
||||
readcount = psf_fread (ubuf.sbuf, sizeof (short), bufferlen, psf) ;
|
||||
dles2f_array (pxi, ubuf.sbuf, readcount, ptr + total, normfact) ;
|
||||
total += readcount ;
|
||||
if (readcount < bufferlen)
|
||||
break ;
|
||||
@ -679,7 +687,8 @@ dpcm_read_dles2f (SF_PRIVATE *psf, float *ptr, sf_count_t len)
|
||||
|
||||
static sf_count_t
|
||||
dpcm_read_dles2d (SF_PRIVATE *psf, double *ptr, sf_count_t len)
|
||||
{ XI_PRIVATE *pxi ;
|
||||
{ BUF_UNION ubuf ;
|
||||
XI_PRIVATE *pxi ;
|
||||
int bufferlen, readcount ;
|
||||
sf_count_t total = 0 ;
|
||||
double normfact ;
|
||||
@ -689,13 +698,13 @@ dpcm_read_dles2d (SF_PRIVATE *psf, double *ptr, sf_count_t len)
|
||||
|
||||
normfact = (psf->norm_double == SF_TRUE) ? 1.0 / ((double) 0x8000) : 1.0 ;
|
||||
|
||||
bufferlen = ARRAY_LEN (psf->u.sbuf) ;
|
||||
bufferlen = ARRAY_LEN (ubuf.sbuf) ;
|
||||
|
||||
while (len > 0)
|
||||
{ if (len < bufferlen)
|
||||
bufferlen = (int) len ;
|
||||
readcount = psf_fread (psf->u.sbuf, sizeof (short), bufferlen, psf) ;
|
||||
dles2d_array (pxi, psf->u.sbuf, readcount, ptr + total, normfact) ;
|
||||
readcount = psf_fread (ubuf.sbuf, sizeof (short), bufferlen, psf) ;
|
||||
dles2d_array (pxi, ubuf.sbuf, readcount, ptr + total, normfact) ;
|
||||
total += readcount ;
|
||||
if (readcount < bufferlen)
|
||||
break ;
|
||||
@ -721,20 +730,21 @@ static void d2dles_array (XI_PRIVATE *pxi, const double *src, short *dest, int c
|
||||
|
||||
static sf_count_t
|
||||
dpcm_write_s2dsc (SF_PRIVATE *psf, const short *ptr, sf_count_t len)
|
||||
{ XI_PRIVATE *pxi ;
|
||||
{ BUF_UNION ubuf ;
|
||||
XI_PRIVATE *pxi ;
|
||||
int bufferlen, writecount ;
|
||||
sf_count_t total = 0 ;
|
||||
|
||||
if ((pxi = psf->codec_data) == NULL)
|
||||
return 0 ;
|
||||
|
||||
bufferlen = ARRAY_LEN (psf->u.ucbuf) ;
|
||||
bufferlen = ARRAY_LEN (ubuf.ucbuf) ;
|
||||
|
||||
while (len > 0)
|
||||
{ if (len < bufferlen)
|
||||
bufferlen = (int) len ;
|
||||
s2dsc_array (pxi, ptr + total, psf->u.scbuf, bufferlen) ;
|
||||
writecount = psf_fwrite (psf->u.scbuf, sizeof (signed char), bufferlen, psf) ;
|
||||
s2dsc_array (pxi, ptr + total, ubuf.scbuf, bufferlen) ;
|
||||
writecount = psf_fwrite (ubuf.scbuf, sizeof (signed char), bufferlen, psf) ;
|
||||
total += writecount ;
|
||||
if (writecount < bufferlen)
|
||||
break ;
|
||||
@ -746,20 +756,21 @@ dpcm_write_s2dsc (SF_PRIVATE *psf, const short *ptr, sf_count_t len)
|
||||
|
||||
static sf_count_t
|
||||
dpcm_write_i2dsc (SF_PRIVATE *psf, const int *ptr, sf_count_t len)
|
||||
{ XI_PRIVATE *pxi ;
|
||||
{ BUF_UNION ubuf ;
|
||||
XI_PRIVATE *pxi ;
|
||||
int bufferlen, writecount ;
|
||||
sf_count_t total = 0 ;
|
||||
|
||||
if ((pxi = psf->codec_data) == NULL)
|
||||
return 0 ;
|
||||
|
||||
bufferlen = ARRAY_LEN (psf->u.ucbuf) ;
|
||||
bufferlen = ARRAY_LEN (ubuf.ucbuf) ;
|
||||
|
||||
while (len > 0)
|
||||
{ if (len < bufferlen)
|
||||
bufferlen = (int) len ;
|
||||
i2dsc_array (pxi, ptr + total, psf->u.scbuf, bufferlen) ;
|
||||
writecount = psf_fwrite (psf->u.scbuf, sizeof (signed char), bufferlen, psf) ;
|
||||
i2dsc_array (pxi, ptr + total, ubuf.scbuf, bufferlen) ;
|
||||
writecount = psf_fwrite (ubuf.scbuf, sizeof (signed char), bufferlen, psf) ;
|
||||
total += writecount ;
|
||||
if (writecount < bufferlen)
|
||||
break ;
|
||||
@ -771,7 +782,8 @@ dpcm_write_i2dsc (SF_PRIVATE *psf, const int *ptr, sf_count_t len)
|
||||
|
||||
static sf_count_t
|
||||
dpcm_write_f2dsc (SF_PRIVATE *psf, const float *ptr, sf_count_t len)
|
||||
{ XI_PRIVATE *pxi ;
|
||||
{ BUF_UNION ubuf ;
|
||||
XI_PRIVATE *pxi ;
|
||||
int bufferlen, writecount ;
|
||||
sf_count_t total = 0 ;
|
||||
float normfact ;
|
||||
@ -781,13 +793,13 @@ dpcm_write_f2dsc (SF_PRIVATE *psf, const float *ptr, sf_count_t len)
|
||||
|
||||
normfact = (psf->norm_float == SF_TRUE) ? (1.0 * 0x7F) : 1.0 ;
|
||||
|
||||
bufferlen = ARRAY_LEN (psf->u.ucbuf) ;
|
||||
bufferlen = ARRAY_LEN (ubuf.ucbuf) ;
|
||||
|
||||
while (len > 0)
|
||||
{ if (len < bufferlen)
|
||||
bufferlen = (int) len ;
|
||||
f2dsc_array (pxi, ptr + total, psf->u.scbuf, bufferlen, normfact) ;
|
||||
writecount = psf_fwrite (psf->u.scbuf, sizeof (signed char), bufferlen, psf) ;
|
||||
f2dsc_array (pxi, ptr + total, ubuf.scbuf, bufferlen, normfact) ;
|
||||
writecount = psf_fwrite (ubuf.scbuf, sizeof (signed char), bufferlen, psf) ;
|
||||
total += writecount ;
|
||||
if (writecount < bufferlen)
|
||||
break ;
|
||||
@ -799,7 +811,8 @@ dpcm_write_f2dsc (SF_PRIVATE *psf, const float *ptr, sf_count_t len)
|
||||
|
||||
static sf_count_t
|
||||
dpcm_write_d2dsc (SF_PRIVATE *psf, const double *ptr, sf_count_t len)
|
||||
{ XI_PRIVATE *pxi ;
|
||||
{ BUF_UNION ubuf ;
|
||||
XI_PRIVATE *pxi ;
|
||||
int bufferlen, writecount ;
|
||||
sf_count_t total = 0 ;
|
||||
double normfact ;
|
||||
@ -809,13 +822,13 @@ dpcm_write_d2dsc (SF_PRIVATE *psf, const double *ptr, sf_count_t len)
|
||||
|
||||
normfact = (psf->norm_double == SF_TRUE) ? (1.0 * 0x7F) : 1.0 ;
|
||||
|
||||
bufferlen = ARRAY_LEN (psf->u.ucbuf) ;
|
||||
bufferlen = ARRAY_LEN (ubuf.ucbuf) ;
|
||||
|
||||
while (len > 0)
|
||||
{ if (len < bufferlen)
|
||||
bufferlen = (int) len ;
|
||||
d2dsc_array (pxi, ptr + total, psf->u.scbuf, bufferlen, normfact) ;
|
||||
writecount = psf_fwrite (psf->u.scbuf, sizeof (signed char), bufferlen, psf) ;
|
||||
d2dsc_array (pxi, ptr + total, ubuf.scbuf, bufferlen, normfact) ;
|
||||
writecount = psf_fwrite (ubuf.scbuf, sizeof (signed char), bufferlen, psf) ;
|
||||
total += writecount ;
|
||||
if (writecount < bufferlen)
|
||||
break ;
|
||||
@ -828,20 +841,21 @@ dpcm_write_d2dsc (SF_PRIVATE *psf, const double *ptr, sf_count_t len)
|
||||
|
||||
static sf_count_t
|
||||
dpcm_write_s2dles (SF_PRIVATE *psf, const short *ptr, sf_count_t len)
|
||||
{ XI_PRIVATE *pxi ;
|
||||
{ BUF_UNION ubuf ;
|
||||
XI_PRIVATE *pxi ;
|
||||
int bufferlen, writecount ;
|
||||
sf_count_t total = 0 ;
|
||||
|
||||
if ((pxi = psf->codec_data) == NULL)
|
||||
return 0 ;
|
||||
|
||||
bufferlen = ARRAY_LEN (psf->u.sbuf) ;
|
||||
bufferlen = ARRAY_LEN (ubuf.sbuf) ;
|
||||
|
||||
while (len > 0)
|
||||
{ if (len < bufferlen)
|
||||
bufferlen = (int) len ;
|
||||
s2dles_array (pxi, ptr + total, psf->u.sbuf, bufferlen) ;
|
||||
writecount = psf_fwrite (psf->u.sbuf, sizeof (short), bufferlen, psf) ;
|
||||
s2dles_array (pxi, ptr + total, ubuf.sbuf, bufferlen) ;
|
||||
writecount = psf_fwrite (ubuf.sbuf, sizeof (short), bufferlen, psf) ;
|
||||
total += writecount ;
|
||||
if (writecount < bufferlen)
|
||||
break ;
|
||||
@ -853,20 +867,21 @@ dpcm_write_s2dles (SF_PRIVATE *psf, const short *ptr, sf_count_t len)
|
||||
|
||||
static sf_count_t
|
||||
dpcm_write_i2dles (SF_PRIVATE *psf, const int *ptr, sf_count_t len)
|
||||
{ XI_PRIVATE *pxi ;
|
||||
{ BUF_UNION ubuf ;
|
||||
XI_PRIVATE *pxi ;
|
||||
int bufferlen, writecount ;
|
||||
sf_count_t total = 0 ;
|
||||
|
||||
if ((pxi = psf->codec_data) == NULL)
|
||||
return 0 ;
|
||||
|
||||
bufferlen = ARRAY_LEN (psf->u.sbuf) ;
|
||||
bufferlen = ARRAY_LEN (ubuf.sbuf) ;
|
||||
|
||||
while (len > 0)
|
||||
{ if (len < bufferlen)
|
||||
bufferlen = (int) len ;
|
||||
i2dles_array (pxi, ptr + total, psf->u.sbuf, bufferlen) ;
|
||||
writecount = psf_fwrite (psf->u.sbuf, sizeof (short), bufferlen, psf) ;
|
||||
i2dles_array (pxi, ptr + total, ubuf.sbuf, bufferlen) ;
|
||||
writecount = psf_fwrite (ubuf.sbuf, sizeof (short), bufferlen, psf) ;
|
||||
total += writecount ;
|
||||
if (writecount < bufferlen)
|
||||
break ;
|
||||
@ -878,7 +893,8 @@ dpcm_write_i2dles (SF_PRIVATE *psf, const int *ptr, sf_count_t len)
|
||||
|
||||
static sf_count_t
|
||||
dpcm_write_f2dles (SF_PRIVATE *psf, const float *ptr, sf_count_t len)
|
||||
{ XI_PRIVATE *pxi ;
|
||||
{ BUF_UNION ubuf ;
|
||||
XI_PRIVATE *pxi ;
|
||||
int bufferlen, writecount ;
|
||||
sf_count_t total = 0 ;
|
||||
float normfact ;
|
||||
@ -888,13 +904,13 @@ dpcm_write_f2dles (SF_PRIVATE *psf, const float *ptr, sf_count_t len)
|
||||
|
||||
normfact = (psf->norm_float == SF_TRUE) ? (1.0 * 0x7FFF) : 1.0 ;
|
||||
|
||||
bufferlen = ARRAY_LEN (psf->u.sbuf) ;
|
||||
bufferlen = ARRAY_LEN (ubuf.sbuf) ;
|
||||
|
||||
while (len > 0)
|
||||
{ if (len < bufferlen)
|
||||
bufferlen = (int) len ;
|
||||
f2dles_array (pxi, ptr + total, psf->u.sbuf, bufferlen, normfact) ;
|
||||
writecount = psf_fwrite (psf->u.sbuf, sizeof (short), bufferlen, psf) ;
|
||||
f2dles_array (pxi, ptr + total, ubuf.sbuf, bufferlen, normfact) ;
|
||||
writecount = psf_fwrite (ubuf.sbuf, sizeof (short), bufferlen, psf) ;
|
||||
total += writecount ;
|
||||
if (writecount < bufferlen)
|
||||
break ;
|
||||
@ -906,7 +922,8 @@ dpcm_write_f2dles (SF_PRIVATE *psf, const float *ptr, sf_count_t len)
|
||||
|
||||
static sf_count_t
|
||||
dpcm_write_d2dles (SF_PRIVATE *psf, const double *ptr, sf_count_t len)
|
||||
{ XI_PRIVATE *pxi ;
|
||||
{ BUF_UNION ubuf ;
|
||||
XI_PRIVATE *pxi ;
|
||||
int bufferlen, writecount ;
|
||||
sf_count_t total = 0 ;
|
||||
double normfact ;
|
||||
@ -916,13 +933,13 @@ dpcm_write_d2dles (SF_PRIVATE *psf, const double *ptr, sf_count_t len)
|
||||
|
||||
normfact = (psf->norm_double == SF_TRUE) ? (1.0 * 0x7FFF) : 1.0 ;
|
||||
|
||||
bufferlen = ARRAY_LEN (psf->u.sbuf) ;
|
||||
bufferlen = ARRAY_LEN (ubuf.sbuf) ;
|
||||
|
||||
while (len > 0)
|
||||
{ if (len < bufferlen)
|
||||
bufferlen = (int) len ;
|
||||
d2dles_array (pxi, ptr + total, psf->u.sbuf, bufferlen, normfact) ;
|
||||
writecount = psf_fwrite (psf->u.sbuf, sizeof (short), bufferlen, psf) ;
|
||||
d2dles_array (pxi, ptr + total, ubuf.sbuf, bufferlen, normfact) ;
|
||||
writecount = psf_fwrite (ubuf.sbuf, sizeof (short), bufferlen, psf) ;
|
||||
total += writecount ;
|
||||
if (writecount < bufferlen)
|
||||
break ;
|
||||
|
Loading…
Reference in New Issue
Block a user