CoreAudio skeleton

This commit is contained in:
Andrew Kelley 2015-07-31 18:52:51 -07:00
parent 1829fbf073
commit 4c5742eb29
9 changed files with 204 additions and 3 deletions

View file

@ -56,6 +56,18 @@ else()
set(ALSA_LIBRARIES "") set(ALSA_LIBRARIES "")
endif() 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 set(LIBSOUNDIO_SOURCES
"${CMAKE_SOURCE_DIR}/src/soundio.cpp" "${CMAKE_SOURCE_DIR}/src/soundio.cpp"
"${CMAKE_SOURCE_DIR}/src/util.cpp" "${CMAKE_SOURCE_DIR}/src/util.cpp"
@ -106,6 +118,14 @@ if(SOUNDIO_HAVE_ALSA)
"${CMAKE_SOURCE_DIR}/src/alsa.cpp" "${CMAKE_SOURCE_DIR}/src/alsa.cpp"
) )
endif() 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++ !! # GTFO, -lstdc++ !!
@ -153,6 +173,7 @@ target_link_libraries(libsoundio_shared LINK_PUBLIC
${JACK_LIBRARY} ${JACK_LIBRARY}
${PULSEAUDIO_LIBRARY} ${PULSEAUDIO_LIBRARY}
${ALSA_LIBRARIES} ${ALSA_LIBRARIES}
${COREAUDIO_LIBRARY}
m m
${CMAKE_THREAD_LIBS_INIT} ${CMAKE_THREAD_LIBS_INIT}
) )
@ -205,7 +226,7 @@ target_link_libraries(unit_tests LINK_PUBLIC
${CMAKE_THREAD_LIBS_INIT} ${CMAKE_THREAD_LIBS_INIT}
${JACK_LIBRARY} ${JACK_LIBRARY}
${PULSEAUDIO_LIBRARY} ${PULSEAUDIO_LIBRARY}
${ALSA_LIBRARIES} ${COREAUDIO_LIBRARY}
m m
) )
set_target_properties(unit_tests PROPERTIES set_target_properties(unit_tests PROPERTIES
@ -252,4 +273,5 @@ message(
"* JACK (optional) : ${STATUS_JACK}\n" "* JACK (optional) : ${STATUS_JACK}\n"
"* PulseAudio (optional) : ${STATUS_PULSEAUDIO}\n" "* PulseAudio (optional) : ${STATUS_PULSEAUDIO}\n"
"* ALSA (optional) : ${STATUS_ALSA}\n" "* ALSA (optional) : ${STATUS_ALSA}\n"
"* CoreAudio (optional) : ${STATUS_COREAUDIO}\n"
) )

View file

@ -23,8 +23,8 @@ behavior on every platform.
- [JACK](http://jackaudio.org/) - [JACK](http://jackaudio.org/)
- [PulseAudio](http://www.freedesktop.org/wiki/Software/PulseAudio/) - [PulseAudio](http://www.freedesktop.org/wiki/Software/PulseAudio/)
- [ALSA](http://www.alsa-project.org/) - [ALSA](http://www.alsa-project.org/)
- Dummy (silence)
- (planned) [CoreAudio](https://developer.apple.com/library/mac/documentation/MusicAudio/Conceptual/CoreAudioOverview/Introduction/Introduction.html) - (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) [WASAPI](https://msdn.microsoft.com/en-us/library/windows/desktop/dd371455%28v=vs.85%29.aspx)
- (planned) [ASIO](http://www.asio4all.com/) - (planned) [ASIO](http://www.asio4all.com/)
* C library. Depends only on the respective backend API libraries and libc. * C library. Depends only on the respective backend API libraries and libc.

16
cmake/FindCoreAudio.cmake Normal file
View file

@ -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)

View file

@ -108,6 +108,7 @@ enum SoundIoBackend {
SoundIoBackendJack, SoundIoBackendJack,
SoundIoBackendPulseAudio, SoundIoBackendPulseAudio,
SoundIoBackendAlsa, SoundIoBackendAlsa,
SoundIoBackendCoreAudio,
SoundIoBackendDummy, SoundIoBackendDummy,
}; };

View file

@ -19,5 +19,6 @@
#cmakedefine SOUNDIO_HAVE_JACK #cmakedefine SOUNDIO_HAVE_JACK
#cmakedefine SOUNDIO_HAVE_PULSEAUDIO #cmakedefine SOUNDIO_HAVE_PULSEAUDIO
#cmakedefine SOUNDIO_HAVE_ALSA #cmakedefine SOUNDIO_HAVE_ALSA
#cmakedefine SOUNDIO_HAVE_COREAUDIO
#endif #endif

102
src/coreaudio.cpp Normal file
View file

@ -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;
}

33
src/coreaudio.hpp Normal file
View file

@ -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

View file

@ -22,6 +22,9 @@ static const SoundIoBackend available_backends[] = {
#endif #endif
#ifdef SOUNDIO_HAVE_ALSA #ifdef SOUNDIO_HAVE_ALSA
SoundIoBackendAlsa, SoundIoBackendAlsa,
#endif
#ifdef SOUNDIO_HAVE_COREAUDIO
SoundIoBackendCoreAudio,
#endif #endif
SoundIoBackendDummy, SoundIoBackendDummy,
}; };
@ -42,6 +45,11 @@ static int (*backend_init_fns[])(SoundIoPrivate *) = {
[SoundIoBackendAlsa] = soundio_alsa_init, [SoundIoBackendAlsa] = soundio_alsa_init,
#else #else
[SoundIoBackendAlsa] = nullptr, [SoundIoBackendAlsa] = nullptr,
#endif
#ifdef SOUNDIO_HAVE_COREAUDIO
[SoundIoBackendCoreAudio] = soundio_coreaudio_init,
#else
[SoundIoBackendCoreAudio] = nullptr,
#endif #endif
[SoundIoBackendDummy] = soundio_dummy_init, [SoundIoBackendDummy] = soundio_dummy_init,
}; };
@ -126,6 +134,7 @@ const char *soundio_backend_name(enum SoundIoBackend backend) {
case SoundIoBackendJack: return "JACK"; case SoundIoBackendJack: return "JACK";
case SoundIoBackendPulseAudio: return "PulseAudio"; case SoundIoBackendPulseAudio: return "PulseAudio";
case SoundIoBackendAlsa: return "ALSA"; case SoundIoBackendAlsa: return "ALSA";
case SoundIoBackendCoreAudio: return "CoreAudio";
case SoundIoBackendDummy: return "Dummy"; case SoundIoBackendDummy: return "Dummy";
} }
return "(invalid backend)"; return "(invalid backend)";

View file

@ -23,6 +23,10 @@
#include "alsa.hpp" #include "alsa.hpp"
#endif #endif
#ifdef SOUNDIO_HAVE_COREAUDIO
#include "coreaudio.hpp"
#endif
#include "dummy.hpp" #include "dummy.hpp"
union SoundIoBackendData { union SoundIoBackendData {
@ -34,6 +38,9 @@ union SoundIoBackendData {
#endif #endif
#ifdef SOUNDIO_HAVE_ALSA #ifdef SOUNDIO_HAVE_ALSA
SoundIoAlsa alsa; SoundIoAlsa alsa;
#endif
#ifdef SOUNDIO_HAVE_COREAUDIO
SoundIoCoreAudio coreaudio;
#endif #endif
SoundIoDummy dummy; SoundIoDummy dummy;
}; };
@ -47,6 +54,9 @@ union SoundIoDeviceBackendData {
#endif #endif
#ifdef SOUNDIO_HAVE_ALSA #ifdef SOUNDIO_HAVE_ALSA
SoundIoDeviceAlsa alsa; SoundIoDeviceAlsa alsa;
#endif
#ifdef SOUNDIO_HAVE_COREAUDIO
SoundIoDeviceCoreAudio coreaudio;
#endif #endif
SoundIoDeviceDummy dummy; SoundIoDeviceDummy dummy;
}; };
@ -60,6 +70,9 @@ union SoundIoOutStreamBackendData {
#endif #endif
#ifdef SOUNDIO_HAVE_ALSA #ifdef SOUNDIO_HAVE_ALSA
SoundIoOutStreamAlsa alsa; SoundIoOutStreamAlsa alsa;
#endif
#ifdef SOUNDIO_HAVE_COREAUDIO
SoundIoOutStreamCoreAudio coreaudio;
#endif #endif
SoundIoOutStreamDummy dummy; SoundIoOutStreamDummy dummy;
}; };
@ -73,6 +86,9 @@ union SoundIoInStreamBackendData {
#endif #endif
#ifdef SOUNDIO_HAVE_ALSA #ifdef SOUNDIO_HAVE_ALSA
SoundIoInStreamAlsa alsa; SoundIoInStreamAlsa alsa;
#endif
#ifdef SOUNDIO_HAVE_COREAUDIO
SoundIoInStreamCoreAudio coreaudio;
#endif #endif
SoundIoInStreamDummy dummy; SoundIoInStreamDummy dummy;
}; };
@ -101,7 +117,6 @@ struct SoundIoPrivate {
// Safe to read from a single thread without a mutex. // Safe to read from a single thread without a mutex.
struct SoundIoDevicesInfo *safe_devices_info; struct SoundIoDevicesInfo *safe_devices_info;
SoundIoBackendData backend_data;
void (*destroy)(struct SoundIoPrivate *); void (*destroy)(struct SoundIoPrivate *);
void (*flush_events)(struct SoundIoPrivate *); void (*flush_events)(struct SoundIoPrivate *);
void (*wait_events)(struct SoundIoPrivate *); void (*wait_events)(struct SoundIoPrivate *);
@ -124,6 +139,8 @@ struct SoundIoPrivate {
SoundIoChannelArea **out_areas, int *frame_count); SoundIoChannelArea **out_areas, int *frame_count);
int (*instream_end_read)(struct SoundIoPrivate *, struct SoundIoInStreamPrivate *); int (*instream_end_read)(struct SoundIoPrivate *, struct SoundIoInStreamPrivate *);
int (*instream_pause)(struct SoundIoPrivate *, struct SoundIoInStreamPrivate *, bool pause); int (*instream_pause)(struct SoundIoPrivate *, struct SoundIoInStreamPrivate *, bool pause);
SoundIoBackendData backend_data;
}; };
struct SoundIoDevicePrivate { struct SoundIoDevicePrivate {