Index: src/synth/sampler.c
===================================================================
--- src/synth/sampler.c	(revision 2f1ab3f2ab2c6dea6b6b5bcd6f8c327a0ab59468)
+++ src/synth/sampler.c	(revision b959a8fe8f15ddc3a88024a84f745a7bf7356cae)
@@ -28,4 +28,5 @@
 
 #define HAVE_THREADS 1
+#define READER_THREAD_ON 0
 #if 0
 #undef HAVE_THREADS
@@ -47,5 +48,7 @@
   uint_t eof;                   // end of file is now
 #ifdef HAVE_THREADS
-  pthread_t read_thread;        // file reading thread
+  // file reading thread
+  pthread_t read_thread;
+  uint_t threaded_read;         // use reading thread?
   pthread_mutex_t read_mutex;
   pthread_cond_t read_avail;
@@ -63,5 +66,10 @@
 
 #ifdef HAVE_THREADS
+static void *aubio_sampler_openfn(void *p);
 static void *aubio_sampler_readfn(void *p);
+static void aubio_sampler_open_opening_thread(aubio_sampler_t *o);
+static void aubio_sampler_open_reading_thread(aubio_sampler_t *o);
+static void aubio_sampler_close_opening_thread(aubio_sampler_t *o);
+static void aubio_sampler_close_reading_thread(aubio_sampler_t *o);
 #endif
 
@@ -82,11 +90,29 @@
   s->eof = 0;
   s->opened = 0;
-
-#ifdef HAVE_THREADS
+  s->available = 0;
+
+#ifdef HAVE_THREADS
+  s->threaded_read = READER_THREAD_ON;
+  aubio_sampler_open_opening_thread(s);
+  if (s->threaded_read) {
+    aubio_sampler_open_reading_thread(s);
+  }
+#endif
+
+  return s;
+beach:
+  AUBIO_FREE(s);
+  return NULL;
+}
+
+#ifdef HAVE_THREADS
+void aubio_sampler_open_opening_thread(aubio_sampler_t *s) {
   pthread_mutex_init(&s->open_mutex, 0);
   s->waited = 0;
   s->open_thread = 0;
   s->open_thread_running = 0;
-
+}
+
+void aubio_sampler_open_reading_thread(aubio_sampler_t *s) {
   s->read_thread_finish = 0;
   pthread_mutex_init(&s->read_mutex, 0);
@@ -94,10 +120,38 @@
   pthread_cond_init (&s->read_request, 0);
   pthread_create(&s->read_thread, 0, aubio_sampler_readfn, s);
-#endif
-  return s;
-beach:
-  AUBIO_FREE(s);
-  return NULL;
-}
+}
+
+void aubio_sampler_close_opening_thread(aubio_sampler_t *o) {
+  // clean up opening thread
+  void *threadret;
+  pthread_mutex_destroy(&o->open_mutex);
+  if (o->open_thread_running) {
+    if (pthread_cancel(o->open_thread)) {
+      AUBIO_WRN("sampler: cancelling file opening thread failed\n");
+    }
+  }
+  if (o->open_thread && pthread_join(o->open_thread, &threadret)) {
+    AUBIO_WRN("sampler: joining file opening thread failed\n");
+  }
+  pthread_mutex_destroy(&o->open_mutex);
+}
+
+void aubio_sampler_close_reading_thread(aubio_sampler_t *o) {
+  // clean up reading thread
+  void *threadret;
+  if (!o->read_thread) return;
+  o->read_thread_finish = 1;
+  pthread_cond_signal(&o->read_request);
+  if (pthread_cancel(o->read_thread)) {
+    AUBIO_WRN("sampler: cancelling file reading thread failed\n");
+  }
+  if (pthread_join(o->read_thread, &threadret)) {
+    AUBIO_WRN("sampler: joining file reading thread failed\n");
+  }
+  pthread_mutex_destroy(&o->read_mutex);
+  pthread_cond_destroy(&o->read_avail);
+  pthread_cond_destroy(&o->read_request);
+}
+#endif
 
 uint_t aubio_sampler_load( aubio_sampler_t * o, const char_t * uri )
@@ -391,30 +445,8 @@
 {
 #ifdef HAVE_THREADS
-  void *threadret;
-
-  // clean up opening thread
-  pthread_mutex_destroy(&o->open_mutex);
-  if (o->open_thread_running) {
-    if (pthread_cancel(o->open_thread)) {
-      AUBIO_WRN("sampler: cancelling file opening thread failed\n");
-    }
-  }
-  if (o->open_thread && pthread_join(o->open_thread, &threadret)) {
-    AUBIO_WRN("sampler: joining file opening thread failed\n");
-  }
-  pthread_mutex_destroy(&o->open_mutex);
-
+  // close opening thread
+  aubio_sampler_close_opening_thread(o);
   // close reading thread
-  o->read_thread_finish = 1;
-  pthread_cond_signal(&o->read_request);
-  if (pthread_cancel(o->read_thread)) {
-    AUBIO_WRN("sampler: cancelling file reading thread failed\n");
-  }
-  if (pthread_join(o->read_thread, &threadret)) {
-    AUBIO_WRN("sampler: joining file reading thread failed\n");
-  }
-  pthread_mutex_destroy(&o->read_mutex);
-  pthread_cond_destroy(&o->read_avail);
-  pthread_cond_destroy(&o->read_request);
+  aubio_sampler_close_reading_thread(o);
 #endif
   if (o->source) {
