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,31 +3960,33 @@ 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);
int framesize = sizeof (float);
int freq = 1;
if (src->type == AL_STREAMING) {
/* streaming: the offset counts from the first processed buffer in the queue. */
BufferQueueItem *item = src->buffer_queue.head;
if (item) {
framesize = (int)(item->buffer->channels * sizeof(float));
freq = (int)(item->buffer->frequency);
framesize = (int) (item->buffer->channels * sizeof (float));
freq = (int) (item->buffer->frequency);
int proc_buf = SDL_AtomicGet(&src->buffer_queue_processed.num_items);
offset = (proc_buf * item->buffer->len + src->offset);
}
} else {
framesize = (int)(src->buffer->channels * sizeof(float));
freq = (int)src->buffer->frequency;
framesize = (int) (src->buffer->channels * sizeof (float));
freq = (int) src->buffer->frequency;
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,21 +3997,17 @@ 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) {
switch (param) {
case AL_SAMPLE_OFFSET:
offset = value * framesize;
break;
@ -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 {