diff options
author | Chris Robinson <[email protected]> | 2018-08-31 07:20:46 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2018-08-31 07:20:46 -0700 |
commit | 68a8c42176989e0f9b1014aa43d3ed6959dd02cb (patch) | |
tree | 01e7323fe5e9b8654c47d899f55c860fd56f631c | |
parent | 8b733728afaae532edc1dd2ce44192893b170145 (diff) |
Calcualte and use the maximum reverb update size
Instead of requiring it to be at least as big as MAX_UPDATE_SAMPLES, which may
not be true in some situations.
-rw-r--r-- | Alc/effects/reverb.c | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/Alc/effects/reverb.c b/Alc/effects/reverb.c index 1b8a08fe..ca8eb359 100644 --- a/Alc/effects/reverb.c +++ b/Alc/effects/reverb.c @@ -311,6 +311,9 @@ typedef struct ALreverbState { /* Indicates the cross-fade point for delay line reads [0,FADE_SAMPLES]. */ ALsizei FadeCount; + /* Maximum number of samples to process at once. */ + ALsizei MaxUpdate[2]; + /* The current write offset for all delay lines. */ ALsizei Offset; @@ -413,6 +416,8 @@ static void ALreverbState_Construct(ALreverbState *state) } state->FadeCount = 0; + state->MaxUpdate[0] = MAX_UPDATE_SAMPLES; + state->MaxUpdate[1] = MAX_UPDATE_SAMPLES; state->Offset = 0; } @@ -774,11 +779,6 @@ static ALvoid UpdateLateLines(const ALfloat density, const ALfloat diffusion, co /* Calculate the delay offset for each delay line. */ Late->Offset[i][1] = float2int(length*frequency + 0.5f); - /* Late reverb is processed in chunks, so ensure the feedback delays - * are long enough to avoid needing to read what's written in a given - * update. - */ - assert(Late->Offset[i][1] >= MAX_UPDATE_SAMPLES); /* Approximate the absorption that the vector all-pass would exhibit * given the current diffusion so we don't have to process a full T60 @@ -948,6 +948,9 @@ static ALvoid ALreverbState_update(ALreverbState *State, const ALCcontext *Conte props->Reverb.ReflectionsGain*gain, props->Reverb.LateReverbGain*gain, State); + /* Calculate the max update size from the smallest relevant delay. */ + State->MaxUpdate[1] = mini(MAX_UPDATE_SAMPLES, State->Late.Offset[0][1]); + /* Determine if delay-line cross-fading is required. TODO: Add some fuzz * for the float comparisons? The math should be stable enough that the * result should be the same if nothing's changed, and changes in the float @@ -1447,10 +1450,14 @@ static ALvoid ALreverbState_process(ALreverbState *State, ALsizei SamplesToDo, c /* Process reverb for these samples. */ for(base = 0;base < SamplesToDo;) { - ALsizei todo = mini(SamplesToDo-base, MAX_UPDATE_SAMPLES); + ALsizei todo = SamplesToDo - base; /* If cross-fading, don't do more samples than there are to fade. */ if(FADE_SAMPLES-fadeCount > 0) + { todo = mini(todo, FADE_SAMPLES-fadeCount); + todo = mini(todo, State->MaxUpdate[0]); + } + todo = mini(todo, State->MaxUpdate[1]); /* Convert B-Format to A-Format for processing. */ memset(afmt, 0, sizeof(*afmt)*NUM_LINES); @@ -1512,6 +1519,7 @@ static ALvoid ALreverbState_process(ALreverbState *State, ALsizei SamplesToDo, c State->Late.T60[c].MidGain[0] = State->Late.T60[c].MidGain[1]; } State->Late.DensityGain[0] = State->Late.DensityGain[1]; + State->MaxUpdate[0] = State->MaxUpdate[1]; } } else |