/// <summary> /// 重畳加算法でsamplesとインパルス応答との畳み込みを計算する /// </summary> public void Convolution(float[] samples) { Debug.Assert(samples.Length == blockSamples); Buffer.BlockCopy(samples, 0, convolutionBuf1X, 0, SizeofFloat * samples.Length); Array.Clear(convolutionBuf1X, samples.Length, blockSize - samples.Length); Array.Clear(convolutionBuf1Y, 0, blockSize); fft.Forward(convolutionBuf1X, convolutionBuf1Y); ComplexMultiple(convolutionBuf2X, convolutionBuf2Y, convolutionBuf1X, convolutionBuf1Y, frequencyResponseX, frequencyResponseY); fft.Inverse(convolutionBuf2X, convolutionBuf2Y); for (int i = blockSamples, j = 0; i < blockSize; ++i, ++j) { convolutionBuf2X[j] += overlap[j]; overlap[j] = convolutionBuf2X[i]; } Buffer.BlockCopy(convolutionBuf2X, 0, convolutionResult, 0, SizeofFloat * blockSamples); }
/// <summary> /// FFTテスト /// </summary> private void FftTest() { if (!fftTestFlg) { return; } debugButton.AddButton("FftTest", () => { float[] x = new float[] { 1, 0, 0, 0 }; float[] y = new float[] { 0, 0, 0, 0 }; var t = new Fft(4); t.Forward(x, y); t.Inverse(x, y); Debug.Log($"result ================================="); for (int i = 0; i < x.Length; ++i) { Debug.Log($"[{i}]:{x[i]:0.00} {y[i]:0.00}"); } }); }