Update mojoAL

This commit is contained in:
Benau 2021-08-26 09:23:53 +08:00
parent bd3fd0957a
commit 6d763a1e26

View File

@ -7,10 +7,11 @@
*/
#include <stdio.h>
#include <stdlib.h> /* needed for alloca */
#include <math.h>
#include <float.h>
#ifdef _MSC_VER
#ifdef _WIN32
#define AL_API __declspec(dllexport)
#define ALC_API __declspec(dllexport)
#endif
@ -532,7 +533,7 @@ struct ALCcontext_struct
};
/* forward declarations */
static int source_get_offset(ALsource *src, ALenum param);
static float source_get_offset(ALsource *src, ALenum param);
static void source_set_offset(ALsource *src, ALenum param, ALfloat value);
/* the just_queued list is backwards. Add it to the queue in the correct order. */
@ -3959,7 +3960,7 @@ static void source_pause(ALCcontext *ctx, const ALuint name)
}
}
static int source_get_offset(ALsource *src, ALenum param)
static float source_get_offset(ALsource *src, ALenum param)
{
int offset = 0;
int framesize = sizeof (float);
@ -3979,11 +3980,13 @@ static int source_get_offset(ALsource *src, ALenum param)
offset = src->offset;
}
switch(param) {
case AL_SAMPLE_OFFSET: return offset / framesize; break;
case AL_SEC_OFFSET: return (offset / framesize) / freq; break;
case AL_BYTE_OFFSET: return offset; break;
default: return 0; break;
case AL_SAMPLE_OFFSET: return (float) (offset / framesize); break;
case AL_SEC_OFFSET: return ((float) (offset / framesize)) / ((float) freq); break;
case AL_BYTE_OFFSET: return (float) offset; break;
default: break;
}
return 0.0f;
}
static void source_set_offset(ALsource *src, ALenum param, ALfloat value)
@ -3994,20 +3997,16 @@ static void source_set_offset(ALsource *src, ALenum param, ALfloat value)
return;
}
int bufflen = 0;
int framesize = sizeof(float);
int freq = 1;
if (src->type == AL_STREAMING) {
FIXME("set_offset for streaming sources not implemented");
return;
} else {
bufflen = (int)src->buffer->len;
framesize = (int)(src->buffer->channels * sizeof(float));
freq = (int)src->buffer->frequency;
}
const int bufflen = (int) src->buffer->len;
const int framesize = (int) (src->buffer->channels * sizeof (float));
const int freq = (int) src->buffer->frequency;
int offset = -1;
switch (param) {
case AL_SAMPLE_OFFSET:
offset = value * framesize;
@ -4019,11 +4018,15 @@ static void source_set_offset(ALsource *src, ALenum param, ALfloat value)
offset = ((int)value / framesize) * framesize;
break;
}
if (offset < 0 || offset > bufflen) {
if ((offset < 0) || (offset > bufflen)) {
set_al_error(ctx, AL_INVALID_VALUE);
return;
}
/* make sure the offset lands on a sample frame boundary. */
offset -= offset % framesize;
if (!SDL_AtomicGet(&src->mixer_accessible)) {
src->offset = offset;
} else {