diff --git a/CMakeLists.txt b/CMakeLists.txt index 7340df2..603b18c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -56,6 +56,18 @@ else() set(ALSA_LIBRARIES "") endif() +find_package(CoreAudio) +if(COREAUDIO_FOUND) + set(STATUS_COREAUDIO "OK") + set(SOUNDIO_HAVE_COREAUDIO true) + include_directories(${COREAUDIO_INCLUDE_DIR}) +else() + set(STATUS_COREAUDIO "not found") + set(SOUNDIO_HAVE_COREAUDIO false) + set(COREAUDIO_LIBRARY "") +endif() + + set(LIBSOUNDIO_SOURCES "${CMAKE_SOURCE_DIR}/src/soundio.cpp" "${CMAKE_SOURCE_DIR}/src/util.cpp" @@ -106,6 +118,14 @@ if(SOUNDIO_HAVE_ALSA) "${CMAKE_SOURCE_DIR}/src/alsa.cpp" ) endif() +if(SOUNDIO_HAVE_COREAUDIO) + set(LIBSOUNDIO_SOURCES ${LIBSOUNDIO_SOURCES} + "${CMAKE_SOURCE_DIR}/src/coreaudio.cpp" + ) + set(TEST_SOURCES ${TEST_SOURCES} + "${CMAKE_SOURCE_DIR}/src/coreaudio.cpp" + ) +endif() # GTFO, -lstdc++ !! @@ -153,6 +173,7 @@ target_link_libraries(libsoundio_shared LINK_PUBLIC ${JACK_LIBRARY} ${PULSEAUDIO_LIBRARY} ${ALSA_LIBRARIES} + ${COREAUDIO_LIBRARY} m ${CMAKE_THREAD_LIBS_INIT} ) @@ -205,7 +226,7 @@ target_link_libraries(unit_tests LINK_PUBLIC ${CMAKE_THREAD_LIBS_INIT} ${JACK_LIBRARY} ${PULSEAUDIO_LIBRARY} - ${ALSA_LIBRARIES} + ${COREAUDIO_LIBRARY} m ) set_target_properties(unit_tests PROPERTIES @@ -252,4 +273,5 @@ message( "* JACK (optional) : ${STATUS_JACK}\n" "* PulseAudio (optional) : ${STATUS_PULSEAUDIO}\n" "* ALSA (optional) : ${STATUS_ALSA}\n" + "* CoreAudio (optional) : ${STATUS_COREAUDIO}\n" ) diff --git a/README.md b/README.md index 62728e2..0196688 100644 --- a/README.md +++ b/README.md @@ -23,8 +23,8 @@ behavior on every platform. - [JACK](http://jackaudio.org/) - [PulseAudio](http://www.freedesktop.org/wiki/Software/PulseAudio/) - [ALSA](http://www.alsa-project.org/) - - Dummy (silence) - (planned) [CoreAudio](https://developer.apple.com/library/mac/documentation/MusicAudio/Conceptual/CoreAudioOverview/Introduction/Introduction.html) + - Dummy (silence) - (planned) [WASAPI](https://msdn.microsoft.com/en-us/library/windows/desktop/dd371455%28v=vs.85%29.aspx) - (planned) [ASIO](http://www.asio4all.com/) * C library. Depends only on the respective backend API libraries and libc. diff --git a/cmake/FindCoreAudio.cmake b/cmake/FindCoreAudio.cmake new file mode 100644 index 0000000..9bbd752 --- /dev/null +++ b/cmake/FindCoreAudio.cmake @@ -0,0 +1,16 @@ +# Copyright (c) 2015 Andrew Kelley +# This file is MIT licensed. +# See http://opensource.org/licenses/MIT + +# COREAUDIO_FOUND +# COREAUDIO_INCLUDE_DIR +# COREAUDIO_LIBRARY + +find_path(COREAUDIO_INCLUDE_DIR NAMES CoreAudio.h) + +find_library(COREAUDIO_LIBRARY NAMES CoreAudio) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(COREAUDIO DEFAULT_MSG COREAUDIO_LIBRARY COREAUDIO_INCLUDE_DIR) + +mark_as_advanced(COREAUDIO_INCLUDE_DIR COREAUDIO_LIBRARY) diff --git a/soundio/soundio.h b/soundio/soundio.h index 6a310bf..8ed1aef 100644 --- a/soundio/soundio.h +++ b/soundio/soundio.h @@ -108,6 +108,7 @@ enum SoundIoBackend { SoundIoBackendJack, SoundIoBackendPulseAudio, SoundIoBackendAlsa, + SoundIoBackendCoreAudio, SoundIoBackendDummy, }; diff --git a/src/config.h.in b/src/config.h.in index 5fc8912..38c7c2e 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -19,5 +19,6 @@ #cmakedefine SOUNDIO_HAVE_JACK #cmakedefine SOUNDIO_HAVE_PULSEAUDIO #cmakedefine SOUNDIO_HAVE_ALSA +#cmakedefine SOUNDIO_HAVE_COREAUDIO #endif diff --git a/src/coreaudio.cpp b/src/coreaudio.cpp new file mode 100644 index 0000000..36e5f46 --- /dev/null +++ b/src/coreaudio.cpp @@ -0,0 +1,102 @@ +#include "coreaudio.hpp" +#include "soundio.hpp" + +static void destroy_ca(struct SoundIoPrivate *) { + soundio_panic("TODO"); +} + +static void flush_events_ca(struct SoundIoPrivate *) { + soundio_panic("TODO"); +} + +static void wait_events_ca(struct SoundIoPrivate *) { + soundio_panic("TODO"); +} + +static void wakeup_ca(struct SoundIoPrivate *) { + soundio_panic("TODO"); +} + + +static int outstream_open_ca(struct SoundIoPrivate *, struct SoundIoOutStreamPrivate *) { + soundio_panic("TODO"); +} + +static void outstream_destroy_ca(struct SoundIoPrivate *, struct SoundIoOutStreamPrivate *) { + soundio_panic("TODO"); +} + +static int outstream_start_ca(struct SoundIoPrivate *, struct SoundIoOutStreamPrivate *) { + soundio_panic("TODO"); +} + +static int outstream_begin_write_ca(struct SoundIoPrivate *, struct SoundIoOutStreamPrivate *, + SoundIoChannelArea **out_areas, int *frame_count) +{ + soundio_panic("TODO"); +} + +static int outstream_end_write_ca(struct SoundIoPrivate *, struct SoundIoOutStreamPrivate *, int frame_count) { + soundio_panic("TODO"); +} + +static int outstream_clear_buffer_ca(struct SoundIoPrivate *, struct SoundIoOutStreamPrivate *) { + soundio_panic("TODO"); +} + +static int outstream_pause_ca(struct SoundIoPrivate *, struct SoundIoOutStreamPrivate *, bool pause) { + soundio_panic("TODO"); +} + + + +static int instream_open_ca(struct SoundIoPrivate *, struct SoundIoInStreamPrivate *) { + soundio_panic("TODO"); +} + +static void instream_destroy_ca(struct SoundIoPrivate *, struct SoundIoInStreamPrivate *) { + soundio_panic("TODO"); +} + +static int instream_start_ca(struct SoundIoPrivate *, struct SoundIoInStreamPrivate *) { + soundio_panic("TODO"); +} + +static int instream_begin_read_ca(struct SoundIoPrivate *, struct SoundIoInStreamPrivate *, + SoundIoChannelArea **out_areas, int *frame_count) +{ + soundio_panic("TODO"); +} + +static int instream_end_read_ca(struct SoundIoPrivate *, struct SoundIoInStreamPrivate *) { + soundio_panic("TODO"); +} + +static int instream_pause_ca(struct SoundIoPrivate *, struct SoundIoInStreamPrivate *, bool pause) { + soundio_panic("TODO"); +} + + +int soundio_coreaudio_init(SoundIoPrivate *si) { + si->destroy = destroy_ca; + si->flush_events = flush_events_ca; + si->wait_events = wait_events_ca; + si->wakeup = wakeup_ca; + + si->outstream_open = outstream_open_ca; + si->outstream_destroy = outstream_destroy_ca; + si->outstream_start = outstream_start_ca; + si->outstream_begin_write = outstream_begin_write_ca; + si->outstream_end_write = outstream_end_write_ca; + si->outstream_clear_buffer = outstream_clear_buffer_ca; + si->outstream_pause = outstream_pause_ca; + + si->instream_open = instream_open_ca; + si->instream_destroy = instream_destroy_ca; + si->instream_start = instream_start_ca; + si->instream_begin_read = instream_begin_read_ca; + si->instream_end_read = instream_end_read_ca; + si->instream_pause = instream_pause_ca; + + return 0; +} diff --git a/src/coreaudio.hpp b/src/coreaudio.hpp new file mode 100644 index 0000000..c06afcc --- /dev/null +++ b/src/coreaudio.hpp @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2015 Andrew Kelley + * + * This file is part of libsoundio, which is MIT licensed. + * See http://opensource.org/licenses/MIT + */ + +#ifndef SOUNDIO_COREAUDIO_HPP +#define SOUNDIO_COREAUDIO_HPP + +#include "soundio/soundio.h" + +int soundio_coreaudio_init(struct SoundIoPrivate *si); + +struct SoundIoDeviceCoreAudio { +}; + +struct SoundIoCoreAudio { +}; + +struct SoundIoOutStreamCoreAudioPort { +}; + +struct SoundIoOutStreamCoreAudio { +}; + +struct SoundIoInStreamCoreAudioPort { +}; + +struct SoundIoInStreamCoreAudio { +}; + +#endif diff --git a/src/soundio.cpp b/src/soundio.cpp index b3af5c5..d98ae2c 100644 --- a/src/soundio.cpp +++ b/src/soundio.cpp @@ -22,6 +22,9 @@ static const SoundIoBackend available_backends[] = { #endif #ifdef SOUNDIO_HAVE_ALSA SoundIoBackendAlsa, +#endif +#ifdef SOUNDIO_HAVE_COREAUDIO + SoundIoBackendCoreAudio, #endif SoundIoBackendDummy, }; @@ -42,6 +45,11 @@ static int (*backend_init_fns[])(SoundIoPrivate *) = { [SoundIoBackendAlsa] = soundio_alsa_init, #else [SoundIoBackendAlsa] = nullptr, +#endif +#ifdef SOUNDIO_HAVE_COREAUDIO + [SoundIoBackendCoreAudio] = soundio_coreaudio_init, +#else + [SoundIoBackendCoreAudio] = nullptr, #endif [SoundIoBackendDummy] = soundio_dummy_init, }; @@ -126,6 +134,7 @@ const char *soundio_backend_name(enum SoundIoBackend backend) { case SoundIoBackendJack: return "JACK"; case SoundIoBackendPulseAudio: return "PulseAudio"; case SoundIoBackendAlsa: return "ALSA"; + case SoundIoBackendCoreAudio: return "CoreAudio"; case SoundIoBackendDummy: return "Dummy"; } return "(invalid backend)"; diff --git a/src/soundio.hpp b/src/soundio.hpp index 03619dc..e229400 100644 --- a/src/soundio.hpp +++ b/src/soundio.hpp @@ -23,6 +23,10 @@ #include "alsa.hpp" #endif +#ifdef SOUNDIO_HAVE_COREAUDIO +#include "coreaudio.hpp" +#endif + #include "dummy.hpp" union SoundIoBackendData { @@ -34,6 +38,9 @@ union SoundIoBackendData { #endif #ifdef SOUNDIO_HAVE_ALSA SoundIoAlsa alsa; +#endif +#ifdef SOUNDIO_HAVE_COREAUDIO + SoundIoCoreAudio coreaudio; #endif SoundIoDummy dummy; }; @@ -47,6 +54,9 @@ union SoundIoDeviceBackendData { #endif #ifdef SOUNDIO_HAVE_ALSA SoundIoDeviceAlsa alsa; +#endif +#ifdef SOUNDIO_HAVE_COREAUDIO + SoundIoDeviceCoreAudio coreaudio; #endif SoundIoDeviceDummy dummy; }; @@ -60,6 +70,9 @@ union SoundIoOutStreamBackendData { #endif #ifdef SOUNDIO_HAVE_ALSA SoundIoOutStreamAlsa alsa; +#endif +#ifdef SOUNDIO_HAVE_COREAUDIO + SoundIoOutStreamCoreAudio coreaudio; #endif SoundIoOutStreamDummy dummy; }; @@ -73,6 +86,9 @@ union SoundIoInStreamBackendData { #endif #ifdef SOUNDIO_HAVE_ALSA SoundIoInStreamAlsa alsa; +#endif +#ifdef SOUNDIO_HAVE_COREAUDIO + SoundIoInStreamCoreAudio coreaudio; #endif SoundIoInStreamDummy dummy; }; @@ -101,7 +117,6 @@ struct SoundIoPrivate { // Safe to read from a single thread without a mutex. struct SoundIoDevicesInfo *safe_devices_info; - SoundIoBackendData backend_data; void (*destroy)(struct SoundIoPrivate *); void (*flush_events)(struct SoundIoPrivate *); void (*wait_events)(struct SoundIoPrivate *); @@ -124,6 +139,8 @@ struct SoundIoPrivate { SoundIoChannelArea **out_areas, int *frame_count); int (*instream_end_read)(struct SoundIoPrivate *, struct SoundIoInStreamPrivate *); int (*instream_pause)(struct SoundIoPrivate *, struct SoundIoInStreamPrivate *, bool pause); + + SoundIoBackendData backend_data; }; struct SoundIoDevicePrivate {