shithub: aubio

Download patch

ref: 4bc92c01cc14de28e93e270a20d3a7c9a42d64a8
parent: d3066e2f44c4b18aa9cea8e491b7cba544250da5
author: Paul Brossier <piem@piem.org>
date: Wed Nov 13 08:26:33 EST 2013

src/io/sink_apple_audio.c: switch to sync mode if async fails

--- a/src/io/sink_apple_audio.c
+++ b/src/io/sink_apple_audio.c
@@ -48,6 +48,7 @@
 
   AudioBufferList bufferList;
   ExtAudioFileRef audioFile;
+  bool async;
 };
 
 aubio_sink_apple_audio_t * new_aubio_sink_apple_audio(char_t * uri, uint_t samplerate) {
@@ -56,6 +57,7 @@
   s->channels = 1;
   s->path = uri;
   s->max_frames = MAX_SIZE;
+  s->async = true;
 
   AudioStreamBasicDescription clientFormat;
   memset(&clientFormat, 0, sizeof(AudioStreamBasicDescription));
@@ -93,7 +95,6 @@
 void aubio_sink_apple_audio_do(aubio_sink_apple_audio_t * s, fvec_t * write_data, uint_t write) {
   OSStatus err = noErr;
   UInt32 c, v;
-  bool async = true;
   short *data = (short*)s->bufferList.mBuffers[0].mData;
   if (write > s->max_frames) {
     AUBIO_WRN("sink_apple_audio: trying to write %d frames, max %d\n", write, s->max_frames);
@@ -109,12 +110,24 @@
           }
       }
   }
-  if (async) {
+  if (s->async) {
     err = ExtAudioFileWriteAsync(s->audioFile, write, &s->bufferList);
-    if (err) { AUBIO_ERROR("error in ExtAudioFileWriteAsync, %d\n", (int)err); }
+
+    if (err) {
+      AUBIO_ERROR("in aubio_sink_apple_audio_do, writing %s\n", s->path);
+      AUBIO_ERROR("ExtAudioFileWriteAsync failed with %d, switching to sync\n", (int)err);
+      s->async = false;
+    } else {
+      return;
+    }
+
   } else {
     err = ExtAudioFileWrite(s->audioFile, write, &s->bufferList);
-    if (err) { AUBIO_ERROR("error in ExtAudioFileWrite, %d\n", (int)err); }
+
+    if (err) {
+      AUBIO_ERROR("in aubio_sink_apple_audio_do, writing %s\n", s->path);
+      AUBIO_ERROR("ExtAudioFileWrite failed with %d, aborting\n", (int)err);
+    }
   }
   return;
 }