Potential fixes for audio on RPI and Emscripten builds.
This commit is contained in:
parent
5463e14886
commit
a0d9913c7c
10
src/audio.c
10
src/audio.c
@ -393,14 +393,23 @@ void InitAudioDevice(void)
|
|||||||
mal_result result = mal_context_init(NULL, 0, &contextConfig, &context);
|
mal_result result = mal_context_init(NULL, 0, &contextConfig, &context);
|
||||||
if (result != MAL_SUCCESS)
|
if (result != MAL_SUCCESS)
|
||||||
{
|
{
|
||||||
|
TraceLog(LOG_ERROR, "Failed to initialize audio context");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Device. Using the default device. Format is floating point because it simplifies mixing.
|
// Device. Using the default device. Format is floating point because it simplifies mixing.
|
||||||
mal_device_config deviceConfig = mal_device_config_init(DEVICE_FORMAT, DEVICE_CHANNELS, DEVICE_SAMPLE_RATE, NULL, OnSendAudioDataToDevice);
|
mal_device_config deviceConfig = mal_device_config_init(DEVICE_FORMAT, DEVICE_CHANNELS, DEVICE_SAMPLE_RATE, NULL, OnSendAudioDataToDevice);
|
||||||
|
|
||||||
|
// Special case for PLATFORM_RPI.
|
||||||
|
#if defined(PLATFORM_RPI)
|
||||||
|
deviceConfig.alsa.noMMap = MAL_TRUE;
|
||||||
|
deviceConfig.bufferSizeInFrames = 2048;
|
||||||
|
#endif
|
||||||
|
|
||||||
result = mal_device_init(&context, mal_device_type_playback, NULL, &deviceConfig, NULL, &device);
|
result = mal_device_init(&context, mal_device_type_playback, NULL, &deviceConfig, NULL, &device);
|
||||||
if (result != MAL_SUCCESS)
|
if (result != MAL_SUCCESS)
|
||||||
{
|
{
|
||||||
|
TraceLog(LOG_ERROR, "Failed to initialize audio playback device");
|
||||||
mal_context_uninit(&context);
|
mal_context_uninit(&context);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -410,6 +419,7 @@ void InitAudioDevice(void)
|
|||||||
result = mal_device_start(&device);
|
result = mal_device_start(&device);
|
||||||
if (result != MAL_SUCCESS)
|
if (result != MAL_SUCCESS)
|
||||||
{
|
{
|
||||||
|
TraceLog(LOG_ERROR, "Failed to start audio playback device");
|
||||||
mal_device_uninit(&device);
|
mal_device_uninit(&device);
|
||||||
mal_context_uninit(&context);
|
mal_context_uninit(&context);
|
||||||
return;
|
return;
|
||||||
|
11
src/external/mini_al.h
vendored
11
src/external/mini_al.h
vendored
@ -8634,7 +8634,7 @@ mal_result mal_device_init__sdl(mal_context* pContext, mal_device_type type, mal
|
|||||||
|
|
||||||
// SDL wants the buffer size to be a power of 2. The SDL_AudioSpec property for this is only a Uint16, so we need
|
// SDL wants the buffer size to be a power of 2. The SDL_AudioSpec property for this is only a Uint16, so we need
|
||||||
// to explicitly clamp this because it will be easy to overflow.
|
// to explicitly clamp this because it will be easy to overflow.
|
||||||
mal_uint32 bufferSize = pConfig->bufferSizeInFrames * pConfig->periods * pConfig->channels;
|
mal_uint32 bufferSize = pConfig->bufferSizeInFrames;
|
||||||
if (bufferSize > 32768) {
|
if (bufferSize > 32768) {
|
||||||
bufferSize = 32768;
|
bufferSize = 32768;
|
||||||
} else {
|
} else {
|
||||||
@ -8696,7 +8696,7 @@ mal_result mal_device_init__sdl(mal_context* pContext, mal_device_type type, mal
|
|||||||
pDevice->internalFormat = mal_format_from_sdl(obtainedSpec.format);
|
pDevice->internalFormat = mal_format_from_sdl(obtainedSpec.format);
|
||||||
pDevice->internalChannels = obtainedSpec.channels;
|
pDevice->internalChannels = obtainedSpec.channels;
|
||||||
pDevice->internalSampleRate = (mal_uint32)obtainedSpec.freq;
|
pDevice->internalSampleRate = (mal_uint32)obtainedSpec.freq;
|
||||||
pDevice->bufferSizeInFrames = obtainedSpec.samples / obtainedSpec.channels;
|
pDevice->bufferSizeInFrames = obtainedSpec.samples;
|
||||||
pDevice->periods = 1; // SDL doesn't seem to tell us what the period count is. Just set this 1.
|
pDevice->periods = 1; // SDL doesn't seem to tell us what the period count is. Just set this 1.
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
@ -10980,6 +10980,7 @@ const char* mal_get_backend_name(mal_backend backend)
|
|||||||
case mal_backend_oss: return "OSS";
|
case mal_backend_oss: return "OSS";
|
||||||
case mal_backend_opensl: return "OpenSL|ES";
|
case mal_backend_opensl: return "OpenSL|ES";
|
||||||
case mal_backend_openal: return "OpenAL";
|
case mal_backend_openal: return "OpenAL";
|
||||||
|
case mal_backend_sdl: return "SDL";
|
||||||
default: return "Unknown";
|
default: return "Unknown";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -11197,7 +11198,8 @@ void mal_pcm_s32_to_f32(float* pOut, const int* pIn, unsigned int count)
|
|||||||
for (unsigned int i = 0; i < count; ++i) {
|
for (unsigned int i = 0; i < count; ++i) {
|
||||||
int x = pIn[i];
|
int x = pIn[i];
|
||||||
double t;
|
double t;
|
||||||
t = (double)(x + 2147483648LL);
|
t = (double)(x + 2147483647);
|
||||||
|
t = t + 1;
|
||||||
t = t * 0.0000000004656612873077392578125;
|
t = t * 0.0000000004656612873077392578125;
|
||||||
r = (float)(t - 1);
|
r = (float)(t - 1);
|
||||||
pOut[i] = (float)r;
|
pOut[i] = (float)r;
|
||||||
@ -11255,7 +11257,8 @@ void mal_pcm_f32_to_s32(int* pOut, const float* pIn, unsigned int count)
|
|||||||
c = ((x < -1) ? -1 : ((x > 1) ? 1 : x));
|
c = ((x < -1) ? -1 : ((x > 1) ? 1 : x));
|
||||||
c = c + 1;
|
c = c + 1;
|
||||||
t = (mal_int64)(c * 2147483647.5);
|
t = (mal_int64)(c * 2147483647.5);
|
||||||
r = (int)(t - 2147483648LL);
|
t = t - 2147483647;
|
||||||
|
r = (int)(t - 1);
|
||||||
pOut[i] = (int)r;
|
pOut[i] = (int)r;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user