From 8bb87c66ab1fc62d21e3b386d81a8269d979f369 Mon Sep 17 00:00:00 2001 From: Mark Harmstone Date: Sun, 22 Mar 2015 18:00:10 +0000 Subject: [PATCH 14/18] dsound: Add delay line EAX functions. MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------2.0.5" This is a multi-part message in MIME format. --------------2.0.5 Content-Type: text/plain; charset=UTF-8; format=fixed Content-Transfer-Encoding: 8bit --- dlls/dsound/dsound_eax.h | 1 + dlls/dsound/eax.c | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) --------------2.0.5 Content-Type: text/x-patch; name="0014-dsound-Add-delay-line-EAX-functions.patch" Content-Transfer-Encoding: 8bit Content-Disposition: attachment; filename="0014-dsound-Add-delay-line-EAX-functions.patch" diff --git a/dlls/dsound/dsound_eax.h b/dlls/dsound/dsound_eax.h index 51bafe0..4e7748c 100644 --- a/dlls/dsound/dsound_eax.h +++ b/dlls/dsound/dsound_eax.h @@ -141,6 +141,7 @@ typedef struct { FILTER LpFilter; DelayLine Delay; + unsigned int DelayTap[2]; unsigned int Offset; } eax_buffer_info; diff --git a/dlls/dsound/eax.c b/dlls/dsound/eax.c index 54d90cd..8aafb2a 100644 --- a/dlls/dsound/eax.c +++ b/dlls/dsound/eax.c @@ -106,11 +106,26 @@ static float lpFilter2P(FILTER *iir, unsigned int offset, float input) return output; } +static void DelayLineIn(DelayLine *Delay, unsigned int offset, float in) +{ + Delay->Line[offset&Delay->Mask] = in; +} + +static float DelayLineOut(DelayLine *Delay, unsigned int offset) +{ + return Delay->Line[offset&Delay->Mask]; +} + static void VerbPass(IDirectSoundBufferImpl* dsb, float in, float* out) { /* Low-pass filter the incoming sample. */ in = lpFilter2P(&dsb->eax.LpFilter, 0, in); + /* Feed the initial delay line. */ + DelayLineIn(&dsb->eax.Delay, dsb->eax.Offset, in); + + in = DelayLineOut(&dsb->eax.Delay, dsb->eax.Offset - dsb->eax.DelayTap[0]); + /* Step all delays forward one sample. */ dsb->eax.Offset++; } @@ -152,6 +167,12 @@ void process_eax_buffer(IDirectSoundBufferImpl* dsb, float* buf, DWORD count) HeapFree(GetProcessHeap(), 0, out); } +static void UpdateDelayLine(float earlyDelay, float lateDelay, unsigned int frequency, eax_buffer_info *State) +{ + State->DelayTap[0] = fastf2u(earlyDelay * frequency); + State->DelayTap[1] = fastf2u((earlyDelay + lateDelay) * frequency); +} + static float lpCoeffCalc(float g, float cw) { float a = 0.0f; @@ -262,6 +283,10 @@ static void ReverbUpdate(IDirectSoundBufferImpl* dsb) cw = CalcI3DL2HFreq(dsb->device->eax.eax_props.flHFReference, dsb->device->pwfx->nSamplesPerSec); dsb->eax.LpFilter.coeff = lpCoeffCalc(dsb->device->eax.eax_props.flGainHF, cw); + + UpdateDelayLine(dsb->device->eax.eax_props.flReflectionsDelay, + dsb->device->eax.eax_props.flLateReverbDelay, + dsb->device->pwfx->nSamplesPerSec, &dsb->eax); } static BOOL ReverbDeviceUpdate(DirectSoundDevice *dev) @@ -286,6 +311,8 @@ void init_eax_buffer(IDirectSoundBufferImpl* dsb) dsb->eax.Delay.Mask = 0; dsb->eax.Delay.Line = NULL; + dsb->eax.DelayTap[0] = 0; + dsb->eax.DelayTap[1] = 0; dsb->eax.Offset = 0; --------------2.0.5--