Index: src/io/source.c
===================================================================
--- src/io/source.c	(revision 3504dfe767149b9ce2f36b39c83f89d37e20931d)
+++ src/io/source.c	(revision afbd7e7adf53deda218ac4111682191dd83d34f6)
@@ -26,4 +26,7 @@
 #include "io/source_apple_audio_file.h"
 #endif /* __APPLE__ */
+#ifdef HAVE_SNDFILE
+#include "io/source_sndfile.h"
+#endif
 
 struct _aubio_source_t { 
@@ -31,11 +34,16 @@
 };
 
-aubio_source_t * new_aubio_source(char_t * uri, uint_t hop_size, uint_t samplerate) {
+aubio_source_t * new_aubio_source(char_t * uri, uint_t samplerate, uint_t hop_size) {
   aubio_source_t * s = AUBIO_NEW(aubio_source_t);
 #ifdef __APPLE__
-  s->source= (void *)new_aubio_source_apple_audio(uri, hop_size, samplerate);
+  s->source= (void *)new_aubio_source_apple_audio(uri, samplerate, hop_size);
+  if (s->source) return s;
+#else /* __APPLE__ */
+#if HAVE_SNDFILE
+  s->source= (void *)new_aubio_source_sndfile(uri, samplerate, hop_size);
+  if (s->source) return s;
+#endif /* HAVE_SNDFILE */
 #endif /* __APPLE__ */
   if (s->source == NULL) return NULL;
-  return s;
 }
 
@@ -43,4 +51,8 @@
 #ifdef __APPLE__
   aubio_source_apple_audio_do((aubio_source_apple_audio_t *)s->source, data, read);
+#else /* __APPLE__ */
+#if HAVE_SNDFILE
+  aubio_source_sndfile_do((aubio_source_sndfile_t *)s->source, data, read);
+#endif /* HAVE_SNDFILE */
 #endif /* __APPLE__ */
 }
@@ -49,4 +61,8 @@
 #ifdef __APPLE__
   del_aubio_source_apple_audio((aubio_source_apple_audio_t *)s->source);
+#else /* __APPLE__ */
+#if HAVE_SNDFILE
+  del_aubio_source_sndfile((aubio_source_sndfile_t *)s->source);
+#endif /* HAVE_SNDFILE */
 #endif /* __APPLE__ */
   AUBIO_FREE(s);
Index: src/io/source_sndfile.c
===================================================================
--- src/io/source_sndfile.c	(revision afbd7e7adf53deda218ac4111682191dd83d34f6)
+++ src/io/source_sndfile.c	(revision afbd7e7adf53deda218ac4111682191dd83d34f6)
@@ -0,0 +1,130 @@
+/*
+  Copyright (C) 2012 Paul Brossier <piem@aubio.org>
+
+  This file is part of aubio.
+
+  aubio is free software: you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation, either version 3 of the License, or
+  (at your option) any later version.
+
+  aubio 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 General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with aubio.  If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+
+#include "config.h"
+
+#ifdef HAVE_SNDFILE
+
+#include <sndfile.h>
+
+#include "aubio_priv.h"
+#include "source_sndfile.h"
+#include "fvec.h"
+#include "mathutils.h"
+
+#define MAX_CHANNELS 6
+#define MAX_SIZE 4096
+
+struct _aubio_source_sndfile_t {
+  uint_t hop_size;
+  uint_t samplerate;
+  uint_t channels;
+  int input_samplerate;
+  int input_channels;
+  int input_format;
+  char_t *path;
+  SNDFILE *handle;
+  uint_t scratch_size;
+  smpl_t *scratch_data;
+};
+
+aubio_source_sndfile_t * new_aubio_source_sndfile(char_t * path, uint_t samplerate, uint_t hop_size) {
+  aubio_source_sndfile_t * s = AUBIO_NEW(aubio_source_sndfile_t);
+
+  if (path == NULL) {
+    AUBIO_ERR("Aborted opening null path\n");
+    return NULL;
+  }
+
+  s->hop_size = hop_size;
+  s->samplerate = samplerate;
+  s->channels = 1;
+  s->path = path;
+
+  // try opening the file, geting the info in sfinfo
+  SF_INFO sfinfo;
+  AUBIO_MEMSET(&sfinfo, 0, sizeof (sfinfo));
+  s->handle = sf_open (s->path, SFM_READ, &sfinfo);
+
+  if (s->handle == NULL) {
+    /* show libsndfile err msg */
+    AUBIO_ERR("Failed opening %s: %s\n", s->path, sf_strerror (NULL));
+    return NULL;
+  }	
+
+  if (sfinfo.channels > MAX_CHANNELS) { 
+    AUBIO_ERR("Not able to process more than %d channels\n", MAX_CHANNELS);
+    return NULL;
+  }
+
+  /* get input specs */
+  s->input_samplerate = sfinfo.samplerate;
+  s->input_channels   = sfinfo.channels;
+  s->input_format     = sfinfo.format;
+
+  if (s->samplerate != s->input_samplerate) {
+    AUBIO_ERR("resampling not implemented yet\n");
+    return NULL;
+  }
+  
+  s->scratch_size = s->hop_size*s->input_channels;
+  s->scratch_data = AUBIO_ARRAY(float,s->scratch_size);
+
+  /* allocate data for de/interleaving reallocated when needed. */
+  if (s->scratch_size >= MAX_SIZE * MAX_CHANNELS) {
+    AUBIO_ERR("%d exceeds maximum aubio_source_sndfile buffer size %d\n", s->scratch_size, MAX_CHANNELS * MAX_CHANNELS);
+    return NULL;
+  }
+
+  return s;
+}
+
+void aubio_source_sndfile_do(aubio_source_sndfile_t * s, fvec_t * read_data, uint_t * read){
+  sf_count_t read_frames;
+  int i,j, input_channels = s->input_channels;
+  int aread;
+  smpl_t *pread;	
+
+  /* do actual reading */
+  read_frames = sf_read_float (s->handle, s->scratch_data, s->scratch_size);
+
+  aread = (int)FLOOR(read_frames/(float)input_channels);
+
+  /* de-interleaving and down-mixing data  */
+  for (j = 0; j < aread; j++) {
+    read_data->data[j] = 0;
+    for (i = 0; i < input_channels; i++) {
+      read_data->data[j] += (smpl_t)s->scratch_data[input_channels*j+i];
+    }
+    read_data->data[j] /= (smpl_t)input_channels;
+  }
+  *read = aread;
+}
+
+void del_aubio_source_sndfile(aubio_source_sndfile_t * s){
+  if (sf_close(s->handle)) {
+    AUBIO_ERR("Error closing file %s: %s", s->path, sf_strerror (NULL));
+  }
+  AUBIO_FREE(s->scratch_data);
+  AUBIO_FREE(s);
+}
+
+#endif /* HAVE_SNDFILE */
Index: src/io/source_sndfile.h
===================================================================
--- src/io/source_sndfile.h	(revision afbd7e7adf53deda218ac4111682191dd83d34f6)
+++ src/io/source_sndfile.h	(revision afbd7e7adf53deda218ac4111682191dd83d34f6)
@@ -0,0 +1,29 @@
+/*
+  Copyright (C) 2012 Paul Brossier <piem@aubio.org>
+
+  This file is part of aubio.
+
+  aubio is free software: you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation, either version 3 of the License, or
+  (at your option) any later version.
+
+  aubio 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 General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with aubio.  If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+#ifndef _AUBIO_SOURCE_SNDFILE_H
+#define _AUBIO_SOURCE_SNDFILE_H
+
+typedef struct _aubio_source_sndfile_t aubio_source_sndfile_t;
+aubio_source_sndfile_t * new_aubio_source_sndfile(char_t * path, uint_t samplerate, uint_t block_size);
+void aubio_source_sndfile_do(aubio_source_sndfile_t * s, fvec_t * read_to, uint_t * read);
+void del_aubio_source_sndfile(aubio_source_sndfile_t * s);
+
+#endif /* _AUBIO_SOURCE_SNDFILE_H */
