Просмотр исходного кода

Signalsmith Stretch: SoA band state, the main prediction off its chain, mono analysis copied (round 190kr)

Signalsmith Stretch was the largest cost of FL's demo "Ookay - Thief" in perfbench (~22 % of all samples, the
sampler voices that keep their pitch through VoicePitchShifter). Exact speed-ups:
- the per-band state ({input, prevInput, output, inputEnergy} structs) and the predictions are now
  structure-of-arrays with zero padding, so fractional reads need no bounds checks; the new-spectrum rotation
  (its running product cached once per configuration), the energies and the preliminary prediction run four
  bands at a time (SSE2, scalar fallback);
- the main prediction first computes everything not on its band-to-band chain for all bands (twists, the
  upward terms from the preliminary outputs, the random time factors drawn in the same order), then the chain
  does only its own work; with two channels the other channel's phase-locked output is computed in the chain
  only when a band above reads it, the rest four at a time afterwards;
- with two channels and no frequency mapping, the rotation and preliminary outputs of a channel that is never
  the maximum-energy one are skipped (all its outputs are phase-locked, its previous inputs replaced);
- a mono source in both channels: the second analysis copies the first spectrum (bit-identical input);
- without split computation: no copy of the whole input history per block (the analysis runs before any new
  input), the output read in runs up to the next block, and the loudness test stops at the first loud sample
  (float sums of non-negative terms round monotonically, so the result of `total < floor` is the same).

Same IEEE operations in the same order per value. perfbench Thief at 480: 55157 -> ~43500 instructions/sample,
hashes identical (Thief 64/128/480 whole song, synth100 inserts50 stream big200 automation demo, Exoplanet);
standalone harness (all factors, mono/stereo, both blocks, 42 rates, mapped/formant/split/exact()) identical
with GCC 15 and clang 18 + libc++, and with the scalar fallback. README notes the modification (MIT kept).
Ka1-S 2 недель назад
Родитель
Сommit
efcc7a19d5

+ 8 - 1
third_party/signalsmith/README.md

@@ -9,4 +9,11 @@ the audio editor).
   `fft.h`, `stft.h`, `approx.h` (no platform back-ends: the built-in FFT is used). MIT licence, see
   LICENSE-linear.txt.
 
-Unmodified copies. `signalsmith-stretch.h` includes `"signalsmith-linear/stft.h"`, which resolves next to it.
+`signalsmith-stretch.h` includes `"signalsmith-linear/stft.h"`, which resolves next to it.
+
+Modified by LYNX (round 190kr, performance; MIT notices kept): the stretcher's per-band state is structure-of-arrays,
+its spectral loops and the FFT's split-complex passes / real-FFT twists run four values at a time with SSE2 (a scalar
+fallback elsewhere), the main prediction computes everything off its band-to-band chain first, a mono source's second
+analysis is copied, a channel that is never the loudest skips its unread preliminary outputs, and the output is read
+in runs. Every value is computed by the same IEEE operations in the same order, so the output is bit-identical to the
+unmodified copies (tests/Perf190krTests.inc pins it). Changes are marked `LYNX (round 190kr)`.

+ 26 - 0
third_party/signalsmith/signalsmith-linear/stft.h

@@ -3,6 +3,8 @@
 
 #include "./fft.h"
 
+#include <algorithm>
+
 namespace signalsmith { namespace linear {
 
 enum {
@@ -246,6 +248,17 @@ struct DynamicSTFT {
 		output.pos = (output.pos + samples)%_blockSamples;
 		_samplesSinceSynthesis += samples;
 	}
+	// LYNX (round 190kr): `samples` times moveOutput(1) (which zeroes each passed position and its window product and
+	// leaves samplesSinceSynthesis() alone), in one pass
+	void clearOutput(size_t samples) {
+		for (size_t i = 0; i < samples; ++i) {
+			for (size_t c = 0; c < _synthesisChannels; ++c) {
+				output.buffer[output.pos + c*_blockSamples] = 0;
+			}
+			output.windowProducts[output.pos] = almostZero;
+			if (++output.pos >= _blockSamples) output.pos = 0;
+		}
+	}
 	size_t samplesSinceSynthesis() const {
 		return _samplesSinceSynthesis;
 	}
@@ -319,6 +332,19 @@ struct DynamicSTFT {
 		norm = mode;
 	}
 	
+	// LYNX (round 190kr): whether two analysis channels hold the same input, bit for bit (then their analyses are equal)
+	bool inputChannelsEqual(size_t channelA, size_t channelB) const {
+		const Sample *a = input.buffer.data() + channelA*_inputLengthSamples;
+		const Sample *b = input.buffer.data() + channelB*_inputLengthSamples;
+		return std::memcmp(a, b, sizeof(Sample)*_inputLengthSamples) == 0;
+	}
+	// LYNX (round 190kr): a channel's analysis taken from another one's (for the same input: the same spectrum, and the
+	// same analysis state as analyseStep leaves)
+	void copyAnalysis(size_t fromChannel, size_t toChannel, size_t samplesInPast=0) {
+		_samplesSinceAnalysis = samplesInPast;
+		std::copy(spectrum(fromChannel), spectrum(fromChannel) + _fftBins, spectrum(toChannel));
+	}
+
 	void analyse(size_t samplesInPast=0) {
 		for (size_t s = 0; s < analyseSteps(); ++s) {
 			analyseStep(s, samplesInPast);

Разница между файлами не показана из-за своего большого размера
+ 859 - 188
third_party/signalsmith/signalsmith-stretch.h


Некоторые файлы не были показаны из-за большого количества измененных файлов