6
由于几天,我试图创建一个均衡器使用C#。 看到NAudio相当多的时间,但我找不到任何适用于naudio的工作均衡器。 现在几天后,我终于来了@stackoverflow,希望你知道一种使用c#创建均衡器的方法。声音与均衡器
PS:我也尝试了System.Media.SoundPlayer。但是这个SoundPlayer甚至不支持与dsp有关的任何事情。那么有没有另一个音频库与外面的“纯粹”音频一起工作?
由于几天,我试图创建一个均衡器使用C#。 看到NAudio相当多的时间,但我找不到任何适用于naudio的工作均衡器。 现在几天后,我终于来了@stackoverflow,希望你知道一种使用c#创建均衡器的方法。声音与均衡器
PS:我也尝试了System.Media.SoundPlayer。但是这个SoundPlayer甚至不支持与dsp有关的任何事情。那么有没有另一个音频库与外面的“纯粹”音频一起工作?
那么,有没有与“纯”外部音频中的另一种声音图书馆?
是的,有一个:https://cscore.codeplex.com
按照EqualizerSample,你可以使用这样的均衡器:
using CSCore;
using CSCore.Codecs;
using CSCore.SoundOut;
using CSCore.Streams;
using System;
using System.Threading;
...
private static void Main(string[] args)
{
const string filename = @"C:\Temp\test.mp3";
EventWaitHandle waitHandle = new AutoResetEvent(false);
try
{
//create a source which provides audio data
using(var source = CodecFactory.Instance.GetCodec(filename))
{
//create the equalizer.
//You can create a custom eq with any bands you want, or you can just use the default 10 band eq.
Equalizer equalizer = Equalizer.Create10BandEqualizer(source);
//create a soundout to play the source
ISoundOut soundOut;
if(WasapiOut.IsSupportedOnCurrentPlatform)
{
soundOut = new WasapiOut();
}
else
{
soundOut = new DirectSoundOut();
}
soundOut.Stopped += (s, e) => waitHandle.Set();
IWaveSource finalSource = equalizer.ToWaveSource(16); //since the equalizer is a samplesource, you have to convert it to a raw wavesource
soundOut.Initialize(finalSource); //initialize the soundOut with the previously created finalSource
soundOut.Play();
/*
* You can change the filter configuration of the equalizer at any time.
*/
equalizer.SampleFilters[0].SetGain(20); //eq set the gain of the first filter to 20dB (if needed, you can set the gain value for each channel of the source individually)
//wait until the playback finished
//of course that is optional
waitHandle.WaitOne();
//remember to dispose and the soundout and the source
soundOut.Dispose();
}
}
catch(NotSupportedException ex)
{
Console.WriteLine("Fileformat not supported: " + ex.Message);
}
catch(Exception ex)
{
Console.WriteLine("Unexpected exception: " + ex.Message);
}
}
可以均衡配置,以任何你想要的东西。而且由于它实时运行100%,所有更改都会立即得到应用。如果需要,还可以单独访问修改每个通道。
嗨!今天我更新了CSCORE,它解决了一个问题,但又造成了另一个问题!现在问题是使用均衡器是不一样的(此代码),我无法弄清楚如何使用它。请问你能帮帮我吗? – ACE