shithub: opus-tools

Download patch

ref: 69b8e72571ca9d046662b73aae7f79a2c7a7a4a3
parent: 2f748dc92ea9e35f4134ca91d739b8cccc019e80
author: Gregory Maxwell <greg@xiph.org>
date: Wed May 16 10:38:02 EDT 2012

Add a real autotools build enviroment.

--- /dev/null
+++ b/AUTHORS
@@ -1,0 +1,1 @@
+Gregory Maxwell (greg@xiph.org)
--- /dev/null
+++ b/COPYING
@@ -1,0 +1,22 @@
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+
+- Redistributions of source code must retain the above copyright
+notice, this list of conditions and the following disclaimer.
+
+- Redistributions in binary form must reproduce the above copyright
+notice, this list of conditions and the following disclaimer in the
+documentation and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
+OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
--- /dev/null
+++ b/ChangeLog
@@ -1,0 +1,3 @@
+2012-05-16  Gregory Maxwell  <greg@xiph.org>
+
+        * Initial public version, 0.1.0
--- /dev/null
+++ b/Makefile.am
@@ -1,0 +1,17 @@
+AUTOMAKE_OPTIONS = subdir-objects
+
+SUBDIRS = .
+
+INCLUDES = -I$(top_srcdir)/src
+
+AM_CFLAGS = $(OGG_CFLAGS) $(Opus_CFLAGS) -DHAVE_GETOPT_H -DEXPORT= -DRANDOM_PREFIX=opustools -DOUTSIDE_SPEEX -DFLOATING_POINT
+
+bin_PROGRAMS = opusenc opusdec
+
+opusenc_SOURCES = src/opus_header.c src/opusenc.c src/resample.c src/audio-in.c src/diag_range.c
+opusenc_LDADD = $(OGG_LIBS) $(Opus_LIBS) -lm
+
+opusdec_SOURCES = src/opus_header.c src/wav_io.c src/wave_out.c src/opusdec.c src/resample.c src/diag_range.c
+opusdec_LDADD = $(OGG_LIBS) $(Opus_LIBS) -lm
+
+#TESTS = FIXME
--- /dev/null
+++ b/autogen.sh
@@ -1,0 +1,115 @@
+#!/bin/sh
+# Run this to set up the build system: configure, makefiles, etc.
+# (based on the version in enlightenment's cvs)
+
+package="opus-tools"
+
+olddir=`pwd`
+srcdir=`dirname $0`
+test -z "$srcdir" && srcdir=.
+
+cd "$srcdir"
+DIE=0
+
+echo "checking for autoconf... "
+(autoconf --version) < /dev/null > /dev/null 2>&1 || {
+        echo
+        echo "You must have autoconf installed to compile $package."
+        echo "Download the appropriate package for your distribution,"
+        echo "or get the source tarball at ftp://ftp.gnu.org/pub/gnu/"
+        DIE=1
+}
+
+VERSIONGREP="sed -e s/.*[^0-9\.]\([0-9]\.[0-9]*\).*/\1/"
+VERSIONMKINT="sed -e s/[^0-9]//"
+
+# do we need automake?
+if test -r Makefile.am; then
+  AM_OPTIONS=`fgrep AUTOMAKE_OPTIONS Makefile.am`
+  AM_NEEDED=`echo $AM_OPTIONS | $VERSIONGREP`
+  if test "$AM_NEEDED" = "$AM_OPTIONS"; then
+    AM_NEEDED=""
+  fi
+  if test -z $AM_NEEDED; then
+    echo -n "checking for automake... "
+    AUTOMAKE=automake
+    ACLOCAL=aclocal
+    if ($AUTOMAKE --version < /dev/null > /dev/null 2>&1); then
+      echo "yes"
+    else
+      echo "no"
+      AUTOMAKE=
+    fi
+  else
+    echo -n "checking for automake $AM_NEEDED or later... "
+    for am in automake-$AM_NEEDED automake$AM_NEEDED automake; do
+      ($am --version < /dev/null > /dev/null 2>&1) || continue
+      ver=`$am --version < /dev/null | head -n 1 | $VERSIONGREP | $VERSIONMKINT`
+      verneeded=`echo $AM_NEEDED | $VERSIONMKINT`
+      if test $ver -ge $verneeded; then
+        AUTOMAKE=$am
+        echo $AUTOMAKE
+        break
+      fi
+    done
+    test -z $AUTOMAKE &&  echo "no"
+    echo -n "checking for aclocal $AM_NEEDED or later... "
+    for ac in aclocal-$AM_NEEDED aclocal$AM_NEEDED aclocal; do
+      ($ac --version < /dev/null > /dev/null 2>&1) || continue
+      ver=`$ac --version < /dev/null | head -n 1 | $VERSIONGREP | $VERSIONMKINT`
+      verneeded=`echo $AM_NEEDED | $VERSIONMKINT`
+      if test $ver -ge $verneeded; then
+        ACLOCAL=$ac
+        echo $ACLOCAL
+        break
+      fi
+    done
+    test -z $ACLOCAL && echo "no"
+  fi
+  test -z $AUTOMAKE || test -z $ACLOCAL && {
+        echo
+        echo "You must have automake installed to compile $package."
+        echo "Download the appropriate package for your distribution,"
+        echo "or get the source tarball at ftp://ftp.gnu.org/pub/gnu/"
+        exit 1
+  }
+fi
+
+echo -n "checking for libtool... "
+for LIBTOOLIZE in libtoolize glibtoolize nope; do
+  ($LIBTOOLIZE --version) < /dev/null > /dev/null 2>&1 && break
+done
+if test x$LIBTOOLIZE = xnope; then
+  echo "nope."
+  LIBTOOLIZE=libtoolize
+else
+  echo $LIBTOOLIZE
+fi
+($LIBTOOLIZE --version) < /dev/null > /dev/null 2>&1 || {
+	echo
+	echo "You must have libtool installed to compile $package."
+	echo "Download the appropriate package for your system,"
+	echo "or get the source from one of the GNU ftp sites"
+	echo "listed in http://www.gnu.org/order/ftp.html"
+	DIE=1
+}
+
+if test "$DIE" -eq 1; then
+        exit 1
+fi
+
+echo "Generating configuration files for $package, please wait...."
+
+echo "  $ACLOCAL $ACLOCAL_FLAGS"
+$ACLOCAL $ACLOCAL_FLAGS || exit 1
+echo "  autoheader"
+autoheader || exit 1
+echo "  $LIBTOOLIZE --automake"
+$LIBTOOLIZE --automake || exit 1
+echo "  $AUTOMAKE --add-missing $AUTOMAKE_FLAGS"
+$AUTOMAKE --add-missing $AUTOMAKE_FLAGS || exit 1
+echo "  autoconf"
+autoconf || exit 1
+
+cd $olddir
+#$srcdir/configure "$@" && echo
--- /dev/null
+++ b/configure.ac
@@ -1,0 +1,237 @@
+dnl Process this file with autoconf to produce a configure script. -*-m4-*-
+
+AC_INIT(src/opusenc.c)
+
+AM_CONFIG_HEADER([config.h])
+
+dnl enable silent rules on automake 1.11 and later
+m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
+
+OPUSTOOLS_MAJOR_VERSION=0
+OPUSTOOLS_MINOR_VERSION=1
+OPUSTOOLS_MICRO_VERSION=0
+OPUSTOOLS_EXTRA_VERSION=
+
+OPUSTOOLS_VERSION="$OPUSTOOLS_MAJOR_VERSION.$OPUSTOOLS_MINOR_VERSION.$OPUSTOOLS_MICRO_VERSION$OPUSTOOLS_EXTRA_VERSION"
+AC_MSG_CHECKING([git revision])
+GIT_VERSION=$(git describe --tags --match 'v*' 2>/dev/null | sed 's/^v//')
+if test -z "$GIT_VERSION"; then
+  AC_MSG_RESULT([no])
+else
+  AC_MSG_RESULT([$GIT_VERSION])
+  OPUSTOOLS_VERSION="$GIT_VERSION"
+fi
+
+# For automake.
+VERSION=$OPUSTOOLS_VERSION
+PACKAGE=opus-tools
+
+# For our version string
+AC_SUBST(OPUSTOOLS_VERSION)
+
+AM_INIT_AUTOMAKE($PACKAGE, $VERSION, no-define)
+AM_MAINTAINER_MODE
+
+AC_CANONICAL_HOST
+AM_PROG_CC_C_O
+
+AC_PROG_CC_C99
+AC_C_BIGENDIAN
+AC_C_CONST
+AC_C_INLINE
+
+#Use a hacked up version of autoconf's AC_C_RESTRICT because it's not
+#strong enough a test to detect old buggy versions of GCC (e.g. 2.95.3)
+AC_CACHE_CHECK([for C/C++ restrict keyword], ac_cv_c_restrict,
+  [ac_cv_c_restrict=no
+   # The order here caters to the fact that C++ does not require restrict.
+   for ac_kw in __restrict __restrict__ _Restrict restrict; do
+     AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
+      [[typedef int * int_ptr;
+	int foo (int_ptr $ac_kw ip, int * $ac_kw baz[]) {
+	return ip[0];
+       }]],
+      [[int s[1];
+	int * $ac_kw t = s;
+	t[0] = 0;
+	return foo(t, (void *)0)]])],
+      [ac_cv_c_restrict=$ac_kw])
+     test "$ac_cv_c_restrict" != no && break
+   done
+  ])
+ AH_VERBATIM([restrict],
+[/* Define to the equivalent of the C99 'restrict' keyword, or to
+   nothing if this is not supported.  Do not define if restrict is
+   supported directly.  */
+#undef restrict
+/* Work around a bug in Sun C++: it does not support _Restrict or
+   __restrict__, even though the corresponding Sun C compiler ends up with
+   "#define restrict _Restrict" or "#define restrict __restrict__" in the
+   previous line.  Perhaps some future version of Sun C++ will work with
+   restrict; if so, hopefully it defines __RESTRICT like Sun C does.  */
+#if defined __SUNPRO_CC && !defined __RESTRICT
+# define _Restrict
+# define __restrict__
+#endif])
+ case $ac_cv_c_restrict in
+   restrict) ;;
+   no) AC_DEFINE([restrict], []) ;;
+   *)  AC_DEFINE_UNQUOTED([restrict], [$ac_cv_c_restrict]) ;;
+ esac
+
+AC_MSG_CHECKING(for C99 variable-size arrays)
+AC_TRY_COMPILE( [], [static int x; char a[++x]; a[sizeof a - 1] = 0; int N; return a[0];],
+[has_var_arrays=yes;AC_DEFINE([VAR_ARRAYS], [], [Use C99 variable-size arrays])
+],
+has_var_arrays=no
+)
+AC_MSG_RESULT($has_var_arrays)
+
+AC_CHECK_FUNC(exp,[fp_libm_not_needed=yes;LIBM=],[fp_libm_not_needed=dunno])
+if test x"$fp_libm_not_needed" = xdunno; then
+  AC_CHECK_LIB([m], [exp], [LIBS="-lm $LIBS"; LIBM="-lm"],[LIBM=])
+fi
+AC_SUBST([LIBM])
+
+AC_DEFINE_UNQUOTED(OPUSTOOLS_VERSION, "${OPUSTOOLS_VERSION}", [Complete version string])
+AC_DEFINE_UNQUOTED(OPUSTOOLS_MAJOR_VERSION, ${OPUSTOOLS_MAJOR_VERSION}, [Version major])
+AC_DEFINE_UNQUOTED(OPUSTOOLS_MINOR_VERSION, ${OPUSTOOLS_MINOR_VERSION}, [Version minor])
+AC_DEFINE_UNQUOTED(OPUSTOOLS_MICRO_VERSION, ${OPUSTOOLS_MICRO_VERSION}, [Version micro])
+AC_DEFINE_UNQUOTED(OPUSTOOLS_EXTRA_VERSION, "${OPUSTOOLS_EXTRA_VERSION}", [Version extra])
+
+ac_enable_assertions="no"
+AC_ARG_ENABLE(assertions, [  --enable-assertions     enable additional software error checking],
+[if test "$enableval" = yes; then
+  ac_enable_assertions="yes"
+  AC_DEFINE([ENABLE_ASSERTIONS], , [Assertions])
+fi])
+
+if test $ac_cv_c_compiler_gnu = yes ; then
+saved_CFLAGS="$CFLAGS"
+CFLAGS="$CFLAGS -fstack-protector-all"
+AC_MSG_CHECKING([if ${CC} supports -fstack-protector-all])
+AC_COMPILE_IFELSE([AC_LANG_SOURCE([char foo;])],
+      [ AC_MSG_RESULT([yes])
+        STACK_PROTECTOR="-fstack-protector-all" ],
+        AC_MSG_RESULT([no]))
+CFLAGS="$saved_CFLAGS $STACK_PROTECTOR"
+fi
+
+CFLAGS="$CFLAGS -W"
+
+saved_CFLAGS="$CFLAGS"
+CFLAGS="$CFLAGS -Wall -Wextra -Wcast-align -Wnested-externs -Wshadow -Wstrict-prototypes"
+AC_MSG_CHECKING([if ${CC} supports -Wall -Wextra -Wcast-align -Wnested-externs -Wshadow -Wstrict-prototypes])
+AC_COMPILE_IFELSE([AC_LANG_SOURCE([char foo;])],
+      [ AC_MSG_RESULT([yes])
+        EXTRA_WARNS="-Wall -Wextra -Wcast-align -Wnested-externs -Wshadow -Wstrict-prototypes" ],
+        AC_MSG_RESULT([no]))
+CFLAGS="$saved_CFLAGS $EXTRA_WARNS"
+
+AC_CHECK_FUNCS([lrintf])
+AC_CHECK_FUNCS([lrint])
+AC_CHECK_FUNCS([__malloc_hook])
+
+AC_CHECK_SIZEOF(short)
+AC_CHECK_SIZEOF(int)
+AC_CHECK_SIZEOF(long)
+AC_CHECK_SIZEOF(long long)
+
+if test x$has_char16 = "xyes" ; then
+        case 1 in
+                $ac_cv_sizeof_short) SIZE16="short";;
+                $ac_cv_sizeof_int) SIZE16="int";;
+        esac
+else
+        case 2 in
+                $ac_cv_sizeof_short) SIZE16="short";;
+                $ac_cv_sizeof_int) SIZE16="int";;
+        esac
+fi
+
+if test x$has_char16 = "xyes" ; then
+        case 2 in
+                $ac_cv_sizeof_int) SIZE32="int";;
+                $ac_cv_sizeof_long) SIZE32="long";;
+                $ac_cv_sizeof_short) SIZE32="short";;
+        esac
+else
+        case 4 in
+                $ac_cv_sizeof_int) SIZE32="int";;
+                $ac_cv_sizeof_long) SIZE32="long";;
+                $ac_cv_sizeof_short) SIZE32="short";;
+        esac
+fi
+
+AC_SUBST(SIZE16)
+AC_SUBST(SIZE32)
+
+dnl check for Ogg
+HAVE_OGG=no
+
+dnl first check through pkg-config since it's more flexible
+
+dnl check for pkg-config itself so we don't try the m4 macro without pkg-config
+AC_CHECK_PROG(HAVE_PKG_CONFIG, pkg-config, yes)
+if test "x$HAVE_PKG_CONFIG" = "xyes"
+then
+  PKG_CHECK_MODULES(OGG, ogg >= 1.3, HAVE_OGG=yes, HAVE_OGG=no)
+fi
+if test "x$HAVE_OGG" = "xno"
+then
+  dnl fall back to the old school test
+  XIPH_PATH_OGG(, AC_MSG_ERROR([
+    libogg is required to build this package!
+    please see http://www.xiph.org/ for how to
+    obtain a copy.
+  ]))
+  cflags_save=$CFLAGS
+  libs_save=$LIBS
+  CFLAGS="$CFLAGS $OGG_CFLAGS"
+  LIBS="$LIBS $OGG_LIBS"
+  AC_CHECK_FUNC(ogg_stream_flush_fill, , [
+    AC_MSG_ERROR([newer libogg version (1.3 or later) required])
+  ])
+  CFLAGS=$cflags_save
+  LIBS=$libs_save
+fi
+
+dnl check for Opus
+HAVE_OPUS=no
+
+dnl first check through pkg-config since it's more flexible
+
+dnl check for pkg-config itself so we don't try the m4 macro without pkg-config
+AC_CHECK_PROG(HAVE_PKG_CONFIG, pkg-config, yes)
+if test "x$HAVE_PKG_CONFIG" = "xyes"
+then
+  PKG_CHECK_MODULES(Opus, opus >= 0.9.10, HAVE_OPUS=yes, HAVE_OPUS=no)
+fi
+if test "x$HAVE_OPUS" = "xno"
+then
+  AC_MSG_ERROR([
+    Opus is required to build this package!
+    please see http://opus-codec.org/ for how to
+    obtain a copy.])
+fi
+
+AC_OUTPUT([Makefile])
+
+AC_MSG_RESULT([
+------------------------------------------------------------------------
+  $PACKAGE $VERSION:  Automatic configuration OK.
+
+    Compiler support:
+
+      C99 var arrays: ................ ${has_var_arrays}
+      C99 lrintf: .................... ${ac_cv_func_lrintf}
+
+    General configuration:
+
+      Assertion checking: ............ ${ac_enable_assertions}
+
+------------------------------------------------------------------------
+])
+
+echo "Type \"make; make install\" to compile and install";
+echo "Type \"make check\" to run the test suite";
--- a/src/audio-in.c
+++ b/src/audio-in.c
@@ -405,14 +405,12 @@
 
 int wav_id(unsigned char *buf, int len)
 {
-    unsigned int flen;
-
     if(len<12) return 0; /* Something screwed up */
 
     if(memcmp(buf, "RIFF", 4))
         return 0; /* Not wave */
 
-    flen = READ_U32_LE(buf+4); /* We don't use this */
+    /*flen = READ_U32_LE(buf+4);*/ /* We don't use this */
 
     if(memcmp(buf+8, "WAVE",4))
         return 0; /* RIFF, but not wave */
--- a/src/diag_range.c
+++ b/src/diag_range.c
@@ -32,7 +32,7 @@
 #endif
 
 #include <stdio.h>
-#include <opus.h>
+#include <opus/opus.h>
 #include "diag_range.h"
 
 /*This is some non-exported code copied wholesale from libopus.
@@ -209,13 +209,13 @@
 }
 
 void save_range(FILE *frange, int frame_size, unsigned char *packet, int nbBytes, opus_uint32 *rngs, int nb_streams){
-  int i, parse_size;
+  int i, parsed_size;
   const unsigned char *subpkt;
   static const char *bw_strings[5]={"NB","MB","WB","SWB","FB"};
   static const char *mode_strings[3]={"LP","HYB","MDCT"};
   fprintf(frange,"%d, %d, ",frame_size,nbBytes);
   subpkt=packet;
-  parse_size=nbBytes;
+  parsed_size=nbBytes;
   for(i=0;i<nb_streams;i++){
     int j,payload_offset,nf;
     const unsigned char *frames[48];
@@ -222,7 +222,7 @@
     unsigned char toc;
     short size[48];
     payload_offset=0;
-    nf=opus_packet_parse_impl(subpkt,parse_size,i+1!=nb_streams,
+    nf=opus_packet_parse_impl(subpkt,parsed_size,i+1!=nb_streams,
       &toc,frames,size,&payload_offset);
     fprintf(frange,"[[%d",(int)(frames[0]-subpkt));
     for(j=0;j<nf;j++)fprintf(frange,", %d",size[j]);
@@ -231,7 +231,7 @@
        bw_strings[opus_packet_get_bandwidth(subpkt)-OPUS_BANDWIDTH_NARROWBAND],
        subpkt[0]&4?'S':'M',opus_packet_get_samples_per_frame(subpkt,48000));
     fprintf(frange,", %llu]%s",(unsigned long long)rngs[i],i+1==nb_streams?"\n":", ");
-    parse_size-=payload_offset;
+    parsed_size-=payload_offset;
     subpkt+=payload_offset;
   }
 }
--- a/src/opus_header.h
+++ b/src/opus_header.h
@@ -1,7 +1,7 @@
 #ifndef OPUS_HEADER_H
 #define OPUS_HEADER_H
 
-#include <opus_types.h>
+#include <opus/opus_types.h>
 
 typedef struct {
    int version;
--- a/src/opusdec.c
+++ b/src/opusdec.c
@@ -45,8 +45,8 @@
 #include <limits.h>
 #include <string.h>
 
-#include <opus.h>
-#include <opus_multistream.h>
+#include <opus/opus.h>
+#include <opus/opus_multistream.h>
 #include <ogg/ogg.h>
 
 #if defined WIN32 || defined _WIN32
@@ -85,6 +85,10 @@
 #include "diag_range.h"
 #include "speex_resampler.h"
 
+#ifndef OPUSTOOLS_VERSION
+#define OPUSTOOLS_VERSION "unknown"
+#endif
+
 #define MINI(_a,_b)      ((_a)<(_b)?(_a):(_b))
 #define MAXI(_a,_b)      ((_a)>(_b)?(_a):(_b))
 #define CLAMPI(_a,_b,_c) (MAXI(_a,MINI(_b,_c)))
@@ -106,7 +110,7 @@
 };
 
 static unsigned int rngseed = 22222;
-static inline unsigned int fast_rand() {
+static inline unsigned int fast_rand(void) {
   rngseed = (rngseed * 96314165) + 907633515;
   return rngseed;
 }
@@ -344,7 +348,7 @@
             exit(1);
          }
          if (strcmp(outFile+strlen(outFile)-4,".wav")==0 || strcmp(outFile+strlen(outFile)-4,".WAV")==0)
-            write_wav_header(fout, rate, *channels, 0, 0);
+            write_wav_header(fout, rate, *channels);
       }
    }
    return fout;
@@ -381,14 +385,14 @@
 
 void version(void)
 {
-   printf ("opusdec (based on %s)\n",opus_get_version_string());
-   printf ("Copyright (C) 2008-2011 Jean-Marc Valin\n");
+   printf("opusdec opus-tools %s (based on %s)\n",OPUSTOOLS_VERSION,opus_get_version_string());
+   printf("Copyright (C) 2008-2012 Xiph.Org Foundation\n");
 }
 
 void version_short(void)
 {
-   printf ("opusdec (based on %s)\n",opus_get_version_string());
-   printf ("Copyright (C) 2008-2011 Jean-Marc Valin\n");
+   printf("opusdec opus-tools %s (based on %s)\n",OPUSTOOLS_VERSION,opus_get_version_string());
+   printf("Copyright (C) 2008-2012 Xiph.Org Foundation\n");
 }
 
 static OpusMSDecoder *process_header(ogg_packet *op, opus_int32 *rate, int *channels, int *preskip, float *gain, int *streams, int quiet)
@@ -465,7 +469,7 @@
      }
 
      if (skip){
-       tmp_skip = (*skip>out_len) ? out_len : *skip;
+       tmp_skip = (*skip>(int)out_len) ? (int)out_len : *skip;
        *skip -= tmp_skip;
      } else {
        tmp_skip = 0;
@@ -475,11 +479,11 @@
      if (shapemem){
        shape_dither_toshort(shapemem,out,output,out_len,channels);
      }else{
-       for (i=0;i<out_len*channels;i++)
+       for (i=0;i<(int)out_len*channels;i++)
          out[i]=(short)lrintf(fmax(-32768,fmin(output[i]*32768.f,32767)));
      }
      if ((le_short(1)!=1)&&file){
-       for (i=0;i<out_len*channels;i++)
+       for (i=0;i<(int)out_len*channels;i++)
          out[i]=le_short(out[i]);
      }
 
@@ -493,7 +497,6 @@
    int option_index = 0;
    char *inFile, *outFile;
    FILE *fin, *fout=NULL, *frange=NULL;
-   char             *range_file;
    float *output;
    int frame_size=0;
    OpusMSDecoder *st=NULL;
@@ -588,7 +591,6 @@
             fprintf(stderr,"Must provide a writable file name.\n");
             exit(1);
           }
-          range_file=optarg;
          } else if (strcmp(long_options[option_index].name,"packet-loss")==0)
          {
             loss_percent = atof(optarg);
--- a/src/opusenc.c
+++ b/src/opusenc.c
@@ -43,8 +43,8 @@
 #define snprintf _snprintf
 #endif
 
-#include <opus.h>
-#include <opus_multistream.h>
+#include <opus/opus.h>
+#include <opus/opus_multistream.h>
 #include <ogg/ogg.h>
 #include "wav_io.h"
 
@@ -58,8 +58,6 @@
 #include <fcntl.h>
 #endif
 
-#define OLD_LIBOGG 1
-
 #ifdef VALGRIND
 #include <valgrind/memcheck.h>
 #define VG_UNDEF(x,y) VALGRIND_MAKE_MEM_UNDEFINED((x),(y))
@@ -69,6 +67,10 @@
 #define VG_CHECK(x,y)
 #endif
 
+#ifndef OPUSTOOLS_VERSION
+#define OPUSTOOLS_VERSION "unknown"
+#endif
+
 static void comment_init(char **comments, int* length, char *vendor_string);
 static void comment_add(char **comments, int* length, char *tag, char *val);
 
@@ -85,15 +87,15 @@
 #define IMIN(a,b) ((a) < (b) ? (a) : (b))   /**< Minimum int value.   */
 #define IMAX(a,b) ((a) > (b) ? (a) : (b))   /**< Maximum int value.   */
 
-void version(const char *version)
+void opustoolsversion(const char *version)
 {
-  printf("opusenc (using %s)\n",version);
+  printf("opusenc opus-tools %s (using %s)\n",OPUSTOOLS_VERSION,version);
   printf("Copyright (C) 2008-2012 Xiph.Org Foundation\n");
 }
 
-void version_short(const char *version)
+void opustoolsversion_short(const char *version)
 {
-  printf("opusenc (using %s)\n",version);
+  printf("opusenc opus-tools %s (using %s)\n",OPUSTOOLS_VERSION,version);
   printf("Copyright (C) 2008-2012 Xiph.Org Foundation\n");
 }
 
@@ -274,7 +276,7 @@
   for(i=0;i<256;i++)mapping[i]=i;
 
   opus_version=opus_get_version_string();
-  snprintf(vendor_string, sizeof(vendor_string), "%s\n",opus_version);
+  snprintf(vendor_string, sizeof(vendor_string), "opus-tools %s (using %s)\n",OPUSTOOLS_VERSION,opus_version);
   comment_init(&comments, &comments_length, vendor_string);
 
 
@@ -305,10 +307,10 @@
           usage();
           exit(0);
         }else if(strcmp(long_options[option_index].name,"version")==0){
-          version(opus_version);
+          opustoolsversion(opus_version);
           exit(0);
         }else if(strcmp(long_options[option_index].name,"version-short")==0){
-          version_short(opus_version);
+          opustoolsversion_short(opus_version);
           exit(0);
         }else if(strcmp(long_options[option_index].name,"raw")==0){
           inopt.rawmode=1;
@@ -425,7 +427,7 @@
         exit(0);
         break;
       case 'v':
-        version(opus_version);
+        opustoolsversion(opus_version);
         exit(0);
         break;
       case '?':
--- a/src/wav_io.c
+++ b/src/wav_io.c
@@ -32,16 +32,13 @@
 
 #include <stdio.h>
 #include <string.h>
-#include "opus_types.h"
+#include <opus/opus_types.h>
 #include "wav_io.h"
 
-void write_wav_header(FILE *file, int rate, int channels, int format, int size)
+void write_wav_header(FILE *file, int rate, int channels)
 {
-   char ch[5];
    opus_int32 itmp;
    opus_int16 stmp;
-
-   ch[4]=0;
 
    fprintf (file, "RIFF");
 
--- a/src/wav_io.h
+++ b/src/wav_io.h
@@ -29,7 +29,7 @@
 #define WAV_IO_H
 
 #include <stdio.h>
-#include "opus_types.h"
+#include <opus/opus_types.h>
 
 #if !defined(__LITTLE_ENDIAN__) && ( defined(WORDS_BIGENDIAN) || defined(__BIG_ENDIAN__) )
 #define le_short(s) ((short) ((unsigned short) (s) << 8) | ((unsigned short) (s) >> 8))
@@ -55,6 +55,6 @@
 #endif
 }
 
-void write_wav_header(FILE *file, int rate, int channels, int format, int size);
+void write_wav_header(FILE *file, int rate, int channels);
 
 #endif