From 21bf405859e1b94252a2b38bf8315b51da04d826 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sat, 8 Aug 2015 15:22:50 -0700 Subject: [PATCH] WASAPI skeleton --- CMakeLists.txt | 21 +++++++++ cmake/FindWASAPI.cmake | 18 ++++++++ soundio/soundio.h | 1 + src/config.h.in | 1 + src/soundio.cpp | 9 ++++ src/soundio.hpp | 16 +++++++ src/wasapi.cpp | 101 +++++++++++++++++++++++++++++++++++++++++ src/wasapi.hpp | 27 +++++++++++ 8 files changed, 194 insertions(+) create mode 100644 cmake/FindWASAPI.cmake create mode 100644 src/wasapi.cpp create mode 100644 src/wasapi.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index d611d22..15683d7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -77,6 +77,16 @@ else() set(AUDIOUNIT_LIBRARY "") endif() +find_package(WASAPI) +if(WASAPI_FOUND) + set(STATUS_WASAPI "OK") + set(SOUNDIO_HAVE_WASAPI true) +else() + set(STATUS_WASAPI "not found") + set(SOUNDIO_HAVE_WASAPI false) + set(WASAPI_LIBRARIES "") +endif() + set(LIBSOUNDIO_SOURCES "${CMAKE_SOURCE_DIR}/src/soundio.cpp" @@ -136,6 +146,14 @@ if(SOUNDIO_HAVE_COREAUDIO) "${CMAKE_SOURCE_DIR}/src/coreaudio.cpp" ) endif() +if(SOUNDIO_HAVE_WASAPI) + set(LIBSOUNDIO_SOURCES ${LIBSOUNDIO_SOURCES} + "${CMAKE_SOURCE_DIR}/src/wasapi.cpp" + ) + set(TEST_SOURCES ${TEST_SOURCES} + "${CMAKE_SOURCE_DIR}/src/wasapi.cpp" + ) +endif() # GTFO, -lstdc++ !! @@ -186,6 +204,7 @@ target_link_libraries(libsoundio_shared LINK_PUBLIC ${COREAUDIO_LIBRARY} ${COREFOUNDATION_LIBRARY} ${AUDIOUNIT_LIBRARY} + ${WASAPI_LIBRARIES} m ${CMAKE_THREAD_LIBS_INIT} ) @@ -242,6 +261,7 @@ target_link_libraries(unit_tests LINK_PUBLIC ${COREAUDIO_LIBRARY} ${COREFOUNDATION_LIBRARY} ${AUDIOUNIT_LIBRARY} + ${WASAPI_LIBRARIES} m ) set_target_properties(unit_tests PROPERTIES @@ -289,4 +309,5 @@ message( "* PulseAudio (optional) : ${STATUS_PULSEAUDIO}\n" "* ALSA (optional) : ${STATUS_ALSA}\n" "* CoreAudio (optional) : ${STATUS_COREAUDIO}\n" + "* WASAPI (optional) : ${STATUS_WASAPI}\n" ) diff --git a/cmake/FindWASAPI.cmake b/cmake/FindWASAPI.cmake new file mode 100644 index 0000000..71a94b4 --- /dev/null +++ b/cmake/FindWASAPI.cmake @@ -0,0 +1,18 @@ +# Copyright (c) 2015 Andrew Kelley +# This file is MIT licensed. +# See http://opensource.org/licenses/MIT + +# WASAPI_FOUND +# WASAPI_INCLUDE_DIR +# WASAPI_LIBRARIES + +if (WIN32) + find_path(WASAPI_INCLUDE_DIR NAMES audioclient.h) + + set(WASAPI_LIBRARIES "") +endif() + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(WASAPI DEFAULT_MSG WASAPI_INCLUDE_DIR) + +mark_as_advanced(WASAPI_INCLUDE_DIR WASAPI_LIBRARIES) diff --git a/soundio/soundio.h b/soundio/soundio.h index b84258d..e220dc4 100644 --- a/soundio/soundio.h +++ b/soundio/soundio.h @@ -154,6 +154,7 @@ enum SoundIoBackend { SoundIoBackendPulseAudio, SoundIoBackendAlsa, SoundIoBackendCoreAudio, + SoundIoBackendWasapi, SoundIoBackendDummy, }; diff --git a/src/config.h.in b/src/config.h.in index 38c7c2e..49bede1 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -20,5 +20,6 @@ #cmakedefine SOUNDIO_HAVE_PULSEAUDIO #cmakedefine SOUNDIO_HAVE_ALSA #cmakedefine SOUNDIO_HAVE_COREAUDIO +#cmakedefine SOUNDIO_HAVE_WASAPI #endif diff --git a/src/soundio.cpp b/src/soundio.cpp index 84e86bc..b23f186 100644 --- a/src/soundio.cpp +++ b/src/soundio.cpp @@ -25,6 +25,9 @@ static const SoundIoBackend available_backends[] = { #endif #ifdef SOUNDIO_HAVE_COREAUDIO SoundIoBackendCoreAudio, +#endif +#ifdef SOUNDIO_HAVE_WASAPI + SoundIoBackendWasapi, #endif SoundIoBackendDummy, }; @@ -50,6 +53,11 @@ static int (*backend_init_fns[])(SoundIoPrivate *) = { [SoundIoBackendCoreAudio] = soundio_coreaudio_init, #else [SoundIoBackendCoreAudio] = nullptr, +#endif +#ifdef SOUNDIO_HAVE_WASAPI + [SoundIoBackendWasapi] = soundio_wasapi_init, +#else + [SoundIoBackendWasapi] = nullptr, #endif [SoundIoBackendDummy] = soundio_dummy_init, }; @@ -137,6 +145,7 @@ const char *soundio_backend_name(enum SoundIoBackend backend) { case SoundIoBackendPulseAudio: return "PulseAudio"; case SoundIoBackendAlsa: return "ALSA"; case SoundIoBackendCoreAudio: return "CoreAudio"; + case SoundIoBackendWasapi: return "WASAPI"; case SoundIoBackendDummy: return "Dummy"; } return "(invalid backend)"; diff --git a/src/soundio.hpp b/src/soundio.hpp index 9adc9d6..2e9d179 100644 --- a/src/soundio.hpp +++ b/src/soundio.hpp @@ -27,6 +27,10 @@ #include "coreaudio.hpp" #endif +#ifdef SOUNDIO_HAVE_WASAPI +#include "wasapi.hpp" +#endif + #include "dummy.hpp" union SoundIoBackendData { @@ -41,6 +45,9 @@ union SoundIoBackendData { #endif #ifdef SOUNDIO_HAVE_COREAUDIO SoundIoCoreAudio coreaudio; +#endif +#ifdef SOUNDIO_HAVE_WASAPI + SoundIoWasapi wasapi; #endif SoundIoDummy dummy; }; @@ -57,6 +64,9 @@ union SoundIoDeviceBackendData { #endif #ifdef SOUNDIO_HAVE_COREAUDIO SoundIoDeviceCoreAudio coreaudio; +#endif +#ifdef SOUNDIO_HAVE_WASAPI + SoundIoDeviceWasapi wasapi; #endif SoundIoDeviceDummy dummy; }; @@ -73,6 +83,9 @@ union SoundIoOutStreamBackendData { #endif #ifdef SOUNDIO_HAVE_COREAUDIO SoundIoOutStreamCoreAudio coreaudio; +#endif +#ifdef SOUNDIO_HAVE_WASAPI + SoundIoOutStreamWasapi wasapi; #endif SoundIoOutStreamDummy dummy; }; @@ -89,6 +102,9 @@ union SoundIoInStreamBackendData { #endif #ifdef SOUNDIO_HAVE_COREAUDIO SoundIoInStreamCoreAudio coreaudio; +#endif +#ifdef SOUNDIO_HAVE_WASAPI + SoundIoInStreamWasapi wasapi; #endif SoundIoInStreamDummy dummy; }; diff --git a/src/wasapi.cpp b/src/wasapi.cpp new file mode 100644 index 0000000..68a1ad8 --- /dev/null +++ b/src/wasapi.cpp @@ -0,0 +1,101 @@ +#include "wasapi.hpp" +#include "soundio.hpp" + +static void flush_events_wasapi(struct SoundIoPrivate *si) { + soundio_panic("TODO"); +} + +static void wait_events_wasapi(struct SoundIoPrivate *si) { + soundio_panic("TODO"); +} + +static void wakeup_wasapi(struct SoundIoPrivate *si) { + soundio_panic("TODO"); +} + +static void outstream_destroy_wasapi(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os) { + soundio_panic("TODO"); +} + +static int outstream_open_wasapi(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os) { + soundio_panic("TODO"); +} + +static int outstream_pause_wasapi(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os, bool pause) { + soundio_panic("TODO"); +} + +static int outstream_start_wasapi(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os) { + soundio_panic("TODO"); +} + +static int outstream_begin_write_wasapi(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os, + SoundIoChannelArea **out_areas, int *frame_count) +{ + soundio_panic("TODO"); +} + +static int outstream_end_write_wasapi(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os) { + soundio_panic("TODO"); +} + +static int outstream_clear_buffer_wasapi(struct SoundIoPrivate *si, struct SoundIoOutStreamPrivate *os) { + soundio_panic("TODO"); +} + + + +static void instream_destroy_wasapi(struct SoundIoPrivate *si, struct SoundIoInStreamPrivate *is) { + soundio_panic("TODO"); +} + +static int instream_open_wasapi(struct SoundIoPrivate *si, struct SoundIoInStreamPrivate *is) { + soundio_panic("TODO"); +} + +static int instream_pause_wasapi(struct SoundIoPrivate *si, struct SoundIoInStreamPrivate *is, bool pause) { + soundio_panic("TODO"); +} + +static int instream_start_wasapi(struct SoundIoPrivate *si, struct SoundIoInStreamPrivate *is) { + soundio_panic("TODO"); +} + +static int instream_begin_read_wasapi(struct SoundIoPrivate *si, struct SoundIoInStreamPrivate *is, + SoundIoChannelArea **out_areas, int *frame_count) +{ + soundio_panic("TODO"); +} + +static int instream_end_read_wasapi(struct SoundIoPrivate *si, struct SoundIoInStreamPrivate *is) { + soundio_panic("TODO"); +} + + +static void destroy_wasapi(struct SoundIoPrivate *si) { + soundio_panic("TODO"); +} + +int soundio_wasapi_init(SoundIoPrivate *si) { + si->destroy = destroy_wasapi; + si->flush_events = flush_events_wasapi; + si->wait_events = wait_events_wasapi; + si->wakeup = wakeup_wasapi; + + si->outstream_open = outstream_open_wasapi; + si->outstream_destroy = outstream_destroy_wasapi; + si->outstream_start = outstream_start_wasapi; + si->outstream_begin_write = outstream_begin_write_wasapi; + si->outstream_end_write = outstream_end_write_wasapi; + si->outstream_clear_buffer = outstream_clear_buffer_wasapi; + si->outstream_pause = outstream_pause_wasapi; + + si->instream_open = instream_open_wasapi; + si->instream_destroy = instream_destroy_wasapi; + si->instream_start = instream_start_wasapi; + si->instream_begin_read = instream_begin_read_wasapi; + si->instream_end_read = instream_end_read_wasapi; + si->instream_pause = instream_pause_wasapi; + + return 0; +} diff --git a/src/wasapi.hpp b/src/wasapi.hpp new file mode 100644 index 0000000..3252c9c --- /dev/null +++ b/src/wasapi.hpp @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2015 Andrew Kelley + * + * This file is part of libsoundio, which is MIT licensed. + * See http://opensource.org/licenses/MIT + */ + +#ifndef SOUNDIO_WASAPI_HPP +#define SOUNDIO_WASAPI_HPP + +#include "soundio/soundio.h" + +int soundio_wasapi_init(struct SoundIoPrivate *si); + +struct SoundIoDeviceWasapi { +}; + +struct SoundIoWasapi { +}; + +struct SoundIoOutStreamWasapi { +}; + +struct SoundIoInStreamWasapi { +}; + +#endif