Skip to content

Commit 37df769

Browse files
committed
m
1 parent b43232b commit 37df769

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

src/core/processor/vae_spatial_processor.hpp

+19-11
Original file line numberDiff line numberDiff line change
@@ -146,15 +146,18 @@ namespace vae { namespace core {
146146
// Linear interpolation between two samples
147147
position = v.time + (s * speed) + fd.timeFract;
148148
const Real lastPosition = std::floor(position);
149-
const Size lastIndex = (Size) lastPosition;
150-
const Size nextIndex = (Size) lastPosition + 1;
149+
150+
Size lastIndex = (Size) lastPosition;
151+
Size nextIndex = (Size) lastIndex + 1;
152+
// TODO this kills vectorization
153+
if (signalLength <= lastIndex) { lastIndex = 0; }
154+
if (signalLength <= nextIndex) { nextIndex = 0; }
151155

152156
Real mix = position - lastPosition;
153-
// mix = 0.5 * (1.0 - cos((mix) * 3.1416)); // cosine interpolation, introduces new harmonics somehow
157+
// mix = 0.5 * (1.0 - cos((mix) * 3.1416)); // cosine interpolation, introduces new harmonics, not really better than linear
154158

155-
// TODO 30% of the time in here is spent on the modulo
156-
const Sample last = signal[0][lastIndex % signalLength];
157-
const Sample next = signal[0][nextIndex % signalLength];
159+
const Sample last = signal[0][lastIndex];
160+
const Sample next = signal[0][nextIndex];
158161
// linear resampling, sounds alright enough
159162
const Sample in = (last + mix * (next - last)) * gain;
160163

@@ -177,15 +180,19 @@ namespace vae { namespace core {
177180
} else {
178181
VAE_PROFILER_SCOPE_NAMED("Non filtered Voice")
179182
if (v.loop) {
183+
VAE_PROFILER_SCOPE_NAMED("Loop")
180184
// put the looped signal in scratch buffer eventhough we're not filtering
181185
// so panning doesn't need to worry about looping
182-
for (SampleIndex s = 0; s < frames; s++) {
183-
mScratchBuffer[0][s] = signal[0][(v.time + s) % signalLength];
186+
for (SampleIndex s = 0, i = v.time; s < frames; s++, i++) {
187+
// reached the end so reset index, this is slighlty faster than modulo
188+
if (signalLength <= i) { i = 0; }
189+
mScratchBuffer[0][s] = signal[0][i];
184190
}
185191
v.time = (v.time + frames); // progress the time
186192
in = mScratchBuffer[0]; // set buffer for panning
187193
finished = false; // never stop the voice
188194
} else {
195+
VAE_PROFILER_SCOPE_NAMED("No Loop")
189196
// Not filtering or looping
190197
// Means we can use the original signal buffer but need to
191198
// set the remaining samples so we don't run over the signal end
@@ -233,7 +240,7 @@ namespace vae { namespace core {
233240
*/
234241
const auto pan = [&](const auto& panner) {
235242
// This is actually constexpr but not according to clangd
236-
constexpr Size channels = std::min(Size(StaticConfig::MaxChannels), panner.speakers);
243+
constexpr Size channels = Size(StaticConfig::MaxChannels);
237244
panner.pan(
238245
relativeDirection, currentVolumes,
239246
distanceAttenuated, emitter.spread
@@ -245,14 +252,15 @@ namespace vae { namespace core {
245252
lastVolumes[c] = currentVolumes[c];
246253
}
247254
}
248-
255+
VAE_PROFILER_SCOPE_NAMED("Apply SPCAP")
249256
Sample t = 0;
250257
for (SampleIndex s = 0; s < remaining; s++) {
251258
const Sample sample = in[s];
252259
// lerp between last and current channel volumes
253260
// Not correct in terms of power convservation, but easy and efficient
254261
for (Size c = 0; c < channels; c++) {
255-
target[c][s] += sample * (lastVolumes[c] + t * (currentVolumes[c] - lastVolumes[c]));
262+
// target[c][s] += sample * (lastVolumes[c] + t * (currentVolumes[c] - lastVolumes[c]));
263+
target[c][s] += sample * currentVolumes[c];
256264
}
257265
t += Sample(1) / Sample(frames);
258266
}

0 commit comments

Comments
 (0)