shithub: sox

Download patch

ref: 1b9a445f06d70e54743d902c4f1b0b895cb6471d
parent: bb4432606f1ac09bf419f6a3c15e8d4c7904f3eb
author: robs <robs>
date: Sun May 20 06:01:05 EDT 2007

Various portability enhancements and clean-ups.
Trying out cmake; works on linux and with MSVC, but no plug-in support
as yet.

--- /dev/null
+++ b/CMakeLists.txt
@@ -1,0 +1,7 @@
+project(sox)
+
+if(CMAKE_COMPILER_IS_GNUCC)
+  add_definitions(-Wall -W -Wmissing-prototypes -Wstrict-prototypes -pedantic)
+endif(CMAKE_COMPILER_IS_GNUCC)
+
+subdirs(src lpc10)
--- a/configure.ac
+++ b/configure.ac
@@ -47,10 +47,10 @@
 
 dnl Checks for header files.
 AC_HEADER_STDC
-AC_CHECK_HEADERS(fcntl.h unistd.h byteswap.h)
+AC_CHECK_HEADERS(fcntl.h unistd.h byteswap.h sys/time.h sys/timeb.h ltdl.h)
 
 dnl Checks for library functions.
-AC_CHECK_FUNCS(strcasecmp strdup)
+AC_CHECK_FUNCS(strcasecmp strdup popen vsnprintf)
 AC_REPLACE_FUNCS(getopt_long)
 AM_CONDITIONAL(GETOPT_LONG, test x$getopt_long = xtrue)
 
--- /dev/null
+++ b/lpc10/CMakeLists.txt
@@ -1,0 +1,1 @@
+add_library(lpc10 analys bitio bsynz chanwr dcbias decode deemp difmag dyptrk encode energy f2clib ham84 hp100 invert irc2pc ivfilt lpcdec lpcenc lpcini lpfilt median mload onset pitsyn placea placev preemp prepro random rcchk synths tbdm voicin vparms)
--- /dev/null
+++ b/src/CMakeLists.txt
@@ -1,0 +1,103 @@
+include(CheckIncludeFiles)
+include(CheckFunctionExists)
+include(CheckLibraryExists)
+include(TestBigEndian)
+
+macro(optional variable header library function source)
+  check_include_files(${header} ${variable}1)
+  if (${variable}1)
+    check_library_exists(${library} ${function} "" ${variable})
+    if (${variable})
+      set(optional_srcs ${optional_srcs} ${source})
+      set(optional_libs ${optional_libs} ${library})
+    endif (${variable})
+  endif (${variable}1)
+endmacro(optional)
+
+macro(optional3 variable header library1 function1 library2 function2 library3 function3 source)
+  check_include_files(${header} ${variable}1)
+  if (${variable}1)
+    check_library_exists(${library1} ${function1} "" ${variable}2)
+    if (${variable}2)
+      check_library_exists(${library2} ${function2} "" ${variable}3)
+      if (${variable}3)
+	check_library_exists(${library3} ${function3} "" ${variable})
+        if (${variable})
+          set(optional_srcs ${optional_srcs} ${source})
+          set(optional_libs ${optional_libs} ${library1} ${library2} ${library3})
+        endif (${variable})
+      endif (${variable}3)
+    endif (${variable}2)
+  endif (${variable}1)
+endmacro(optional3)
+
+check_include_files("byteswap.h"         HAVE_BYTESWAP_H)
+check_include_files("inttypes.h"         HAVE_INTTYPES_H)
+check_include_files("io.h"               HAVE_IO_H)
+#check_include_files("ltdl.h"             HAVE_LTDL_H) # no plug-ins as yet
+check_include_files("stdint.h"           HAVE_STDINT_H)
+check_include_files("string.h"           HAVE_STRING_H)
+check_include_files("sys/time.h"         HAVE_SYS_TIME_H)
+check_include_files("sys/timeb.h"        HAVE_SYS_TIMEB_H)
+check_include_files("unistd.h"           HAVE_UNISTD_H)
+
+check_function_exists("fseeko"           HAVE_FSEEKO)
+check_function_exists("getopt_long"      HAVE_GETOPT_LONG)
+check_function_exists("gettimeofday"     HAVE_GETTIMEOFDAY)
+check_function_exists("popen"            HAVE_POPEN)
+check_function_exists("strcasecmp"       HAVE_STRCASECMP)
+check_function_exists("strdup"           HAVE_STRDUP)
+check_function_exists("strrstr"          HAVE_STRRSTR)
+check_function_exists("vsnprintf"        HAVE_VSNPRINTF)
+
+test_big_endian(WORDS_BIGENDIAN)
+
+optional(NEED_LIBM math.h m pow "")
+optional(EXTERNAL_GSM gsm/gsm.h gsm gsm_create "")
+optional(HAVE_ALSA alsa/asoundlib.h asound snd_pcm_open alsa)
+optional(HAVE_LIBAMRNB amrnb/sp_dec.h amrnb Decoder_Interface_init amr-nb)
+optional(HAVE_LIBAMRWB amrwb/dec.h amrwb D_IF_init amr-wb)
+optional(HAVE_LIBAO ao/ao.h ao ao_play ao)
+optional(HAVE_LIBFLAC FLAC/all.h FLAC FLAC__stream_encoder_new flac)
+optional(HAVE_LIBMAD mad.h mad mad_stream_buffer mp3)
+optional(HAVE_LIBMP3LAME lame/lame.h mp3lame lame_init mp3)
+optional(HAVE_SAMPLERATE_H samplerate.h samplerate src_simple rabbit)
+optional(HAVE_SNDFILE_H sndfile.h sndfile sf_open sndfile)
+optional(HAVE_SNDFILE_1_0_12 sndfile.h sndfile sf_open_virtual "")
+optional(HAVE_SUN_AUDIOIO_H sun/audioio.h c ioctl sunaudio)
+if (NOT HAVE_SUN_AUDIOIO_H)
+  optional(HAVE_SYS_AUDIOIO_H sys/audioio.h c ioctl sunaudio)
+endif (NOT HAVE_SUN_AUDIOIO_H)
+optional(HAVE_SYS_SOUNDCARD_H sys/soundcard.h c ioctl oss)
+if (NOT HAVE_SYS_SOUNDCARD_H)
+  optional(HAVE_MACHINE_SOUNDCARD_H machine/soundcard.h ossaudio _oss_ioctl oss)
+endif (NOT HAVE_SYS_SOUNDCARD_H)
+optional3(HAVE_LIBVORBIS vorbis/codec.h vorbis vorbis_analysis_headerout vorbisfile ov_clear vorbisenc vorbis_encode_init_vbr vorbis)
+optional3(HAVE_LIBAVPLUGIN ffmpeg/avformat.h avformat av_open_input_file avutil av_rescale_q avcodec avcodec_encode_audio ffmpeg)
+
+configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}config.h)
+
+#include_directories(${liblpc10_BINARY_DIR}/lpc10)
+#link_directories(${liblpc10_SOURCE_DIR}/lpc10)
+
+if(CMAKE_COMPILER_IS_GNUCC)
+#  add_definitions(-Wconversion)
+endif(CMAKE_COMPILER_IS_GNUCC)
+
+if (NOT EXTERNAL_GSM)
+  add_subdirectory(libgsm)
+  set(optional_libs ${optional_libs} gsm)
+endif (NOT EXTERNAL_GSM)
+
+add_custom_command(
+  OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/soxstdint.h
+  COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/soxstdint.h.cmake ${CMAKE_CURRENT_SOURCE_DIR}/soxstdint.h
+  DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/soxstdint.h.cmake
+  )
+
+add_library(lib${PROJECT_NAME} 8svx adpcm adpcms aifc-fmt aiff aiff-fmt al-fmt au auto avr biquad biquads cdr chorus compand compandt cvsd cvsd-fmt dat dcshift dither dvms-fmt earwax echo echos fade FFT filter flanger g711 g721 g723_24 g723_40 g72x getopt1 getopt gsm handlers hcom ima-fmt ima_rw la-fmt lpc10 lu-fmt maud mcompand misc mixer noiseprof noisered nulfile pad pan phaser pitch polyphas prc rate raw raw-fmt repeat resample reverb reverse s1-fmt s2-fmt s3-fmt s4-fmt sf silence skeleff skelform smp sndrtool soxio speed sphere stat stretch swap synth tremolo trim tx16w u1-fmt u2-fmt u3-fmt u4-fmt ul-fmt util vibro voc vol vox vox-fmt wav wve xa xmalloc soxstdint ${optional_srcs})
+add_executable(${PROJECT_NAME} ${PROJECT_NAME}.c)
+target_link_libraries(${PROJECT_NAME} lib${PROJECT_NAME} lpc10 ${optional_libs})
+add_executable(sox_sample_test sox_sample_test.c)
+add_custom_target(rec ALL ln -sf sox rec DEPENDS sox)
+add_custom_target(play ALL ln -sf sox play DEPENDS sox)
--- a/src/auto.c
+++ b/src/auto.c
@@ -17,12 +17,6 @@
 #include "sox_i.h"
 #include <string.h>
 
-#if defined(DOS) || defined(WIN32)
-#define LASTCHAR '\\'
-#else
-#define LASTCHAR '/'
-#endif
-
 static int sox_autostartread(ft_t ft)
 {
     char *type = NULL;
@@ -153,25 +147,11 @@
     } /* if (seekable) */
 
     if (type == NULL)
-    {
-        /* Use filename extension to determine audio type. */
+      type = find_file_extension(ft->filename);
 
-        /* First, chop off any path portions of filename.  This
-         * prevents the next search from considering that part. */
-        if ((type = strrchr(ft->filename, LASTCHAR)) == NULL)
-            type = ft->filename;
-
-        /* Now look for an filename extension */
-        if ((type = strrchr(type, '.')) != NULL)
-            type++;
-        else
-            type = NULL;
-    }
-
-    if (type == NULL)
-    {
-        sox_fail_errno(ft,SOX_EFMT, "Could not determine file type.");
-        return (SOX_EOF);
+    if (type == NULL) {
+      sox_fail_errno(ft,SOX_EFMT, "Could not determine file type.");
+      return SOX_EOF;
     }
     free(ft->filetype);
     ft->filetype = strdup(type);
--- /dev/null
+++ b/src/formats.h
@@ -1,0 +1,74 @@
+  FORMAT(aifc)
+  FORMAT(aiff)
+  FORMAT(al)
+  FORMAT(au)
+  FORMAT(auto)
+  FORMAT(avr)
+  FORMAT(cdr)
+  FORMAT(cvsd)
+  FORMAT(dat)
+  FORMAT(dvms)
+  FORMAT(gsm)
+  FORMAT(hcom)
+  FORMAT(ima)
+  FORMAT(la)
+  FORMAT(lpc10)
+  FORMAT(lu)
+  FORMAT(maud)
+  FORMAT(nul)
+  FORMAT(prc)
+  FORMAT(raw)
+  FORMAT(s1)
+  FORMAT(s2)
+  FORMAT(s3)
+  FORMAT(s4)
+  FORMAT(sf)
+  FORMAT(smp)
+  FORMAT(sndrtool)
+  FORMAT(sphere)
+  FORMAT(svx)
+  FORMAT(txw)
+  FORMAT(u1)
+  FORMAT(u2)
+  FORMAT(u3)
+  FORMAT(u4)
+  FORMAT(ul)
+  FORMAT(voc)
+  FORMAT(vox)
+  FORMAT(wav)
+  FORMAT(wve)
+  FORMAT(xa)
+
+#if defined HAVE_ALSA
+  FORMAT(alsa)
+#endif
+#if defined HAVE_LIBAMRNB
+  FORMAT(amr_nb)
+#endif
+#if defined HAVE_LIBAMRWB
+  FORMAT(amr_wb)
+#endif
+#if defined HAVE_LIBAO
+  FORMAT(ao)
+#endif
+#if defined HAVE_LIBAVPLUGIN
+  FORMAT(ffmpeg)
+#endif
+#if defined HAVE_LIBFLAC
+  FORMAT(flac)
+#endif
+#if defined(HAVE_LIBMAD) || defined(HAVE_LIBMP3LAME)
+  FORMAT(mp3)
+#endif
+#if defined(HAVE_SYS_SOUNDCARD_H) || defined(HAVE_MACHINE_SOUNDCARD_H)
+  FORMAT(oss)
+#endif
+#if defined HAVE_SNDFILE_H
+  FORMAT(sndfile)
+#endif
+#if defined(HAVE_SYS_AUDIOIO_H) || defined(HAVE_SUN_AUDIOIO_H)
+  FORMAT(sun)
+#endif
+#if defined HAVE_LIBVORBIS
+  FORMAT(vorbis)
+#endif
--- a/src/handlers.c
+++ b/src/handlers.c
@@ -9,18 +9,29 @@
 
 #include "sox_i.h"
 
-#define MAX_FORMATS 256
-unsigned sox_formats = 0;
-sox_format_tab_t sox_format_fns[MAX_FORMATS];
-
-/* Effects handlers. */
-
 /*
- * SOX_EFF_CHAN means that the number of channels can change.
- * SOX_EFF_RATE means that the sample rate can change.
- * SOX_EFF_MCHAN means that the effect is coded for multiple channels.
- *
+ * libSoX file format and effect tables.
  */
+
+/* File format handlers. */
+
+#ifdef HAVE_LTDL_H
+  #define MAX_FORMATS 256
+  unsigned sox_formats = 0;
+  sox_format_tab_t sox_format_fns[MAX_FORMATS];
+#else
+  #define FORMAT(f) extern sox_format_t const * sox_##f##_format_fn(void);
+  #include "formats.h"
+  #undef FORMAT
+  sox_format_tab_t sox_format_fns[] = {
+  #define FORMAT(f) {0, sox_##f##_format_fn},
+  #include "formats.h"
+  #undef FORMAT
+  };
+  unsigned sox_formats = array_length(sox_format_fns);
+#endif 
+
+/* Effects handlers. */
 
 sox_effect_fn_t sox_effect_fns[] = {
   sox_allpass_effect_fn,
--- /dev/null
+++ b/src/libgsm/CMakeLists.txt
@@ -1,0 +1,1 @@
+add_library(gsm add code decode gsm_create gsm_decode gsm_destroy gsm_encode gsm_option long_term lpc preprocess rpe short_term table)
--- a/src/misc.c
+++ b/src/misc.c
@@ -359,6 +359,21 @@
   return a * (b / sox_gcd(a, b));
 }
 
+char const * find_file_extension(char const * pathname)
+{
+  /* First, chop off any path portions of filename.  This
+   * prevents the next search from considering that part. */
+  char const * result = LAST_SLASH(pathname);
+  if (!result)
+    result = pathname;
+
+  /* Now look for an filename extension */
+  result = strrchr(result, '.');
+  if (result)
+    ++result;
+  return result;
+}
+
 #ifndef HAVE_STRCASECMP
 /*
  * Portable strcasecmp() function
@@ -562,12 +577,14 @@
 FILE * xfopen(char const * identifier, char const * mode) 
 { 
   if (is_uri(identifier)) {
-    FILE * f; 
+    FILE * f = 0; 
+#ifdef HAVE_POPEN
     char const * const command_format = "wget -q -O- \"%s\"";
     char * command = xmalloc(strlen(command_format) + strlen(identifier)); 
     sprintf(command, command_format, identifier); 
     f = popen(command, "r"); 
-    free(command); 
+    free(command);
+#endif 
     return f;
   }
   return fopen(identifier, mode);
--- a/src/oss.c
+++ b/src/oss.c
@@ -27,18 +27,17 @@
 
 #include "sox_i.h"
 
-#ifdef HAVE_OSS
-
 #include <unistd.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <fcntl.h>
 #ifdef HAVE_SYS_SOUNDCARD_H
-#include <sys/soundcard.h>
+  #include <sys/soundcard.h>
 #endif
 #ifdef HAVE_MACHINE_SOUNDCARD_H
-#include <machine/soundcard.h>
+  #include <machine/soundcard.h>
 #endif
+
 #include <sys/ioctl.h>
 
 /* common r/w initialization code */
@@ -236,4 +235,3 @@
 {
     return &sox_oss_format;
 }
-#endif
--- a/src/sox.c
+++ b/src/sox.c
@@ -23,38 +23,52 @@
  */
 
 #include "sox_i.h"
+
+#include <ctype.h>
+#include <errno.h>
 #include <math.h>
+#include <signal.h>
 #include <stdio.h>
-#include <string.h>
 #include <stdlib.h>
-#include <signal.h>
-#include <sys/time.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
 #include <time.h>
-#include <ctype.h>
-#include <errno.h>
+
+#ifdef HAVE_IO_H
+  #include <io.h>
+#endif
+
+#ifdef HAVE_LTDL_H
+  #include <ltdl.h>
+#endif
+
+#ifdef HAVE_SYS_TIME_H
+  #include <sys/time.h>
+#endif
+
+#ifdef HAVE_SYS_TIMEB_H
+  #include <sys/timeb.h>
+#endif
+
 #ifdef HAVE_UNISTD_H
-#include <unistd.h>             /* for unlink() */
+  #include <unistd.h>
 #endif
-#include <ltdl.h>
 
 #ifdef HAVE_GETOPT_LONG
-#include <getopt.h>
+  #include <getopt.h>
 #else
-#include "getopt.h"
+  #include "getopt.h"
 #endif
 
-#include <sys/types.h> /* for fstat() */
-#include <sys/stat.h> /* for fstat() */
-#ifdef _MSC_VER
-/*
- * __STDC__ is defined, so these symbols aren't created.
- */
-#define S_IFMT   _S_IFMT
-#define S_IFREG  _S_IFREG
-#define fstat _fstat
-#define strdup _strdup
-#define isatty _isatty
-#include <io.h>
+#ifdef HAVE_GETTIMEOFDAY
+  #define TIME_FRAC 1e6
+#else
+  #define timeval timeb
+  #define gettimeofday(a,b) ftime(a)
+  #define tv_sec time
+  #define tv_usec millitm
+  #define TIME_FRAC 1e3
 #endif
 
 static sox_bool play = sox_false, rec = sox_false;
@@ -209,10 +223,12 @@
     free(ofile);
   }
 
+#ifdef HAVE_LTDL_H
   if (plugins_initted && (ret = lt_dlexit()) != 0) {
     sox_fail("lt_dlexit failed with %d error(s): %s", ret, lt_dlerror());
     exit(1);
   }
+#endif
 }
 
 static file_t new_file(void)
@@ -235,7 +251,7 @@
 
 static void set_device(file_t f, sox_bool recording)
 {
-#ifdef HAVE_AO_AO_H
+#ifdef HAVE_LIBAO
   if (!recording) {
     f->filetype = "ao";
     f->filename = xstrdup("default");
@@ -245,10 +261,10 @@
 #if defined(HAVE_ALSA)
   f->filetype = "alsa";
   f->filename = xstrdup("default");
-#elif defined(HAVE_OSS)
+#elif defined(HAVE_SYS_SOUNDCARD_H) || defined(HAVE_MACHINE_SOUNDCARD_H)
   f->filetype = "ossdsp";
   f->filename = xstrdup("/dev/dsp");
-#elif defined (HAVE_SUN_AUDIO)
+#elif defined(HAVE_SYS_AUDIOIO_H) || defined(HAVE_SUN_AUDIOIO_H)
   char *device = getenv("AUDIODEV");
   f->filetype = "sunau";
   f->filename = xstrdup(device ? device : "/dev/audio");
@@ -291,11 +307,7 @@
   size_t text_length = 100;
   char * text = xmalloc(text_length + 1);
   char * dirname = xstrdup(filename);
-#if defined(DOS) || defined(WIN32)
-  char * slash_pos = max(strrchr(dirname, '/'), strrchr(dirname, '\\'));
-#else
-  char * slash_pos = strrchr(dirname, '/');
-#endif
+  char * slash_pos = LAST_SLASH(dirname);
   FILE * file = xfopen(filename, "r");
   int c;
 
@@ -350,11 +362,7 @@
 
       f = new_file();
       *f = *f0;
-      if (!dirname[0] || is_uri(id)
-#if defined(DOS) || defined(WIN32)
-          || id[0] == '\\' || id[1] == ':'
-#endif
-          || id[0] == '/')
+      if (!dirname[0] || is_uri(id) || IS_ABSOLUTE(id))
         f->filename = xstrdup(id);
       else {
         f->filename = xmalloc(strlen(dirname) + strlen(id) + 2); 
@@ -446,6 +454,7 @@
   }
 }
 
+#ifdef HAVE_LTDL_H
 #define MAX_NAME_LEN 1024
 static int init_format(const char *file, lt_ptr data)
 {
@@ -468,9 +477,11 @@
 
   return -1;
 }
+#endif
 
 static void find_formats(void)
 {
+#ifdef HAVE_LTDL_H
   int ret;
 
   if ((ret = lt_dlinit()) != 0) {
@@ -480,6 +491,7 @@
   plugins_initted = sox_true;
 
   lt_dlforeachfile(PKGLIBDIR, init_format, NULL);
+#endif
 }
 
 int main(int argc, char **argv)
@@ -1035,7 +1047,7 @@
   time_t d;
   gettimeofday(&now, NULL);
   d = now.tv_sec - then->tv_sec;
-  ret = d > ceil(secs) || now.tv_usec - then->tv_usec + d * 1e6 >= secs * 1e6;
+  ret = d > ceil(secs) || now.tv_usec - then->tv_usec + d * TIME_FRAC >= secs * TIME_FRAC;
   if (ret || always_reset)
     *then = now;
   return ret;
--- a/src/sox.h
+++ b/src/sox.h
@@ -28,6 +28,8 @@
 /* Avoid warnings about unused parameters. */
 #ifdef __GNUC__
 #define UNUSED __attribute__ ((unused))
+#else
+#define UNUSED
 #endif
 
 /* Boolean type, assignment (but not necessarily binary) compatible with
--- a/src/sox_i.h
+++ b/src/sox_i.h
@@ -32,8 +32,31 @@
 #define NORET
 #endif
 
-/* C language enhancements: */
+#ifdef _MSC_VER
+#define __STDC__ 1
+#define S_IFMT   _S_IFMT
+#define S_IFREG  _S_IFREG
+#define O_BINARY _O_BINARY
+#define fstat _fstat
+#define ftime _ftime
+#define inline __inline
+#define isatty _isatty
+#define popen _popen
+#define stat _stat
+#define strdup _strdup
+#define timeb _timeb
+#endif
 
+#if defined(DOS) || defined(WIN32) || defined(__NT__) || defined(__DJGPP__)
+  #define LAST_SLASH(path) max(strrchr(path, '/'), strrchr(path, '\\'))
+  #define IS_ABSOLUTE(path) ((path)[0] == '/' || (path)[0] == '\\' || (path)[1] == ':')
+  #define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY)
+#else
+  #define LAST_SLASH(path) strrchr(path, '/')
+  #define IS_ABSOLUTE(path) ((path)[0] == '/')
+  #define SET_BINARY_MODE(file)
+#endif
+
 /* Compile-time ("static") assertion */
 /*   e.g. assert_static(sizeof(int) >= 4, int_type_too_small)    */
 #define assert_static(e,f) enum {assert_static__##f = 1/(e)}
@@ -56,6 +79,7 @@
 #define array_length(a) (sizeof(a)/sizeof(a[0]))
 
 /* declared in misc.c */
+char const * find_file_extension(char const * pathname);
 typedef struct {char const *text; int value;} enum_item;
 #define ENUM_ITEM(prefix, item) {#item, prefix##item},
 enum_item const * find_enum_text(
@@ -237,21 +261,6 @@
 
 extern unsigned sox_formats;
 extern sox_format_tab_t sox_format_fns[];
-
-const sox_format_t *sox_auto_format_fn(void);
-const sox_format_t *sox_raw_format_fn(void);
-const sox_format_t *sox_al_format_fn(void);
-const sox_format_t *sox_la_format_fn(void);
-const sox_format_t *sox_lu_format_fn(void);
-const sox_format_t *sox_s3_format_fn(void);
-const sox_format_t *sox_sb_format_fn(void);
-const sox_format_t *sox_sl_format_fn(void);
-const sox_format_t *sox_sw_format_fn(void);
-const sox_format_t *sox_u3_format_fn(void);
-const sox_format_t *sox_ub_format_fn(void);
-const sox_format_t *sox_u4_format_fn(void);
-const sox_format_t *sox_ul_format_fn(void);
-const sox_format_t *sox_uw_format_fn(void);
 
 /* Raw I/O */
 int sox_rawstartread(ft_t ft);
--- /dev/null
+++ b/src/soxconfig.h.cmake
@@ -1,0 +1,38 @@
+#define PACKAGE_VERSION "14.0.0"
+
+#cmakedefine EXTERNAL_GSM             1
+#cmakedefine HAVE_ALSA                1
+#cmakedefine HAVE_BYTESWAP_H          1
+#cmakedefine HAVE_FSEEKO              1
+#cmakedefine HAVE_GETOPT_LONG         1
+#cmakedefine HAVE_GETTIMEOFDAY        1
+#cmakedefine HAVE_INTTYPES_H          1
+#cmakedefine HAVE_IO_H                1
+#cmakedefine HAVE_LIBAMRNB            1
+#cmakedefine HAVE_LIBAMRWB            1
+#cmakedefine HAVE_LIBAO               1
+#cmakedefine HAVE_LIBAVPLUGIN         1
+#cmakedefine HAVE_LIBFLAC             1
+#cmakedefine HAVE_LIBMAD              1
+#cmakedefine HAVE_LIBMP3LAME          1
+#cmakedefine HAVE_LIBVORBIS           1
+#cmakedefine HAVE_LTDL_H              1
+#cmakedefine HAVE_MACHINE_SOUNDCARD_H 1
+#cmakedefine HAVE_MSVC                1
+#cmakedefine HAVE_POPEN               1
+#cmakedefine HAVE_SAMPLERATE_H        1
+#cmakedefine HAVE_SNDFILE_1_0_12      1
+#cmakedefine HAVE_SNDFILE_H           1
+#cmakedefine HAVE_STDINT_H            1
+#cmakedefine HAVE_STRCASECMP          1
+#cmakedefine HAVE_STRDUP              1
+#cmakedefine HAVE_STRING_H            1
+#cmakedefine HAVE_STRRSTR             1
+#cmakedefine HAVE_SUN_AUDIOIO_H       1
+#cmakedefine HAVE_SYS_AUDIOIO_H       1
+#cmakedefine HAVE_SYS_SOUNDCARD_H     1
+#cmakedefine HAVE_SYS_TIMEB_H         1
+#cmakedefine HAVE_SYS_TIME_H          1
+#cmakedefine HAVE_UNISTD_H            1
+#cmakedefine HAVE_VSNPRINTF           1
+#cmakedefine WORDS_BIGENDIAN          1
--- a/src/soxio.c
+++ b/src/soxio.c
@@ -1,29 +1,16 @@
 #include "sox_i.h"
 
-#include <string.h>
 #include <errno.h>
+#include <fcntl.h>
 #include <stdlib.h>
-#include <sys/types.h> /* for fstat() */
-#include <sys/stat.h> /* for fstat() */
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
 
-#ifdef _MSC_VER
-/* __STDC__ is defined, so these symbols aren't created. */
-#define S_IFMT   _S_IFMT
-#define S_IFREG  _S_IFREG
-#define fstat _fstat
+#ifdef HAVE_IO_H
+  #include <io.h>
 #endif
 
-/* Based on zlib's minigzip: */
-#if defined(WIN32) || defined(__NT__) || defined(__DJGPP__)
-#include <fcntl.h>
-#include <io.h>
-#ifndef O_BINARY
-#define O_BINARY _O_BINARY
-#endif
-#define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY)
-#else
-#define SET_BINARY_MODE(file)
-#endif
 
 sox_size_t sox_bufsiz = 8192;
 sox_global_info_t sox_global_info;
@@ -183,12 +170,6 @@
     return NULL;
 }
 
-#if defined(DOS) || defined(WIN32)
-#define LASTCHAR '\\'
-#else
-#define LASTCHAR '/'
-#endif
-
 ft_t sox_open_write(
     sox_bool (*overwrite_permitted)(const char *filename),
     const char *path,
@@ -206,25 +187,11 @@
     ft->filename = xstrdup(path);
 
     if (!filetype) {
-        char *chop;
-        int len;
-
-        len = strlen(ft->filename);
-
-        /* Use filename extension to determine audio type.
-         * Search for the last '.' appearing in the filename, same
-         * as for input files.
-         */
-        chop = ft->filename + len;
-        while (chop > ft->filename && *chop != LASTCHAR && *chop != '.')
-            chop--;
-
-        if (*chop == '.') {
-            chop++;
-            ft->filetype = xstrdup(chop);
-        }
+      char const * extension = find_file_extension(ft->filename);
+      if (extension)
+        ft->filetype = xstrdup(extension);
     } else
-        ft->filetype = xstrdup(filetype);
+      ft->filetype = xstrdup(filetype);
 
     if (!ft->filetype || sox_gettype(ft, no_filetype_given) != SOX_SUCCESS)
     {
--- /dev/null
+++ b/src/soxstdint.h.cmake
@@ -1,0 +1,28 @@
+#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 long int32_t;
+    typedef short int16_t;
+    typedef unsigned char uint8_t;
+    typedef unsigned long 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/sunaudio.c
+++ b/src/sunaudio.c
@@ -20,10 +20,10 @@
 #include <sys/ioctl.h>
 #include <sys/types.h>
 #ifdef HAVE_SUN_AUDIOIO_H
-#include <sun/audioio.h>
+  #include <sun/audioio.h>
 #else
 #ifdef HAVE_SYS_AUDIOIO_H
-#include <sys/audioio.h>
+  #include <sys/audioio.h>
 #endif
 #endif
 #include <errno.h>
--- a/src/util.c
+++ b/src/util.c
@@ -15,9 +15,6 @@
 #include <string.h>
 #include <ctype.h>
 #include <stdarg.h>
-#ifdef _MSC_VER
-#define popen _popen
-#endif
 
 sox_output_message_handler_t sox_output_message_handler = NULL;
 unsigned sox_output_verbosity_level = 2;
@@ -102,10 +99,10 @@
         ft->sox_errno = sox_errno;
 
         va_start(args, fmt);
-#ifdef _MSC_VER
-        vsprintf(ft->sox_errstr, fmt, args);
-#else
+#ifdef HAVE_VSNPRINTF
         vsnprintf(ft->sox_errstr, sizeof(ft->sox_errstr), fmt, args);
+#else
+        vsprintf(ft->sox_errstr, fmt, args);
 #endif
         va_end(args);
         ft->sox_errstr[255] = '\0';