|
| 1 | +From 5320d2504651758bc787e4253a12f3ce7a99bca6 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Mark Harmstone < [email protected]> |
| 3 | +Date: Thu, 19 Mar 2015 21:59:29 +0000 |
| 4 | +Subject: [PATCH 01/17] dsound: Apply filters before sound is multiplied to |
| 5 | + speakers. |
| 6 | +MIME-Version: 1.0 |
| 7 | +Content-Type: multipart/mixed; boundary="------------2.0.5" |
| 8 | + |
| 9 | +This is a multi-part message in MIME format. |
| 10 | +--------------2.0.5 |
| 11 | +Content-Type: text/plain; charset=UTF-8; format=fixed |
| 12 | +Content-Transfer-Encoding: 8bit |
| 13 | + |
| 14 | +--- |
| 15 | + dlls/dsound/mixer.c | 97 ++++++++++++++++++++++++++++++++++++++++++----------- |
| 16 | + 1 file changed, 78 insertions(+), 19 deletions(-) |
| 17 | + |
| 18 | + |
| 19 | +--------------2.0.5 |
| 20 | +Content-Type: text/x-patch; name="0001-dsound-Apply-filters-before-sound-is-multiplied-to-s.patch" |
| 21 | +Content-Transfer-Encoding: 8bit |
| 22 | +Content-Disposition: attachment; filename="0001-dsound-Apply-filters-before-sound-is-multiplied-to-s.patch" |
| 23 | + |
| 24 | +diff --git a/dlls/dsound/mixer.c b/dlls/dsound/mixer.c |
| 25 | +index 85ab14a..c41ef3a 100644 |
| 26 | +--- a/dlls/dsound/mixer.c |
| 27 | ++++ b/dlls/dsound/mixer.c |
| 28 | +@@ -266,15 +266,62 @@ static inline float get_current_sample(const IDirectSoundBufferImpl *dsb, |
| 29 | + return dsb->get(dsb, mixpos % dsb->buflen, channel); |
| 30 | + } |
| 31 | + |
| 32 | ++static void apply_filters(IDirectSoundBufferImpl *dsb, float* buf, UINT count) |
| 33 | ++{ |
| 34 | ++ int i; |
| 35 | ++ HRESULT hr; |
| 36 | ++ |
| 37 | ++ if (count > 0) { |
| 38 | ++ for (i = 0; i < dsb->num_filters; i++) { |
| 39 | ++ if (dsb->filters[i].inplace) { |
| 40 | ++ hr = IMediaObjectInPlace_Process(dsb->filters[i].inplace, count * dsb->mix_channels * sizeof(float), |
| 41 | ++ (BYTE*)buf, 0, DMO_INPLACE_NORMAL); |
| 42 | ++ |
| 43 | ++ if (FAILED(hr)) |
| 44 | ++ WARN("IMediaObjectInPlace_Process failed for filter %u\n", i); |
| 45 | ++ } else |
| 46 | ++ WARN("filter %u has no inplace object - unsupported\n", i); |
| 47 | ++ } |
| 48 | ++ } |
| 49 | ++} |
| 50 | ++ |
| 51 | + static UINT cp_fields_noresample(IDirectSoundBufferImpl *dsb, UINT count) |
| 52 | + { |
| 53 | + UINT istride = dsb->pwfx->nBlockAlign; |
| 54 | + UINT ostride = dsb->device->pwfx->nChannels * sizeof(float); |
| 55 | + DWORD channel, i; |
| 56 | +- for (i = 0; i < count; i++) |
| 57 | +- for (channel = 0; channel < dsb->mix_channels; channel++) |
| 58 | +- dsb->put(dsb, i * ostride, channel, get_current_sample(dsb, |
| 59 | +- dsb->sec_mixpos + i * istride, channel)); |
| 60 | ++ BOOL using_filters = dsb->num_filters > 0; |
| 61 | ++ float *buf, *buftmp; |
| 62 | ++ |
| 63 | ++ if (using_filters) { |
| 64 | ++ buf = HeapAlloc(GetProcessHeap(), 0, count * dsb->mix_channels * sizeof(float)); |
| 65 | ++ buftmp = buf; |
| 66 | ++ |
| 67 | ++ for (i = 0; i < count; i++) { |
| 68 | ++ for (channel = 0; channel < dsb->mix_channels; channel++) { |
| 69 | ++ *buftmp = get_current_sample(dsb, dsb->sec_mixpos + i*istride, channel); |
| 70 | ++ buftmp++; |
| 71 | ++ } |
| 72 | ++ } |
| 73 | ++ |
| 74 | ++ apply_filters(dsb, buf, count); |
| 75 | ++ |
| 76 | ++ buftmp = buf; |
| 77 | ++ for (i = 0; i < count; i++) { |
| 78 | ++ for (channel = 0; channel < dsb->mix_channels; channel++) { |
| 79 | ++ dsb->put(dsb, i * ostride, channel, *buftmp); |
| 80 | ++ buftmp++; |
| 81 | ++ } |
| 82 | ++ } |
| 83 | ++ |
| 84 | ++ HeapFree(GetProcessHeap(), 0, buf); |
| 85 | ++ } else { |
| 86 | ++ for (i = 0; i < count; i++) |
| 87 | ++ for (channel = 0; channel < dsb->mix_channels; channel++) |
| 88 | ++ dsb->put(dsb, i * ostride, channel, get_current_sample(dsb, |
| 89 | ++ dsb->sec_mixpos + i * istride, channel)); |
| 90 | ++ } |
| 91 | ++ |
| 92 | + return count; |
| 93 | + } |
| 94 | + |
| 95 | +@@ -299,6 +346,9 @@ static UINT cp_fields_resample(IDirectSoundBufferImpl *dsb, UINT count, LONG64 * |
| 96 | + float* fir_copy = HeapAlloc(GetProcessHeap(), 0, |
| 97 | + sizeof(float) * fir_cachesize); |
| 98 | + |
| 99 | ++ BOOL using_filters = dsb->num_filters > 0; |
| 100 | ++ float *buf = NULL, *buftmp = NULL; |
| 101 | ++ |
| 102 | + /* Important: this buffer MUST be non-interleaved |
| 103 | + * if you want -msse3 to have any effect. |
| 104 | + * This is good for CPU cache effects, too. |
| 105 | +@@ -309,6 +359,11 @@ static UINT cp_fields_resample(IDirectSoundBufferImpl *dsb, UINT count, LONG64 * |
| 106 | + *(itmp++) = get_current_sample(dsb, |
| 107 | + dsb->sec_mixpos + i * istride, channel); |
| 108 | + |
| 109 | ++ if (using_filters) { |
| 110 | ++ buf = HeapAlloc(GetProcessHeap(), 0, sizeof(float) * count * dsb->mix_channels); |
| 111 | ++ buftmp = buf; |
| 112 | ++ } |
| 113 | ++ |
| 114 | + for(i = 0; i < count; ++i) { |
| 115 | + UINT int_fir_steps = (freqAcc_start + i * dsb->freqAdjustNum) * dsbfirstep / dsb->freqAdjustDen; |
| 116 | + float total_fir_steps = (freqAcc_start + i * dsb->freqAdjustNum) * dsbfirstep / (float)dsb->freqAdjustDen; |
| 117 | +@@ -332,10 +387,28 @@ static UINT cp_fields_resample(IDirectSoundBufferImpl *dsb, UINT count, LONG64 * |
| 118 | + float* cache = &intermediate[channel * required_input + ipos]; |
| 119 | + for (j = 0; j < fir_used; j++) |
| 120 | + sum += fir_copy[j] * cache[j]; |
| 121 | +- dsb->put(dsb, i * ostride, channel, sum * dsb->firgain); |
| 122 | ++ |
| 123 | ++ if (using_filters) |
| 124 | ++ *(buftmp++) = sum * dsb->firgain; |
| 125 | ++ else |
| 126 | ++ dsb->put(dsb, i * ostride, channel, sum * dsb->firgain); |
| 127 | + } |
| 128 | + } |
| 129 | + |
| 130 | ++ if (using_filters) { |
| 131 | ++ apply_filters(dsb, buf, count); |
| 132 | ++ |
| 133 | ++ buftmp = buf; |
| 134 | ++ for (i = 0; i < count; i++) { |
| 135 | ++ for (channel = 0; channel < dsb->mix_channels; channel++) { |
| 136 | ++ dsb->put(dsb, i * ostride, channel, *buftmp); |
| 137 | ++ buftmp++; |
| 138 | ++ } |
| 139 | ++ } |
| 140 | ++ |
| 141 | ++ HeapFree(GetProcessHeap(), 0, buf); |
| 142 | ++ } |
| 143 | ++ |
| 144 | + *freqAccNum = freqAcc_end % dsb->freqAdjustDen; |
| 145 | + |
| 146 | + HeapFree(GetProcessHeap(), 0, fir_copy); |
| 147 | +@@ -397,8 +470,6 @@ static inline DWORD DSOUND_BufPtrDiff(DWORD buflen, DWORD ptr1, DWORD ptr2) |
| 148 | + static void DSOUND_MixToTemporary(IDirectSoundBufferImpl *dsb, DWORD frames) |
| 149 | + { |
| 150 | + UINT size_bytes = frames * sizeof(float) * dsb->device->pwfx->nChannels; |
| 151 | +- HRESULT hr; |
| 152 | +- int i; |
| 153 | + |
| 154 | + if (dsb->device->tmp_buffer_len < size_bytes || !dsb->device->tmp_buffer) |
| 155 | + { |
| 156 | +@@ -410,18 +481,6 @@ static void DSOUND_MixToTemporary(IDirectSoundBufferImpl *dsb, DWORD frames) |
| 157 | + } |
| 158 | + |
| 159 | + cp_fields(dsb, frames, &dsb->freqAccNum); |
| 160 | +- |
| 161 | +- if (size_bytes > 0) { |
| 162 | +- for (i = 0; i < dsb->num_filters; i++) { |
| 163 | +- if (dsb->filters[i].inplace) { |
| 164 | +- hr = IMediaObjectInPlace_Process(dsb->filters[i].inplace, size_bytes, (BYTE*)dsb->device->tmp_buffer, 0, DMO_INPLACE_NORMAL); |
| 165 | +- |
| 166 | +- if (FAILED(hr)) |
| 167 | +- WARN("IMediaObjectInPlace_Process failed for filter %u\n", i); |
| 168 | +- } else |
| 169 | +- WARN("filter %u has no inplace object - unsupported\n", i); |
| 170 | +- } |
| 171 | +- } |
| 172 | + } |
| 173 | + |
| 174 | + static void DSOUND_MixerVol(const IDirectSoundBufferImpl *dsb, INT frames) |
| 175 | + |
| 176 | +--------------2.0.5-- |
| 177 | + |
| 178 | + |
0 commit comments