Commit 0f5cb782 authored by David Reid's avatar David Reid

Version 0.10.38

parent 922c9599
/*
Audio playback and capture library. Choice of public domain or MIT-0. See license statements at the end of this file.
miniaudio - v0.10.37 - 2021-07-06
miniaudio - v0.10.38 - 2021-07-14
David Reid - mackron@gmail.com
......@@ -1950,8 +1950,6 @@ static ma_result ma_allocation_callbacks_init_copy(ma_allocation_callbacks* pDst
Logging
**************************************************************************************************************************************************************/
#if defined(MA_DEBUG_OUTPUT)
MA_API const char* ma_log_level_to_string(ma_uint32 logLevel)
{
switch (logLevel)
......@@ -1964,6 +1962,8 @@ MA_API const char* ma_log_level_to_string(ma_uint32 logLevel)
}
}
#if defined(MA_DEBUG_OUTPUT)
/* Customize this to use a specific tag in __android_log_print() for debug output messages. */
#ifndef MA_ANDROID_LOG_TAG
#define MA_ANDROID_LOG_TAG "miniaudio"
......@@ -2246,7 +2246,9 @@ MA_API ma_result ma_log_postv(ma_log* pLog, ma_uint32 level, const char* pFormat
*/
#if defined(_MSC_VER) && _MSC_VER >= 1200 /* 1200 = VC6 */
{
ma_result result;
int formattedLen;
char* pFormattedMessage = NULL;
va_list args2;
#if _MSC_VER >= 1800
......@@ -2262,32 +2264,30 @@ MA_API ma_result ma_log_postv(ma_log* pLog, ma_uint32 level, const char* pFormat
formattedLen = ma_vscprintf(&pLog->allocationCallbacks, pFormat, args2);
va_end(args2);
if (formattedLen > 0) {
char* pFormattedMessage = NULL;
if (formattedLen <= 0) {
return MA_INVALID_OPERATION;
}
pFormattedMessage = (char*)ma_malloc(formattedLen + 1, &pLog->allocationCallbacks);
if (pFormattedMessage != NULL) {
ma_result result;
pFormattedMessage = (char*)ma_malloc(formattedLen + 1, &pLog->allocationCallbacks);
if (pFormattedMessage == NULL) {
return MA_OUT_OF_MEMORY;
}
/* We'll get errors on newer versions of Visual Studio if we try to use vsprintf(). */
#if _MSC_VER >= 1400 /* 1400 = Visual Studio 2005 */
{
vsprintf_s(pFormattedMessage, formattedLen + 1, pFormat, args);
}
#else
{
vsprintf(pFormattedMessage, pFormat, args);
}
#endif
/* We'll get errors on newer versions of Visual Studio if we try to use vsprintf(). */
#if _MSC_VER >= 1400 /* 1400 = Visual Studio 2005 */
{
vsprintf_s(pFormattedMessage, formattedLen + 1, pFormat, args);
}
#else
{
vsprintf(pFormattedMessage, pFormat, args);
}
#endif
result = ma_log_post(pLog, level, pFormattedMessage);
ma_free(pFormattedMessage, &pLog->allocationCallbacks);
result = ma_log_post(pLog, level, pFormattedMessage);
ma_free(pFormattedMessage, &pLog->allocationCallbacks);
return result;
}
} else {
return MA_INVALID_OPERATION;
}
return result;
}
#else
{
......@@ -15210,6 +15210,7 @@ to check for type safety. We cannot do this when linking at run time because the
#define MA_PA_ERR_ACCESS PA_ERR_ACCESS
#define MA_PA_ERR_INVALID PA_ERR_INVALID
#define MA_PA_ERR_NOENTITY PA_ERR_NOENTITY
#define MA_PA_ERR_NOTSUPPORTED PA_ERR_NOTSUPPORTED
#define MA_PA_CHANNELS_MAX PA_CHANNELS_MAX
#define MA_PA_RATE_MAX PA_RATE_MAX
......@@ -15405,12 +15406,14 @@ typedef pa_sink_info_cb_t ma_pa_sink_info_cb_t;
typedef pa_source_info_cb_t ma_pa_source_info_cb_t;
typedef pa_stream_success_cb_t ma_pa_stream_success_cb_t;
typedef pa_stream_request_cb_t ma_pa_stream_request_cb_t;
typedef pa_stream_notify_cb_t ma_pa_stream_notify_cb_t;
typedef pa_free_cb_t ma_pa_free_cb_t;
#else
#define MA_PA_OK 0
#define MA_PA_ERR_ACCESS 1
#define MA_PA_ERR_INVALID 2
#define MA_PA_ERR_NOENTITY 5
#define MA_PA_ERR_NOTSUPPORTED 19
#define MA_PA_CHANNELS_MAX 32
#define MA_PA_RATE_MAX 384000
......@@ -15684,6 +15687,7 @@ typedef void (* ma_pa_sink_info_cb_t) (ma_pa_context* c, const ma_pa_sink_in
typedef void (* ma_pa_source_info_cb_t) (ma_pa_context* c, const ma_pa_source_info* i, int eol, void* userdata);
typedef void (* ma_pa_stream_success_cb_t)(ma_pa_stream* s, int success, void* userdata);
typedef void (* ma_pa_stream_request_cb_t)(ma_pa_stream* s, size_t nbytes, void* userdata);
typedef void (* ma_pa_stream_notify_cb_t) (ma_pa_stream* s, void* userdata);
typedef void (* ma_pa_free_cb_t) (void* p);
#endif
......@@ -15735,6 +15739,8 @@ typedef ma_pa_operation* (* ma_pa_stream_set_buffer_attr_proc) (
typedef const char* (* ma_pa_stream_get_device_name_proc) (ma_pa_stream* s);
typedef void (* ma_pa_stream_set_write_callback_proc) (ma_pa_stream* s, ma_pa_stream_request_cb_t cb, void* userdata);
typedef void (* ma_pa_stream_set_read_callback_proc) (ma_pa_stream* s, ma_pa_stream_request_cb_t cb, void* userdata);
typedef void (* ma_pa_stream_set_suspended_callback_proc) (ma_pa_stream* s, ma_pa_stream_notify_cb_t cb, void* userdata);
typedef int (* ma_pa_stream_is_suspended_proc) (const ma_pa_stream* s);
typedef ma_pa_operation* (* ma_pa_stream_flush_proc) (ma_pa_stream* s, ma_pa_stream_success_cb_t cb, void* userdata);
typedef ma_pa_operation* (* ma_pa_stream_drain_proc) (ma_pa_stream* s, ma_pa_stream_success_cb_t cb, void* userdata);
typedef int (* ma_pa_stream_is_corked_proc) (ma_pa_stream* s);
......@@ -16607,6 +16613,36 @@ static void ma_device_on_write__pulse(ma_pa_stream* pStream, size_t byteCount, v
}
}
static void ma_device_on_suspended__pulse(ma_pa_stream* pStream, void* pUserData)
{
ma_device* pDevice = (ma_device*)pUserData;
int suspended;
(void)pStream;
suspended = ((ma_pa_stream_is_suspended_proc)pDevice->pContext->pulse.pa_stream_is_suspended)(pStream);
ma_log_postf(ma_device_get_log(pDevice), MA_LOG_LEVEL_DEBUG, "[Pulse] Device suspended state changed. pa_stream_is_suspended() returned %d.\n", suspended);
if (suspended < 0) {
return;
}
if (suspended == 1) {
ma_log_post(ma_device_get_log(pDevice), MA_LOG_LEVEL_DEBUG, "[Pulse] Device suspended state changed. Suspended.\n");
/* Locking this behind MA_DEBUG_OUTPUT for the moment while this is still in an experimental state. */
#if defined(MA_DEBUG_OUTPUT)
{
if (pDevice->onStop) {
pDevice->onStop(pDevice);
}
}
#endif
} else {
ma_log_post(ma_device_get_log(pDevice), MA_LOG_LEVEL_DEBUG, "[Pulse] Device suspended state changed. Resumed.\n");
}
}
static ma_result ma_device_init__pulse(ma_device* pDevice, const ma_device_config* pConfig, ma_device_descriptor* pDescriptorPlayback, ma_device_descriptor* pDescriptorCapture)
{
/*
......@@ -16826,6 +16862,9 @@ static ma_result ma_device_init__pulse(ma_device* pDevice, const ma_device_confi
*/
((ma_pa_stream_set_write_callback_proc)pDevice->pContext->pulse.pa_stream_set_write_callback)((ma_pa_stream*)pDevice->pulse.pStreamPlayback, ma_device_on_write__pulse, pDevice);
/* State callback for checking when the device has been corked. */
((ma_pa_stream_set_suspended_callback_proc)pDevice->pContext->pulse.pa_stream_set_suspended_callback)((ma_pa_stream*)pDevice->pulse.pStreamPlayback, ma_device_on_suspended__pulse, pDevice);
/* Connect after we've got all of our internal state set up. */
streamFlags = MA_PA_STREAM_START_CORKED | MA_PA_STREAM_ADJUST_LATENCY | MA_PA_STREAM_FIX_FORMAT | MA_PA_STREAM_FIX_RATE | MA_PA_STREAM_FIX_CHANNELS;
......@@ -17146,6 +17185,8 @@ static ma_result ma_context_init__pulse(ma_context* pContext, const ma_context_c
pContext->pulse.pa_stream_get_device_name = (ma_proc)ma_dlsym(pContext, pContext->pulse.pulseSO, "pa_stream_get_device_name");
pContext->pulse.pa_stream_set_write_callback = (ma_proc)ma_dlsym(pContext, pContext->pulse.pulseSO, "pa_stream_set_write_callback");
pContext->pulse.pa_stream_set_read_callback = (ma_proc)ma_dlsym(pContext, pContext->pulse.pulseSO, "pa_stream_set_read_callback");
pContext->pulse.pa_stream_set_suspended_callback = (ma_proc)ma_dlsym(pContext, pContext->pulse.pulseSO, "pa_stream_set_suspended_callback");
pContext->pulse.pa_stream_is_suspended = (ma_proc)ma_dlsym(pContext, pContext->pulse.pulseSO, "pa_stream_is_suspended");
pContext->pulse.pa_stream_flush = (ma_proc)ma_dlsym(pContext, pContext->pulse.pulseSO, "pa_stream_flush");
pContext->pulse.pa_stream_drain = (ma_proc)ma_dlsym(pContext, pContext->pulse.pulseSO, "pa_stream_drain");
pContext->pulse.pa_stream_is_corked = (ma_proc)ma_dlsym(pContext, pContext->pulse.pulseSO, "pa_stream_is_corked");
......@@ -17206,6 +17247,8 @@ static ma_result ma_context_init__pulse(ma_context* pContext, const ma_context_c
ma_pa_stream_get_device_name_proc _pa_stream_get_device_name = pa_stream_get_device_name;
ma_pa_stream_set_write_callback_proc _pa_stream_set_write_callback = pa_stream_set_write_callback;
ma_pa_stream_set_read_callback_proc _pa_stream_set_read_callback = pa_stream_set_read_callback;
ma_pa_stream_set_suspended_callback_proc _pa_stream_set_suspended_callback = pa_stream_set_suspended_callback;
ma_pa_stream_is_suspended_proc _pa_stream_is_suspended = pa_stream_is_suspended;
ma_pa_stream_flush_proc _pa_stream_flush = pa_stream_flush;
ma_pa_stream_drain_proc _pa_stream_drain = pa_stream_drain;
ma_pa_stream_is_corked_proc _pa_stream_is_corked = pa_stream_is_corked;
......@@ -17265,6 +17308,8 @@ static ma_result ma_context_init__pulse(ma_context* pContext, const ma_context_c
pContext->pulse.pa_stream_get_device_name = (ma_proc)_pa_stream_get_device_name;
pContext->pulse.pa_stream_set_write_callback = (ma_proc)_pa_stream_set_write_callback;
pContext->pulse.pa_stream_set_read_callback = (ma_proc)_pa_stream_set_read_callback;
pContext->pulse.pa_stream_set_suspended_callback = (ma_proc)_pa_stream_set_suspended_callback;
pContext->pulse.pa_stream_is_suspended = (ma_proc)_pa_stream_is_suspended;
pContext->pulse.pa_stream_flush = (ma_proc)_pa_stream_flush;
pContext->pulse.pa_stream_drain = (ma_proc)_pa_stream_drain;
pContext->pulse.pa_stream_is_corked = (ma_proc)_pa_stream_is_corked;
......@@ -24901,8 +24946,11 @@ static ma_result ma_device_init__opensl(ma_device* pDevice, const ma_device_conf
SLDataLocator_AndroidSimpleBufferQueue queue;
SLresult resultSL;
size_t bufferSizeInBytes;
SLInterfaceID itfIDs1[1];
const SLboolean itfIDsRequired1[] = {SL_BOOLEAN_TRUE};
SLInterfaceID itfIDs[2];
const SLboolean itfIDsRequired[] = {
SL_BOOLEAN_TRUE, /* SL_IID_ANDROIDSIMPLEBUFFERQUEUE */
SL_BOOLEAN_FALSE /* SL_IID_ANDROIDCONFIGURATION */
};
#endif
MA_ASSERT(g_maOpenSLInitCounter > 0); /* <-- If you trigger this it means you've either not initialized the context, or you've uninitialized it and then attempted to initialize a new device. */
......@@ -24920,7 +24968,8 @@ static ma_result ma_device_init__opensl(ma_device* pDevice, const ma_device_conf
queues).
*/
#ifdef MA_ANDROID
itfIDs1[0] = (SLInterfaceID)pDevice->pContext->opensl.SL_IID_ANDROIDSIMPLEBUFFERQUEUE;
itfIDs[0] = (SLInterfaceID)pDevice->pContext->opensl.SL_IID_ANDROIDSIMPLEBUFFERQUEUE;
itfIDs[1] = (SLInterfaceID)pDevice->pContext->opensl.SL_IID_ANDROIDCONFIGURATION;
/* No exclusive mode with OpenSL|ES. */
if (((pConfig->deviceType == ma_device_type_playback || pConfig->deviceType == ma_device_type_duplex) && pDescriptorPlayback->shareMode == ma_share_mode_exclusive) ||
......@@ -24956,7 +25005,7 @@ static ma_result ma_device_init__opensl(ma_device* pDevice, const ma_device_conf
sink.pLocator = &queue;
sink.pFormat = (SLDataFormat_PCM*)&pcm;
resultSL = (*g_maEngineSL)->CreateAudioRecorder(g_maEngineSL, (SLObjectItf*)&pDevice->opensl.pAudioRecorderObj, &source, &sink, 1, itfIDs1, itfIDsRequired1);
resultSL = (*g_maEngineSL)->CreateAudioRecorder(g_maEngineSL, (SLObjectItf*)&pDevice->opensl.pAudioRecorderObj, &source, &sink, ma_countof(itfIDs), itfIDs, itfIDsRequired);
if (resultSL == SL_RESULT_CONTENT_UNSUPPORTED) {
/* Unsupported format. Fall back to something safer and try again. If this fails, just abort. */
pcm.formatType = SL_DATAFORMAT_PCM;
......@@ -24965,7 +25014,7 @@ static ma_result ma_device_init__opensl(ma_device* pDevice, const ma_device_conf
pcm.bitsPerSample = 16;
pcm.containerSize = pcm.bitsPerSample; /* Always tightly packed for now. */
pcm.channelMask = SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT;
resultSL = (*g_maEngineSL)->CreateAudioRecorder(g_maEngineSL, (SLObjectItf*)&pDevice->opensl.pAudioRecorderObj, &source, &sink, 1, itfIDs1, itfIDsRequired1);
resultSL = (*g_maEngineSL)->CreateAudioRecorder(g_maEngineSL, (SLObjectItf*)&pDevice->opensl.pAudioRecorderObj, &source, &sink, ma_countof(itfIDs), itfIDs, itfIDsRequired);
}
if (resultSL != SL_RESULT_SUCCESS) {
......@@ -25070,7 +25119,7 @@ static ma_result ma_device_init__opensl(ma_device* pDevice, const ma_device_conf
sink.pLocator = &outmixLocator;
sink.pFormat = NULL;
resultSL = (*g_maEngineSL)->CreateAudioPlayer(g_maEngineSL, (SLObjectItf*)&pDevice->opensl.pAudioPlayerObj, &source, &sink, 1, itfIDs1, itfIDsRequired1);
resultSL = (*g_maEngineSL)->CreateAudioPlayer(g_maEngineSL, (SLObjectItf*)&pDevice->opensl.pAudioPlayerObj, &source, &sink, ma_countof(itfIDs), itfIDs, itfIDsRequired);
if (resultSL == SL_RESULT_CONTENT_UNSUPPORTED) {
/* Unsupported format. Fall back to something safer and try again. If this fails, just abort. */
pcm.formatType = SL_DATAFORMAT_PCM;
......@@ -25079,7 +25128,7 @@ static ma_result ma_device_init__opensl(ma_device* pDevice, const ma_device_conf
pcm.bitsPerSample = 16;
pcm.containerSize = pcm.bitsPerSample; /* Always tightly packed for now. */
pcm.channelMask = SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT;
resultSL = (*g_maEngineSL)->CreateAudioPlayer(g_maEngineSL, (SLObjectItf*)&pDevice->opensl.pAudioPlayerObj, &source, &sink, 1, itfIDs1, itfIDsRequired1);
resultSL = (*g_maEngineSL)->CreateAudioPlayer(g_maEngineSL, (SLObjectItf*)&pDevice->opensl.pAudioPlayerObj, &source, &sink, ma_countof(itfIDs), itfIDs, itfIDsRequired);
}
if (resultSL != SL_RESULT_SUCCESS) {
......@@ -43760,6 +43809,14 @@ static ma_result ma_decoder_init__internal(ma_decoder_read_proc onRead, ma_decod
}
}
/*
If we get to this point and we still haven't found a decoder, and the caller has requested a
specific encoding format, there's no hope for it. Abort.
*/
if (pConfig->encodingFormat != ma_encoding_format_unknown) {
return MA_NO_BACKEND;
}
#ifdef MA_HAS_WAV
if (result != MA_SUCCESS) {
result = ma_decoder_init_wav__internal(pConfig, pDecoder);
......@@ -44277,6 +44334,26 @@ MA_API ma_result ma_decoder_init_vfs(ma_vfs* pVFS, const char* pFilePath, const
if (result != MA_SUCCESS) {
/* Getting here means we weren't able to initialize a decoder of a specific encoding format. */
/*
We use trial and error to open a decoder. We prioritize custom decoders so that if they
implement the same encoding format they take priority over the built-in decoders.
*/
if (result != MA_SUCCESS) {
result = ma_decoder_init_custom__internal(&config, pDecoder);
if (result != MA_SUCCESS) {
ma_decoder__on_seek_vfs(pDecoder, 0, ma_seek_origin_start);
}
}
/*
If we get to this point and we still haven't found a decoder, and the caller has requested a
specific encoding format, there's no hope for it. Abort.
*/
if (config.encodingFormat != ma_encoding_format_unknown) {
return MA_NO_BACKEND;
}
#ifdef MA_HAS_WAV
if (result != MA_SUCCESS && ma_path_extension_equal(pFilePath, "wav")) {
result = ma_decoder_init_wav__internal(&config, pDecoder);
......@@ -44463,6 +44540,26 @@ MA_API ma_result ma_decoder_init_vfs_w(ma_vfs* pVFS, const wchar_t* pFilePath, c
if (result != MA_SUCCESS) {
/* Getting here means we weren't able to initialize a decoder of a specific encoding format. */
/*
We use trial and error to open a decoder. We prioritize custom decoders so that if they
implement the same encoding format they take priority over the built-in decoders.
*/
if (result != MA_SUCCESS) {
result = ma_decoder_init_custom__internal(&config, pDecoder);
if (result != MA_SUCCESS) {
ma_decoder__on_seek_vfs(pDecoder, 0, ma_seek_origin_start);
}
}
/*
If we get to this point and we still haven't found a decoder, and the caller has requested a
specific encoding format, there's no hope for it. Abort.
*/
if (config.encodingFormat != ma_encoding_format_unknown) {
return MA_NO_BACKEND;
}
#ifdef MA_HAS_WAV
if (result != MA_SUCCESS && ma_path_extension_equal_w(pFilePath, L"wav")) {
result = ma_decoder_init_wav__internal(&config, pDecoder);
/*
Audio playback and capture library. Choice of public domain or MIT-0. See license statements at the end of this file.
miniaudio - v0.10.37 - 2021-07-06
miniaudio - v0.10.38 - 2021-07-14
David Reid - mackron@gmail.com
......@@ -20,7 +20,7 @@ extern "C" {
#define MA_VERSION_MAJOR 0
#define MA_VERSION_MINOR 10
#define MA_VERSION_REVISION 37
#define MA_VERSION_REVISION 38
#define MA_VERSION_STRING MA_XSTRINGIFY(MA_VERSION_MAJOR) "." MA_XSTRINGIFY(MA_VERSION_MINOR) "." MA_XSTRINGIFY(MA_VERSION_REVISION)
#if defined(_MSC_VER) && !defined(__clang__)
......@@ -2384,6 +2384,8 @@ struct ma_context
ma_proc pa_stream_get_device_name;
ma_proc pa_stream_set_write_callback;
ma_proc pa_stream_set_read_callback;
ma_proc pa_stream_set_suspended_callback;
ma_proc pa_stream_is_suspended;
ma_proc pa_stream_flush;
ma_proc pa_stream_drain;
ma_proc pa_stream_is_corked;
......
/*
Audio playback and capture library. Choice of public domain or MIT-0. See license statements at the end of this file.
miniaudio - v0.10.38 - TBD
miniaudio - v0.10.38 - 2021-07-14
David Reid - mackron@gmail.com
......@@ -69393,7 +69393,7 @@ The following miscellaneous changes have also been made.
/*
REVISION HISTORY
================
v0.10.38 - TBD
v0.10.38 - 2021-07-14
- Fix a linking error when MA_DEBUG_OUTPUT is not enabled.
- Fix an error where ma_log_postv() does not return a value.
- OpenSL: Fix a bug with setting of stream types and recording presets.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment