Index: src/io/source.c
===================================================================
--- src/io/source.c	(revision db8000e44f4ab4e150738d91f3d02f5bf7c1e4ec)
+++ src/io/source.c	(revision 87b0c03a3df667611bd79aac04c4df265e04e453)
@@ -72,2 +72,12 @@
 }
 
+uint_t aubio_source_get_samplerate(aubio_source_t * s) {
+#ifdef __APPLE__
+  return aubio_source_apple_audio_get_samplerate((aubio_source_apple_audio_t *)s->source);
+#else /* __APPLE__ */
+#if HAVE_SNDFILE
+  return aubio_source_sndfile_get_samplerate((aubio_source_sndfile_t *)s->source);
+#endif /* HAVE_SNDFILE */
+#endif /* __APPLE__ */
+}
+
Index: src/io/source.h
===================================================================
--- src/io/source.h	(revision db8000e44f4ab4e150738d91f3d02f5bf7c1e4ec)
+++ src/io/source.h	(revision 87b0c03a3df667611bd79aac04c4df265e04e453)
@@ -37,4 +37,6 @@
 void del_aubio_source(aubio_source_t * s);
 
+uint_t aubio_source_get_samplerate(aubio_source_t * s);
+
 #ifdef __cplusplus
 }
Index: src/io/source_apple_audio.c
===================================================================
--- src/io/source_apple_audio.c	(revision db8000e44f4ab4e150738d91f3d02f5bf7c1e4ec)
+++ src/io/source_apple_audio.c	(revision 87b0c03a3df667611bd79aac04c4df265e04e453)
@@ -55,5 +55,4 @@
 
   s->path = path;
-  s->samplerate = samplerate;
   s->block_size = block_size;
   s->channels = 1;
@@ -61,17 +60,4 @@
   OSStatus err = noErr;
   UInt32 propSize;
-
-  AudioStreamBasicDescription clientFormat;
-  propSize = sizeof(clientFormat);
-  memset(&clientFormat, 0, sizeof(AudioStreamBasicDescription));
-  clientFormat.mFormatID         = kAudioFormatLinearPCM;
-  clientFormat.mSampleRate       = (Float64)(s->samplerate);
-  clientFormat.mFormatFlags      = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked;
-  clientFormat.mChannelsPerFrame = s->channels;
-  clientFormat.mBitsPerChannel   = sizeof(short) * 8;
-  clientFormat.mFramesPerPacket  = 1;
-  clientFormat.mBytesPerFrame    = clientFormat.mBitsPerChannel * clientFormat.mChannelsPerFrame / 8;
-  clientFormat.mBytesPerPacket   = clientFormat.mFramesPerPacket * clientFormat.mBytesPerFrame;
-  clientFormat.mReserved         = 0;
 
   // open the resource url
@@ -89,4 +75,23 @@
       kExtAudioFileProperty_FileDataFormat, &propSize, &fileFormat);
   if (err) { AUBIO_ERROR("error in ExtAudioFileGetProperty, %d\n", (int)err); goto beach;}
+
+  if (samplerate == 0) {
+    samplerate = fileFormat.mSampleRate;
+    AUBIO_WRN("sampling rate set to 0, automagically adjusting to %d", samplerate);
+  }
+  s->samplerate = samplerate;
+
+  AudioStreamBasicDescription clientFormat;
+  propSize = sizeof(clientFormat);
+  memset(&clientFormat, 0, sizeof(AudioStreamBasicDescription));
+  clientFormat.mFormatID         = kAudioFormatLinearPCM;
+  clientFormat.mSampleRate       = (Float64)(s->samplerate);
+  clientFormat.mFormatFlags      = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked;
+  clientFormat.mChannelsPerFrame = s->channels;
+  clientFormat.mBitsPerChannel   = sizeof(short) * 8;
+  clientFormat.mFramesPerPacket  = 1;
+  clientFormat.mBytesPerFrame    = clientFormat.mBitsPerChannel * clientFormat.mChannelsPerFrame / 8;
+  clientFormat.mBytesPerPacket   = clientFormat.mFramesPerPacket * clientFormat.mBytesPerFrame;
+  clientFormat.mReserved         = 0;
 
   // set the client format description
@@ -176,3 +181,7 @@
 }
 
+uint_t aubio_source_apple_audio_get_samplerate(aubio_source_apple_audio_t * s) {
+  return s->samplerate;
+}
+
 #endif /* __APPLE__ */
Index: src/io/source_apple_audio.h
===================================================================
--- src/io/source_apple_audio.h	(revision db8000e44f4ab4e150738d91f3d02f5bf7c1e4ec)
+++ src/io/source_apple_audio.h	(revision 87b0c03a3df667611bd79aac04c4df265e04e453)
@@ -27,3 +27,5 @@
 void del_aubio_source_apple_audio(aubio_source_apple_audio_t * s);
 
+uint_t aubio_source_apple_audio_get_samplerate(aubio_source_apple_audio_t * s);
+
 #endif /* _AUBIO_SOURCE_APPLE_AUDIO_H */
