gpt4 book ai didi

c# - 从 FFT 抑制频率

转载 作者:太空宇宙 更新时间:2023-11-03 11:00:17 27 4
gpt4 key购买 nike

我想做的是从某首歌中检索频率并抑制所有未出现在人声范围或一般任何范围内的频率。这是我的抑制功能。

    public void SupressAndWrite(Func<FrequencyUnit, bool> func)
{
this.WaveManipulated = true;
while (this.mainWave.WAVFile.NumSamplesRemaining > 0)
{
FrequencyUnit[] freqUnits = this.mainWave.NextFrequencyUnits();

Complex[] compUnits = (from item
in freqUnits
select (func(item)
? new Complex(item.Frequency, 0) :Complex.Zero))
.ToArray();

FourierTransform.FFT(compUnits, FourierTransform.Direction.Backward);

short[] shorts = (from item
in compUnits
select (short)item.Real).ToArray();

foreach (short item in shorts)
{
this.ManipulatedFile.AddSample16bit(item);
}
}
this.ManipulatedFile.Close();
}

这是我的 wave 类(class)。

public sealed class ComplexWave
{
public readonly WAVFile WAVFile;
public readonly Int32 SampleSize;

private FourierTransform.Direction fourierDirection { get; set; }

private long position;
/// <param name="file"></param>
/// <param name="sampleSize in BLOCKS"></param>
public ComplexWave(WAVFile file, int sampleSize)
{
file.NullReferenceExceptionCheck();

this.WAVFile = file;
this.SampleSize = sampleSize;

if (this.SampleSize % 8 != 0)
{
if (this.SampleSize % 16 != 0)
{
throw new ArgumentException("Sample Size");
}
}
if (!MathTools.IsPowerOf2(sampleSize))
{
throw new ArgumentException("Sample Size");
}
this.fourierDirection = FourierTransform.Direction.Forward;
}
public Complex[] NextSampleFourierTransform()
{
short[] newInput = this.GetNextSample();
Complex[] data = newInput.CopyToComplex();

if (newInput.Any((x) => x != 0))
{
Debug.Write("done");
}
FourierTransform.FFT(data, this.fourierDirection);

return data;
}
public FrequencyUnit[] NextFrequencyUnits()
{
Complex[] cm = this.NextSampleFourierTransform();
FrequencyUnit[] freqUn = new FrequencyUnit[(cm.Length / 2)];
int max = (cm.Length / 2);
for (int i = 0; i < max; i++)
{
freqUn[i] = new FrequencyUnit(cm[i], this.WAVFile.SampleRateHz, i, cm.Length);
}
Array.Sort(freqUn);
return freqUn;
}
private short[] GetNextSample()
{
short[] retval = new short[this.SampleSize];

for (int i = 0; i < this.SampleSize; i++)
{
if (this.WAVFile.NumSamplesRemaining > 0)
{
retval[i] = this.WAVFile.GetNextSampleAs16Bit();
this.position++;
}
}
return retval;
}
}

FFT 正向和 FFT 反向都能正常工作。你能告诉我我的错误是什么吗?

最佳答案

不幸的是,即使在唱歌时,人声也不在“频率范围”内。它通常有一个主频率和多个谐波,具体取决于音素。

使用这个 https://play.google.com/store/apps/details?id=radonsoft.net.spectralview&hl=en或一些类似的应用程序来了解我的意思 - 然后重新定义您的策略。还有谷歌“卡拉 OK”效果。

下一步:

从您的示例中看并不明显,但您应该在 Windows 中扫描整个文件(谷歌“fft 窗口”)以处理整个文件。

关于c# - 从 FFT 抑制频率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17912397/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com