19 int windowSize = 1 << windowOrder;
21 if (stream.Channels <= targetChannel)
23 throw new ArgumentException(
24 $
"TargetChannel ({targetChannel}) exceeded stream channels ({stream.Channels})",
25 nameof(targetChannel));
28 float[] samples = stream.IsolateChannel(targetChannel).Cache().Samples;
30 int sampleOffset = (int)((samples.Length - windowSize) / (double)(windowCount - 1));
33 while (sampleOffset <= 0 && windowOrder > 4)
36 windowSize = 1 << windowOrder;
38 sampleOffset = (int)((samples.Length - windowSize) / (double)(windowCount - 1));
43 throw new ArgumentException(
"Clip too short to evaluate");
46 if (maxFreq ==
double.PositiveInfinity)
49 maxFreq = FrequencyDomain.GetComplexSampleFrequency(windowSize, windowSize / 2);
53 maxFreq = Math.Min(maxFreq, FrequencyDomain.GetComplexSampleFrequency(windowSize, windowSize / 2));
56 minFreq = Math.Max(minFreq, FrequencyDomain.GetComplexSampleFrequency(windowSize, 1));
59 SpectralDecomp decomp =
new SpectralDecomp(minFreq, maxFreq, windowSize, windowCount);
67 for (
int window = 0; window < windowCount; window++)
69 int specificOffset = sampleOffset * window;
70 hammingWindow.
Reset();
73 for (
int i = 0; i < windowSize; i++)
76 fftBuffer[i] = samples[specificOffset + i] * hammingWindow.
ReadNextSample();
81 decomp.Add(window, fftBuffer);
void Reset()
Sets this internal state of this stream to the initial state
float ReadNextSample()
Returns the next sample in the BGCEnvelopeStream
Represents a complex number with double-precision floating point components
Support for Fourier Transforms. Borrows heavily from Mathnet.Numerics.
static void Forward(Complex32[] samples)
static CosineEnvelope HammingWindow(double duration, bool open)