Skip to content

Commit

Permalink
PortAudio with Android Oboe support (squashed)
Browse files Browse the repository at this point in the history
* Preparation to start patching - TODOS and directory src/hostapi/Oboe

* Added src/hostapi/oboe/README.md

* Added include/pa_oboe.h and src/hostapi/oboe/pa_oboe.cpp

* Added PA_USE_OBOE section to CMakeLists.txt

* Added PA_USE_OBOE section to CMakeLists.txt

* Heavily reworked CMake dependencies, added FindOboe.cmake, updated pa_oboe.cpp, more work needed

* Included build_all_PaOboe.sh, more work needed on CMake

* Included build_all_PaOboe.sh, more work needed on CMake

* Update src/hostapi/oboe/README.md

* bindings/cpp: CMake: support pkgconfig with RelWithDebInfo (PortAudio#822)

bindings/cpp: add  `RelWithDebInfo` to the configurations allowed to install portaudiocpp.pc, otherwise you won't have support for pkg-config when building a release package with separate debugging information. Besides that, RelWithDebInfo is identical to Release.

* Fix MSVC warning C4018 signed/unsigned mismatch (PortAudio#821)

See PortAudio#810

* Built shared library

* Polished bits

* mme: don't restrict the host buffer to 16-bit

Currently, the MME Host API code only creates 16-bit integer MME
buffers. All audio data provided by the user is therefore converted by
PortAudio to and from 16-bit, regardless of the user buffer format.

This basically makes it impossible to pass 24-bit audio through the
MME Host API.

If the user buffer format is not 16-bit, this also causes pointless
conversions to take place, *even if the hardware is running at 16-bit*,
because modern Windows versions (Vista+) convert the data to floating
point behind the scenes before it is handed off to the hardware. This
can lead to silly situations where 32-bit float samples from the user
are (lossily) converted to 16-bit by PortAudio, then ended off to
Windows via MME, only to be converted back to 32-bit float again, before
finally being converted to the format the hardware device is configured
to use. This can easily lead to two layers of 16-bit dithering (one from
PortAudio, and one from Windows) being piled on top of each other,
resulting in an elevated noise floor.

This commit fixes this problem by configuring the MME buffers to use the
same format as the user buffer. This should stop PortAudio from
converting samples in all cases except paInt8, which is not supported by
WAVEFORMATEX (only paUInt8 is). This is pretty much the same idea as

The new code assumes that MME will accept whatever format we throw at
it. I feel confident that this is always true on Vista+ regardless of
hardware, because starting from Vista MME does not access hardware
directly - it always goes through the Windows Audio Engine which
supports all formats in both directions (I verified this using
paloopback).

On pre-Vista Windows, this should still work all the way back to Windows
98 SE, because MME goes through KMixer which supports all formats [1].
Nevertheless, it's difficult to be sure, so this code checks the Windows
version it's running on and preserves the old behavior (i.e. always use
Int16) on pre-Vista Windows.

[1]: https://learn.microsoft.com/en-us/windows-hardware/drivers/audio/background-of-non-pcm-support#waveout-api

Fixes PortAudio#139

* Don't use absolute path when linking to macOS frameworks (PortAudio#829)

fixes PortAudio#828

* Fixing old problems

* Added some debug messages

* added new build script

* Added paOboe in the paHostApi array

* Added paOboe in pa_unix_hostapis.c

* Working patch

* win: New PaWinUtil_GetOsVersion() function for getting Windows OS version. Refactored WASAPI, DS, MME and WDMKS host back-ends to use PaWinUtil_GetOsVersion() instead of direct OS API.

* Ready for other users to compile/build

* Updated oboe/Readme.md

* Added sharing mode selection

* Fixed minor issue with sharing mode selection

* Removed references to KCTI

* Fixed error callback, added performance mode autoselection

* Minor change to CMakeLists, added low latency costant in pa_oboe.h

* Deleted Build_PaOboe.sh

* Ready to push (removed my paths to Oboe directory and Android NDK)

* Update README.md

* Update README.md

* remove all alternative sample conversion code using lrintf in pa_converters.c (PortAudio#403)

removes the code guarded by PA_USE_C99_LRINTF
See PortAudio#390

* updated readme

* fixed CMakeLists.txt

* fixed FindOboe.cmake

* Preparation to start patching - TODOS and directory src/hostapi/Oboe

* Added src/hostapi/oboe/README.md

* Added include/pa_oboe.h and src/hostapi/oboe/pa_oboe.cpp

* Added PA_USE_OBOE section to CMakeLists.txt

* Added PA_USE_OBOE section to CMakeLists.txt

* Heavily reworked CMake dependencies, added FindOboe.cmake, updated pa_oboe.cpp, more work needed

* Included build_all_PaOboe.sh, more work needed on CMake

* Included build_all_PaOboe.sh, more work needed on CMake

* Built shared library

* Polished bits

* Fixing old problems

* Added some debug messages

* added new build script

* Added paOboe in the paHostApi array

* Added paOboe in pa_unix_hostapis.c

* Working patch

* Ready for other users to compile/build

* Updated oboe/Readme.md

* Added sharing mode selection

* Fixed minor issue with sharing mode selection

* Removed references to KCTI

* Fixed error callback, added performance mode autoselection

* Minor change to CMakeLists, added low latency costant in pa_oboe.h

* Deleted Build_PaOboe.sh

* Ready to push (removed my paths to Oboe directory and Android NDK)

* Update src/hostapi/oboe/README.md

* Update README.md

* Update README.md

* updated readme

* fixed CMakeLists.txt

* fixed FindOboe.cmake

* corrected oboe/Readme.md

* Updated oboe/Readme.md

* PulseAudio Portaudio HostAPI (PortAudio#336)

Adds support for PulseAudio API on Linux.

For more information about Pulseaudio visit: https://www.freedesktop.org/wiki/Software/PulseAudio/

---------

Signed-off-by: Mario Kleiner <mario.kleiner.de@gmail.com>
Co-authored-by: sqweek <sqweek@gmail.com>
Co-authored-by: Daniel Schürmann <daschuer@mixxx.org>
Co-authored-by: Mooneer Salem <mooneer@gmail.com>
Co-authored-by: Be <be.0@gmx.com>
Co-authored-by: Mario Kleiner <mario.kleiner.de@gmail.com>

* pulseaudio: Move Pulseaudio include in correct place when using autoconf (PortAudio#843)

As Jack and Pulseaudio both needs Ringbuffer that include can
be done in same place. In configure.in also Pulseaudio header
file was included before it was sure that it was really needed.

Commit makes sure that Pulseaudio include is available only if
it's needed as it can cause failing in build if Pulseaudio
develoment files are not available.

* added .idea to gitignore

* added .idea to gitignore

* restored workflows directory

* Minor fixes to FindOboe.cmake

* Enhanced prebuilt libraries compatibility in FindOboe.cmake

* Minor changes to Pa_Oboe/Readme and pa_oboe.cpp

* Removed auto latency tuning in favor of simpler impleentation in pa_oboe.cpp

* Set paFloat32 as default format in pa_oboe.cpp

* Renamed most of the variables according to best coding practices.

* Added separate callback class to fix the single-stream issue.

* Modified OboeEngine accordingly

* Adjusted the code in the rest of pa_oboe.cpp

* Removed stop and close phases of OboeEngine::restartStream

* Updated functions' description

* minor description corrections

* fixed all compiling errors generated by typos

* Added OboeMediator class in place of OboeCallback, that mediates PortAudio C stream struct and the C++ OboeEngine class

* Fixed allocation problem, working PaOboe implementation

* Fix 'pulseaudioHostApi' use-after-free/null ptr deref in PaPulseAudio_Initialize (PortAudio#847)

The call to PaPulseAudio_UnLock( pulseaudioHostApi->mainloop ) in error-label is performed on 'pulseaudioHostApi' after 'pulseaudioHostApi' has been freed by PaPulseAudio_Free and set to NULL.

* wdmks: declare GUIDs with selectany attribute (PortAudio#846)

* wdmks: declare GUIDs with selectany attribute

Match the behavior of guiddef.h in both mingw and the Windows SDK headers. This prevents linking errors caused by multiply defined symbols when linking against certain Windows SDK libs (like dxguid.lib).

* Make sure this works even if DECLSPEC_SELECTANY is not defined

---------

Co-authored-by: Ross Bencina <rossb@audiomulch.com>

* fixed README.md indenting

* Removed .idea folder from repo

* replaced 'g_' with 'paOboe_' in non-static global variables

* replaced 'm_' prefix with 'm' prefix

* fixed OboeEngine::tryStream as requested

* PulseAudio Portaudio HostAPI (PortAudio#336)

Adds support for PulseAudio API on Linux.

For more information about Pulseaudio visit: https://www.freedesktop.org/wiki/Software/PulseAudio/

---------

Signed-off-by: Mario Kleiner <mario.kleiner.de@gmail.com>
Co-authored-by: sqweek <sqweek@gmail.com>
Co-authored-by: Daniel Schürmann <daschuer@mixxx.org>
Co-authored-by: Mooneer Salem <mooneer@gmail.com>
Co-authored-by: Be <be.0@gmx.com>
Co-authored-by: Mario Kleiner <mario.kleiner.de@gmail.com>

* pulseaudio: Move Pulseaudio include in correct place when using autoconf (PortAudio#843)

As Jack and Pulseaudio both needs Ringbuffer that include can
be done in same place. In configure.in also Pulseaudio header
file was included before it was sure that it was really needed.

Commit makes sure that Pulseaudio include is available only if
it's needed as it can cause failing in build if Pulseaudio
develoment files are not available.

* restored workflows directory

* Minor fixes to FindOboe.cmake

* Enhanced prebuilt libraries compatibility in FindOboe.cmake

* Minor changes to Pa_Oboe/Readme and pa_oboe.cpp

* Removed auto latency tuning in favor of simpler impleentation in pa_oboe.cpp

* Set paFloat32 as default format in pa_oboe.cpp

* Renamed most of the variables according to best coding practices.

* Added separate callback class to fix the single-stream issue.

* Modified OboeEngine accordingly

* Adjusted the code in the rest of pa_oboe.cpp

* Removed stop and close phases of OboeEngine::restartStream

* Updated functions' description

* minor description corrections

* fixed all compiling errors generated by typos

* Added OboeMediator class in place of OboeCallback, that mediates PortAudio C stream struct and the C++ OboeEngine class

* Fixed allocation problem, working PaOboe implementation

* fixed README.md indenting

* Removed .idea folder from repo

* replaced 'g_' with 'paOboe_' in non-static global variables

* replaced 'm_' prefix with 'm' prefix

* fixed OboeEngine::tryStream as requested

* Changed names to improve readability, i.e. OboeStream -> PaOboeStream

* fixed all compiling errors generated by typos

* Fixed minor problem with TryStream

* fixed long line in FindOboe.cmake

* fixed typos in pa_oboe.cpp

* set to verbose some logs

* Fixed minor problem with TryStream

* fixed long line in FindOboe.cmake

* fixed typos in pa_oboe.cpp

* set to verbose some logs

* Better handling of format in paOboe, removed junk code from CMakeLists

* Improved readability of some variables

* Removed '#include oboe/Oboe.h' from pa_oboe.h, and modified host api implementation accordingly

* static cast fixes

---------

Signed-off-by: Mario Kleiner <mario.kleiner.de@gmail.com>
Co-authored-by: Carlo Benfatti <benfatti@netresults.it>
Co-authored-by: hopefulGiupplo <116260612+hopefulGiupplo@users.noreply.github.com>
Co-authored-by: Carlo Bramini <30959007+carlo-bramini@users.noreply.github.com>
Co-authored-by: Etienne Dechamps <etienne@edechamps.fr>
Co-authored-by: Daniel Schürmann <daschuer@mixxx.org>
Co-authored-by: dmitrykos <dmitrykos@neutroncode.com>
Co-authored-by: Ross Bencina <rossb@audiomulch.com>
Co-authored-by: Tuukka Pasanen <pasanen.tuukka@gmail.com>
Co-authored-by: sqweek <sqweek@gmail.com>
Co-authored-by: Mooneer Salem <mooneer@gmail.com>
Co-authored-by: Be <be.0@gmx.com>
Co-authored-by: Mario Kleiner <mario.kleiner.de@gmail.com>
Co-authored-by: Tuukka Pasanen <tuukka.pasanen@ilmi.fi>
Co-authored-by: invertego <invertego@users.noreply.github.com>
  • Loading branch information
15 people committed Mar 6, 2024
1 parent 4600d81 commit b06979e
Show file tree
Hide file tree
Showing 12 changed files with 2,230 additions and 4 deletions.
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ libtool
portaudio-2.0.pc
autom4te.cache/*

# build_all_PaOboe.sh CMake output folder
build
build_old

# Precompiled Headers
*.gch
*.pch
Expand Down Expand Up @@ -54,5 +58,7 @@ CMakeSettings.json
# VSCode
.vscode*

# idea
.idea*

# Common build directories of users and VSCode
build*
32 changes: 32 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,36 @@ elseif(UNIX)
set(PKGCONFIG_LDFLAGS_PRIVATE "${PKGCONFIG_LDFLAGS_PUBLIC} -lm -lpthread")
set(PKGCONFIG_CFLAGS "${PKGCONFIG_CFLAGS} -pthread")

IF(CMAKE_SYSTEM_NAME STREQUAL "Android")
set(PKGCONFIG_LDFLAGS_PRIVATE "${PA_PKGCONFIG_LDFLAGS} -lm")
ELSE()
set(PKGCONFIG_LDFLAGS_PRIVATE "${PKGCONFIG_LDFLAGS_PUBLIC} -lm -lpthread")
target_link_libraries(PortAudio PRIVATE pthread)
set(PKGCONFIG_CFLAGS "${PKGCONFIG_CFLAGS} -pthread")
ENDIF()


# Oboe only works on Android, which has a Unix kernel.
find_package(Oboe)
cmake_dependent_option(PA_USE_OBOE "Enable support for Oboe" ON OBOE_FOUND OFF)
if(PA_USE_OBOE)
message("-- Oboe structure found")
target_include_directories(PortAudio PRIVATE ${OBOE_INCLUDE_DIR})
target_link_libraries(PortAudio PUBLIC Oboe::oboe)
target_sources(PortAudio PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/hostapi/oboe/pa_oboe.cpp)
set(PORTAUDIO_PUBLIC_HEADERS "${PORTAUDIO_PUBLIC_HEADERS}" include/pa_oboe.h)
target_compile_definitions(PortAudio PUBLIC PA_USE_OBOE=1)
set(PKGCONFIG_CFLAGS "${PKGCONFIG_CFLAGS} -DPA_USE_OBOE=1")
endif()

IF(CMAKE_SYSTEM_NAME STREQUAL "Android")
SET(PA_PKGCONFIG_LDFLAGS "${PA_PKGCONFIG_LDFLAGS} -lm")
SET(PA_LIBRARY_DEPENDENCIES ${PA_LIBRARY_DEPENDENCIES} m)
ELSE()
SET(PA_PKGCONFIG_LDFLAGS "${PA_PKGCONFIG_LDFLAGS} -lm -lpthread")
SET(PA_LIBRARY_DEPENDENCIES ${PA_LIBRARY_DEPENDENCIES} m pthread)
ENDIF()

if(APPLE)
set(CMAKE_MACOSX_RPATH 1)
target_sources(PortAudio PRIVATE
Expand Down Expand Up @@ -390,6 +420,8 @@ elseif(UNIX)
install(FILES cmake/modules/FindPulseAudio.cmake DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/portaudio/modules")
endif()

endif()

pkg_check_modules(SNDIO sndio)
cmake_dependent_option(PA_USE_SNDIO "Enable support for sndio" ON SNDIO_FOUND OFF)
if(PA_USE_SNDIO)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ Please feel free to join. See http://www.portaudio.com for details.
src/os = os specific (but host api neutral) code
src/hostapi = implementations for different host apis


### Host API Implementations:

src/hostapi/alsa = Advanced Linux Sound Architecture (ALSA)
Expand All @@ -40,6 +39,7 @@ Please feel free to join. See http://www.portaudio.com for details.
src/hostapi/coreaudio = Macintosh Core Audio for OS X
src/hostapi/dsound = Windows Direct Sound
src/hostapi/jack = JACK Audio Connection Kit
src/hostapi/oboe = Oboe Library for Android (see src/hostapi/oboe/README.md)
src/hostapi/oss = Unix Open Sound System (OSS)
src/hostapi/pulseaudio = Sound system for POSIX OSes
src/hostapi/sndio = Small audio and MIDI framework (sndio)
Expand Down
46 changes: 46 additions & 0 deletions build_all_PaOboe.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash
# Script used to build Portaudio for multiple Android ABIs, useful for its Oboe host API.
#
# Ensure that ANDROID_NDK environment variable is set to your Android NDK location
# e.g. /Library/Android/sdk/ndk-bundle

if [ -z "$ANDROID_NDK" ]; then
echo "Please set ANDROID_NDK to the Android NDK folder"
exit 1
fi

# Build directory
BUILD_DIR=build

CMAKE_ARGS="-H. \
-DBUILD_SHARED_LIBS=true \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DANDROID_TOOLCHAIN=clang \
-DANDROID_STL=c++_shared \
-DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK}/build/cmake/android.toolchain.cmake \
-DCMAKE_INSTALL_PREFIX=."

function build_PaOboe {

ABI=$1
MINIMUM_API_LEVEL=$2
ABI_BUILD_DIR=${BUILD_DIR}/${ABI}

echo "Building Pa_Oboe for ${ABI}"

mkdir -p ${ABI_BUILD_DIR} ${ABI_BUILD_DIR}/${STAGING_DIR}

cmake -B${ABI_BUILD_DIR} \
-DANDROID_ABI=${ABI} \
-DANDROID_PLATFORM=android-${MINIMUM_API_LEVEL}\
${CMAKE_ARGS}

pushd ${ABI_BUILD_DIR}
make -j5
popd
}

#build_PaOboe armeabi-v7a 16
build_PaOboe arm64-v8a 21
#build_PaOboe x86 16
build_PaOboe x86_64 21
74 changes: 74 additions & 0 deletions cmake/modules/FindOboe.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#[=======================================================================[.rst:
Findoboe
--------
Finds the oboe library. OBOE_DIRECTORY has to be set to the path of the directory where
the oboe repository was cloned (see src/hostapi/oboe/README.md for more information).
Imported Targets
^^^^^^^^^^^^^^^^
This module provides the following imported target, if found:
``Oboe::oboe``
The OBOE library
#]=======================================================================]

if(NOT DEFINED OBOE_DIRECTORY)
#Insert the path of the directory where you cloned Oboe, i.e. ${CMAKE_CURRENT_SOURCE_DIR}/../oboe
set(OBOE_DIRECTORY FALSE)
endif()

if(NOT OBOE_DIRECTORY)
message(AUTHOR_WARNING
"If you're trying to use Oboe as a Host API, please specify the directory where you "
"cloned its repository. For further information, please read src/hostapi/oboe/README.md"
)
set(OBOE_FOUND FALSE)
else()
if(NOT DEFINED OBOE_INCLUDE_DIR)
set(OBOE_INCLUDE_DIR ${OBOE_DIRECTORY}/include)
endif()

if(NOT DEFINED OBOE_LIBRARY_DIRS)
set(OBOE_LIBRARY_DIRS ${OBOE_DIRECTORY}/build/${ANDROID_ABI})
endif()
set(OBOE_LIBRARIES ${OBOE_LIBRARY_DIRS}/liboboe.so)

find_package(PkgConfig QUIET)
if(PkgConfig_FOUND)
pkg_check_modules(OBOE Oboe)
else()
find_library(OBOE_LIBRARIES
NAMES liboboe.so
HINTS ${OBOE_LIBRARY_DIRS}
DOC "Oboe Library"
)
find_path(OBOE_INCLUDE_DIR
NAMES oboe/Oboe.h
DOC "Oboe header"
)
endif()

find_library(LOG_LIBRARY log) #used by pa_oboe.cpp and pa_oboe.h as a logging tool

set(OBOE_LINK_LIBRARIES ${OBOE_LIBRARIES} ${LOG_LIBRARY})

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(
Oboe
DEFAULT_MSG
OBOE_LINK_LIBRARIES
OBOE_INCLUDE_DIR
)

if(OBOE_INCLUDE_DIR AND OBOE_LINK_LIBRARIES)
set(OBOE_FOUND TRUE)
if(NOT TARGET Oboe::oboe)
add_library(Oboe::oboe INTERFACE IMPORTED GLOBAL)
target_link_libraries(Oboe::oboe INTERFACE "${OBOE_LINK_LIBRARIES}")
target_include_directories(Oboe::oboe INTERFACE "${OBOE_INCLUDE_DIR}")
endif()
endif()
endif()
141 changes: 141 additions & 0 deletions include/pa_oboe.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
/*
* $Id:
* PortAudio Portable Real-Time Audio Library
* Latest Version at: http://www.portaudio.com
*
* Android Oboe implementation of PortAudio.
*
****************************************************************************************
* Author: *
* Carlo Benfatti <benfatti@netresults.it> *
****************************************************************************************
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

/*
* The text above constitutes the entire PortAudio license; however,
* the PortAudio community also makes the following non-binding requests:
*
* Any person wishing to distribute modifications to the Software is
* requested to send the modifications to the original developer so that
* they can be incorporated into the canonical version. It is also
* requested that these non-binding requests be included along with the
* license above.
*/

#ifndef PA_OBOE_H
#define PA_OBOE_H

/**
* @file
* @ingroup public_header
* @brief Android Oboe-specific PortAudio API extension header file.
*/

#include "portaudio.h"

#ifdef __cplusplus
extern "C" {
#endif //__cplusplus

#define TIMEOUT_NS 1000000000 //Arbitrary timeout of the read/write functions
#define LOW_LATENCY_MS 300.0 //Arbitrary value used to automatically determine if low latency performance mode is doable

/**
* Enum class that emulates Oboe::Direction.
*/
enum class PaOboe_Direction: int32_t { Output = 0, Input = 1 };

/**
* Enum class that emulates Oboe::Usage.
*/
enum class PaOboe_Usage : int32_t {
Media = 1 , VoiceCommunication = 2 , VoiceCommunicationSignalling = 3 , Alarm = 4 ,
Notification = 5 , NotificationRingtone = 6 , NotificationEvent = 10 , AssistanceAccessibility = 11 ,
AssistanceNavigationGuidance = 12 , AssistanceSonification = 13 , Game = 14 , Assistant = 16
};

/**
* Enum class that emulates Oboe::InputPreset
*/
enum class PaOboe_InputPreset : int32_t {
Generic = 1 , Camcorder = 5 , VoiceRecognition = 6 , VoiceCommunication = 7 ,
Unprocessed = 9 , VoicePerformance = 10
};

/**
* Enum class that emulates Oboe::PerformanceMode
*/
enum class PaOboe_PerformanceMode : int32_t { None = 10 , PowerSaving = 11 , LowLatency = 12 };

/**
* The android stream type and recording preset as defined in Oboe.
*/
typedef struct PaOboeStreamInfo {
PaOboe_Usage androidOutputUsage;
PaOboe_InputPreset androidInputPreset;
} PaOboeStreamInfo;


/**
* Provide PaOboe with the ID of the device the user chose - oboe cannot build a device list,
* but can select the device if provided with its ID.
* @param direction - the direction of the stream for which we want to set the device.
* @param deviceID - the ID of the chosen device chosen by the user.
*/
void PaOboe_SetSelectedDevice(PaOboe_Direction direction, int32_t deviceID);


/**
* \brief Provide PaOboe with the performance mode chosen by the user. If this method isn't called, the default mode
* is LowLatency.
* @param direction - the direction of the stream for which we want to set the performance mode.
* @param performanceMode - the performance mode chosen by the user.
*/
void PaOboe_SetPerformanceMode(PaOboe_Direction direction, PaOboe_PerformanceMode performanceMode);


/**
* Provide PA Oboe with native buffer information. If you call this function, you must do so before
* calling Pa_Initialize. To have optimal latency, this function should be called - otherwise,
* PA Oboe will use potentially non-optimal values as default.
* @param bufferSize the native buffersize as returned by AudioManager's
* PROPERTY_OUTPUT_FRAMES_PER_BUFFER. It is recommended you set the number of buffers to 1 if API>17
* as well, and use the sample rate defined in AudioManager's android.media.property.OUTPUT_SAMPLE_RATE.
* All three together will enable the AUDIO_OUTPUT_FLAG_FAST flag.
*/
void PaOboe_SetNativeBufferSize(unsigned long bufferSize);

/**
* Provide PA Oboe with native buffer information. If you call this function, you must do so before
* calling Pa_Initialize. To have optimal latency and enable the AUDIO_OUTPUT_FLAG_FAST flag, this
* function should be called - otherwise, PA Oboe will use potentially non-optimal values (2) as default.
* @param buffers The number of buffers can be reduced to 1 on API >17. Make sure you set the native
* buffer size when doing this, and use the sample rate defined in AudioManager's
* android.media.property.OUTPUT_SAMPLE_RATE.
*/
void PaOboe_SetNumberOfBuffers(unsigned numberOfBuffers);

#ifdef __cplusplus
}
#endif //__cplusplus

#endif //PA_OBOE_H
4 changes: 3 additions & 1 deletion include/portaudio.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ PaHostApiIndex Pa_GetDefaultHostApi( void );
@see PaHostApiInfo
*/

typedef enum PaHostApiTypeId
{
paInDevelopment=0, /* use while developing support for a new host API */
Expand All @@ -291,7 +292,8 @@ typedef enum PaHostApiTypeId
paAudioScienceHPI=14,
paAudioIO=15,
paPulseAudio=16,
paSndio=17
paSndio=17,
paOboe=18
} PaHostApiTypeId;


Expand Down
7 changes: 7 additions & 0 deletions src/common/pa_hostapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,13 @@ are defaulted to 1.
#define PA_USE_ASIHPI 1
#endif

#ifndef PA_USE_OBOE
#define PA_USE_OBOE 0
#elif (PA_USE_OBOE != 0) && (PA_USE_OBOE != 1)
#undef PA_USE_OBOE
#define PA_USE_OBOE 1
#endif

#ifdef __cplusplus
extern "C"
{
Expand Down
Loading

0 comments on commit b06979e

Please sign in to comment.