Index: Makefile
===================================================================
--- Makefile	(revision 59be50dfa19e13f55ac5be918b9b6505cf679c14)
+++ Makefile	(revision 24c207f23ec4eb69f5f92af98896e56def59af19)
@@ -11,5 +11,4 @@
 
 WAFCMD=python waf
-WAFURL=https://waf.io/waf-1.9.6
 
 #WAFOPTS:=
Index: circle.yml
===================================================================
--- circle.yml	(revision 24c207f23ec4eb69f5f92af98896e56def59af19)
+++ circle.yml	(revision 24c207f23ec4eb69f5f92af98896e56def59af19)
@@ -0,0 +1,9 @@
+dependencies:
+  pre:
+    - sudo apt-get update; sudo apt-get install make sox pkg-config libavcodec-dev libavformat-dev libavresample-dev libavutil-dev libsndfile1-dev libsamplerate-dev
+
+test:
+  pre:
+    - make create_test_sounds
+  override:
+    - nose2 -v
Index: python/lib/moresetuptools.py
===================================================================
--- python/lib/moresetuptools.py	(revision 59be50dfa19e13f55ac5be918b9b6505cf679c14)
+++ python/lib/moresetuptools.py	(revision 24c207f23ec4eb69f5f92af98896e56def59af19)
@@ -75,7 +75,6 @@
     # loof for additional packages
     print("Info: looking for *optional* additional packages")
-    packages = ['libavcodec', 'libavformat', 'libavutil', 'libavresample',
-                'jack',
-                'jack',
+    packages = ['libavcodec', 'libavformat', 'libavutil',
+                'libswresample', 'libavresample',
                 'sndfile',
                 #'fftw3f',
@@ -89,9 +88,11 @@
     if 'avcodec' in ext.libraries \
             and 'avformat' in ext.libraries \
-            and 'avutil' in ext.libraries \
-            and 'avresample' in ext.libraries:
-        ext.define_macros += [('HAVE_LIBAV', 1)]
-    if 'jack' in ext.libraries:
-        ext.define_macros += [('HAVE_JACK', 1)]
+            and 'avutil' in ext.libraries:
+        if 'swresample' in ext.libraries:
+            ext.define_macros += [('HAVE_SWRESAMPLE', 1)]
+        elif 'avresample' in ext.libraries:
+            ext.define_macros += [('HAVE_AVRESAMPLE', 1)]
+        if 'swresample' in ext.libraries or 'avresample' in ext.libraries:
+            ext.define_macros += [('HAVE_LIBAV', 1)]
     if 'sndfile' in ext.libraries:
         ext.define_macros += [('HAVE_SNDFILE', 1)]
Index: scripts/build_mingw
===================================================================
--- scripts/build_mingw	(revision 59be50dfa19e13f55ac5be918b9b6505cf679c14)
+++ scripts/build_mingw	(revision 24c207f23ec4eb69f5f92af98896e56def59af19)
@@ -1,7 +1,9 @@
 #! /bin/bash
 
-# This script cross compiles aubio for windows using mingw, both for 32 and 64
-# bits. Built binaries will be placed in ./dist-win32 and ./dist-win64.
-
+# This script cross compiles aubio for windows using mingw, four times:
+#
+#  - 32 and 64 bits with no external dependencies
+#  - 32 and 64 bits against ffmpeg
+#
 # On debian or ubuntu, you will want to 'apt-get install gcc-mingw-w64'
 
@@ -9,20 +11,105 @@
 set -x
 
-WAFOPTS="-v --disable-avcodec --disable-samplerate --disable-jack --disable-sndfile"
+source VERSION
+VERSION="$AUBIO_MAJOR_VERSION.$AUBIO_MINOR_VERSION.$AUBIO_PATCH_VERSION"
+VERSION+="$AUBIO_VERSION_STATUS"
 
-[ -d dist-win32 ] && rm -rf dist-win32
-[ -d dist-win64 ] && rm -rf dist-win64
+FFMPEG_BUILDS_URL="https://ffmpeg.zeranoe.com/builds"
+FFMPEG_DEFAULT="20170315-6c4665d"
 
-CFLAGS="-Os" \
-  LDFLAGS="" \
-  CC=x86_64-w64-mingw32-gcc \
-  ./waf distclean configure build install --destdir=$PWD/dist-win64 \
-    --testcmd="echo %s" \
-    $WAFOPTS --with-target-platform=win64
+# define some default CFLAGS
+DEF_CFLAGS="-Os -I/usr/share/mingw-w64"
+DEF_LDFLAGS=""
 
-CFLAGS="-Os" \
-  LDFLAGS="" \
-  CC=i686-w64-mingw32-gcc \
-  ./waf distclean configure build install --destdir=$PWD/dist-win32 \
-    --testcmd="echo %s" \
-    $WAFOPTS --with-target-platform=win32
+WAFOPTS=""
+# disable external deps to make sure we don't try to use the host package
+WAFOPTS+=" --disable-samplerate --disable-jack --disable-sndfile"
+# enable ffmpeg build
+WAFOPTS+=" --disable-avcodec"
+# install without a prefix
+WAFOPTS+=" --prefix=/"
+# compile the tests, but fake running them
+# passing this option WAFOPTS fails (escaping?), added in actual waf call below
+#WAFOPTS+=" --testcmd='echo %s'"
+
+# debugging
+#WAFOPTS+=" -v"
+#WAFOPTS+=" -j1"
+#WAFOPTS+=" --notests"
+
+function fetch_ffpmeg() {
+  ## manually add ffmpeg (no pkg-config .pc files in bins)
+  [ -n "$FFMPEG_VERSION" ] || FFMPEG_VERSION=$FFMPEG_DEFAULT
+  FFMPEG_TARBALL="$PWD/ffmpeg-$FFMPEG_VERSION-$TARGET-dev.zip"
+  FFMPEG_BINARIES="${FFMPEG_TARBALL%%.zip}"
+  if [ ! -d "$FFMPEG_BINARIES" ]
+  then
+    if [ ! -f "$FFMPEG_TARBALL" ]
+    then
+      curl -O $FFMPEG_BUILDS_URL/$TARGET/dev/ffmpeg-$FFMPEG_VERSION-$TARGET-dev.zip
+    else
+      echo "using $FFMPEG_TARBALL"
+    fi
+    unzip -x $FFMPEG_TARBALL
+  else
+    echo "using $FFMPEG_BINARIES"
+  fi
+}
+
+function get_cflags() {
+  CFLAGS="$DEF_CFLAGS"
+  LDFLAGS="$DEF_LDFLAGS"
+  if [ -n "$WITH_FFMEG" ]
+  then
+    fetch_ffpmeg
+    CFLAGS+=" -DHAVE_LIBAV=1 -DHAVE_SWRESAMPLE=1"
+    CFLAGS+=" -I$FFMPEG_BINARIES/include"
+    LDFLAGS+=" -lavcodec -lavformat -lavutil -lswresample"
+    LDFLAGS+=" -L$FFMPEG_BINARIES/lib"
+  fi
+}
+
+function build_mingw() {
+  DESTDIR="$PWD/aubio-$VERSION-$TARGET"
+  [ -n "$WITH_FFMEG" ] && DESTDIR+="-ffmpeg"
+  [ -f $DESTDIR.zip ] && echo "Remove existing $DESTDIR.zip first" && exit 1
+  [ -d $DESTDIR ] && rm -rf $DESTDIR
+  WAFOPTS_TGT="$WAFOPTS --destdir=$DESTDIR"
+  WAFOPTS_TGT+=" --with-target-platform=$TARGET"
+  get_cflags
+  CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" \
+    ./waf distclean configure build install $WAFOPTS_TGT --testcmd='echo %s'
+  zip -r $DESTDIR.zip `basename $DESTDIR`
+  rm -rf $DESTDIR
+  sha256sum $DESTDIR.zip > $DESTDIR.zip.sha256
+}
+
+function build_mingw32() {
+  TARGET=win32
+  export CC=i686-w64-mingw32-gcc
+  build_mingw
+}
+
+function build_mingw64() {
+  TARGET=win64
+  export CC=x86_64-w64-mingw32-gcc
+  build_mingw
+}
+
+# fetch waf if needed
+[ -f "waf" ] || make getwaf
+
+# first build without ffmpeg
+build_mingw32
+build_mingw64
+
+# then build against ffmpeg
+WITH_FFMEG=1
+build_mingw32
+build_mingw64
+
+set +x
+echo ""
+echo "All done! The following files were generated:"
+echo ""
+ls -lart aubio*.zip*
Index: scripts/get_waf.sh
===================================================================
--- scripts/get_waf.sh	(revision 59be50dfa19e13f55ac5be918b9b6505cf679c14)
+++ scripts/get_waf.sh	(revision 24c207f23ec4eb69f5f92af98896e56def59af19)
@@ -4,5 +4,5 @@
 set -x
 
-WAFURL=https://waf.io/waf-1.8.22
+WAFURL=https://waf.io/waf-1.9.6
 
 ( which wget > /dev/null && wget -qO waf $WAFURL ) || ( which curl > /dev/null && curl $WAFURL > waf )
Index: src/io/source_avcodec.c
===================================================================
--- src/io/source_avcodec.c	(revision 59be50dfa19e13f55ac5be918b9b6505cf679c14)
+++ src/io/source_avcodec.c	(revision 24c207f23ec4eb69f5f92af98896e56def59af19)
@@ -25,5 +25,9 @@
 #include <libavcodec/avcodec.h>
 #include <libavformat/avformat.h>
+#if defined(HAVE_SWRESAMPLE)
+#include <libswresample/swresample.h>
+#elif defined(HAVE_AVRESAMPLE)
 #include <libavresample/avresample.h>
+#endif
 #include <libavutil/opt.h>
 #include <stdlib.h>
@@ -69,5 +73,9 @@
   AVFrame *avFrame;
   AVPacket avPacket;
+#ifdef HAVE_AVRESAMPLE
   AVAudioResampleContext *avr;
+#elif defined(HAVE_SWRESAMPLE)
+  SwrContext *avr;
+#endif
   smpl_t *output;
   uint_t read_samples;
@@ -277,6 +285,11 @@
     uint_t output_channels = multi ? s->input_channels : 1;
     int64_t output_layout = av_get_default_channel_layout(output_channels);
+#ifdef HAVE_AVRESAMPLE
     AVAudioResampleContext *avr = avresample_alloc_context();
     AVAudioResampleContext *oldavr = s->avr;
+#elif defined(HAVE_SWRESAMPLE)
+    SwrContext *avr = swr_alloc();
+    SwrContext *oldavr = s->avr;
+#endif /* HAVE_AVRESAMPLE || HAVE_SWRESAMPLE */
 
     av_opt_set_int(avr, "in_channel_layout",  input_layout,           0);
@@ -293,5 +306,9 @@
     //av_opt_set_int(avr, "out_sample_fmt",     AV_SAMPLE_FMT_FLTP,      0);
     int err;
+#ifdef HAVE_AVRESAMPLE
     if ( ( err = avresample_open(avr) ) < 0) {
+#elif defined(HAVE_SWRESAMPLE)
+    if ( ( err = swr_init(avr) ) < 0) {
+#endif /* HAVE_AVRESAMPLE || HAVE_SWRESAMPLE */
       char errorstr[256];
       av_strerror (err, errorstr, sizeof(errorstr));
@@ -303,5 +320,9 @@
     s->avr = avr;
     if (oldavr != NULL) {
+#ifdef HAVE_AVRESAMPLE
       avresample_close( oldavr );
+#elif defined(HAVE_SWRESAMPLE)
+      swr_close ( oldavr );
+#endif /* HAVE_AVRESAMPLE || HAVE_SWRESAMPLE */
       av_free ( oldavr );
       oldavr = NULL;
@@ -317,5 +338,9 @@
   AVPacket avPacket = s->avPacket;
   av_init_packet (&avPacket);
+#ifdef HAVE_AVRESAMPLE
   AVAudioResampleContext *avr = s->avr;
+#elif defined(HAVE_SWRESAMPLE)
+  SwrContext *avr = s->avr;
+#endif /* HAVE_AVRESAMPLE || HAVE_SWRESAMPLE */
   smpl_t *output = s->output;
   *read_samples = 0;
@@ -332,4 +357,5 @@
       av_strerror (err, errorstr, sizeof(errorstr));
       AUBIO_ERR("source_avcodec: could not read frame in %s (%s)\n", s->path, errorstr);
+      s->eof = 1;
       goto beach;
     }
@@ -370,4 +396,5 @@
   }
 
+#ifdef HAVE_AVRESAMPLE
   int in_linesize = 0;
   av_samples_get_buffer_size(&in_linesize, avCodecCtx->channels,
@@ -379,4 +406,11 @@
         (uint8_t **)&output, out_linesize, max_out_samples,
         (uint8_t **)avFrame->data, in_linesize, in_samples);
+#elif defined(HAVE_SWRESAMPLE)
+  int in_samples = avFrame->nb_samples;
+  int max_out_samples = AUBIO_AVCODEC_MAX_BUFFER_SIZE / avCodecCtx->channels;
+  int out_samples = swr_convert( avr,
+      (uint8_t **)&output, max_out_samples,
+      (const uint8_t **)avFrame->data, in_samples);
+#endif /* HAVE_AVRESAMPLE || HAVE_SWRESAMPLE */
   if (out_samples <= 0) {
     AUBIO_WRN("source_avcodec: no sample found while converting frame (%s)\n", s->path);
@@ -390,5 +424,7 @@
   s->avCodecCtx = avCodecCtx;
   s->avFrame = avFrame;
+#if defined(HAVE_AVRESAMPLE) || defined(HAVE_SWRESAMPLE)
   s->avr = avr;
+#endif /* HAVE_AVRESAMPLE || HAVE_SWRESAMPLE */
   s->output = output;
 
@@ -499,7 +535,12 @@
   s->read_index = 0;
   s->read_samples = 0;
+#ifdef HAVE_AVRESAMPLE
   // reset the AVAudioResampleContext
   avresample_close(s->avr);
   avresample_open(s->avr);
+#elif defined(HAVE_SWRESAMPLE)
+  swr_close(s->avr);
+  swr_init(s->avr);
+#endif
   return ret;
 }
@@ -515,10 +556,18 @@
 uint_t aubio_source_avcodec_close(aubio_source_avcodec_t * s) {
   if (s->avr != NULL) {
+#ifdef HAVE_AVRESAMPLE
     avresample_close( s->avr );
+#elif defined(HAVE_SWRESAMPLE)
+    swr_close ( s->avr );
+#endif
     av_free ( s->avr );
   }
   s->avr = NULL;
   if (s->avCodecCtx != NULL) {
+#ifndef HAVE_AUBIO_LIBAVCODEC_DEPRECATED
+    avcodec_free_context( &s->avCodecCtx );
+#else
     avcodec_close ( s->avCodecCtx );
+#endif
   }
   s->avCodecCtx = NULL;
Index: src/utils/windll.c
===================================================================
--- src/utils/windll.c	(revision 59be50dfa19e13f55ac5be918b9b6505cf679c14)
+++ src/utils/windll.c	(revision 24c207f23ec4eb69f5f92af98896e56def59af19)
@@ -42,7 +42,7 @@
 #include "aubio.h"
 
-BOOL APIENTRY DllMain( HMODULE hModule,
+BOOL APIENTRY DllMain( HMODULE hModule UNUSED,
                        DWORD  ul_reason_for_call,
-                       LPVOID lpReserved )
+                       LPVOID lpReserved UNUSED)
 {
   switch (ul_reason_for_call)
Index: src/wscript_build
===================================================================
--- src/wscript_build	(revision 59be50dfa19e13f55ac5be918b9b6505cf679c14)
+++ src/wscript_build	(revision 24c207f23ec4eb69f5f92af98896e56def59af19)
@@ -8,4 +8,5 @@
 uselib += ['AVCODEC']
 uselib += ['AVFORMAT']
+uselib += ['SWRESAMPLE']
 uselib += ['AVRESAMPLE']
 uselib += ['AVUTIL']
Index: wscript
===================================================================
--- wscript	(revision 59be50dfa19e13f55ac5be918b9b6505cf679c14)
+++ wscript	(revision 24c207f23ec4eb69f5f92af98896e56def59af19)
@@ -323,13 +323,29 @@
                 args = '--cflags --libs', uselib_store = 'AVUTIL',
                 mandatory = ctx.options.enable_avcodec)
-        ctx.check_cfg(package = 'libavresample', atleast_version = '1.0.1',
-                args = '--cflags --libs', uselib_store = 'AVRESAMPLE',
-                mandatory = ctx.options.enable_avcodec)
-        if all ( 'HAVE_' + i in ctx.env
-                for i in ['AVCODEC', 'AVFORMAT', 'AVUTIL', 'AVRESAMPLE'] ):
+        ctx.check_cfg(package = 'libswresample', atleast_version = '2.3.0',
+                args = '--cflags --libs', uselib_store = 'SWRESAMPLE',
+                mandatory = False)
+        if 'HAVE_SWRESAMPLE' not in ctx.env:
+            ctx.check_cfg(package = 'libavresample', atleast_version = '1.0.1',
+                    args = '--cflags --libs', uselib_store = 'AVRESAMPLE',
+                    mandatory = False)
+
+        msg_check = 'Checking for all libav libraries'
+        if 'HAVE_AVCODEC' not in ctx.env:
+            ctx.msg(msg_check, 'not found (missing avcodec)', color = 'YELLOW')
+        elif 'HAVE_AVFORMAT' not in ctx.env:
+            ctx.msg(msg_check, 'not found (missing avformat)', color = 'YELLOW')
+        elif 'HAVE_AVUTIL' not in ctx.env:
+            ctx.msg(msg_check, 'not found (missing avutil)', color = 'YELLOW')
+        elif 'HAVE_SWRESAMPLE' not in ctx.env and 'HAVE_AVRESAMPLE' not in ctx.env:
+            resample_missing = 'not found (avresample or swresample required)'
+            ctx.msg(msg_check, resample_missing, color = 'YELLOW')
+        else:
+            ctx.msg(msg_check, 'yes')
+            if 'HAVE_SWRESAMPLE' in ctx.env:
+                ctx.define('HAVE_SWRESAMPLE', 1)
+            elif 'HAVE_AVRESAMPLE' in ctx.env:
+                ctx.define('HAVE_AVRESAMPLE', 1)
             ctx.define('HAVE_LIBAV', 1)
-            ctx.msg('Checking for all libav libraries', 'yes')
-        else:
-            ctx.msg('Checking for all libav libraries', 'not found', color = 'YELLOW')
 
     if (ctx.options.enable_wavread != False):
