void ProcessCommon(AudioReader reader, ref float[] impulse) { int targetLen = QMath.Base2Ceil((int)reader.Length) << 1; Complex[] commonSpectrum = new Complex[targetLen]; FFTCache cache = new FFTCache(targetLen); for (int ch = 0; ch < reader.ChannelCount; ++ch) { float[] channel = new float[targetLen]; WaveformUtils.ExtractChannel(impulse, channel, ch, reader.ChannelCount); Complex[] spectrum = Measurements.FFT(channel, cache); for (int band = 0; band < spectrum.Length; ++band) { commonSpectrum[band] += spectrum[band]; } } float mul = 1f / reader.ChannelCount; for (int band = 0; band < commonSpectrum.Length; ++band) { commonSpectrum[band] = (commonSpectrum[band] * mul).Invert(); } Array.Resize(ref impulse, impulse.Length << 1); for (int ch = 0; ch < reader.ChannelCount; ++ch) { Convolver filter = GetFilter(commonSpectrum, 1, reader.SampleRate); filter.Process(impulse, ch, reader.ChannelCount); } }
void ProcessPerChannel(AudioReader reader, ref float[] impulse) { int targetLen = QMath.Base2Ceil((int)reader.Length) << 1; Convolver[] filters = new Convolver[reader.ChannelCount]; FFTCache cache = new FFTCache(targetLen); for (int ch = 0; ch < reader.ChannelCount; ++ch) { float[] channel = new float[targetLen]; WaveformUtils.ExtractChannel(impulse, channel, ch, reader.ChannelCount); Complex[] spectrum = Measurements.FFT(channel, cache); for (int band = 0; band < spectrum.Length; ++band) { spectrum[band] = spectrum[band].Invert(); } filters[ch] = GetFilter(spectrum, WaveformUtils.GetRMS(channel), reader.SampleRate); } Array.Resize(ref impulse, impulse.Length << 1); for (int ch = 0; ch < reader.ChannelCount; ++ch) { filters[ch].Process(impulse, ch, reader.ChannelCount); } }