mirror of
https://github.com/cookiengineer/audacity
synced 2025-11-21 16:37:12 +01:00
Upgrades libsndfile to 1.0.24.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
** Copyright (C) 1999-2009 Erik de Castro Lopo <erikd@mega-nerd.com>
|
||||
** Copyright (C) 1999-2011 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
|
||||
@@ -22,15 +22,16 @@
|
||||
#include "sfconfig.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#if HAVE_STDINT_H
|
||||
#include <stdint.h>
|
||||
#elif HAVE_INTTYPES_H
|
||||
#include <inttypes.h>
|
||||
#endif
|
||||
|
||||
#ifndef SNDFILE_H
|
||||
#include "sndfile.h"
|
||||
#elif HAVE_INTTYPES_H
|
||||
#include <inttypes.h>
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
@@ -39,6 +40,8 @@
|
||||
|
||||
#if (SIZEOF_LONG == 8)
|
||||
# define SF_PLATFORM_S64(x) x##l
|
||||
#elif (SIZEOF_LONG_LONG == 8)
|
||||
# define SF_PLATFORM_S64(x) x##ll
|
||||
#elif COMPILER_IS_GCC
|
||||
# define SF_PLATFORM_S64(x) x##ll
|
||||
#elif OS_IS_WIN32
|
||||
@@ -87,6 +90,8 @@
|
||||
|
||||
#define ARRAY_LEN(x) ((int) (sizeof (x) / sizeof ((x) [0])))
|
||||
|
||||
#define NOT(x) (! (x))
|
||||
|
||||
#if (COMPILER_IS_GCC == 1)
|
||||
#define SF_MAX(x,y) ({ \
|
||||
typeof (x) sf_max_x1 = (x) ; \
|
||||
@@ -104,6 +109,17 @@
|
||||
#define SF_MIN(a,b) ((a) < (b) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
|
||||
#define SF_MAX_CHANNELS 256
|
||||
|
||||
|
||||
#define SF_ASSERT(expr) \
|
||||
{ if (! (expr)) \
|
||||
{ printf ("%s %d : assert '" #expr "' failed!\n", __FILE__, __LINE__) ;\
|
||||
exit (1) ; \
|
||||
} ;\
|
||||
}
|
||||
|
||||
/*
|
||||
* Macros for spliting the format file of SF_INFI into contrainer type,
|
||||
** codec type and endian-ness.
|
||||
@@ -112,7 +128,6 @@
|
||||
#define SF_CODEC(x) ((x) & SF_FORMAT_SUBMASK)
|
||||
#define SF_ENDIAN(x) ((x) & SF_FORMAT_ENDMASK)
|
||||
|
||||
|
||||
enum
|
||||
{ /* PEAK chunk location. */
|
||||
SF_PEAK_START = 42,
|
||||
@@ -214,22 +229,72 @@ make_size_t (int x)
|
||||
{ return (size_t) x ;
|
||||
} /* size_t_of_int */
|
||||
|
||||
typedef SF_BROADCAST_INFO_VAR (16 * 1024) SF_BROADCAST_INFO_16K ;
|
||||
|
||||
#if SIZEOF_WCHAR_T == 2
|
||||
typedef wchar_t sfwchar_t ;
|
||||
#else
|
||||
typedef int16_t sfwchar_t ;
|
||||
#endif
|
||||
|
||||
/*
|
||||
** This version of isprint specifically ignores any locale info. Its used for
|
||||
** determining which characters can be printed in things like hexdumps.
|
||||
*/
|
||||
static inline int
|
||||
psf_isprint (int ch)
|
||||
{ return (ch >= ' ' && ch <= '~') ;
|
||||
} /* psf_isprint */
|
||||
|
||||
/*=======================================================================================
|
||||
** SF_PRIVATE stuct - a pointer to this struct is passed back to the caller of the
|
||||
** sf_open_XXXX functions. The caller however has no knowledge of the struct's
|
||||
** contents.
|
||||
*/
|
||||
|
||||
|
||||
typedef struct
|
||||
{ int size ;
|
||||
SF_BROADCAST_INFO binfo ;
|
||||
} SF_BROADCAST_VAR ;
|
||||
{
|
||||
union
|
||||
{ char c [SF_FILENAME_LEN] ;
|
||||
sfwchar_t wc [SF_FILENAME_LEN] ;
|
||||
} path ;
|
||||
|
||||
union
|
||||
{ char c [SF_FILENAME_LEN] ;
|
||||
sfwchar_t wc [SF_FILENAME_LEN] ;
|
||||
} dir ;
|
||||
|
||||
union
|
||||
{ char c [SF_FILENAME_LEN / 4] ;
|
||||
sfwchar_t wc [SF_FILENAME_LEN / 4] ;
|
||||
} name ;
|
||||
|
||||
#if USE_WINDOWS_API
|
||||
/*
|
||||
** These fields can only be used in src/file_io.c.
|
||||
** They are basically the same as a windows file HANDLE.
|
||||
*/
|
||||
void *handle, *hsaved ;
|
||||
|
||||
int use_wchar ;
|
||||
#else
|
||||
/* These fields can only be used in src/file_io.c. */
|
||||
int filedes, savedes ;
|
||||
#endif
|
||||
|
||||
int do_not_close_descriptor ;
|
||||
int mode ; /* Open mode : SFM_READ, SFM_WRITE or SFM_RDWR. */
|
||||
} PSF_FILE ;
|
||||
|
||||
|
||||
typedef struct sf_private_tag
|
||||
{
|
||||
/* Canary in a coal mine. */
|
||||
char canary [64] ;
|
||||
union
|
||||
{ /* Place a double here to encourage double alignment. */
|
||||
double d [2] ;
|
||||
char c [16] ;
|
||||
} canary ;
|
||||
|
||||
/* Force the compiler to double align the start of buffer. */
|
||||
union
|
||||
@@ -247,10 +312,8 @@ typedef struct sf_private_tag
|
||||
unsigned char ucbuf [SF_BUFFER_LEN / sizeof (signed char)] ;
|
||||
} u ;
|
||||
|
||||
char filepath [SF_FILENAME_LEN] ;
|
||||
char rsrcpath [SF_FILENAME_LEN] ;
|
||||
char directory [SF_FILENAME_LEN] ;
|
||||
char filename [SF_FILENAME_LEN / 4] ;
|
||||
|
||||
PSF_FILE file, rsrc ;
|
||||
|
||||
char syserr [SF_SYSERR_LEN] ;
|
||||
|
||||
@@ -278,22 +341,9 @@ typedef struct sf_private_tag
|
||||
int logindex ;
|
||||
int headindex, headend ;
|
||||
int has_text ;
|
||||
int do_not_close_descriptor ;
|
||||
|
||||
#if USE_WINDOWS_API
|
||||
/*
|
||||
** These fields can only be used in src/file_io.c.
|
||||
** They are basically the same as a windows file HANDLE.
|
||||
*/
|
||||
void *hfile, *hrsrc, *hsaved ;
|
||||
#else
|
||||
/* These fields can only be used in src/file_io.c. */
|
||||
int filedes, rsrcdes, savedes ;
|
||||
#endif
|
||||
|
||||
int error ;
|
||||
|
||||
int mode ; /* Open mode : SFM_READ, SFM_WRITE or SFM_RDWR. */
|
||||
int endian ; /* File endianness : SF_ENDIAN_LITTLE or SF_ENDIAN_BIG. */
|
||||
int data_endswap ; /* Need to endswap data? */
|
||||
|
||||
@@ -323,7 +373,7 @@ typedef struct sf_private_tag
|
||||
SF_INSTRUMENT *instrument ;
|
||||
|
||||
/* Broadcast (EBU) Info */
|
||||
SF_BROADCAST_VAR *broadcast_var ;
|
||||
SF_BROADCAST_INFO_16K *broadcast_16k ;
|
||||
|
||||
/* Channel map data (if present) : an array of ints. */
|
||||
int *channel_map ;
|
||||
@@ -453,6 +503,7 @@ enum
|
||||
SFE_RDWR_BAD_HEADER,
|
||||
SFE_CMD_HAS_DATA,
|
||||
SFE_BAD_BROADCAST_INFO_SIZE,
|
||||
SFE_BAD_BROADCAST_INFO_TOO_BIG,
|
||||
|
||||
SFE_STR_NO_SUPPORT,
|
||||
SFE_STR_NOT_WRITE,
|
||||
@@ -612,6 +663,9 @@ void psf_log_SF_INFO (SF_PRIVATE *psf) ;
|
||||
|
||||
int32_t psf_rand_int32 (void) ;
|
||||
|
||||
void append_snprintf (char * dest, size_t maxlen, const char * fmt, ...) ;
|
||||
void psf_strlcpy_crlf (char *dest, const char *src, size_t destmax, size_t srcmax) ;
|
||||
|
||||
/* Functions used when writing file headers. */
|
||||
|
||||
int psf_binheader_writef (SF_PRIVATE *psf, const char *format, ...) ;
|
||||
@@ -665,13 +719,15 @@ int macos_guess_file_type (SF_PRIVATE *psf, const char *filename) ;
|
||||
** some 32 bit OSes. Implementation in file_io.c.
|
||||
*/
|
||||
|
||||
int psf_fopen (SF_PRIVATE *psf, const char *pathname, int flags) ;
|
||||
int psf_set_stdio (SF_PRIVATE *psf, int mode) ;
|
||||
int psf_fopen (SF_PRIVATE *psf) ;
|
||||
int psf_set_stdio (SF_PRIVATE *psf) ;
|
||||
int psf_file_valid (SF_PRIVATE *psf) ;
|
||||
void psf_set_file (SF_PRIVATE *psf, int fd) ;
|
||||
void psf_init_files (SF_PRIVATE *psf) ;
|
||||
void psf_use_rsrc (SF_PRIVATE *psf, int on_off) ;
|
||||
|
||||
SNDFILE * psf_open_file (SF_PRIVATE *psf, SF_INFO *sfinfo) ;
|
||||
|
||||
sf_count_t psf_fseek (SF_PRIVATE *psf, sf_count_t offset, int whence) ;
|
||||
sf_count_t psf_fread (void *ptr, sf_count_t bytes, sf_count_t count, SF_PRIVATE *psf) ;
|
||||
sf_count_t psf_fwrite (const void *ptr, sf_count_t bytes, sf_count_t count, SF_PRIVATE *psf) ;
|
||||
@@ -687,7 +743,7 @@ int psf_ftruncate (SF_PRIVATE *psf, sf_count_t len) ;
|
||||
int psf_fclose (SF_PRIVATE *psf) ;
|
||||
|
||||
/* Open and close the resource fork of a file. */
|
||||
int psf_open_rsrc (SF_PRIVATE *psf, int mode) ;
|
||||
int psf_open_rsrc (SF_PRIVATE *psf) ;
|
||||
int psf_close_rsrc (SF_PRIVATE *psf) ;
|
||||
|
||||
/*
|
||||
@@ -774,6 +830,30 @@ typedef struct
|
||||
void pchk4_store (PRIV_CHUNK4 * pchk, int marker, sf_count_t offset, sf_count_t len) ;
|
||||
int pchk4_find (PRIV_CHUNK4 * pchk, int marker) ;
|
||||
|
||||
/*------------------------------------------------------------------------------------
|
||||
** Functions that work like OpenBSD's strlcpy/strlcat to replace strncpy/strncat.
|
||||
**
|
||||
** See : http://www.gratisoft.us/todd/papers/strlcpy.html
|
||||
**
|
||||
** These functions are available on *BSD, but are not avaialble everywhere so we
|
||||
** implement them here.
|
||||
**
|
||||
** The argument order has been changed to that of strncpy/strncat to cause
|
||||
** compiler errors if code is carelessly converted from one to the other.
|
||||
*/
|
||||
|
||||
static inline void
|
||||
psf_strlcat (char *dest, size_t n, const char *src)
|
||||
{ strncat (dest, src, n - strlen (dest) - 1) ;
|
||||
dest [n - 1] = 0 ;
|
||||
} /* psf_strlcat */
|
||||
|
||||
static inline void
|
||||
psf_strlcpy (char *dest, size_t n, const char *src)
|
||||
{ strncpy (dest, src, n - 1) ;
|
||||
dest [n - 1] = 0 ;
|
||||
} /* psf_strlcpy */
|
||||
|
||||
/*------------------------------------------------------------------------------------
|
||||
** Other helper functions.
|
||||
*/
|
||||
@@ -787,7 +867,7 @@ void psf_sanitize_string (char * cptr, int len) ;
|
||||
/* Generate the current date as a string. */
|
||||
void psf_get_date_str (char *str, int maxlen) ;
|
||||
|
||||
SF_BROADCAST_VAR* broadcast_var_alloc (size_t datasize) ;
|
||||
SF_BROADCAST_INFO_16K * broadcast_var_alloc (void) ;
|
||||
int broadcast_var_set (SF_PRIVATE *psf, const SF_BROADCAST_INFO * data, size_t datasize) ;
|
||||
int broadcast_var_get (SF_PRIVATE *psf, SF_BROADCAST_INFO * data, size_t datasize) ;
|
||||
|
||||
@@ -798,7 +878,7 @@ typedef struct
|
||||
} AUDIO_DETECT ;
|
||||
|
||||
int audio_detect (SF_PRIVATE * psf, AUDIO_DETECT *ad, const unsigned char * data, int datalen) ;
|
||||
|
||||
int id3_skip (SF_PRIVATE * psf) ;
|
||||
|
||||
/*------------------------------------------------------------------------------------
|
||||
** Helper/debug functions.
|
||||
@@ -811,29 +891,6 @@ const char * str_of_minor_format (int format) ;
|
||||
const char * str_of_open_mode (int mode) ;
|
||||
const char * str_of_endianness (int end) ;
|
||||
|
||||
/*------------------------------------------------------------------------------------
|
||||
** Here's how we fix systems which don't snprintf / vsnprintf.
|
||||
** Systems without these functions should use the
|
||||
*/
|
||||
|
||||
#if USE_WINDOWS_API
|
||||
#define LSF_SNPRINTF _snprintf
|
||||
#elif (HAVE_SNPRINTF && ! FORCE_MISSING_SNPRINTF)
|
||||
#define LSF_SNPRINTF snprintf
|
||||
#else
|
||||
int missing_snprintf (char *str, size_t n, char const *fmt, ...) ;
|
||||
#define LSF_SNPRINTF missing_snprintf
|
||||
#endif
|
||||
|
||||
#if USE_WINDOWS_API
|
||||
#define LSF_VSNPRINTF _vsnprintf
|
||||
#elif (HAVE_VSNPRINTF && ! FORCE_MISSING_SNPRINTF)
|
||||
#define LSF_VSNPRINTF vsnprintf
|
||||
#else
|
||||
int missing_vsnprintf (char *str, size_t n, const char *fmt, ...) ;
|
||||
#define LSF_VSNPRINTF missing_vsnprintf
|
||||
#endif
|
||||
|
||||
/*------------------------------------------------------------------------------------
|
||||
** Extra commands for sf_command(). Not for public use yet.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user