From e7caffb39ccb77cf5041055701f7e1157fb61a7a Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Wed, 14 Feb 2024 14:23:33 +0900 Subject: [PATCH] internal/oboe: update to v1.8.1 --- internal/oboe/gen.go | 2 +- .../oboe_common_AudioStreamBuilder_android.cpp | 8 +++++++- .../oboe_flowgraph_FlowgraphUtilities_android.h | 15 +++++++++++++++ ...ph_resampler_MultiChannelResampler_android.cpp | 2 +- .../oboe/oboe_oboe_AudioStreamBuilder_android.h | 8 ++++++++ .../oboe/oboe_oboe_AudioStreamCallback_android.h | 3 ++- internal/oboe/oboe_oboe_AudioStream_android.h | 7 +++++++ internal/oboe/oboe_oboe_Version_android.h | 2 +- ...opensles_AudioOutputStreamOpenSLES_android.cpp | 12 +++++------- 9 files changed, 47 insertions(+), 12 deletions(-) diff --git a/internal/oboe/gen.go b/internal/oboe/gen.go index b7e91db..6e1de26 100644 --- a/internal/oboe/gen.go +++ b/internal/oboe/gen.go @@ -29,7 +29,7 @@ import ( "strings" ) -const oboeVersion = "1.8.0" +const oboeVersion = "1.8.1" func main() { if err := run(); err != nil { diff --git a/internal/oboe/oboe_common_AudioStreamBuilder_android.cpp b/internal/oboe/oboe_common_AudioStreamBuilder_android.cpp index 1fd5b3a..05a24bb 100644 --- a/internal/oboe/oboe_common_AudioStreamBuilder_android.cpp +++ b/internal/oboe/oboe_common_AudioStreamBuilder_android.cpp @@ -89,6 +89,11 @@ bool AudioStreamBuilder::isCompatible(AudioStreamBase &other) { } Result AudioStreamBuilder::openStream(AudioStream **streamPP) { + LOGW("Passing AudioStream pointer deprecated, Use openStream(std::shared_ptr &stream) instead."); + return openStreamInternal(streamPP); +} + +Result AudioStreamBuilder::openStreamInternal(AudioStream **streamPP) { auto result = isValidConfig(); if (result != Result::OK) { LOGW("%s() invalid config %d", __func__, result); @@ -202,6 +207,7 @@ Result AudioStreamBuilder::openStream(AudioStream **streamPP) { } Result AudioStreamBuilder::openManagedStream(oboe::ManagedStream &stream) { + LOGW("`openManagedStream` is deprecated. Use openStream(std::shared_ptr &stream) instead."); stream.reset(); AudioStream *streamptr; auto result = openStream(&streamptr); @@ -212,7 +218,7 @@ Result AudioStreamBuilder::openManagedStream(oboe::ManagedStream &stream) { Result AudioStreamBuilder::openStream(std::shared_ptr &sharedStream) { sharedStream.reset(); AudioStream *streamptr; - auto result = openStream(&streamptr); + auto result = openStreamInternal(&streamptr); if (result == Result::OK) { sharedStream.reset(streamptr); // Save a weak_ptr in the stream for use with callbacks. diff --git a/internal/oboe/oboe_flowgraph_FlowgraphUtilities_android.h b/internal/oboe/oboe_flowgraph_FlowgraphUtilities_android.h index 5e90588..e277d6e 100644 --- a/internal/oboe/oboe_flowgraph_FlowgraphUtilities_android.h +++ b/internal/oboe/oboe_flowgraph_FlowgraphUtilities_android.h @@ -17,6 +17,7 @@ #ifndef FLOWGRAPH_UTILITIES_H #define FLOWGRAPH_UTILITIES_H +#include #include using namespace FLOWGRAPH_OUTER_NAMESPACE::flowgraph; @@ -50,6 +51,20 @@ static int32_t clamp32FromFloat(float f) return f > 0 ? f + 0.5 : f - 0.5; } +/** + * Convert a single-precision floating point value to a Q0.23 integer value, stored in a + * 32 bit signed integer (technically stored as Q8.23, but clamped to Q0.23). + * + * Values outside the range [-1.0, 1.0) are properly clamped to -8388608 and 8388607, + * including -Inf and +Inf. NaN values are considered undefined, and behavior may change + * depending on hardware and future implementation of this function. + */ +static int32_t clamp24FromFloat(float f) +{ + static const float scale = 1 << 23; + return (int32_t) lroundf(fmaxf(fminf(f * scale, scale - 1.f), -scale)); +} + }; #endif // FLOWGRAPH_UTILITIES_H diff --git a/internal/oboe/oboe_flowgraph_resampler_MultiChannelResampler_android.cpp b/internal/oboe/oboe_flowgraph_resampler_MultiChannelResampler_android.cpp index 367cb00..89b947a 100644 --- a/internal/oboe/oboe_flowgraph_resampler_MultiChannelResampler_android.cpp +++ b/internal/oboe/oboe_flowgraph_resampler_MultiChannelResampler_android.cpp @@ -120,7 +120,7 @@ void MultiChannelResampler::writeFrame(const float *frame) { } float MultiChannelResampler::sinc(float radians) { - if (abs(radians) < 1.0e-9) return 1.0f; // avoid divide by zero + if (fabsf(radians) < 1.0e-9f) return 1.0f; // avoid divide by zero return sinf(radians) / radians; // Sinc function } diff --git a/internal/oboe/oboe_oboe_AudioStreamBuilder_android.h b/internal/oboe/oboe_oboe_AudioStreamBuilder_android.h index ab8ca4c..ab026d9 100644 --- a/internal/oboe/oboe_oboe_AudioStreamBuilder_android.h +++ b/internal/oboe/oboe_oboe_AudioStreamBuilder_android.h @@ -647,6 +647,14 @@ class AudioStreamBuilder : public AudioStreamBase { private: + /** + * Use this internally to implement opening with a shared_ptr. + * + * @param stream pointer to a variable to receive the stream address + * @return OBOE_OK if successful or a negative error code. + */ + Result openStreamInternal(AudioStream **streamPP); + /** * @param other * @return true if channels, format and sample rate match diff --git a/internal/oboe/oboe_oboe_AudioStreamCallback_android.h b/internal/oboe/oboe_oboe_AudioStreamCallback_android.h index 35e544a..63119bd 100644 --- a/internal/oboe/oboe_oboe_AudioStreamCallback_android.h +++ b/internal/oboe/oboe_oboe_AudioStreamCallback_android.h @@ -48,7 +48,8 @@ class AudioStreamDataCallback { * write() on the stream that is making the callback. * * Note that numFrames can vary unless AudioStreamBuilder::setFramesPerCallback() - * is called. + * is called. If AudioStreamBuilder::setFramesPerCallback() is NOT called then + * numFrames should always be <= AudioStream::getFramesPerBurst(). * * Also note that this callback function should be considered a "real-time" function. * It must not do anything that could cause an unbounded delay because that can cause the diff --git a/internal/oboe/oboe_oboe_AudioStream_android.h b/internal/oboe/oboe_oboe_AudioStream_android.h index b2afb4b..fc9cd55 100644 --- a/internal/oboe/oboe_oboe_AudioStream_android.h +++ b/internal/oboe/oboe_oboe_AudioStream_android.h @@ -194,6 +194,13 @@ class AudioStream : public AudioStreamBase { * * This cannot be set higher than getBufferCapacity(). * + * This should only be used with Output streams. It will + * be ignored for Input streams because they are generally kept as empty as possible. + * + * For OpenSL ES, this method only has an effect on output stream that do NOT + * use a callback. The blocking writes goes into a buffer in Oboe and the size of that + * buffer is controlled by this method. + * * @param requestedFrames requested number of frames that can be filled without blocking * @return the resulting buffer size in frames (obtained using value()) or an error (obtained * using error()) diff --git a/internal/oboe/oboe_oboe_Version_android.h b/internal/oboe/oboe_oboe_Version_android.h index 4c77a67..96ef82b 100644 --- a/internal/oboe/oboe_oboe_Version_android.h +++ b/internal/oboe/oboe_oboe_Version_android.h @@ -37,7 +37,7 @@ #define OBOE_VERSION_MINOR 8 // Type: 16-bit unsigned int. Min value: 0 Max value: 65535. See below for description. -#define OBOE_VERSION_PATCH 0 +#define OBOE_VERSION_PATCH 1 #define OBOE_STRINGIFY(x) #x #define OBOE_TOSTRING(x) OBOE_STRINGIFY(x) diff --git a/internal/oboe/oboe_opensles_AudioOutputStreamOpenSLES_android.cpp b/internal/oboe/oboe_opensles_AudioOutputStreamOpenSLES_android.cpp index 225d93a..45bd12c 100644 --- a/internal/oboe/oboe_opensles_AudioOutputStreamOpenSLES_android.cpp +++ b/internal/oboe/oboe_opensles_AudioOutputStreamOpenSLES_android.cpp @@ -30,9 +30,10 @@ using namespace oboe; static SLuint32 OpenSLES_convertOutputUsage(Usage oboeUsage) { - SLuint32 openslStream = SL_ANDROID_STREAM_MEDIA; + SLuint32 openslStream; switch(oboeUsage) { case Usage::Media: + case Usage::Game: openslStream = SL_ANDROID_STREAM_MEDIA; break; case Usage::VoiceCommunication: @@ -43,18 +44,15 @@ static SLuint32 OpenSLES_convertOutputUsage(Usage oboeUsage) { openslStream = SL_ANDROID_STREAM_ALARM; break; case Usage::Notification: - case Usage::NotificationRingtone: case Usage::NotificationEvent: openslStream = SL_ANDROID_STREAM_NOTIFICATION; break; + case Usage::NotificationRingtone: + openslStream = SL_ANDROID_STREAM_RING; + break; case Usage::AssistanceAccessibility: case Usage::AssistanceNavigationGuidance: case Usage::AssistanceSonification: - openslStream = SL_ANDROID_STREAM_SYSTEM; - break; - case Usage::Game: - openslStream = SL_ANDROID_STREAM_MEDIA; - break; case Usage::Assistant: default: openslStream = SL_ANDROID_STREAM_SYSTEM;