ref: 88eec9c75d0a23c6c4d5d61af76c6ebd56b82b51
parent: e29e9ceb7c25a2d83c09bc8a601de117fc65563c
author: Doug Cook <idigdoug@users.sourceforge.net>
date: Sat Mar 26 13:13:58 EDT 2011
Portability fixes for sox.h The point of this change is to make sox.h more convenient and portable for users of libsox. The libsox API should depend only on the system's ABI and should be independent of soxconfig.h or CRT-specific definitions. It should also minimize its impact on the program in which it is included. sox.h changes: - Don't include soxstdint.h from sox.h. soxstdint.h includes soxconfig.h. The sox.h header should be self-contained for easy management, and should especially not depend on a non-constant header like soxconfig.h (which is different depending on how sox was built). - Minimize the impact on client program by including as few headers as possible. stdio.h and stdlib.h aren't really needed to describe the libsox api, so remove them. stdarg.h is needed for va_list. stddef.h is needed to define size_t. limits.h is needed to get integer sizes. These headers were part of the 1989 C freestanding implementation, so there should be no problem in using them in 2011. - Use limits.h to automatically determine appropriate 8, 16, 32, and 64 bit types without referencing soxconfig.h. stdint.h would be even better, but there are still a few environments that don't have stdint.h. Any C implementation that has a long long type with corresponding macros in limits.h should work with this compile-time auto-detection. My GCC raises a warning about the use of long long, so GCC warnings had to be suppressed for this header. I'm hoping this will be enough to support most systems on which SoX is supported, but if I missed something, it shouldn't be too hard to add support for it. - Use sox_intN_t instead of intN_t for the width-specified integer types referenced by sox.h. All types of the form intN_t, including int24_t, are potentially defined by stdint.h. Sox.h should not be defining any type that might be defined by a standard header. (With this change, sox.h is now "clean" in that every definition made in sox.h starts with either SOX_ or LSX_.) - Change format_t's fp from FILE* to void*. The FILE structure can be defined differently for different C runtimes, causing problems if a libsox shared library uses a different C runtime than the one used by the client. Sox should not expose CRT-specific details such as FILE* to its client API, and should definitely not be encouraging clients to directly access the fp. The clients should be using API calls, and if an API call is missing, it should be added to SoX. - Similarly, it is not safe for the client to pass a FILE* to SoX for use in sox_output_message. The primary magic performed by sox_output_message was its determination of the file's basename, so replace sox_output_message with a new sox_basename function. The client can then call sox_basename to format the filename, then use its own mechanism to print the output message. Summary of other changes in patch: - deleted soxstdint.h.cmake, removed from cmakelists.txt, removed from Makefile.am. - lpc10.h no longer includes soxstdint.h. INT16 and INT32 are auto-detected and defined based on limits.h. - format->fp is now void*, so plugins have to cast it to FILE* for now. In the future, I would like to make fp completely opaque (probably even plugins should not access fp directly), but this is a good start for now. - stdio.h and stdlib.h inclusion moved to sox_i.h. - util.h defines the non-prefixed uint64_t and similar, based on inttypes.h, stdint.h, or limits.h, depending on what soxconfig.h says is available. I'm staying away from int24_t because it isn't present in any stdint.h I know about, but it is specifically mentioned in the C standard as an example of something that stdint.h might define. I don't have a way to determine whether or not stdint.h has defined it, so users of int24_t need to now use sox_int24_t instead. - util.h now defines PRId64 and PRIu64 for use in printf formatting of 64-bit integers. - Change int24_t to sox_int24_t everywhere. - Cast format->fp to FILE*. - Fix samples to work with updated sox.h.
--- a/lpc10/lpc10.h
+++ b/lpc10/lpc10.h
@@ -23,7 +23,7 @@
#ifndef __LPC10_H__
#define __LPC10_H__
-#include "soxstdint.h"
+#include <limits.h>
/* aliases */
#define analys_ lsx_lpc10_analys_
@@ -73,17 +73,21 @@
#define LPC10_BITS_IN_COMPRESSED_FRAME 54
-/*
+#if defined(SHRT_MAX) && defined(SHRT_MIN) && SHRT_MAX==32767 && SHRT_MIN==(-32768)
+typedef short INT16;
+#elif defined(INT_MAX) && defined(INT_MIN) && INT_MAX==32767 && INT_MIN==(-32768)
+typedef int INT16;
+#else
+#error Unable to determine an appropriate definition for INT16.
+#endif
- The "#if defined"'s in this file are by no means intended to be
- complete. They are what Nautilus uses, which has been successfully
- compiled under DOS with the Microsoft C compiler, and under a few
- versions of Unix with the GNU C compiler.
-
- */
-
-typedef int16_t INT16;
-typedef int32_t INT32;
+#if defined(INT_MAX) && defined(INT_MIN) && INT_MAX==2147483647 && INT_MIN==(-2147483647-1)
+typedef int INT32;
+#elif defined(LONG_MAX) && defined(LONG_MIN) && LONG_MAX==2147483647 && LONG_MIN==(-2147483647-1)
+typedef long INT32;
+#else
+#error Unable to determine an appropriate definition for INT32.
+#endif
/* The initial values for every member of this structure is 0, except
--- a/msvc10/LibSoX.vcxproj
+++ b/msvc10/LibSoX.vcxproj
@@ -132,7 +132,6 @@
<ClInclude Include="..\src\win32-ltdl.h" />
<ClInclude Include="..\src\xmalloc.h" />
<ClInclude Include="SoX\soxconfig.h" />
- <ClInclude Include="SoX\soxstdint.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\src\alsa.c">
--- a/msvc10/LibSoX.vcxproj.filters
+++ b/msvc10/LibSoX.vcxproj.filters
@@ -136,9 +136,6 @@
<ClInclude Include="SoX\soxconfig.h">
<Filter>Config Headers</Filter>
</ClInclude>
- <ClInclude Include="SoX\soxstdint.h">
- <Filter>Config Headers</Filter>
- </ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\src\alsa.c">
--- a/msvc10/Makefile.am
+++ b/msvc10/Makefile.am
@@ -44,6 +44,4 @@
SndFile/inttypes.h \
SndFile/sndfile.h \
SndFile/sys/time.h \
- SoX/soxconfig.h \
- SoX/soxstdint.h
-
+ SoX/soxconfig.h
--- a/msvc10/SoX/soxconfig.h
+++ b/msvc10/SoX/soxconfig.h
@@ -15,11 +15,6 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-/* Used only by sox.c: */
-#define MORE_INTERACTIVE
-
-#define PACKAGE_EXTRA "msvc"
-
/* Enable some extra warnings.
Track the number of times each warning has been helpful. */
#pragma warning(3: 4287) /* 0 - constant sign mismatch */
@@ -38,6 +33,11 @@
#pragma warning(3: 4905) /* 0 - string assignment mismatch */
#pragma warning(3: 4906) /* 0 - string assignment mismatch */
+/* Used only by sox.c: */
+#define MORE_INTERACTIVE
+
+#define PACKAGE_EXTRA "msvc"
+
/* Special behavior defined by win32-ltdl: "./" is replaced with the name of the
directory containing sox.exe. */
#define PKGLIBDIR "./soxlib"
@@ -105,6 +105,7 @@
#define HAVE_MEMORY_H 1
#define HAVE_POPEN 1
#define HAVE_SPEEXDSP 1
+#define HAVE_STDINT_H 1
#define HAVE_STDLIB_H 1
#define HAVE_STRDUP 1
#define HAVE_STRING_H 1
--- a/msvc10/SoX/soxstdint.h
+++ /dev/null
@@ -1,18 +1,0 @@
-/* libSoX stub file for MSVC9: (c) 2009 SoX contributors
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2.1 of the License, or (at
- * your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
- * General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this library; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#include "../../src/soxstdint.h.cmake"
--- a/msvc9/.gitignore
+++ b/msvc9/.gitignore
@@ -1,5 +1,7 @@
*.user
-Sox.suo
-Sox.ncb
+Debug
Makefile
Makefile.in
+Release
+Sox.ncb
+Sox.suo
--- a/msvc9/LibSoX.vcproj
+++ b/msvc9/LibSoX.vcproj
@@ -323,10 +323,6 @@
RelativePath=".\SoX\soxconfig.h"
>
</File>
- <File
- RelativePath=".\SoX\soxstdint.h"
- >
- </File>
</Filter>
<Filter
Name="Excluded Sources"
--- a/msvc9/Makefile.am
+++ b/msvc9/Makefile.am
@@ -27,5 +27,4 @@
SndFile/inttypes.h \
SndFile/sndfile.h \
SndFile/sys/time.h \
- Sox/soxconfig.h \
- Sox/soxstdint.h
+ Sox/soxconfig.h
--- a/msvc9/Sox/soxstdint.h
+++ /dev/null
@@ -1,18 +1,0 @@
-/* libSoX stub file for MSVC9: (c) 2009 SoX contributors
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2.1 of the License, or (at
- * your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
- * General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this library; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#include "../../src/soxstdint.h.cmake"
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -20,12 +20,6 @@
set(optional_libs ${optional_libs} gsm)
endif (NOT EXTERNAL_GSM)
-add_custom_command(
- OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/soxstdint.h
- COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/soxstdint.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/soxstdint.h
- DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/soxstdint.h.cmake
-)
-
# Format with: !xargs echo|tr ' ' '\n'|sort|column|expand|sed 's/^/ /'
set(effects_srcs
bend dither gain phaser stat
@@ -62,7 +56,7 @@
add_library(lib${PROJECT_NAME}
effects formats_i libsox_i
effects_i ${formats_srcs} ${optional_srcs}
- effects_i_dsp getopt soxstdint
+ effects_i_dsp getopt
${effects_srcs} getopt1 util
formats libsox xmalloc
)
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -38,7 +38,6 @@
EXTRA_PROGRAMS = example0 example1 example2 example3 example4 example5 sox_sample_test
lib_LTLIBRARIES = libsox.la
include_HEADERS = sox.h
-nodist_include_HEADERS = soxstdint.h
sox_SOURCES = sox.c
if HAVE_WIN32_GLOB
sox_SOURCES += win32-glob.c win32-glob.h
@@ -141,7 +140,7 @@
example5_LDADD = ${sox_LDADD}
EXTRA_DIST = monkey.au monkey.wav optional-fmts.am \
- CMakeLists.txt soxstdint.h.cmake soxconfig.h.cmake \
+ CMakeLists.txt soxconfig.h.cmake \
tests.sh testall.sh tests.bat testall.bat test-comments
all: sox$(EXEEXT) play rec soxi sox_sample_test$(EXEEXT) example0$(EXEEXT) example1$(EXEEXT) example2$(EXEEXT) example3$(EXEEXT) example4$(EXEEXT) example5$(EXEEXT)
@@ -178,12 +177,10 @@
$(RM) example0$(EXEEXT) example1$(EXEEXT) example2$(EXEEXT) example3$(EXEEXT) example4$(EXEEXT) example5$(EXEEXT)
distclean-local:
- $(RM) soxstdint.h
loc:
sloccount \
$(include_HEADERS) \
- $(nodist_include_HEADERS) \
$(sox_SOURCES) \
$(example0_SOURCES) \
$(example1_SOURCES) \
--- a/src/alsa.c
+++ b/src/alsa.c
@@ -186,12 +186,12 @@
break;
}
case SND_PCM_FORMAT_S24: {
- int24_t * buf1 = (int24_t *)p->buf;
+ sox_int24_t * buf1 = (sox_int24_t *)p->buf;
while (i--) *buf++ = SOX_SIGNED_24BIT_TO_SAMPLE(*buf1++,);
break;
}
case SND_PCM_FORMAT_U24: {
- uint24_t * buf1 = (uint24_t *)p->buf;
+ sox_uint24_t * buf1 = (sox_uint24_t *)p->buf;
while (i--) *buf++ = SOX_UNSIGNED_24BIT_TO_SAMPLE(*buf1++,);
break;
}
@@ -249,12 +249,12 @@
break;
}
case SND_PCM_FORMAT_S24: {
- int24_t * buf1 = (int24_t *)p->buf;
+ sox_int24_t * buf1 = (sox_int24_t *)p->buf;
while (i--) *buf1++ = SOX_SAMPLE_TO_SIGNED_24BIT(*buf++, ft->clips);
break;
}
case SND_PCM_FORMAT_U24: {
- uint24_t * buf1 = (uint24_t *)p->buf;
+ sox_uint24_t * buf1 = (sox_uint24_t *)p->buf;
while (i--) *buf1++ = SOX_SAMPLE_TO_UNSIGNED_24BIT(*buf++, ft->clips);
break;
}
--- a/src/example3.c
+++ b/src/example3.c
@@ -33,8 +33,10 @@
{
char const * const str[] = {"FAIL", "WARN", "INFO", "DBUG"};
if (sox_globals.verbosity >= level) {
- fprintf(stderr, "%s ", str[min(level - 1, 3)]);
- sox_output_message(stderr, filename, fmt, ap);
+ char base_name[128];
+ sox_basename(base_name, sizeof(base_name), filename);
+ fprintf(stderr, "%s %s: ", str[min(level - 1, 3)], base_name);
+ vfprintf(stderr, fmt, ap);
fprintf(stderr, "\n");
}
}
--- a/src/example4.c
+++ b/src/example4.c
@@ -18,6 +18,7 @@
*/
#include "sox.h"
+#include <stdio.h>
/* Concatenate audio files. Note that the files must have the same number
* of channels and the same sample rate.
--- a/src/formats.c
+++ b/src/formats.c
@@ -322,7 +322,7 @@
assert(ft);
if (!ft->fp)
return sox_false;
- fstat(fileno(ft->fp), &st);
+ fstat(fileno((FILE*)ft->fp), &st);
return ((st.st_mode & S_IFMT) == S_IFREG);
}
--- a/src/formats_i.c
+++ b/src/formats_i.c
@@ -95,8 +95,8 @@
*/
size_t lsx_readbuf(sox_format_t * ft, void *buf, size_t len)
{
- size_t ret = fread(buf, (size_t) 1, len, ft->fp);
- if (ret != len && ferror(ft->fp))
+ size_t ret = fread(buf, (size_t) 1, len, (FILE*)ft->fp);
+ if (ret != len && ferror((FILE*)ft->fp))
lsx_fail_errno(ft, errno, "lsx_readbuf");
ft->tell_off += ret;
return ret;
@@ -129,10 +129,10 @@
*/
size_t lsx_writebuf(sox_format_t * ft, void const * buf, size_t len)
{
- size_t ret = fwrite(buf, (size_t) 1, len, ft->fp);
+ size_t ret = fwrite(buf, (size_t) 1, len, (FILE*)ft->fp);
if (ret != len) {
lsx_fail_errno(ft, errno, "error writing output file");
- clearerr(ft->fp); /* Allows us to seek back to write header */
+ clearerr((FILE*)ft->fp); /* Allows us to seek back to write header */
}
ft->tell_off += ret;
return ret;
@@ -141,7 +141,7 @@
uint64_t lsx_filelength(sox_format_t * ft)
{
struct stat st;
- int ret = fstat(fileno(ft->fp), &st);
+ int ret = fstat(fileno((FILE*)ft->fp), &st);
return (!ret && (st.st_mode & S_IFREG))? (uint64_t)st.st_size : 0;
}
@@ -148,33 +148,33 @@
int lsx_flush(sox_format_t * ft)
{
- return fflush(ft->fp);
+ return fflush((FILE*)ft->fp);
}
off_t lsx_tell(sox_format_t * ft)
{
- return ft->seekable? (off_t)ftello(ft->fp) : (off_t)ft->tell_off;
+ return ft->seekable? (off_t)ftello((FILE*)ft->fp) : (off_t)ft->tell_off;
}
int lsx_eof(sox_format_t * ft)
{
- return feof(ft->fp);
+ return feof((FILE*)ft->fp);
}
int lsx_error(sox_format_t * ft)
{
- return ferror(ft->fp);
+ return ferror((FILE*)ft->fp);
}
void lsx_rewind(sox_format_t * ft)
{
- rewind(ft->fp);
+ rewind((FILE*)ft->fp);
ft->tell_off = 0;
}
void lsx_clearerr(sox_format_t * ft)
{
- clearerr(ft->fp);
+ clearerr((FILE*)ft->fp);
ft->sox_errno = 0;
}
@@ -194,8 +194,8 @@
if (ft->seekable == 0) {
/* If a stream peel off chars else EPERM */
if (whence == SEEK_CUR) {
- while (offset > 0 && !feof(ft->fp)) {
- getc(ft->fp);
+ while (offset > 0 && !feof((FILE*)ft->fp)) {
+ getc((FILE*)ft->fp);
offset--;
++ft->tell_off;
}
@@ -206,7 +206,7 @@
} else
lsx_fail_errno(ft,SOX_EPERM, "file not seekable");
} else {
- if (fseeko(ft->fp, offset, whence) == -1)
+ if (fseeko((FILE*)ft->fp, offset, whence) == -1)
lsx_fail_errno(ft,errno, "%s", strerror(errno));
else
ft->sox_errno = SOX_SUCCESS;
@@ -374,7 +374,7 @@
READ_FUNC(b, 1, uint8_t, TWIDDLE_BYTE)
READ_FUNC(w, 2, uint16_t, TWIDDLE_WORD)
-READ_FUNC_UNPACK(3, 3, uint24_t, TWIDDLE_WORD)
+READ_FUNC_UNPACK(3, 3, sox_uint24_t, TWIDDLE_WORD)
READ_FUNC(dw, 4, uint32_t, TWIDDLE_WORD)
READ_FUNC(qw, 8, uint64_t, TWIDDLE_WORD)
READ_FUNC(f, sizeof(float), float, TWIDDLE_FLOAT)
@@ -393,7 +393,7 @@
READ1_FUNC(b, uint8_t)
READ1_FUNC(w, uint16_t)
-READ1_FUNC(3, uint24_t)
+READ1_FUNC(3, sox_uint24_t)
READ1_FUNC(dw, uint32_t)
READ1_FUNC(qw, uint64_t)
READ1_FUNC(f, float)
@@ -445,7 +445,7 @@
WRITE_FUNC(b, 1, uint8_t, TWIDDLE_BYTE)
WRITE_FUNC(w, 2, uint16_t, TWIDDLE_WORD)
-WRITE_FUNC_PACK(3, 3, uint24_t, TWIDDLE_WORD)
+WRITE_FUNC_PACK(3, 3, sox_uint24_t, TWIDDLE_WORD)
WRITE_FUNC(dw, 4, uint32_t, TWIDDLE_WORD)
WRITE_FUNC(qw, 8, uint64_t, TWIDDLE_WORD)
WRITE_FUNC(f, sizeof(float), float, TWIDDLE_FLOAT)
@@ -471,7 +471,7 @@
WRITE1U_FUNC(b, uint8_t)
WRITE1U_FUNC(w, uint16_t)
-WRITE1U_FUNC(3, uint24_t)
+WRITE1U_FUNC(3, sox_uint24_t)
WRITE1U_FUNC(dw, uint32_t)
WRITE1_FUNC(qw, uint64_t)
WRITE1S_FUNC(b, uint8_t)
--- a/src/libsox.c
+++ b/src/libsox.c
@@ -113,7 +113,10 @@
unsigned level, const char *filename, const char *fmt, va_list ap)
{
if (sox_globals.verbosity >= level) {
- sox_output_message(stderr, filename, fmt, ap);
+ char base_name[128];
+ sox_basename(base_name, sizeof(base_name), filename);
+ fprintf(stderr, "%s: ", base_name);
+ vfprintf(stderr, fmt, ap);
fprintf(stderr, "\n");
}
}
@@ -151,13 +154,28 @@
return errors[sox_errno];
}
-void sox_output_message(FILE *file, const char *filename, const char *fmt, va_list ap)
+int sox_basename(char * base_buffer, size_t base_buffer_len, const char * filename)
{
- char const * slash_pos = LAST_SLASH(filename);
- char const * base_name = slash_pos? slash_pos + 1 : filename;
- char const * dot_pos = strrchr(base_name, '.');
- fprintf(file, "%.*s: ", dot_pos? (int)(dot_pos - base_name) : -1, base_name);
- vfprintf(file, fmt, ap);
+ if (!base_buffer || !base_buffer_len)
+ {
+ return 0;
+ }
+ else
+ {
+ char const * slash_pos = LAST_SLASH(filename);
+ char const * base_name = slash_pos ? slash_pos + 1 : filename;
+ char const * dot_pos = strrchr(base_name, '.');
+ size_t i, len;
+ dot_pos = dot_pos ? dot_pos : base_name + strlen(base_name);
+ len = dot_pos - base_name;
+ len = min(len, base_buffer_len - 1);
+ for (i = 0; i < len; i++)
+ {
+ base_buffer[i] = base_name[i];
+ }
+ base_buffer[i] = 0;
+ return i;
+ }
}
#undef lsx_fail
--- a/src/mp3.c
+++ b/src/mp3.c
@@ -362,7 +362,7 @@
if (ft->seekable) {
#ifdef USING_ID3TAG
read_comments(ft);
- rewind(ft->fp);
+ rewind((FILE*)ft->fp);
if (!ft->signal.length)
#endif
if (!ignore_length)
@@ -381,7 +381,7 @@
* can be processed later.
*/
ReadSize = lsx_readbuf(ft, p->mp3_buffer, p->mp3_buffer_size);
- if (ReadSize != p->mp3_buffer_size && ferror(ft->fp))
+ if (ReadSize != p->mp3_buffer_size && ferror((FILE*)ft->fp))
return SOX_EOF;
p->mad_stream_buffer(&p->Stream, p->mp3_buffer, ReadSize);
@@ -545,7 +545,7 @@
uint64_t to_skip_samples = 0;
/* Reset all */
- rewind(ft->fp);
+ rewind((FILE*)ft->fp);
mad_timer_reset(&p->Timer);
p->FrameCount = 0;
@@ -566,7 +566,7 @@
size_t leftover = p->Stream.bufend - p->Stream.next_frame;
memcpy(p->mp3_buffer, p->Stream.this_frame, leftover);
- read = fread(p->mp3_buffer + leftover, (size_t) 1, p->mp3_buffer_size - leftover, ft->fp);
+ read = fread(p->mp3_buffer + leftover, (size_t) 1, p->mp3_buffer_size - leftover, (FILE*)ft->fp);
if (read <= 0) {
lsx_debug("seek failure. unexpected EOF (frames=%lu leftover=%lu)", (unsigned long)p->FrameCount, (unsigned long)leftover);
break;
@@ -592,7 +592,7 @@
tagsize = tagtype(p->Stream.this_frame, (size_t) available);
if (tagsize) { /* It's some ID3 tags, so just skip */
if (tagsize >= available) {
- fseeko(ft->fp, (off_t)(tagsize - available), SEEK_CUR);
+ fseeko((FILE*)ft->fp, (off_t)(tagsize - available), SEEK_CUR);
depadded = sox_false;
}
p->mad_stream_skip(&p->Stream, min(tagsize, available));
--- a/src/raw.c
+++ b/src/raw.c
@@ -10,10 +10,10 @@
#include "sox_i.h"
#include "g711.h"
-typedef uint16_t uint14_t;
-typedef uint16_t uint13_t;
-typedef int16_t int14_t;
-typedef int16_t int13_t;
+typedef sox_uint16_t sox_uint14_t;
+typedef sox_uint16_t sox_uint13_t;
+typedef sox_int16_t sox_int14_t;
+typedef sox_int16_t sox_int13_t;
#define SOX_ULAW_BYTE_TO_SAMPLE(d,clips) SOX_SIGNED_16BIT_TO_SAMPLE(sox_ulaw2linear16(d),clips)
#define SOX_ALAW_BYTE_TO_SAMPLE(d,clips) SOX_SIGNED_16BIT_TO_SAMPLE(sox_alaw2linear16(d),clips)
#define SOX_SAMPLE_TO_ULAW_BYTE(d,c) sox_14linear2ulaw(SOX_SAMPLE_TO_UNSIGNED(14,d,c) - 0x2000)
@@ -87,8 +87,8 @@
READ_SAMPLES_FUNC(b, 1, alaw, uint8_t, uint8_t, SOX_ALAW_BYTE_TO_SAMPLE)
READ_SAMPLES_FUNC(w, 2, u, uint16_t, uint16_t, SOX_UNSIGNED_16BIT_TO_SAMPLE)
READ_SAMPLES_FUNC(w, 2, s, int16_t, uint16_t, SOX_SIGNED_16BIT_TO_SAMPLE)
-READ_SAMPLES_FUNC(3, 3, u, uint24_t, uint24_t, SOX_UNSIGNED_24BIT_TO_SAMPLE)
-READ_SAMPLES_FUNC(3, 3, s, int24_t, uint24_t, SOX_SIGNED_24BIT_TO_SAMPLE)
+READ_SAMPLES_FUNC(3, 3, u, sox_uint24_t, sox_uint24_t, SOX_UNSIGNED_24BIT_TO_SAMPLE)
+READ_SAMPLES_FUNC(3, 3, s, sox_int24_t, sox_uint24_t, SOX_SIGNED_24BIT_TO_SAMPLE)
READ_SAMPLES_FUNC(dw, 4, u, uint32_t, uint32_t, SOX_UNSIGNED_32BIT_TO_SAMPLE)
READ_SAMPLES_FUNC(dw, 4, s, int32_t, uint32_t, SOX_SIGNED_32BIT_TO_SAMPLE)
READ_SAMPLES_FUNC(f, sizeof(float), su, float, float, SOX_FLOAT_32BIT_TO_SAMPLE)
@@ -116,8 +116,8 @@
WRITE_SAMPLES_FUNC(b, 1, alaw, uint8_t, uint8_t, SOX_SAMPLE_TO_ALAW_BYTE)
WRITE_SAMPLES_FUNC(w, 2, u, uint16_t, uint16_t, SOX_SAMPLE_TO_UNSIGNED_16BIT)
WRITE_SAMPLES_FUNC(w, 2, s, int16_t, uint16_t, SOX_SAMPLE_TO_SIGNED_16BIT)
-WRITE_SAMPLES_FUNC(3, 3, u, uint24_t, uint24_t, SOX_SAMPLE_TO_UNSIGNED_24BIT)
-WRITE_SAMPLES_FUNC(3, 3, s, int24_t, uint24_t, SOX_SAMPLE_TO_SIGNED_24BIT)
+WRITE_SAMPLES_FUNC(3, 3, u, sox_uint24_t, sox_uint24_t, SOX_SAMPLE_TO_UNSIGNED_24BIT)
+WRITE_SAMPLES_FUNC(3, 3, s, sox_int24_t, sox_uint24_t, SOX_SAMPLE_TO_SIGNED_24BIT)
WRITE_SAMPLES_FUNC(dw, 4, u, uint32_t, uint32_t, SOX_SAMPLE_TO_UNSIGNED_32BIT)
WRITE_SAMPLES_FUNC(dw, 4, s, int32_t, uint32_t, SOX_SAMPLE_TO_SIGNED_32BIT)
WRITE_SAMPLES_FUNC(f, sizeof(float), su, float, float, SOX_SAMPLE_TO_FLOAT_32BIT)
--- a/src/skelform.c
+++ b/src/skelform.c
@@ -82,9 +82,9 @@
unsigned char sample;
for (done = 0; done < len; done++) {
- if (feof(ft->fp)) /* no more samples */
+ if (feof((FILE*)ft->fp)) /* no more samples */
break;
- sample = fgetc(ft->fp);
+ sample = fgetc((FILE*)ft->fp);
switch (ft->encoding.bits_per_sample) {
case 8:
switch (ft->encoding.encoding) {
--- a/src/sox.c
+++ b/src/sox.c
@@ -230,8 +230,8 @@
if (ofile->ft) {
if (!success && ofile->ft->fp) { /* If we failed part way through */
struct stat st; /* writing a normal file, remove it. */
- fstat(fileno(ofile->ft->fp), &st);
- if ((st.st_mode & S_IFMT) == S_IFREG)
+ if (!stat(ofile->ft->filename, &st) &&
+ (st.st_mode & S_IFMT) == S_IFREG)
unlink(ofile->ft->filename);
}
sox_close(ofile->ft); /* Assume we can unlink a file before closing it. */
@@ -1204,7 +1204,7 @@
#elif defined(HAVE_AUDIOIO_H)
static void adjust_volume(int delta)
{
- int vol1 = 0, vol2 = 0, fd = fileno(ofile->ft->fp);
+ int vol1 = 0, vol2 = 0, fd = fileno((FILE*)ofile->ft->fp);
if (fd >= 0) {
audio_info_t audio_info;
if (ioctl(fd, AUDIO_GETINFO, &audio_info) >= 0) {
@@ -2673,8 +2673,10 @@
{
char const * const str[] = {"FAIL", "WARN", "INFO", "DBUG"};
if (sox_globals.verbosity >= level) {
- fprintf(stderr, "%s %s ", myname, str[min(level - 1, 3)]);
- sox_output_message(stderr, filename, fmt, ap);
+ char base_name[128];
+ sox_basename(base_name, sizeof(base_name), filename);
+ fprintf(stderr, "%s %s %s: ", myname, str[min(level - 1, 3)], base_name);
+ vfprintf(stderr, fmt, ap);
fprintf(stderr, "\n");
}
}
--- a/src/sox.h
+++ b/src/sox.h
@@ -13,15 +13,84 @@
#include <limits.h>
#include <stdarg.h>
-#include <stddef.h> /* Ensure NULL etc. are available throughout SoX */
-#include <stdio.h>
-#include <stdlib.h>
+#include <stddef.h>
-/* TODO: soxstdint.h can conflict with standard C headers -- needs work. */
-#include "soxstdint.h"
-typedef int32_t int24_t; /* int24_t == int32_t (beware of the extra byte) */
-typedef uint32_t uint24_t; /* uint24_t == uint32_t (beware of the extra byte) */
+/* Suppress warnings from use of type long long */
+#if defined __GNUC__
+#pragma GCC system_header
+#endif
+#if SCHAR_MAX==127 && SCHAR_MIN==(-128)
+typedef signed char sox_int8_t;
+#elif CHAR_MAX==127 && CHAR_MIN==(-128)
+typedef char sox_int8_t;
+#else
+#error Unable to determine an appropriate definition for sox_int8_t.
+#endif
+
+#if UCHAR_MAX==0xff
+typedef unsigned char sox_uint8_t;
+#elif CHAR_MAX==0xff && CHAR_MIN==0
+typedef char sox_uint8_t;
+#else
+#error Unable to determine an appropriate definition for sox_uint8_t.
+#endif
+
+#if SHRT_MAX==32767 && SHRT_MIN==(-32768)
+typedef short sox_int16_t;
+#elif INT_MAX==32767 && INT_MIN==(-32768)
+typedef int sox_int16_t;
+#else
+#error Unable to determine an appropriate definition for sox_int16_t.
+#endif
+
+#if USHRT_MAX==0xffff
+typedef unsigned short sox_uint16_t;
+#elif UINT_MAX==0xffff
+typedef unsigned int sox_uint16_t;
+#else
+#error Unable to determine an appropriate definition for sox_uint16_t.
+#endif
+
+#if INT_MAX==2147483647 && INT_MIN==(-2147483647-1)
+typedef int sox_int32_t;
+#elif LONG_MAX==2147483647 && LONG_MIN==(-2147483647-1)
+typedef long sox_int32_t;
+#else
+#error Unable to determine an appropriate definition for sox_int32_t.
+#endif
+
+#if UINT_MAX==0xffffffff
+typedef unsigned int sox_uint32_t;
+#elif ULONG_MAX==0xffffffff
+typedef unsigned long sox_uint32_t;
+#else
+#error Unable to determine an appropriate definition for sox_uint32_t.
+#endif
+
+#if LONG_MAX==9223372036854775807 && LONG_MIN==(-9223372036854775807-1)
+typedef long sox_int64_t;
+#elif defined(LLONG_MAX) && defined(LLONG_MIN) && LLONG_MAX==9223372036854775807 && LLONG_MIN==(-9223372036854775807-1)
+typedef long long sox_int64_t;
+#elif defined(_MSC_VER)
+typedef __int64 sox_int64_t;
+#else
+#error Unable to determine an appropriate definition for sox_int64_t.
+#endif
+
+#if ULONG_MAX==0xffffffffffffffff
+typedef unsigned long sox_uint64_t;
+#elif ULLONG_MAX==0xffffffffffffffff
+typedef unsigned long long sox_uint64_t;
+#elif defined(_MSC_VER)
+typedef unsigned __int64 sox_uint64_t;
+#else
+#error Unable to determine an appropriate definition for sox_uint64_t.
+#endif
+
+typedef sox_int32_t sox_int24_t; /* sox_int24_t == sox_int32_t (beware of the extra byte) */
+typedef sox_uint32_t sox_uint24_t; /* sox_uint24_t == sox_uint32_t (beware of the extra byte) */
+
#if defined(__cplusplus)
extern "C" {
#endif
@@ -62,7 +131,7 @@
typedef struct sox_version_info_t {
size_t size; /* structure size = sizeof(sox_version_info_t) */
sox_version_flags_t flags; /* feature flags = popen | magic | threads | memopen */
- uint32_t version_code; /* version number = SOX_LIB_VERSION_CODE, i.e. 0x140400 */
+ sox_uint32_t version_code; /* version number = SOX_LIB_VERSION_CODE, i.e. 0x140400 */
const char * version; /* version string = sox_version(), i.e. "14.4.0" */
const char * version_extra;/* version extra info or null = "PACKAGE_EXTRA", i.e. "beta" */
const char * time; /* build time = "__DATE__ __TIME__", i.e. "Jan 7 2010 03:31:50" */
@@ -103,7 +172,7 @@
#define SOX_INT32_MAX SOX_INT_MAX(32) /* = 0x7FFFFFFF */
/* native SoX audio sample type */
-typedef int32_t sox_sample_t;
+typedef sox_int32_t sox_sample_t;
/* Minimum and maximum values a sample can hold. */
#define SOX_SAMPLE_PRECISION 32 /* bits in a sox_sample_t = 32 */
@@ -139,9 +208,9 @@
#define SOX_SAMPLE_NEG SOX_INT_MIN(32) /* sign bit for sox_sample_t = 0x80000000 */
#define SOX_SAMPLE_TO_UNSIGNED(bits,d,clips) \
- (uint##bits##_t)(SOX_SAMPLE_TO_SIGNED(bits,d,clips)^SOX_INT_MIN(bits))
+ (sox_uint##bits##_t)(SOX_SAMPLE_TO_SIGNED(bits,d,clips)^SOX_INT_MIN(bits))
#define SOX_SAMPLE_TO_SIGNED(bits,d,clips) \
- (int##bits##_t)(LSX_UNUSED_VAR(sox_macro_temp_double),sox_macro_temp_sample=(d),sox_macro_temp_sample>SOX_SAMPLE_MAX-(1<<(31-bits))?++(clips),SOX_INT_MAX(bits):((uint32_t)(sox_macro_temp_sample+(1<<(31-bits))))>>(32-bits))
+ (sox_int##bits##_t)(LSX_UNUSED_VAR(sox_macro_temp_double),sox_macro_temp_sample=(d),sox_macro_temp_sample>SOX_SAMPLE_MAX-(1<<(31-bits))?++(clips),SOX_INT_MAX(bits):((sox_uint32_t)(sox_macro_temp_sample+(1<<(31-bits))))>>(32-bits))
#define SOX_SIGNED_TO_SAMPLE(bits,d)((sox_sample_t)(d)<<(32-bits))
#define SOX_UNSIGNED_TO_SAMPLE(bits,d)(SOX_SIGNED_TO_SAMPLE(bits,d)^SOX_SAMPLE_NEG)
@@ -161,8 +230,8 @@
#define SOX_SAMPLE_TO_SIGNED_16BIT(d,clips) SOX_SAMPLE_TO_SIGNED(16,d,clips)
#define SOX_SAMPLE_TO_UNSIGNED_24BIT(d,clips) SOX_SAMPLE_TO_UNSIGNED(24,d,clips)
#define SOX_SAMPLE_TO_SIGNED_24BIT(d,clips) SOX_SAMPLE_TO_SIGNED(24,d,clips)
-#define SOX_SAMPLE_TO_UNSIGNED_32BIT(d,clips) (uint32_t)((d)^SOX_SAMPLE_NEG)
-#define SOX_SAMPLE_TO_SIGNED_32BIT(d,clips) (int32_t)(d)
+#define SOX_SAMPLE_TO_UNSIGNED_32BIT(d,clips) (sox_uint32_t)((d)^SOX_SAMPLE_NEG)
+#define SOX_SAMPLE_TO_SIGNED_32BIT(d,clips) (sox_int32_t)(d)
#define SOX_SAMPLE_TO_FLOAT_32BIT(d,clips) (LSX_UNUSED_VAR(sox_macro_temp_double),sox_macro_temp_sample=(d),sox_macro_temp_sample>SOX_SAMPLE_MAX-128?++(clips),1:(((sox_macro_temp_sample+128)&~255)*(1./(SOX_SAMPLE_MAX+1.))))
#define SOX_SAMPLE_TO_FLOAT_64BIT(d,clips) ((d)*(1./(SOX_SAMPLE_MAX+1.)))
@@ -201,7 +270,8 @@
typedef void (*sox_output_message_handler_t)(
unsigned level,
const char *filename,
- const char *fmt, va_list ap);
+ const char *fmt,
+ va_list ap);
/* Global parameters (for effects & formats) */
typedef struct sox_globals_t {
@@ -216,7 +286,7 @@
size_t bufsiz; /* default size (in bytes) used for blocks of sample data */
size_t input_bufsiz; /* default size (in bytes) used for blocks of input sample data */
- int32_t ranqd1; /* Can be used to re-seed libSoX's PRNG */
+ sox_int32_t ranqd1; /* Can be used to re-seed libSoX's PRNG */
/* private: */
char const * stdin_in_use_by; /* tracks the name of the handler currently using stdin */
@@ -234,7 +304,7 @@
typedef double sox_rate_t;
#define SOX_UNSPEC 0 /* unknown value for signal parameter = 0 */
-#define SOX_IGNORE_LENGTH (uint64_t)(-1) /* unspecified length for signal.length = -1 */
+#define SOX_IGNORE_LENGTH (sox_uint64_t)(-1) /* unspecified length for signal.length = -1 */
/* Signal parameters; SOX_UNSPEC (= 0) if unknown */
typedef struct sox_signalinfo_t {
@@ -241,7 +311,7 @@
sox_rate_t rate; /* samples per second, 0 if unknown */
unsigned channels; /* number of sound channels, 0 if unknown */
unsigned precision; /* bits per sample, 0 if unknown */
- uint64_t length; /* samples * chans in file, 0 if unknown, -1 if unspecified */
+ sox_uint64_t length; /* samples * chans in file, 0 if unknown, -1 if unspecified */
double * mult; /* Effects headroom multiplier; may be null */
} sox_signalinfo_t;
@@ -350,16 +420,16 @@
sox_loop_8 = 32, /* 8 loops (??) = 32 */
sox_loop_sustain_decay = 64 /* AIFF style, one sustain & one decay loop = 64 */
};
-#define SOX_LOOP_NONE ((uint8_t)sox_loop_none) /* single-shot = 0 */
-#define SOX_LOOP_8 ((uint8_t)sox_loop_8) /* 8 loops (??) = 32 */
-#define SOX_LOOP_SUSTAIN_DECAY ((uint8_t)sox_loop_sustain_decay) /* AIFF style, one sustain & one decay loop = 64 */
+#define SOX_LOOP_NONE ((unsigned char)sox_loop_none) /* single-shot = 0 */
+#define SOX_LOOP_8 ((unsigned char)sox_loop_8) /* 8 loops (??) = 32 */
+#define SOX_LOOP_SUSTAIN_DECAY ((unsigned char)sox_loop_sustain_decay) /* AIFF style, one sustain & one decay loop = 64 */
/* Looping parameters (out-of-band data) */
typedef struct sox_loopinfo_t {
- uint64_t start; /* first sample */
- uint64_t length; /* length */
- unsigned count; /* number of repeats, 0=forever */
- uint8_t type; /* 0=no, 1=forward, 2=forward/back (see sox_loop_... for valid values) */
+ sox_uint64_t start; /* first sample */
+ sox_uint64_t length; /* length */
+ unsigned count; /* number of repeats, 0=forever */
+ unsigned char type; /* 0=no, 1=forward, 2=forward/back (see sox_loop_... for valid values) */
} sox_loopinfo_t;
/* Instrument parameters */
@@ -368,10 +438,10 @@
/* instrument information */
typedef struct sox_instrinfo_t{
- int8_t MIDInote; /* for unity pitch playback */
- int8_t MIDIlow; /* MIDI pitch-bend low range */
- int8_t MIDIhi; /* MIDI pitch-bend high range */
- uint8_t loopmode; /* 0=no, 1=forward, 2=forward/back (see sox_loop_... values) */
+ signed char MIDInote; /* for unity pitch playback */
+ signed char MIDIlow; /* MIDI pitch-bend low range */
+ signed char MIDIhi; /* MIDI pitch-bend high range */
+ unsigned char loopmode; /* 0=no, 1=forward, 2=forward/back (see sox_loop_... values) */
unsigned nloops; /* number of active loops (max SOX_MAX_NLOOPS) */
} sox_instrinfo_t;
@@ -398,7 +468,7 @@
int (*startwrite)(sox_format_t * ft); /* called to initialize writer (encoder) */
size_t (*write)(sox_format_t * ft, const sox_sample_t *buf, size_t len); /* called to write (encode) a block of samples */
int (*stopwrite)(sox_format_t * ft); /* called to close writer (decoder); may be null if no closing necessary */
- int (*seek)(sox_format_t * ft, uint64_t offset); /* called to reposition reader; may be null if not supported */
+ int (*seek)(sox_format_t * ft, sox_uint64_t offset); /* called to reposition reader; may be null if not supported */
/* Array of values indicating the encodings and precisions supported for
* writing (encoding). Precisions specified with default precision first.
@@ -483,14 +553,14 @@
sox_oob_t oob; /* comments, instrument info, loop info (out-of-band data) */
sox_bool seekable; /* Can seek on this file */
char mode; /* Read or write mode ('r' or 'w') */
- uint64_t olength; /* Samples * chans written to file */
+ sox_uint64_t olength; /* Samples * chans written to file */
size_t clips; /* Incremented if clipping occurs */
int sox_errno; /* Failure error code */
char sox_errstr[256]; /* Failure error text */
- FILE * fp; /* File stream pointer */
+ void * fp; /* File stream pointer */
lsx_io_type io_type; /* Stores whether this is a file, pipe or URL */
- uint64_t tell_off; /* Current offset within file */
- uint64_t data_start; /* Offset at which headers end and sound data begins (set by lsx_check_read_params) */
+ sox_uint64_t tell_off; /* Current offset within file */
+ sox_uint64_t data_start; /* Offset at which headers end and sound data begins (set by lsx_check_read_params) */
sox_format_handler_t handler; /* Format handler for this file */
void * priv; /* Format handler's private data area */
};
@@ -596,7 +666,7 @@
#define SOX_SEEK_SET 0
/* Sets the location at which next samples will be decoded. Returns SOX_SUCCESS if successful. */
-int sox_seek(sox_format_t * ft, uint64_t offset, int whence);
+int sox_seek(sox_format_t * ft, sox_uint64_t offset, int whence);
/* Finds a format handler by name. */
sox_format_handler_t const * sox_find_format(char const * name, sox_bool ignore_devices);
@@ -742,9 +812,9 @@
* wants to trim and use a sox_seek() operation instead. After
* sox_seek()'ing, you should set the trim option to 0.
*/
-uint64_t sox_trim_get_start(sox_effect_t * effp);
+sox_uint64_t sox_trim_get_start(sox_effect_t * effp);
void sox_trim_clear_start(sox_effect_t * effp);
-uint64_t sox_crop_get_start(sox_effect_t * effp);
+sox_uint64_t sox_crop_get_start(sox_effect_t * effp);
void sox_crop_clear_start(sox_effect_t * effp);
typedef int (* sox_playlist_callback_t)(void *, char *);
@@ -758,8 +828,9 @@
/* Converts a SoX error code into an error string. */
char const * sox_strerror(int sox_errno);
-/* Writes an error message regarding the specified filename to the given output file stream */
-void sox_output_message(FILE *file, const char *filename, const char *fmt, va_list ap);
+/* Gets the basename of the specified file, i.e. for "/a/b/c.d", gets "c".
+ * Returns the number of characters written to base_buffer, excluding the null. */
+int sox_basename(char * base_buffer, size_t base_buffer_len, const char * filename);
/* WARNING BEGIN
*
--- a/src/sox_i.h
+++ b/src/sox_i.h
@@ -13,15 +13,19 @@
#ifndef SOX_I_H
#define SOX_I_H
-#include "soxomp.h" /* Make this 1st in list (for soxconfig) */
+#include "soxomp.h" /* Note: soxomp.h includes soxconfig.h */
+#include "sox.h"
+
#if defined HAVE_FMEMOPEN
#define _GNU_SOURCE
#endif
-#include "sox.h"
-#include "util.h"
#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "util.h"
+
#if defined(LSX_EFF_ALIAS)
#undef lsx_debug
#undef lsx_fail
@@ -150,7 +154,7 @@
void lsx_set_signal_defaults(sox_format_t * ft);
#define lsx_writechars(ft, chars, len) (lsx_writebuf(ft, chars, len) == len? SOX_SUCCESS : SOX_EOF)
-size_t lsx_read_3_buf(sox_format_t * ft, uint24_t *buf, size_t len);
+size_t lsx_read_3_buf(sox_format_t * ft, sox_uint24_t *buf, size_t len);
size_t lsx_read_b_buf(sox_format_t * ft, uint8_t *buf, size_t len);
size_t lsx_read_df_buf(sox_format_t * ft, double *buf, size_t len);
size_t lsx_read_dw_buf(sox_format_t * ft, uint32_t *buf, size_t len);
@@ -158,7 +162,7 @@
size_t lsx_read_f_buf(sox_format_t * ft, float *buf, size_t len);
size_t lsx_read_w_buf(sox_format_t * ft, uint16_t *buf, size_t len);
-size_t lsx_write_3_buf(sox_format_t * ft, uint24_t *buf, size_t len);
+size_t lsx_write_3_buf(sox_format_t * ft, sox_uint24_t *buf, size_t len);
size_t lsx_write_b_buf(sox_format_t * ft, uint8_t *buf, size_t len);
size_t lsx_write_df_buf(sox_format_t * ft, double *buf, size_t len);
size_t lsx_write_dw_buf(sox_format_t * ft, uint32_t *buf, size_t len);
@@ -166,7 +170,7 @@
size_t lsx_write_f_buf(sox_format_t * ft, float *buf, size_t len);
size_t lsx_write_w_buf(sox_format_t * ft, uint16_t *buf, size_t len);
-int lsx_read3(sox_format_t * ft, uint24_t * u3);
+int lsx_read3(sox_format_t * ft, sox_uint24_t * u3);
int lsx_readb(sox_format_t * ft, uint8_t * ub);
int lsx_readchars(sox_format_t * ft, char * chars, size_t len);
int lsx_readdf(sox_format_t * ft, double * d);
--- a/src/sox_sample_test.h
+++ b/src/sox_sample_test.h
@@ -147,17 +147,17 @@
int main()
{
- int8_t int8;
- int16_t int16;
- int24_t int24;
+ sox_int8_t int8;
+ sox_int16_t int16;
+ sox_int24_t int24;
- uint8_t uint8;
- uint16_t uint16;
- uint24_t uint24;
+ sox_uint8_t uint8;
+ sox_uint16_t uint16;
+ sox_uint24_t uint24;
- int8_t int8_2;
- int16_t int16_2;
- int24_t int24_2;
+ sox_int8_t int8_2;
+ sox_int16_t int16_2;
+ sox_int24_t int24_2;
sox_sample_t sample;
size_t clips = 0;
--- a/src/soxstdint.h.cmake
+++ /dev/null
@@ -1,28 +1,0 @@
-#include "soxconfig.h"
-
-#ifdef HAVE_STDINT_H
- #include <stdint.h>
-#else
- #ifdef HAVE_INTTYPES_H
- #include <inttypes.h>
- #else
- #ifdef _MSC_VER
- typedef __int64 int64_t;
- typedef unsigned __int64 uint64_t;
- #else
- typedef long long int64_t;
- typedef unsigned long long uint64_t;
- #endif
- typedef char int8_t;
- typedef int int32_t;
- typedef short int16_t;
- typedef unsigned char uint8_t;
- typedef unsigned int uint32_t;
- typedef unsigned short uint16_t;
-
- typedef int8_t INT8;
- typedef int16_t INT16;
- typedef int32_t INT32;
- typedef int64_t INT64;
- #endif
-#endif
--- a/src/util.h
+++ b/src/util.h
@@ -17,6 +17,9 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include <stdio.h>
+#include <stdlib.h>
+
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h> /* For off_t not found in stdio.h */
#endif
@@ -28,6 +31,40 @@
#include "xmalloc.h"
/*---------------------------- Portability stuff -----------------------------*/
+
+#if defined(HAVE_INTTYPES_H)
+ #include <inttypes.h>
+#elif defined(HAVE_STDINT_H)
+ #include <stdint.h>
+#else
+ typedef sox_int8_t int8_t;
+ typedef sox_uint8_t uint8_t;
+ typedef sox_int16_t int16_t;
+ typedef sox_uint16_t uint16_t;
+ typedef sox_int32_t int32_t;
+ typedef sox_uint32_t uint32_t;
+ typedef sox_int64_t int64_t;
+ typedef sox_uint64_t uint64_t;
+#endif
+
+/* Define the format specifier to use for int64_t values.
+ * Example: printf("You may have already won $ %" PRId64 " !!!", n64); */
+#ifndef PRId64 /* Maybe <inttypes.h> already defined this. */
+#ifdef _MSC_VER /* Older versions of MSC don't recognize %lld. */
+#define PRId64 "I64d"
+#else
+#define PRId64 "lld"
+#endif
+#endif /* PRId64 */
+
+/* Define the format specifier to use for uint64_t values. */
+#ifndef PRIu64 /* Maybe <inttypes.h> already defined this. */
+#ifdef _MSC_VER /* Older versions of MSC don't recognize %llu. */
+#define PRIu64 "I64u"
+#else
+#define PRIu64 "llu"
+#endif
+#endif /* PRIu64 */
#ifdef __GNUC__
#define NORET __attribute__((noreturn))
--- a/src/voc.c
+++ b/src/voc.c
@@ -554,7 +554,7 @@
{
priv_t * v = (priv_t *) ft->priv;
unsigned char uc, block;
- uint24_t sblen;
+ sox_uint24_t sblen;
uint16_t new_rate_16;
uint32_t new_rate_32;
--- a/src/waveaudio.c
+++ b/src/waveaudio.c
@@ -360,7 +360,7 @@
case 3:
for (i = 0; i < ready; ++i)
{
- int24_t x = *(UNALIGNED int24_t*)(header->lpData + header->dwUser * 3);
+ sox_int24_t x = *(UNALIGNED sox_int24_t*)(header->lpData + header->dwUser * 3);
buf[copied++] = SOX_SIGNED_24BIT_TO_SAMPLE(x, dummy);
header->dwUser++;
}
@@ -431,7 +431,7 @@
{
SOX_SAMPLE_LOCALS;
unsigned char* pdata = (unsigned char*)header->lpData + header->dwUser * 3;
- int24_t x = SOX_SAMPLE_TO_SIGNED_24BIT(buf[copied++], clips);
+ sox_int24_t x = SOX_SAMPLE_TO_SIGNED_24BIT(buf[copied++], clips);
*pdata++ = x;
*pdata++ = x >> 8;
*pdata++ = x >> 16;