summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2017-10-21 19:21:26 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2019-04-12 19:22:46 +0200
commit03eaf1a9b3e0538a77a9fc07322d939e937a3bc9 (patch)
tree015d8daf0c10ad97d5415d3238083c854ef1169a
parent723343269d161b2bba7aee4597357ffc32f26f04 (diff)
Skeleton code for CoreAudio output module.
-rw-r--r--configure.ac17
-rw-r--r--drumgizmo/Makefile.am8
-rw-r--r--drumgizmo/enginefactory.cc9
-rw-r--r--drumgizmo/enginefactory.h4
-rw-r--r--drumgizmo/output/coreaudio.cc147
-rw-r--r--drumgizmo/output/coreaudio.h55
6 files changed, 239 insertions, 1 deletions
diff --git a/configure.ac b/configure.ac
index 556d3c0..c6a7976 100644
--- a/configure.ac
+++ b/configure.ac
@@ -451,6 +451,20 @@ AS_IF(
have_output_alsa=no]
)
+ dnl *** coreaudio
+ AC_ARG_ENABLE([output_coreaudio],
+ AS_HELP_STRING([--enable-output-coreaudio], [Enable output coreaudio plugin [default=disabled]]),,
+ [enable_output_coreaudio="no"])
+
+ AS_IF(
+ [test "x$enable_output_coreaudio" = "xyes"],
+ [have_output_coreaudio=yes
+ COREAUDIO_LIBS="-framework CoreAudio -framework CoreServices -framework AudioUnit"],
+
+ [AC_MSG_RESULT([*** output coreaudio plugin disabled per user request ***])
+ have_output_coreaudio=no]
+ )
+
dnl *** wavfile
AC_ARG_ENABLE([output_wavfile],
AS_HELP_STRING([--disable-output-wavfile], [Disable output wavfile plugin [default=enabled]]),,
@@ -501,7 +515,7 @@ AS_IF(
have_output_oss=no]
)
- OUTPUT_PLUGINS="dummy alsa wavfile jackaudio oss"
+ OUTPUT_PLUGINS="dummy alsa coreaudio wavfile jackaudio oss"
AC_SUBST(OUTPUT_PLUGINS)
dnl
@@ -526,6 +540,7 @@ AM_CONDITIONAL([HAVE_INPUT_OSSMIDI], [test "x$have_input_ossmidi" = "xyes"])
AM_CONDITIONAL([HAVE_INPUT_MIDIFILE], [test "x$have_input_midifile" = "xyes"])
AM_CONDITIONAL([HAVE_OUTPUT_DUMMY], [test "x$have_output_dummy" = "xyes"])
AM_CONDITIONAL([HAVE_OUTPUT_ALSA], [test "x$have_output_alsa" = "xyes"])
+AM_CONDITIONAL([HAVE_OUTPUT_COREAUDIO], [test "x$have_output_coreaudio" = "xyes"])
AM_CONDITIONAL([HAVE_OUTPUT_WAVFILE], [test "x$have_output_wavfile" = "xyes"])
AM_CONDITIONAL([HAVE_OUTPUT_JACKAUDIO], [test "x$have_output_jackaudio" = "xyes"])
AM_CONDITIONAL([HAVE_OUTPUT_OSS], [test "x$have_output_oss" = "xyes"])
diff --git a/drumgizmo/Makefile.am b/drumgizmo/Makefile.am
index 40bddc9..a85e7ca 100644
--- a/drumgizmo/Makefile.am
+++ b/drumgizmo/Makefile.am
@@ -60,6 +60,13 @@ drumgizmo_SOURCES += output/alsa.cc
drumgizmo_CXXFLAGS += -DHAVE_OUTPUT_ALSA
endif # HAVE_OUTPUT_ALSA
+if HAVE_OUTPUT_COREAUDIO
+drumgizmo_CXXFLAGS += $(COREAUDIO_CFLAGS)
+drumgizmo_LDFLAGS += $(COREAUDIO_LIBS)
+drumgizmo_SOURCES += output/coreaudio.cc
+drumgizmo_CXXFLAGS += -DHAVE_OUTPUT_COREAUDIO
+endif # HAVE_OUTPUT_COREAUDIO
+
if HAVE_OUTPUT_JACKAUDIO
drumgizmo_CXXFLAGS += $(JACK_CFLAGS)
drumgizmo_LDFLAGS += $(JACK_LIBS)
@@ -96,6 +103,7 @@ EXTRA_DIST = \
input/midifile.h \
input/ossmidi.h \
output/alsa.h \
+ output/coreaudio.h \
output/jackaudio.h \
output/outputdummy.h \
output/oss.h \
diff --git a/drumgizmo/enginefactory.cc b/drumgizmo/enginefactory.cc
index c93607e..21ed93d 100644
--- a/drumgizmo/enginefactory.cc
+++ b/drumgizmo/enginefactory.cc
@@ -63,6 +63,9 @@ EngineFactory::EngineFactory()
#ifdef HAVE_OUTPUT_ALSA
output.push_back("alsa");
#endif
+#ifdef HAVE_OUTPUT_COREAUDIO
+ output.push_back("coreaudio");
+#endif
#ifdef HAVE_OUTPUT_JACKAUDIO
output.push_back("jackaudio");
#endif
@@ -151,6 +154,12 @@ std::unique_ptr<AudioOutputEngine> EngineFactory::createOutput(const std::string
return std::make_unique<AlsaOutputEngine>();
}
#endif
+#ifdef HAVE_OUTPUT_COREAUDIO
+ if(name == "coreaudio")
+ {
+ return std::make_unique<CoreAudioOutputEngine>();
+ }
+#endif
#ifdef HAVE_OUTPUT_JACKAUDIO
if(name == "jackaudio")
{
diff --git a/drumgizmo/enginefactory.h b/drumgizmo/enginefactory.h
index 0b37c6e..23fb485 100644
--- a/drumgizmo/enginefactory.h
+++ b/drumgizmo/enginefactory.h
@@ -69,6 +69,10 @@
#include "output/alsa.h"
#endif
+#ifdef HAVE_OUTPUT_COREAUDIO
+#include "output/coreaudio.h"
+#endif
+
#ifdef HAVE_OUTPUT_JACKAUDIO
#include "output/jackaudio.h"
#endif
diff --git a/drumgizmo/output/coreaudio.cc b/drumgizmo/output/coreaudio.cc
new file mode 100644
index 0000000..7cae44a
--- /dev/null
+++ b/drumgizmo/output/coreaudio.cc
@@ -0,0 +1,147 @@
+/* -*- Mode: c++ -*- */
+/***************************************************************************
+ * coreaudio.cc
+ *
+ * Sat Oct 21 18:27:52 CEST 2017
+ * Copyright 2017 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of DrumGizmo.
+ *
+ * DrumGizmo is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DrumGizmo 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 Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with DrumGizmo; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#include "coreaudio.h"
+
+#include <hugin.hpp>
+
+static const char* errorString(OSStatus err)
+{
+ const char* err_string = "unknown";
+ switch (err) {
+ case kAudioHardwareNoError:
+ err_string = "kAudioHardwareNoError";
+ break;
+ case kAudioHardwareNotRunningError:
+ err_string = "kAudioHardwareNotRunningError";
+ break;
+ case kAudioHardwareUnspecifiedError:
+ err_string = "kAudioHardwareUnspecifiedError";
+ break;
+ case kAudioHardwareUnknownPropertyError:
+ err_string = "kAudioHardwareUnknownPropertyError";
+ break;
+ case kAudioHardwareBadPropertySizeError:
+ err_string = "kAudioHardwareBadPropertySizeError";
+ break;
+ case kAudioHardwareIllegalOperationError:
+ err_string = "kAudioHardwareIllegalOperationError";
+ break;
+ case kAudioHardwareBadDeviceError:
+ err_string = "kAudioHardwareBadDeviceError";
+ break;
+ case kAudioHardwareBadStreamError:
+ err_string = "kAudioHardwareBadStreamError";
+ break;
+ case kAudioDeviceUnsupportedFormatError:
+ err_string = "kAudioDeviceUnsupportedFormatError";
+ break;
+ case kAudioDevicePermissionsError:
+ err_string = "kAudioDevicePermissionsError";
+ break;
+ default:
+ break;
+ }
+
+ return err_string;
+}
+
+
+CoreAudioOutputEngine::CoreAudioOutputEngine()
+{
+ OSStatus err;
+ std::uint32_t size;
+
+ size = sizeof(AudioDeviceID);
+ err = AudioHardwareGetProperty(kAudioHardwarePropertyDefaultOutputDevice,
+ &size, &device_id);
+ if(err != noErr)
+ {
+ ERR(coreaudio, "Error kAudioHardwarePropertyDefaultOutputDevice: %s",
+ errorString(err));
+ }
+
+ char device_name[256];
+ memset(device_name, 0, sizeof(device_name));
+ size = sizeof(device_name) - 1; // leave space for terminating zero
+ err = AudioDeviceGetProperty(device_id, 0, false,
+ kAudioDevicePropertyDeviceName,
+ &size, device_name);
+ if(err != noErr)
+ {
+ ERR(coreaudio, "Error kAudioDevicePropertyDeviceName: %s",
+ errorString(err));
+ }
+
+ DEBUG(coreaudio, "default device id: %d (%s)", device_id, device_name);
+}
+
+CoreAudioOutputEngine::~CoreAudioOutputEngine()
+{
+}
+
+bool CoreAudioOutputEngine::init(const Channels& channels)
+{
+ return true;
+}
+
+void CoreAudioOutputEngine::setParm(const std::string& parm,
+ const std::string& value)
+{
+}
+
+bool CoreAudioOutputEngine::start()
+{
+ return true;
+}
+
+void CoreAudioOutputEngine::stop()
+{
+}
+
+void CoreAudioOutputEngine::pre(size_t nsamples)
+{
+}
+
+void CoreAudioOutputEngine::run(int ch, sample_t* samples, size_t nsamples)
+{
+ // Write channel data in interleaved buffer
+}
+
+void CoreAudioOutputEngine::post(size_t nsamples)
+{
+ // Write the interleaved buffer to the soundcard
+}
+
+size_t CoreAudioOutputEngine::getSamplerate() const
+{
+ return 0;
+}
+
+bool CoreAudioOutputEngine::isFreewheeling() const
+{
+ return false;
+}
diff --git a/drumgizmo/output/coreaudio.h b/drumgizmo/output/coreaudio.h
new file mode 100644
index 0000000..44df0a0
--- /dev/null
+++ b/drumgizmo/output/coreaudio.h
@@ -0,0 +1,55 @@
+/* -*- Mode: c++ -*- */
+/***************************************************************************
+ * coreaudio.h
+ *
+ * Sat Oct 21 18:27:52 CEST 2017
+ * Copyright 2017 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of DrumGizmo.
+ *
+ * DrumGizmo is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * DrumGizmo 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 Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with DrumGizmo; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#pragma once
+
+#include <audiotypes.h>
+#include <CoreAudio/CoreAudio.h>
+#include <AudioUnit/AudioUnit.h>
+
+#include "audiooutputengine.h"
+
+class CoreAudioOutputEngine
+ : public AudioOutputEngine
+{
+public:
+ CoreAudioOutputEngine();
+ ~CoreAudioOutputEngine();
+
+ // based on AudioOutputEngine
+ bool init(const Channels& chan) override;
+ void setParm(const std::string& parm, const std::string& value) override;
+ bool start() override;
+ void stop() override;
+ void pre(size_t nsamples) override;
+ void run(int ch, sample_t* samples, size_t nsamples) override;
+ void post(size_t nsamples) override;
+ size_t getSamplerate() const override;
+ bool isFreewheeling() const override;
+
+private:
+ AudioDeviceID device_id;
+};