chiark / gitweb /
Merge Core Audio fixes
[disorder] / clients / playrtp-coreaudio.c
index a22c8af8c24c0ccaabd53bd242fc3e8ff1473290..dae70272e6874e619f00746909d6816f28d3c11b 100644 (file)
@@ -2,39 +2,34 @@
  * This file is part of DisOrder.
  * Copyright (C) 2007 Richard Kettlewell
  *
- * This program is free software; you can redistribute it and/or modify
+ * This program 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 2 of the License, or
+ * the Free Software Foundation, either version 3 of the License, or
  * (at your option) any later version.
  *
- * This program 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.
- *
+ * This program 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 this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- * USA
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 /** @file clients/playrtp-coreaudio.c
  * @brief RTP player - Core Audio support
  */
 
-#include <config.h>
+#include "common.h"
 
 #if HAVE_COREAUDIO_AUDIOHARDWARE_H
-#include "types.h"
-
-#include <assert.h>
 #include <pthread.h>
-#include <CoreAudio/AudioHardware.h>
 
 #include "mem.h"
 #include "log.h"
 #include "vector.h"
 #include "heap.h"
 #include "playrtp.h"
+#include "coreaudio.h"
 
 /** @brief Callback from Core Audio */
 static OSStatus adioproc
@@ -67,6 +62,14 @@ static OSStatus adioproc
           samples_available = samplesOutLeft;
         next_timestamp += samples_available;
         samplesOutLeft -= samples_available;
+        if(dump_buffer) {
+          size_t n;
+
+          for(n = 0; n < samples_available; ++n) {
+            dump_buffer[dump_index++] = (int16_t)ntohs(ptr[n]);
+            dump_index %= dump_size;
+          }
+        }
         while(samples_available-- > 0)
           *samplesOut++ = (int16_t)ntohs(*ptr++) * (0.5 / 32767);
         /* We don't bother junking the packet - that'll be dealt with next time
@@ -82,6 +85,14 @@ static OSStatus adioproc
         next_timestamp += samples_available;
         samplesOut += samples_available;
         samplesOutLeft -= samples_available;
+        if(dump_buffer) {
+          size_t n;
+
+          for(n = 0; n < samples_available; ++n) {
+            dump_buffer[dump_index++] = 0;
+            dump_index %= dump_size;
+          }
+        }
       }
     }
     ++ab;
@@ -101,13 +112,8 @@ void playrtp_coreaudio(void) {
    * excellent reason for that... */
 
   /* TODO report errors as strings not numbers */
-  propertySize = sizeof adid;
-  status = AudioHardwareGetProperty(kAudioHardwarePropertyDefaultOutputDevice,
-                                   &propertySize, &adid);
-  if(status)
-    fatal(0, "AudioHardwareGetProperty: %d", (int)status);
-  if(adid == kAudioDeviceUnknown)
-    fatal(0, "no output device");
+  /* Identify the device to use */
+  adid = coreaudio_getdevice(device);
   propertySize = sizeof asbd;
   status = AudioDeviceGetProperty(adid, 0, false,
                                  kAudioDevicePropertyStreamFormat,