我正在尝试使用NAudio将BiQuad过滤器(或通常只是过滤器)应用于WaveFileReader.ToSampleSource,我需要能够设置过滤器何时启用以及启用时间。理想情况下,我不想播放音频文件并实时应用过滤器。
我尝试使用Filter.Process()方法并跳过不需要处理的字节,但是理想情况下,我需要一种方法,我也可以提供牺牲品来源,以及应在何处以及多长时间应用过滤器
if (randomPosition) // if set to true for use in testing purposes generates random positions and cut durations
{
var random = new Random();
var usableTrackLength = trackLength.Seconds / 3; // attempt to pick the middle of the song to avoid applying filters on the intro and outro
var cutLocations = new List<CutLocation>();
for (int i = 0; i < random.Next(10); i++)
{
cutLocations.Add(new CutLocation(GenerateNotchLocation(random, usableTrackLength), TimeSpan.FromSeconds(random.Next(50))));
}
cutMap = new FrequencyCutMap(cutLocations, 6000);
var sampleSource = WaveFile.ToSampleSource().AppendSource(x => new BiQuadFilterSource(x));
foreach (var cutLocation in cutLocations) // create filters using our map of locations and durations
{
var filter = new NotchFilter(WaveFile.WaveFormat.SampleRate, 500); // ideally need to be able to provide a start and end timestamp to these
sampleSource.Filter = filter;
}
}