diff options
author | Chris Robinson <[email protected]> | 2015-10-15 07:29:25 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2015-10-15 07:29:25 -0700 |
commit | 97f53d941c32b24470a0f589853ce60cfbe7f15b (patch) | |
tree | 06ced97b1b83511279a5a237d5e2721ac14bbda2 /OpenAL32 | |
parent | 3c54ba3901d93093406a7e5129bb43badcc6cf50 (diff) |
Store the source's previous samples with the voice
This helps avoid different results when looping is toggled within a couple
samples of the loop point, or when a processed buffer is removed while the
source is only a couple samples into the next buffer.
Diffstat (limited to 'OpenAL32')
-rw-r--r-- | OpenAL32/Include/alSource.h | 2 | ||||
-rw-r--r-- | OpenAL32/Include/alu.h | 3 | ||||
-rw-r--r-- | OpenAL32/alSource.c | 12 |
3 files changed, 17 insertions, 0 deletions
diff --git a/OpenAL32/Include/alSource.h b/OpenAL32/Include/alSource.h index 89c210b9..34c3575b 100644 --- a/OpenAL32/Include/alSource.h +++ b/OpenAL32/Include/alSource.h @@ -35,6 +35,8 @@ typedef struct ALvoice { ALuint Offset; /* Number of output samples mixed since starting. */ + alignas(16) ALfloat PrevSamples[MAX_INPUT_CHANNELS][MAX_PREVIOUS_SAMPLES]; + DirectParams Direct; SendParams Send[MAX_SENDS]; } ALvoice; diff --git a/OpenAL32/Include/alu.h b/OpenAL32/Include/alu.h index 051a0f0d..ba7afedb 100644 --- a/OpenAL32/Include/alu.h +++ b/OpenAL32/Include/alu.h @@ -32,6 +32,9 @@ #define MAX_PITCH (255) +/* Maximum number of previous buffer samples needed for resampling. */ +#define MAX_PREVIOUS_SAMPLES 4 + #ifdef __cplusplus extern "C" { diff --git a/OpenAL32/alSource.c b/OpenAL32/alSource.c index f5b7111f..f91b3878 100644 --- a/OpenAL32/alSource.c +++ b/OpenAL32/alSource.c @@ -2574,6 +2574,7 @@ ALvoid SetSourceState(ALsource *Source, ALCcontext *Context, ALenum state) { ALCdevice *device = Context->Device; ALbufferlistitem *BufferList; + ALboolean discontinuity; ALvoice *voice = NULL; ALsizei i; @@ -2594,13 +2595,20 @@ ALvoid SetSourceState(ALsource *Source, ALCcontext *Context, ALenum state) Source->position = 0; Source->position_fraction = 0; ATOMIC_STORE(&Source->current_buffer, BufferList); + discontinuity = AL_TRUE; } else + { Source->state = AL_PLAYING; + discontinuity = AL_FALSE; + } // Check if an Offset has been set if(Source->Offset >= 0.0) + { ApplyOffset(Source); + /* discontinuity = AL_TRUE;??? */ + } /* If there's nothing to play, or device is disconnected, go right to * stopped */ @@ -2631,6 +2639,10 @@ ALvoid SetSourceState(ALsource *Source, ALCcontext *Context, ALenum state) voice->Source = Source; } + /* Clear previous samples if playback is discontinuous. */ + if(discontinuity) + memset(voice->PrevSamples, 0, sizeof(voice->PrevSamples)); + voice->Direct.Moving = AL_FALSE; voice->Direct.Counter = 0; for(i = 0;i < MAX_INPUT_CHANNELS;i++) |