Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
miniaudio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
miniaudio
Commits
bc393dbb
Commit
bc393dbb
authored
Feb 01, 2023
by
David Reid
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Experimental workaround for an Android bug in AAudio.
parent
6720b511
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
33 deletions
+38
-33
miniaudio.h
miniaudio.h
+38
-33
No files found.
miniaudio.h
View file @
bc393dbb
...
@@ -6815,6 +6815,7 @@ struct ma_device_config
...
@@ -6815,6 +6815,7 @@ struct ma_device_config
{
{
ma_opensl_stream_type streamType;
ma_opensl_stream_type streamType;
ma_opensl_recording_preset recordingPreset;
ma_opensl_recording_preset recordingPreset;
ma_bool32 enableCompatibilityWorkarounds;
} opensl;
} opensl;
struct
struct
{
{
...
@@ -6823,6 +6824,7 @@ struct ma_device_config
...
@@ -6823,6 +6824,7 @@ struct ma_device_config
ma_aaudio_input_preset inputPreset;
ma_aaudio_input_preset inputPreset;
ma_aaudio_allowed_capture_policy allowedCapturePolicy;
ma_aaudio_allowed_capture_policy allowedCapturePolicy;
ma_bool32 noAutoStartAfterReroute;
ma_bool32 noAutoStartAfterReroute;
ma_bool32 enableCompatibilityWorkarounds;
} aaudio;
} aaudio;
};
};
...
@@ -11823,6 +11825,20 @@ static MA_INLINE void ma_restore_denormals(unsigned int prevState)
...
@@ -11823,6 +11825,20 @@ static MA_INLINE void ma_restore_denormals(unsigned int prevState)
}
}
#ifdef MA_ANDROID
#include <sys/system_properties.h>
int ma_android_sdk_version()
{
char sdkVersion[PROP_VALUE_MAX + 1] = {0, };
if (__system_property_get("ro.build.version.sdk", sdkVersion)) {
return atoi(sdkVersion);
}
return 0;
}
#endif
#ifndef MA_COINIT_VALUE
#ifndef MA_COINIT_VALUE
#define MA_COINIT_VALUE 0 /* 0 = COINIT_MULTITHREADED */
#define MA_COINIT_VALUE 0 /* 0 = COINIT_MULTITHREADED */
...
@@ -17676,10 +17692,6 @@ DEVICE I/O
...
@@ -17676,10 +17692,6 @@ DEVICE I/O
#include <mach/mach_time.h> /* For mach_absolute_time() */
#include <mach/mach_time.h> /* For mach_absolute_time() */
#endif
#endif
#ifdef MA_ANDROID
#include <sys/system_properties.h>
#endif
#ifdef MA_POSIX
#ifdef MA_POSIX
#include <sys/types.h>
#include <sys/types.h>
#include <unistd.h>
#include <unistd.h>
...
@@ -17836,16 +17848,7 @@ MA_API ma_bool32 ma_is_backend_enabled(ma_backend backend)
...
@@ -17836,16 +17848,7 @@ MA_API ma_bool32 ma_is_backend_enabled(ma_backend backend)
#if defined(MA_HAS_AAUDIO)
#if defined(MA_HAS_AAUDIO)
#if defined(MA_ANDROID)
#if defined(MA_ANDROID)
{
{
char sdkVersion[PROP_VALUE_MAX + 1] = {0, };
return ma_android_sdk_version() >= 26;
if (__system_property_get("ro.build.version.sdk", sdkVersion)) {
if (atoi(sdkVersion) >= 26) {
return MA_TRUE;
} else {
return MA_FALSE;
}
} else {
return MA_FALSE;
}
}
}
#else
#else
return MA_FALSE;
return MA_FALSE;
...
@@ -17857,16 +17860,7 @@ MA_API ma_bool32 ma_is_backend_enabled(ma_backend backend)
...
@@ -17857,16 +17860,7 @@ MA_API ma_bool32 ma_is_backend_enabled(ma_backend backend)
#if defined(MA_HAS_OPENSL)
#if defined(MA_HAS_OPENSL)
#if defined(MA_ANDROID)
#if defined(MA_ANDROID)
{
{
char sdkVersion[PROP_VALUE_MAX + 1] = {0, };
return ma_android_sdk_version() >= 9;
if (__system_property_get("ro.build.version.sdk", sdkVersion)) {
if (atoi(sdkVersion) >= 9) {
return MA_TRUE;
} else {
return MA_FALSE;
}
} else {
return MA_FALSE;
}
}
}
#else
#else
return MA_TRUE;
return MA_TRUE;
...
@@ -36910,6 +36904,9 @@ static ma_result ma_context_init__oss(ma_context* pContext, const ma_context_con
...
@@ -36910,6 +36904,9 @@ static ma_result ma_context_init__oss(ma_context* pContext, const ma_context_con
#endif /* OSS */
#endif /* OSS */
/******************************************************************************
/******************************************************************************
AAudio Backend
AAudio Backend
...
@@ -37181,7 +37178,6 @@ static ma_result ma_create_and_configure_AAudioStreamBuilder__aaudio(ma_context*
...
@@ -37181,7 +37178,6 @@ static ma_result ma_create_and_configure_AAudioStreamBuilder__aaudio(ma_context*
{
{
ma_AAudioStreamBuilder* pBuilder;
ma_AAudioStreamBuilder* pBuilder;
ma_aaudio_result_t resultAA;
ma_aaudio_result_t resultAA;
ma_uint32 bufferCapacityInFrames;
/* Safety. */
/* Safety. */
*ppBuilder = NULL;
*ppBuilder = NULL;
...
@@ -37223,17 +37219,26 @@ static ma_result ma_create_and_configure_AAudioStreamBuilder__aaudio(ma_context*
...
@@ -37223,17 +37219,26 @@ static ma_result ma_create_and_configure_AAudioStreamBuilder__aaudio(ma_context*
}
}
}
}
/*
AAudio is annoying when it comes to it's buffer calculation stuff because it doesn't let you
retrieve the actual sample rate until after you've opened the stream. But you need to configure
the buffer capacity before you open the stream... :/
To solve, we're just going to assume MA_DEFAULT_SAMPLE_RATE (48000) and move on.
/*
There have been reports where setting the frames per data callback results in an error
later on from Android. To address this, I'm experimenting with simply not setting it on
anything from Android 11 and earlier. Suggestions welcome on how we might be able to make
this more targetted.
*/
*/
bufferCapacityInFrames = ma_calculate_buffer_size_in_frames_from_descriptor(pDescriptor, pDescriptor->sampleRate, pConfig->performanceProfile) * pDescriptor->periodCount;
if (pConfig->aaudio.enableCompatibilityWorkarounds && ma_android_sdk_version() > 30) {
/*
AAudio is annoying when it comes to it's buffer calculation stuff because it doesn't let you
retrieve the actual sample rate until after you've opened the stream. But you need to configure
the buffer capacity before you open the stream... :/
To solve, we're just going to assume MA_DEFAULT_SAMPLE_RATE (48000) and move on.
*/
ma_uint32 bufferCapacityInFrames = ma_calculate_buffer_size_in_frames_from_descriptor(pDescriptor, pDescriptor->sampleRate, pConfig->performanceProfile) * pDescriptor->periodCount;
((MA_PFN_AAudioStreamBuilder_setBufferCapacityInFrames)pContext->aaudio.AAudioStreamBuilder_setBufferCapacityInFrames)(pBuilder, bufferCapacityInFrames);
((MA_PFN_AAudioStreamBuilder_setBufferCapacityInFrames)pContext->aaudio.AAudioStreamBuilder_setBufferCapacityInFrames)(pBuilder, bufferCapacityInFrames);
((MA_PFN_AAudioStreamBuilder_setFramesPerDataCallback)pContext->aaudio.AAudioStreamBuilder_setFramesPerDataCallback)(pBuilder, bufferCapacityInFrames / pDescriptor->periodCount);
((MA_PFN_AAudioStreamBuilder_setFramesPerDataCallback)pContext->aaudio.AAudioStreamBuilder_setFramesPerDataCallback)(pBuilder, bufferCapacityInFrames / pDescriptor->periodCount);
}
if (deviceType == ma_device_type_capture) {
if (deviceType == ma_device_type_capture) {
if (pConfig->aaudio.inputPreset != ma_aaudio_input_preset_default && pContext->aaudio.AAudioStreamBuilder_setInputPreset != NULL) {
if (pConfig->aaudio.inputPreset != ma_aaudio_input_preset_default && pContext->aaudio.AAudioStreamBuilder_setInputPreset != NULL) {
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment