diff --git a/jni/OpenAL/Alc/ALc.c b/jni/OpenAL/Alc/ALc.c index c57e02b..8f4d7a4 100644 --- a/jni/OpenAL/Alc/ALc.c +++ b/jni/OpenAL/Alc/ALc.c @@ -1193,6 +1193,7 @@ static ALvoid InitContext(ALCcontext *pContext) pContext->DopplerFactor = int2ALfp(1); pContext->DopplerVelocity = int2ALfp(1); pContext->flSpeedOfSound = float2ALfp(SPEEDOFSOUNDMETRESPERSEC); + pContext->PrioritySlots = 0; pContext->ExtensionList = alExtList; } diff --git a/jni/OpenAL/OpenAL32/Include/alMain.h b/jni/OpenAL/OpenAL32/Include/alMain.h index af3fc25..61448b2 100644 --- a/jni/OpenAL/OpenAL32/Include/alMain.h +++ b/jni/OpenAL/OpenAL32/Include/alMain.h @@ -449,6 +449,9 @@ struct ALCcontext_struct ALsizei ActiveSourceCount; ALsizei MaxActiveSources; + // Apportable Extension + ALsizei PrioritySlots; + ALCdevice *Device; const ALCchar *ExtensionList; diff --git a/jni/OpenAL/OpenAL32/Include/alSource.h b/jni/OpenAL/OpenAL32/Include/alSource.h index c802212..b4a91e9 100644 --- a/jni/OpenAL/OpenAL32/Include/alSource.h +++ b/jni/OpenAL/OpenAL32/Include/alSource.h @@ -52,6 +52,9 @@ typedef struct ALsource ALboolean bLooping; ALenum DistanceModel; + // Apportably Extension + ALuint priority; + resampler_t Resampler; ALenum state; diff --git a/jni/OpenAL/OpenAL32/alExtension.c b/jni/OpenAL/OpenAL32/alExtension.c index 0febf22..2ec8c80 100644 --- a/jni/OpenAL/OpenAL32/alExtension.c +++ b/jni/OpenAL/OpenAL32/alExtension.c @@ -176,6 +176,10 @@ static const ALenums enumeration[] = { { "AL_EXPONENT_DISTANCE", AL_EXPONENT_DISTANCE }, { "AL_EXPONENT_DISTANCE_CLAMPED", AL_EXPONENT_DISTANCE_CLAMPED }, + // Apportable Extensions + { "AL_PRIORITY", AL_PRIORITY }, + { "AL_PRIORITY_SLOTS", AL_PRIORITY_SLOTS }, + // Filter types { "AL_FILTER_TYPE", AL_FILTER_TYPE }, { "AL_FILTER_NULL", AL_FILTER_NULL }, diff --git a/jni/OpenAL/OpenAL32/alListener.c b/jni/OpenAL/OpenAL32/alListener.c index c21c605..78e6583 100644 --- a/jni/OpenAL/OpenAL32/alListener.c +++ b/jni/OpenAL/OpenAL32/alListener.c @@ -193,6 +193,10 @@ AL_API ALvoid AL_APIENTRY alListeneri(ALenum eParam, ALint lValue) switch(eParam) { + case AL_PRIORITY_SLOTS: + pContext->PrioritySlots = (ALsizei)lValue; + break; + default: alSetError(pContext, AL_INVALID_ENUM); break; @@ -397,6 +401,10 @@ AL_API ALvoid AL_APIENTRY alGetListeneri(ALenum eParam, ALint *plValue) { switch(eParam) { + case AL_PRIORITY_SLOTS: + *plValue = (ALint)pContext->PrioritySlots; + break; + default: alSetError(pContext, AL_INVALID_ENUM); break; diff --git a/jni/OpenAL/OpenAL32/alSource.c b/jni/OpenAL/OpenAL32/alSource.c index 3f8f8bf..9ce7640 100644 --- a/jni/OpenAL/OpenAL32/alSource.c +++ b/jni/OpenAL/OpenAL32/alSource.c @@ -695,6 +695,10 @@ AL_API ALvoid AL_APIENTRY alSourcei(ALuint source,ALenum eParam,ALint lValue) alSetError(pContext, AL_INVALID_VALUE); break; + case AL_PRIORITY: + Source->priority = lValue; + break; + default: alSetError(pContext, AL_INVALID_ENUM); break; @@ -1307,17 +1311,6 @@ AL_API ALvoid AL_APIENTRY alSourcePlayv(ALsizei n, const ALuint *sources) } } -#ifdef MAX_SOURCES_LOW - // Apportable: Cap the number of active source that are playing - if (Context->ActiveSourceCount + n > alc_max_sources) { - LOGV("Skipping starting some sources due to lack of CPU time"); - if (Context->ActiveSourceCount > alc_max_sources) { - n = 0; - } else { - n = alc_max_sources - Context->ActiveSourceCount; - } - } -#endif while(Context->MaxActiveSources-Context->ActiveSourceCount < n) { @@ -1338,16 +1331,18 @@ AL_API ALvoid AL_APIENTRY alSourcePlayv(ALsizei n, const ALuint *sources) Context->MaxActiveSources = newcount; } -#ifdef MAX_SOURCES_LOW - //Apportable Need to give the ALC platform code a hint for setting Source limit based on performance - // LOGI("Playing %d/%d ActiveSources", Context->ActiveSourceCount, alc_max_sources); - alc_active_sources = Context->ActiveSourceCount; -#endif for(i = 0;i < n;i++) { Source = (ALsource*)ALTHUNK_LOOKUPENTRY(sources[i]); +#ifdef MAX_SOURCES_LOW + if (Context->ActiveSourceCount >= (alc_max_sources - Context->PrioritySlots) && Source->priority < 127) { + LOGV("Skipping starting source %d due to lack of CPU time.", sources[i]); + continue; + } +#endif + // Check that there is a queue containing at least one non-null, non zero length AL Buffer BufferList = Source->queue; while(BufferList) @@ -1403,6 +1398,11 @@ AL_API ALvoid AL_APIENTRY alSourcePlayv(ALsizei n, const ALuint *sources) } } +#ifdef MAX_SOURCES_LOW + //Apportable Need to give the ALC platform code a hint for setting Source limit based on performance + alc_active_sources = Context->ActiveSourceCount; +#endif + done: ProcessContext(Context); } @@ -1813,6 +1813,7 @@ static ALvoid InitSourceParams(ALsource *Source) Source->NeedsUpdate = AL_TRUE; Source->Buffer = NULL; + Source->priority = 0; } diff --git a/jni/OpenAL/al.h b/jni/OpenAL/al.h index 44db779..b469326 100644 --- a/jni/OpenAL/al.h +++ b/jni/OpenAL/al.h @@ -360,6 +360,17 @@ typedef void ALvoid; #define AL_EXPONENT_DISTANCE 0xD005 #define AL_EXPONENT_DISTANCE_CLAMPED 0xD006 + +/** + * Priority + * + * Apportable Extension. + * Used to prevent dynamic throttling of this source + * + */ +#define AL_PRIORITY 0xE001 +#define AL_PRIORITY_SLOTS 0xE002 + /* * Renderer State management */ diff --git a/jni/OpenAL/include/AL/al.h b/jni/OpenAL/include/AL/al.h index 3af7bc6..e084b3e 100644 --- a/jni/OpenAL/include/AL/al.h +++ b/jni/OpenAL/include/AL/al.h @@ -452,6 +452,15 @@ typedef void ALvoid; #define AL_EXPONENT_DISTANCE 0xD005 #define AL_EXPONENT_DISTANCE_CLAMPED 0xD006 +/** + * Priority + * + * Apportable Extension. + * Used to prevent dynamic throttling of this source. + * + */ +#define AL_PRIORITY 0xE001 +#define AL_PRIORITY_SLOTS 0xE002 /* * Renderer State management */