mirror of
https://gitee.com/openharmony/third_party_libsnd
synced 2024-11-23 09:59:54 +00:00
More PEAK info handling updates.
This commit is contained in:
parent
4e8d38fb7f
commit
c4fe0c644d
@ -1,6 +1,6 @@
|
||||
2005-07-24 Erik de Castro Lopo <erikd AT mega-nerd DOT com>
|
||||
|
||||
* src/common.h src/double64.c src/float32.c
|
||||
* src/common.h src/double64.c src/float32.c src/sndfile.c
|
||||
Change the way PEAK chunk info is stored. Peaks now stored as an sf_count_t
|
||||
for position and a double as the value.
|
||||
|
||||
|
51
src/aiff.c
51
src/aiff.c
@ -94,6 +94,8 @@
|
||||
#define AIFC_IMA4_BLOCK_LEN 34
|
||||
#define AIFC_IMA4_SAMPLES_PER_BLOCK 64
|
||||
|
||||
#define AIFF_PEAK_CHUNK_SIZE(ch) (2 * sizeof (int) + ch * (sizeof (float) + sizeof (int)))
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Typedefs for file chunks.
|
||||
*/
|
||||
@ -211,10 +213,9 @@ aiff_open (SF_PRIVATE *psf)
|
||||
return SFE_BAD_OPEN_FORMAT ;
|
||||
|
||||
if (psf->mode == SFM_WRITE && (subformat == SF_FORMAT_FLOAT || subformat == SF_FORMAT_DOUBLE))
|
||||
{ psf->pchunk = calloc (1, sizeof (PEAK_INFO) + psf->sf.channels * sizeof (PEAK_POS)) ;
|
||||
if (psf->pchunk == NULL)
|
||||
{ if ((psf->peak_info = peak_info_calloc (psf->sf.channels)) == NULL)
|
||||
return SFE_MALLOC_FAILED ;
|
||||
psf->pchunk->peak_loc = SF_PEAK_START ;
|
||||
psf->peak_info->peak_loc = SF_PEAK_START ;
|
||||
} ;
|
||||
|
||||
if (psf->mode != SFM_RDWR || psf->filelength < 40)
|
||||
@ -324,9 +325,8 @@ aiff_open (SF_PRIVATE *psf)
|
||||
static int
|
||||
aiff_read_header (SF_PRIVATE *psf, COMM_CHUNK *comm_fmt)
|
||||
{ SSND_CHUNK ssnd_fmt ;
|
||||
int marker, dword, bytesread, k ;
|
||||
int FORMsize, SSNDsize ;
|
||||
int filetype, found_chunk = 0, done = 0, error = 0 ;
|
||||
unsigned marker, dword, FORMsize, SSNDsize, bytesread ;
|
||||
int k, filetype, found_chunk = 0, done = 0, error = 0 ;
|
||||
char *cptr, byte ;
|
||||
|
||||
/* Set position to start of file to begin reading header. */
|
||||
@ -400,38 +400,37 @@ aiff_read_header (SF_PRIVATE *psf, COMM_CHUNK *comm_fmt)
|
||||
psf_binheader_readf (psf, "E4", &dword) ;
|
||||
|
||||
psf_log_printf (psf, "%M : %d\n", marker, dword) ;
|
||||
if (dword != 2 * SIGNED_SIZEOF (int) + psf->sf.channels * SIGNED_SIZEOF (PEAK_POS))
|
||||
if (dword != AIFF_PEAK_CHUNK_SIZE (psf->sf.channels))
|
||||
{ psf_binheader_readf (psf, "j", dword) ;
|
||||
psf_log_printf (psf, "*** File PEAK chunk too big.\n") ;
|
||||
return SFE_WAV_BAD_PEAK ;
|
||||
} ;
|
||||
|
||||
psf->pchunk = calloc (1, sizeof (PEAK_INFO) + psf->sf.channels * sizeof (PEAK_POS)) ;
|
||||
if (psf->pchunk == NULL)
|
||||
if ((psf->peak_info = peak_info_calloc (psf->sf.channels)) == NULL)
|
||||
return SFE_MALLOC_FAILED ;
|
||||
|
||||
/* read in rest of PEAK chunk. */
|
||||
psf_binheader_readf (psf, "E44", &(psf->pchunk->version), &(psf->pchunk->timestamp)) ;
|
||||
psf_binheader_readf (psf, "E44", &(psf->peak_info->version), &(psf->peak_info->timestamp)) ;
|
||||
|
||||
if (psf->pchunk->version != 1)
|
||||
psf_log_printf (psf, " version : %d *** (should be version 1)\n", psf->pchunk->version) ;
|
||||
if (psf->peak_info->version != 1)
|
||||
psf_log_printf (psf, " version : %d *** (should be version 1)\n", psf->peak_info->version) ;
|
||||
else
|
||||
psf_log_printf (psf, " version : %d\n", psf->pchunk->version) ;
|
||||
psf_log_printf (psf, " version : %d\n", psf->peak_info->version) ;
|
||||
|
||||
psf_log_printf (psf, " time stamp : %d\n", psf->pchunk->timestamp) ;
|
||||
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 (dword = 0 ; dword < psf->sf.channels ; dword++)
|
||||
for (dword = 0 ; dword < (unsigned) psf->sf.channels ; dword++)
|
||||
{ float value ;
|
||||
unsigned int position ;
|
||||
|
||||
|
||||
psf_binheader_readf (psf, "Ef4", &value, &position) ;
|
||||
psf->pchunk->peaks [dword].value = value ;
|
||||
psf->pchunk->peaks [dword].position = position ;
|
||||
psf->peak_info->peaks [dword].value = value ;
|
||||
psf->peak_info->peaks [dword].position = position ;
|
||||
|
||||
LSF_SNPRINTF (cptr, sizeof (psf->u.scbuf), " %2d %-12ld %g\n",
|
||||
dword, (long) psf->pchunk->peaks [dword].position, psf->pchunk->peaks [dword].value) ;
|
||||
dword, (long) psf->peak_info->peaks [dword].position, psf->peak_info->peaks [dword].value) ;
|
||||
cptr [sizeof (psf->u.scbuf) - 1] = 0 ;
|
||||
psf_log_printf (psf, cptr) ;
|
||||
} ;
|
||||
@ -544,7 +543,7 @@ aiff_read_header (SF_PRIVATE *psf, COMM_CHUNK *comm_fmt)
|
||||
psf_binheader_readf (psf, "b", cptr, dword + (dword & 1)) ;
|
||||
cptr [dword] = 0 ;
|
||||
|
||||
for (k = 0 ; k < dword ; k++)
|
||||
for (k = 0 ; k < (int) dword ; k++)
|
||||
if (! isprint (cptr [k]))
|
||||
{ cptr [k] = 0 ;
|
||||
break ;
|
||||
@ -1068,11 +1067,11 @@ aiff_write_header (SF_PRIVATE *psf, int calc_length)
|
||||
if (psf->str_flags & SF_STR_LOCATE_START)
|
||||
aiff_write_strings (psf, SF_STR_LOCATE_START) ;
|
||||
|
||||
if (psf->pchunk != NULL && psf->pchunk->peak_loc == SF_PEAK_START)
|
||||
{ psf_binheader_writef (psf, "Em4", PEAK_MARKER, 2 * sizeof (int) + psf->sf.channels * sizeof (PEAK_POS)) ;
|
||||
if (psf->peak_info != NULL && psf->peak_info->peak_loc == SF_PEAK_START)
|
||||
{ psf_binheader_writef (psf, "Em4", PEAK_MARKER, AIFF_PEAK_CHUNK_SIZE (psf->sf.channels)) ;
|
||||
psf_binheader_writef (psf, "E44", 1, time (NULL)) ;
|
||||
for (k = 0 ; k < psf->sf.channels ; k++)
|
||||
psf_binheader_writef (psf, "Eft8", (float) psf->pchunk->peaks [k].value, psf->pchunk->peaks [k].position) ;
|
||||
psf_binheader_writef (psf, "Eft8", (float) psf->peak_info->peaks [k].value, psf->peak_info->peaks [k].position) ;
|
||||
} ;
|
||||
|
||||
/* Write SSND chunk. */
|
||||
@ -1104,11 +1103,11 @@ aiff_write_tailer (SF_PRIVATE *psf)
|
||||
|
||||
psf->dataend = psf_fseek (psf, 0, SEEK_END) ;
|
||||
|
||||
if (psf->pchunk != NULL && psf->pchunk->peak_loc == SF_PEAK_END)
|
||||
{ psf_binheader_writef (psf, "Em4", PEAK_MARKER, 2 * sizeof (int) + psf->sf.channels * sizeof (PEAK_POS)) ;
|
||||
if (psf->peak_info != NULL && psf->peak_info->peak_loc == SF_PEAK_END)
|
||||
{ psf_binheader_writef (psf, "Em4", PEAK_MARKER, AIFF_PEAK_CHUNK_SIZE (psf->sf.channels)) ;
|
||||
psf_binheader_writef (psf, "E44", 1, time (NULL)) ;
|
||||
for (k = 0 ; k < psf->sf.channels ; k++)
|
||||
psf_binheader_writef (psf, "Eft8", (float) psf->pchunk->peaks [k].value, psf->pchunk->peaks [k].position) ;
|
||||
psf_binheader_writef (psf, "Eft8", (float) psf->peak_info->peaks [k].value, psf->peak_info->peaks [k].position) ;
|
||||
} ;
|
||||
|
||||
if (psf->str_flags & SF_STR_LOCATE_END)
|
||||
|
10
src/caf.c
10
src/caf.c
@ -126,10 +126,10 @@ caf_open (SF_PRIVATE *psf)
|
||||
** can be switched off using sf_command (SFC_SET_PEAK_CHUNK, SF_FALSE).
|
||||
*/
|
||||
if (psf->mode == SFM_WRITE && (subformat == SF_FORMAT_FLOAT || subformat == SF_FORMAT_DOUBLE))
|
||||
{ psf->pchunk = calloc (1, 2 * sizeof (int) * psf->sf.channels * sizeof (PEAK_POS)) ;
|
||||
if (psf->pchunk == NULL)
|
||||
{ psf->peak_info = calloc (1, 2 * sizeof (int) * psf->sf.channels * sizeof (PEAK_POS)) ;
|
||||
if (psf->peak_info == NULL)
|
||||
return SFE_MALLOC_FAILED ;
|
||||
psf->pchunk->peak_loc = SF_PEAK_START ;
|
||||
psf->peak_info->peak_loc = SF_PEAK_START ;
|
||||
} ;
|
||||
|
||||
if ((error = caf_write_header (psf, SF_FALSE)) != 0)
|
||||
@ -503,11 +503,11 @@ caf_write_header (SF_PRIVATE *psf, int calc_length)
|
||||
if (psf->str_flags & SF_STR_LOCATE_START)
|
||||
caf_write_strings (psf, SF_STR_LOCATE_START) ;
|
||||
|
||||
if (psf->pchunk != NULL && psf->pchunk->peak_loc == SF_PEAK_START)
|
||||
if (psf->peak_info != NULL && psf->peak_info->peak_loc == SF_PEAK_START)
|
||||
{ psf_binheader_writef (psf, "em4", PEAK_MARKER, 2 * sizeof (int) + psf->sf.channels * sizeof (PEAK_POS)) ;
|
||||
psf_binheader_writef (psf, "e44", 1, time (NULL)) ;
|
||||
for (k = 0 ; k < psf->sf.channels ; k++)
|
||||
psf_binheader_writef (psf, "ef4", psf->pchunk->peaks [k].value, psf->pchunk->peaks [k].position) ;
|
||||
psf_binheader_writef (psf, "ef4", psf->peak_info->peaks [k].value, psf->peak_info->peaks [k].position) ;
|
||||
} ;
|
||||
#endif
|
||||
|
||||
|
19
src/common.h
19
src/common.h
@ -21,6 +21,8 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#if HAVE_STDINT_H
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
@ -43,7 +45,7 @@
|
||||
#endif
|
||||
|
||||
#ifdef __GNUC__
|
||||
# define WARN_UNUSED __attribute__((warn_unused_result))
|
||||
# define WARN_UNUSED __attribute__ ((warn_unused_result))
|
||||
#else
|
||||
# define WARN_UNUSED
|
||||
#endif
|
||||
@ -136,10 +138,16 @@ typedef struct
|
||||
} PEAK_POS ;
|
||||
|
||||
typedef struct
|
||||
{ int peak_loc ; /* Write a PEAK chunk at the start or end of the file? */
|
||||
{ /* libsndfile internal : write a PEAK chunk at the start or end of the file? */
|
||||
int peak_loc ;
|
||||
|
||||
/* WAV/AIFF */
|
||||
unsigned int version ; /* version of the PEAK chunk */
|
||||
unsigned int timestamp ; /* secs since 1/1/1970 */
|
||||
|
||||
/* CAF */
|
||||
unsigned int edit_number ;
|
||||
|
||||
#if HAVE_FLEXIBLE_ARRAY
|
||||
/* the per channel peak info */
|
||||
PEAK_POS peaks [] ;
|
||||
@ -155,6 +163,11 @@ typedef struct
|
||||
#endif
|
||||
} PEAK_INFO ;
|
||||
|
||||
static inline PEAK_INFO *
|
||||
peak_info_calloc (int channels)
|
||||
{ return calloc (1, sizeof (PEAK_INFO) + channels * sizeof (PEAK_POS)) ;
|
||||
} /* peak_info_calloc */
|
||||
|
||||
typedef struct
|
||||
{ int type ;
|
||||
int flags ;
|
||||
@ -241,7 +254,7 @@ typedef struct sf_private_tag
|
||||
SF_INFO sf ;
|
||||
|
||||
int have_written ; /* Has a single write been done to the file? */
|
||||
PEAK_INFO *pchunk ;
|
||||
PEAK_INFO *peak_info ;
|
||||
|
||||
/* Loop Info */
|
||||
SF_LOOP_INFO *loop_info ;
|
||||
|
@ -437,9 +437,9 @@ double64_peak_update (SF_PRIVATE *psf, const double *buffer, int count, sf_count
|
||||
position = k ;
|
||||
} ;
|
||||
|
||||
if (fmaxval > psf->pchunk->peaks [chan].value)
|
||||
{ psf->pchunk->peaks [chan].value = fmaxval ;
|
||||
psf->pchunk->peaks [chan].position = psf->write_current + indx + (position / psf->sf.channels) ;
|
||||
if (fmaxval > psf->peak_info->peaks [chan].value)
|
||||
{ psf->peak_info->peaks [chan].value = fmaxval ;
|
||||
psf->peak_info->peaks [chan].position = psf->write_current + indx + (position / psf->sf.channels) ;
|
||||
} ;
|
||||
} ;
|
||||
|
||||
@ -643,7 +643,7 @@ host_write_s2d (SF_PRIVATE *psf, const short *ptr, sf_count_t len)
|
||||
|
||||
s2d_array (ptr + total, psf->u.dbuf, bufferlen) ;
|
||||
|
||||
if (psf->pchunk)
|
||||
if (psf->peak_info)
|
||||
double64_peak_update (psf, psf->u.dbuf, bufferlen, total / psf->sf.channels) ;
|
||||
|
||||
if (psf->float_endswap == SF_TRUE)
|
||||
@ -671,7 +671,7 @@ host_write_i2d (SF_PRIVATE *psf, const int *ptr, sf_count_t len)
|
||||
bufferlen = (int) len ;
|
||||
i2d_array (ptr + total, psf->u.dbuf, bufferlen) ;
|
||||
|
||||
if (psf->pchunk)
|
||||
if (psf->peak_info)
|
||||
double64_peak_update (psf, psf->u.dbuf, bufferlen, total / psf->sf.channels) ;
|
||||
|
||||
if (psf->float_endswap == SF_TRUE)
|
||||
@ -699,7 +699,7 @@ host_write_f2d (SF_PRIVATE *psf, const float *ptr, sf_count_t len)
|
||||
bufferlen = (int) len ;
|
||||
f2d_array (ptr + total, psf->u.dbuf, bufferlen) ;
|
||||
|
||||
if (psf->pchunk)
|
||||
if (psf->peak_info)
|
||||
double64_peak_update (psf, psf->u.dbuf, bufferlen, total / psf->sf.channels) ;
|
||||
|
||||
if (psf->float_endswap == SF_TRUE)
|
||||
@ -720,7 +720,7 @@ host_write_d (SF_PRIVATE *psf, const double *ptr, sf_count_t len)
|
||||
{ int bufferlen, writecount ;
|
||||
sf_count_t total = 0 ;
|
||||
|
||||
if (psf->pchunk)
|
||||
if (psf->peak_info)
|
||||
double64_peak_update (psf, ptr, len, 0) ;
|
||||
|
||||
if (psf->float_endswap != SF_TRUE)
|
||||
@ -874,7 +874,7 @@ replace_write_s2d (SF_PRIVATE *psf, const short *ptr, sf_count_t len)
|
||||
bufferlen = (int) len ;
|
||||
s2d_array (ptr + total, psf->u.dbuf, bufferlen) ;
|
||||
|
||||
if (psf->pchunk)
|
||||
if (psf->peak_info)
|
||||
double64_peak_update (psf, psf->u.dbuf, bufferlen, total / psf->sf.channels) ;
|
||||
|
||||
bd2d_write (psf->u.dbuf, bufferlen) ;
|
||||
@ -904,7 +904,7 @@ replace_write_i2d (SF_PRIVATE *psf, const int *ptr, sf_count_t len)
|
||||
bufferlen = (int) len ;
|
||||
i2d_array (ptr + total, psf->u.dbuf, bufferlen) ;
|
||||
|
||||
if (psf->pchunk)
|
||||
if (psf->peak_info)
|
||||
double64_peak_update (psf, psf->u.dbuf, bufferlen, total / psf->sf.channels) ;
|
||||
|
||||
bd2d_write (psf->u.dbuf, bufferlen) ;
|
||||
@ -955,7 +955,7 @@ replace_write_d (SF_PRIVATE *psf, const double *ptr, sf_count_t len)
|
||||
sf_count_t total = 0 ;
|
||||
|
||||
/* FIXME : This is probably nowhere near optimal. */
|
||||
if (psf->pchunk)
|
||||
if (psf->peak_info)
|
||||
double64_peak_update (psf, ptr, len, 0) ;
|
||||
|
||||
bufferlen = ARRAY_LEN (psf->u.dbuf) ;
|
||||
|
@ -389,9 +389,9 @@ float32_peak_update (SF_PRIVATE *psf, const float *buffer, int count, sf_count_t
|
||||
position = k ;
|
||||
} ;
|
||||
|
||||
if (fmaxval > psf->pchunk->peaks [chan].value)
|
||||
{ psf->pchunk->peaks [chan].value = fmaxval ;
|
||||
psf->pchunk->peaks [chan].position = psf->write_current + indx + (position / psf->sf.channels) ;
|
||||
if (fmaxval > psf->peak_info->peaks [chan].value)
|
||||
{ psf->peak_info->peaks [chan].value = fmaxval ;
|
||||
psf->peak_info->peaks [chan].position = psf->write_current + indx + (position / psf->sf.channels) ;
|
||||
} ;
|
||||
} ;
|
||||
|
||||
@ -592,7 +592,7 @@ host_write_s2f (SF_PRIVATE *psf, const short *ptr, sf_count_t len)
|
||||
bufferlen = (int) len ;
|
||||
s2f_array (ptr + total, psf->u.fbuf, bufferlen) ;
|
||||
|
||||
if (psf->pchunk)
|
||||
if (psf->peak_info)
|
||||
float32_peak_update (psf, psf->u.fbuf, bufferlen, total / psf->sf.channels) ;
|
||||
|
||||
if (psf->float_endswap == SF_TRUE)
|
||||
@ -620,7 +620,7 @@ host_write_i2f (SF_PRIVATE *psf, const int *ptr, sf_count_t len)
|
||||
bufferlen = (int) len ;
|
||||
i2f_array (ptr + total, psf->u.fbuf, bufferlen) ;
|
||||
|
||||
if (psf->pchunk)
|
||||
if (psf->peak_info)
|
||||
float32_peak_update (psf, psf->u.fbuf, bufferlen, total / psf->sf.channels) ;
|
||||
|
||||
if (psf->float_endswap == SF_TRUE)
|
||||
@ -641,7 +641,7 @@ host_write_f (SF_PRIVATE *psf, const float *ptr, sf_count_t len)
|
||||
{ int bufferlen, writecount ;
|
||||
sf_count_t total = 0 ;
|
||||
|
||||
if (psf->pchunk)
|
||||
if (psf->peak_info)
|
||||
float32_peak_update (psf, ptr, len, 0) ;
|
||||
|
||||
if (psf->float_endswap != SF_TRUE)
|
||||
@ -678,7 +678,7 @@ host_write_d2f (SF_PRIVATE *psf, const double *ptr, sf_count_t len)
|
||||
|
||||
d2f_array (ptr + total, psf->u.fbuf, bufferlen) ;
|
||||
|
||||
if (psf->pchunk)
|
||||
if (psf->peak_info)
|
||||
float32_peak_update (psf, psf->u.fbuf, bufferlen, total / psf->sf.channels) ;
|
||||
|
||||
if (psf->float_endswap == SF_TRUE)
|
||||
@ -824,7 +824,7 @@ replace_write_s2f (SF_PRIVATE *psf, const short *ptr, sf_count_t len)
|
||||
bufferlen = (int) len ;
|
||||
s2f_array (ptr + total, psf->u.fbuf, bufferlen) ;
|
||||
|
||||
if (psf->pchunk)
|
||||
if (psf->peak_info)
|
||||
float32_peak_update (psf, psf->u.fbuf, bufferlen, total / psf->sf.channels) ;
|
||||
|
||||
f2bf_array (psf->u.fbuf, bufferlen) ;
|
||||
@ -854,7 +854,7 @@ replace_write_i2f (SF_PRIVATE *psf, const int *ptr, sf_count_t len)
|
||||
bufferlen = (int) len ;
|
||||
i2f_array (ptr + total, psf->u.fbuf, bufferlen) ;
|
||||
|
||||
if (psf->pchunk)
|
||||
if (psf->peak_info)
|
||||
float32_peak_update (psf, psf->u.fbuf, bufferlen, total / psf->sf.channels) ;
|
||||
|
||||
f2bf_array (psf->u.fbuf, bufferlen) ;
|
||||
@ -878,7 +878,7 @@ replace_write_f (SF_PRIVATE *psf, const float *ptr, sf_count_t len)
|
||||
sf_count_t total = 0 ;
|
||||
|
||||
/* FIX THIS */
|
||||
if (psf->pchunk)
|
||||
if (psf->peak_info)
|
||||
float32_peak_update (psf, ptr, len, 0) ;
|
||||
|
||||
bufferlen = ARRAY_LEN (psf->u.fbuf) ;
|
||||
@ -916,7 +916,7 @@ replace_write_d2f (SF_PRIVATE *psf, const double *ptr, sf_count_t len)
|
||||
bufferlen = (int) len ;
|
||||
d2f_array (ptr + total, psf->u.fbuf, bufferlen) ;
|
||||
|
||||
if (psf->pchunk)
|
||||
if (psf->peak_info)
|
||||
float32_peak_update (psf, psf->u.fbuf, bufferlen, total / psf->sf.channels) ;
|
||||
|
||||
f2bf_array (psf->u.fbuf, bufferlen) ;
|
||||
|
@ -2287,8 +2287,8 @@ psf_close (SF_PRIVATE *psf)
|
||||
if (psf->dither)
|
||||
free (psf->dither) ;
|
||||
|
||||
if (psf->pchunk)
|
||||
free (psf->pchunk) ;
|
||||
if (psf->peak_info)
|
||||
free (psf->peak_info) ;
|
||||
|
||||
if (psf->format_desc)
|
||||
{ memset (psf->format_desc, 0, strlen (psf->format_desc)) ;
|
||||
|
57
src/wav.c
57
src/wav.c
@ -79,6 +79,8 @@
|
||||
#define wvpk_MARKER (MAKE_MARKER ('w', 'v', 'p', 'k'))
|
||||
#define OggS_MARKER (MAKE_MARKER ('O', 'g', 'g', 'S'))
|
||||
|
||||
#define WAV_PEAK_CHUNK_SIZE(ch) (2 * sizeof (int) + ch * (sizeof (float) + sizeof (int)))
|
||||
|
||||
enum
|
||||
{ HAVE_RIFF = 0x01,
|
||||
HAVE_WAVE = 0x02,
|
||||
@ -186,10 +188,9 @@ wav_open (SF_PRIVATE *psf)
|
||||
** can be switched off using sf_command (SFC_SET_PEAK_CHUNK, SF_FALSE).
|
||||
*/
|
||||
if (psf->mode == SFM_WRITE && (subformat == SF_FORMAT_FLOAT || subformat == SF_FORMAT_DOUBLE))
|
||||
{ psf->pchunk = calloc (1, sizeof (PEAK_INFO) + psf->sf.channels * sizeof (PEAK_POS)) ;
|
||||
if (psf->pchunk == NULL)
|
||||
{ if ((psf->peak_info = peak_info_calloc (psf->sf.channels)) == NULL)
|
||||
return SFE_MALLOC_FAILED ;
|
||||
psf->pchunk->peak_loc = SF_PEAK_START ;
|
||||
psf->peak_info->peak_loc = SF_PEAK_START ;
|
||||
} ;
|
||||
|
||||
psf->write_header = (format == SF_FORMAT_WAV) ? wav_write_header : wavex_write_header ;
|
||||
@ -253,7 +254,7 @@ static int
|
||||
wav_read_header (SF_PRIVATE *psf, int *blockalign, int *framesperblock)
|
||||
{ WAV_FMT wav_fmt ;
|
||||
FACT_CHUNK fact_chunk ;
|
||||
int dword, marker, RIFFsize, done = 0 ;
|
||||
unsigned dword, marker, RIFFsize, done = 0 ;
|
||||
int parsestage = 0, error, format = 0 ;
|
||||
char *cptr ;
|
||||
|
||||
@ -390,48 +391,47 @@ wav_read_header (SF_PRIVATE *psf, int *blockalign, int *framesperblock)
|
||||
psf_binheader_readf (psf, "e4", &dword) ;
|
||||
|
||||
psf_log_printf (psf, "%M : %d\n", marker, dword) ;
|
||||
if (dword != 2 * SIGNED_SIZEOF (int) + psf->sf.channels * SIGNED_SIZEOF (PEAK_POS))
|
||||
if (dword != WAV_PEAK_CHUNK_SIZE (psf->sf.channels))
|
||||
{ psf_binheader_readf (psf, "j", dword) ;
|
||||
psf_log_printf (psf, "*** File PEAK chunk size doesn't fit with number of channels.\n") ;
|
||||
psf_log_printf (psf, "*** File PEAK chunk size doesn't fit with number of channels (%d).\n", psf->sf.channels) ;
|
||||
return SFE_WAV_BAD_PEAK ;
|
||||
} ;
|
||||
|
||||
psf->pchunk = calloc (1, sizeof (PEAK_INFO) + psf->sf.channels * sizeof (PEAK_POS)) ;
|
||||
if (psf->pchunk == NULL)
|
||||
if ((psf->peak_info = peak_info_calloc (psf->sf.channels)) == NULL)
|
||||
return SFE_MALLOC_FAILED ;
|
||||
|
||||
/* read in rest of PEAK chunk. */
|
||||
psf_binheader_readf (psf, "e44", & (psf->pchunk->version), & (psf->pchunk->timestamp)) ;
|
||||
psf_binheader_readf (psf, "e44", & (psf->peak_info->version), & (psf->peak_info->timestamp)) ;
|
||||
|
||||
if (psf->pchunk->version != 1)
|
||||
psf_log_printf (psf, " version : %d *** (should be version 1)\n", psf->pchunk->version) ;
|
||||
if (psf->peak_info->version != 1)
|
||||
psf_log_printf (psf, " version : %d *** (should be version 1)\n", psf->peak_info->version) ;
|
||||
else
|
||||
psf_log_printf (psf, " version : %d\n", psf->pchunk->version) ;
|
||||
psf_log_printf (psf, " version : %d\n", psf->peak_info->version) ;
|
||||
|
||||
psf_log_printf (psf, " time stamp : %d\n", psf->pchunk->timestamp) ;
|
||||
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 (dword = 0 ; dword < psf->sf.channels ; dword++)
|
||||
for (dword = 0 ; dword < (unsigned) psf->sf.channels ; dword++)
|
||||
{ float value ;
|
||||
unsigned int position ;
|
||||
psf_binheader_readf (psf, "ef4", &value, &position) ;
|
||||
psf->pchunk->peaks [dword].value = value ;
|
||||
psf->pchunk->peaks [dword].position = position ;
|
||||
psf->peak_info->peaks [dword].value = value ;
|
||||
psf->peak_info->peaks [dword].position = position ;
|
||||
|
||||
LSF_SNPRINTF (cptr, sizeof (psf->u.cbuf), " %2d %-12ld %g\n",
|
||||
dword, (long) psf->pchunk->peaks [dword].position, psf->pchunk->peaks [dword].value) ;
|
||||
dword, (long) psf->peak_info->peaks [dword].position, psf->peak_info->peaks [dword].value) ;
|
||||
cptr [sizeof (psf->u.cbuf) - 1] = 0 ;
|
||||
psf_log_printf (psf, cptr) ;
|
||||
} ;
|
||||
|
||||
psf->pchunk->peak_loc = ((parsestage & HAVE_data) == 0) ? SF_PEAK_START : SF_PEAK_END ;
|
||||
psf->peak_info->peak_loc = ((parsestage & HAVE_data) == 0) ? SF_PEAK_START : SF_PEAK_END ;
|
||||
break ;
|
||||
|
||||
case cue_MARKER :
|
||||
parsestage |= HAVE_other ;
|
||||
|
||||
{ int bytesread, cue_count ;
|
||||
{ unsigned bytesread, cue_count ;
|
||||
int id, position, chunk_id, chunk_start, block_start, offset ;
|
||||
|
||||
bytesread = psf_binheader_readf (psf, "e44", &dword, &cue_count) ;
|
||||
@ -793,11 +793,11 @@ wav_write_header (SF_PRIVATE *psf, int calc_length)
|
||||
if (psf->str_flags & SF_STR_LOCATE_START)
|
||||
wav_write_strings (psf, SF_STR_LOCATE_START) ;
|
||||
|
||||
if (psf->pchunk != NULL && psf->pchunk->peak_loc == SF_PEAK_START)
|
||||
{ psf_binheader_writef (psf, "em4", PEAK_MARKER, 2 * sizeof (int) + psf->sf.channels * sizeof (PEAK_POS)) ;
|
||||
if (psf->peak_info != NULL && psf->peak_info->peak_loc == SF_PEAK_START)
|
||||
{ psf_binheader_writef (psf, "em4", PEAK_MARKER, WAV_PEAK_CHUNK_SIZE (psf->sf.channels)) ;
|
||||
psf_binheader_writef (psf, "e44", 1, time (NULL)) ;
|
||||
for (k = 0 ; k < psf->sf.channels ; k++)
|
||||
psf_binheader_writef (psf, "eft8", (float) psf->pchunk->peaks [k].value, psf->pchunk->peaks [k].position) ;
|
||||
psf_binheader_writef (psf, "eft8", (float) psf->peak_info->peaks [k].value, psf->peak_info->peaks [k].position) ;
|
||||
} ;
|
||||
|
||||
psf_binheader_writef (psf, "etm8", data_MARKER, psf->datalength) ;
|
||||
@ -962,18 +962,17 @@ wavex_write_header (SF_PRIVATE *psf, int calc_length)
|
||||
default : return SFE_UNIMPLEMENTED ;
|
||||
} ;
|
||||
|
||||
|
||||
if (add_fact_chunk)
|
||||
psf_binheader_writef (psf, "etm48", fact_MARKER, 4, psf->sf.frames) ;
|
||||
|
||||
if (psf->str_flags & SF_STR_LOCATE_START)
|
||||
wav_write_strings (psf, SF_STR_LOCATE_START) ;
|
||||
|
||||
if (psf->pchunk != NULL && psf->pchunk->peak_loc == SF_PEAK_START)
|
||||
{ psf_binheader_writef (psf, "em4", PEAK_MARKER, 2 * sizeof (int) + psf->sf.channels * sizeof (PEAK_POS)) ;
|
||||
if (psf->peak_info != NULL && psf->peak_info->peak_loc == SF_PEAK_START)
|
||||
{ psf_binheader_writef (psf, "em4", PEAK_MARKER, WAV_PEAK_CHUNK_SIZE (psf->sf.channels)) ;
|
||||
psf_binheader_writef (psf, "e44", 1, time (NULL)) ;
|
||||
for (k = 0 ; k < psf->sf.channels ; k++)
|
||||
psf_binheader_writef (psf, "eft8", (float) psf->pchunk->peaks [k].value, psf->pchunk->peaks [k].position) ;
|
||||
psf_binheader_writef (psf, "eft8", (float) psf->peak_info->peaks [k].value, psf->peak_info->peaks [k].position) ;
|
||||
} ;
|
||||
|
||||
psf_binheader_writef (psf, "etm8", data_MARKER, psf->datalength) ;
|
||||
@ -1004,11 +1003,11 @@ wav_write_tailer (SF_PRIVATE *psf)
|
||||
psf->dataend = psf_fseek (psf, 0, SEEK_END) ;
|
||||
|
||||
/* Add a PEAK chunk if requested. */
|
||||
if (psf->pchunk != NULL && psf->pchunk->peak_loc == SF_PEAK_END)
|
||||
{ psf_binheader_writef (psf, "em4", PEAK_MARKER, 2 * sizeof (int) + psf->sf.channels * sizeof (PEAK_POS)) ;
|
||||
if (psf->peak_info != NULL && psf->peak_info->peak_loc == SF_PEAK_END)
|
||||
{ psf_binheader_writef (psf, "em4", PEAK_MARKER, WAV_PEAK_CHUNK_SIZE (psf->sf.channels)) ;
|
||||
psf_binheader_writef (psf, "e44", 1, time (NULL)) ;
|
||||
for (k = 0 ; k < psf->sf.channels ; k++)
|
||||
psf_binheader_writef (psf, "ef4", psf->pchunk->peaks [k].value, psf->pchunk->peaks [k].position) ;
|
||||
psf_binheader_writef (psf, "ef4", psf->peak_info->peaks [k].value, psf->peak_info->peaks [k].position) ;
|
||||
} ;
|
||||
|
||||
if (psf->str_flags & SF_STR_LOCATE_END)
|
||||
|
Loading…
Reference in New Issue
Block a user