[PATCH 0/5] MR10182: dsound: Speed up resampling, part 2
From: Anton Baskanov <baskanov@gmail.com> --- dlls/dsound/mixer.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/dlls/dsound/mixer.c b/dlls/dsound/mixer.c index b90a7e98469..d36e7aa2e9b 100644 --- a/dlls/dsound/mixer.c +++ b/dlls/dsound/mixer.c @@ -330,10 +330,9 @@ static UINT cp_fields_resample(IDirectSoundBufferImpl *dsb, UINT count, LONG64 * UINT fir_cachesize = (fir_len + dsbfirstep - 2) / dsbfirstep; UINT required_input = max_ipos + fir_cachesize; - float *intermediate, *fir_copy, *itmp; + float *intermediate, *itmp; DWORD len = required_input * channels; - len += fir_cachesize; len *= sizeof(float); *freqAccNum = freqAcc_end % dsb->freqAdjustDen; @@ -349,8 +348,7 @@ static UINT cp_fields_resample(IDirectSoundBufferImpl *dsb, UINT count, LONG64 * dsb->device->cp_buffer_len = len; } - fir_copy = dsb->device->cp_buffer; - intermediate = fir_copy + fir_cachesize; + intermediate = dsb->device->cp_buffer; if(dsb->use_committed) { committed_samples = (dsb->writelead - dsb->committed_mixpos) / istride; @@ -379,11 +377,7 @@ static UINT cp_fields_resample(IDirectSoundBufferImpl *dsb, UINT count, LONG64 * UINT idx = dsbfirstep - 1 - idx_num / dsb->freqAdjustDen; float rem = 1.0f - idx_num % dsb->freqAdjustDen / (float)dsb->freqAdjustDen; - int fir_used = 0; - while (idx < fir_len - 1) { - fir_copy[fir_used++] = fir[idx] * (1.0f - rem) + fir[idx + 1] * rem; - idx += dsb->firstep; - } + int fir_used = (fir_len - 1 - idx + dsbfirstep - 1) / dsbfirstep; assert(fir_used <= fir_cachesize); assert(ipos + fir_used <= required_input); @@ -393,7 +387,7 @@ static UINT cp_fields_resample(IDirectSoundBufferImpl *dsb, UINT count, LONG64 * float sum = 0.0; float* cache = &intermediate[channel * required_input + ipos]; for (j = 0; j < fir_used; j++) - sum += fir_copy[j] * cache[j]; + sum += (fir[idx + j * dsbfirstep] * (1.0f - rem) + fir[idx + j * dsbfirstep + 1] * rem) * cache[j]; dsb->put(dsb, i * ostride, channel, sum * dsb->firgain); } } -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10182
From: Anton Baskanov <baskanov@gmail.com> --- dlls/dsound/mixer.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/dlls/dsound/mixer.c b/dlls/dsound/mixer.c index d36e7aa2e9b..fa857fe96b4 100644 --- a/dlls/dsound/mixer.c +++ b/dlls/dsound/mixer.c @@ -369,23 +369,24 @@ static UINT cp_fields_resample(IDirectSoundBufferImpl *dsb, UINT count, LONG64 * dsb->buflen, dsb->sec_mixpos + i * istride, channel); } - for(i = 0; i < count; ++i) { - LONG64 ipos_num = freqAcc_start + i * dsb->freqAdjustNum; - UINT ipos = ipos_num / dsb->freqAdjustDen; - - UINT idx_num = ipos_num % dsb->freqAdjustDen * dsbfirstep; - UINT idx = dsbfirstep - 1 - idx_num / dsb->freqAdjustDen; - float rem = 1.0f - idx_num % dsb->freqAdjustDen / (float)dsb->freqAdjustDen; + for (channel = 0; channel < channels; channel++) { + for(i = 0; i < count; ++i) { + LONG64 ipos_num = freqAcc_start + i * dsb->freqAdjustNum; + UINT ipos = ipos_num / dsb->freqAdjustDen; - int fir_used = (fir_len - 1 - idx + dsbfirstep - 1) / dsbfirstep; + UINT idx_num = ipos_num % dsb->freqAdjustDen * dsbfirstep; + UINT idx = dsbfirstep - 1 - idx_num / dsb->freqAdjustDen; + float rem = 1.0f - idx_num % dsb->freqAdjustDen / (float)dsb->freqAdjustDen; - assert(fir_used <= fir_cachesize); - assert(ipos + fir_used <= required_input); + int fir_used = (fir_len - 1 - idx + dsbfirstep - 1) / dsbfirstep; - for (channel = 0; channel < dsb->mix_channels; channel++) { int j; float sum = 0.0; float* cache = &intermediate[channel * required_input + ipos]; + + assert(fir_used <= fir_cachesize); + assert(ipos + fir_used <= required_input); + for (j = 0; j < fir_used; j++) sum += (fir[idx + j * dsbfirstep] * (1.0f - rem) + fir[idx + j * dsbfirstep + 1] * rem) * cache[j]; dsb->put(dsb, i * ostride, channel, sum * dsb->firgain); -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10182
From: Anton Baskanov <baskanov@gmail.com> --- dlls/dsound/mixer.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/dlls/dsound/mixer.c b/dlls/dsound/mixer.c index fa857fe96b4..ac8ab72e0f9 100644 --- a/dlls/dsound/mixer.c +++ b/dlls/dsound/mixer.c @@ -330,9 +330,10 @@ static UINT cp_fields_resample(IDirectSoundBufferImpl *dsb, UINT count, LONG64 * UINT fir_cachesize = (fir_len + dsbfirstep - 2) / dsbfirstep; UINT required_input = max_ipos + fir_cachesize; - float *intermediate, *itmp; + float *intermediate, *output, *itmp; DWORD len = required_input * channels; + len += count * channels; len *= sizeof(float); *freqAccNum = freqAcc_end % dsb->freqAdjustDen; @@ -349,6 +350,7 @@ static UINT cp_fields_resample(IDirectSoundBufferImpl *dsb, UINT count, LONG64 * } intermediate = dsb->device->cp_buffer; + output = intermediate + required_input * channels; if(dsb->use_committed) { committed_samples = (dsb->writelead - dsb->committed_mixpos) / istride; @@ -389,10 +391,14 @@ static UINT cp_fields_resample(IDirectSoundBufferImpl *dsb, UINT count, LONG64 * for (j = 0; j < fir_used; j++) sum += (fir[idx + j * dsbfirstep] * (1.0f - rem) + fir[idx + j * dsbfirstep + 1] * rem) * cache[j]; - dsb->put(dsb, i * ostride, channel, sum * dsb->firgain); + output[channel * count + i] = sum * dsb->firgain; } } + for(i = 0; i < count; ++i) + for (channel = 0; channel < channels; channel++) + dsb->put(dsb, i * ostride, channel, output[channel * count + i]); + return max_ipos; } -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10182
From: Anton Baskanov <baskanov@gmail.com> --- dlls/dsound/mixer.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/dlls/dsound/mixer.c b/dlls/dsound/mixer.c index ac8ab72e0f9..ab351d2c9cb 100644 --- a/dlls/dsound/mixer.c +++ b/dlls/dsound/mixer.c @@ -386,9 +386,6 @@ static UINT cp_fields_resample(IDirectSoundBufferImpl *dsb, UINT count, LONG64 * float sum = 0.0; float* cache = &intermediate[channel * required_input + ipos]; - assert(fir_used <= fir_cachesize); - assert(ipos + fir_used <= required_input); - for (j = 0; j < fir_used; j++) sum += (fir[idx + j * dsbfirstep] * (1.0f - rem) + fir[idx + j * dsbfirstep + 1] * rem) * cache[j]; output[channel * count + i] = sum * dsb->firgain; -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10182
From: Anton Baskanov <baskanov@gmail.com> --- dlls/dsound/mixer.c | 48 ++++++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/dlls/dsound/mixer.c b/dlls/dsound/mixer.c index ab351d2c9cb..d3c6421627c 100644 --- a/dlls/dsound/mixer.c +++ b/dlls/dsound/mixer.c @@ -315,6 +315,31 @@ static UINT cp_fields_noresample(IDirectSoundBufferImpl *dsb, UINT count) return count; } +static void resample(LONG64 freq_adjust_num, LONG64 freq_adjust_den, LONG64 freq_acc_start, + UINT dsbfirstep, float firgain, UINT count, float *input, float *output) +{ + UINT i; + + for(i = 0; i < count; ++i) { + LONG64 ipos_num = freq_acc_start + i * freq_adjust_num; + UINT ipos = ipos_num / freq_adjust_den; + + UINT idx_num = ipos_num % freq_adjust_den * dsbfirstep; + UINT idx = dsbfirstep - 1 - idx_num / freq_adjust_den; + float rem = 1.0f - idx_num % freq_adjust_den / (float)freq_adjust_den; + + int fir_used = (fir_len - 1 - idx + dsbfirstep - 1) / dsbfirstep; + + int j; + float sum = 0.0; + float* cache = &input[ipos]; + + for (j = 0; j < fir_used; j++) + sum += (fir[idx + j * dsbfirstep] * (1.0f - rem) + fir[idx + j * dsbfirstep + 1] * rem) * cache[j]; + output[i] = sum * firgain; + } +} + static UINT cp_fields_resample(IDirectSoundBufferImpl *dsb, UINT count, LONG64 *freqAccNum) { UINT i, channel; @@ -371,26 +396,9 @@ static UINT cp_fields_resample(IDirectSoundBufferImpl *dsb, UINT count, LONG64 * dsb->buflen, dsb->sec_mixpos + i * istride, channel); } - for (channel = 0; channel < channels; channel++) { - for(i = 0; i < count; ++i) { - LONG64 ipos_num = freqAcc_start + i * dsb->freqAdjustNum; - UINT ipos = ipos_num / dsb->freqAdjustDen; - - UINT idx_num = ipos_num % dsb->freqAdjustDen * dsbfirstep; - UINT idx = dsbfirstep - 1 - idx_num / dsb->freqAdjustDen; - float rem = 1.0f - idx_num % dsb->freqAdjustDen / (float)dsb->freqAdjustDen; - - int fir_used = (fir_len - 1 - idx + dsbfirstep - 1) / dsbfirstep; - - int j; - float sum = 0.0; - float* cache = &intermediate[channel * required_input + ipos]; - - for (j = 0; j < fir_used; j++) - sum += (fir[idx + j * dsbfirstep] * (1.0f - rem) + fir[idx + j * dsbfirstep + 1] * rem) * cache[j]; - output[channel * count + i] = sum * dsb->firgain; - } - } + for (channel = 0; channel < channels; channel++) + resample(dsb->freqAdjustNum, dsb->freqAdjustDen, freqAcc_start, dsbfirstep, dsb->firgain, + count, intermediate + channel * required_input, output + channel * count); for(i = 0; i < count; ++i) for (channel = 0; channel < channels; channel++) -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10182
This merge request was approved by Matteo Bruni. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/10182
This merge request was approved by Huw Davies. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/10182
participants (4)
-
Anton Baskanov -
Anton Baskanov (@baskanov) -
Huw Davies (@huw) -
Matteo Bruni (@Mystral)