イコライザー付きサウンド[終了]
質問
数日前からC#を使ってイコライザーを作成しようとしています。NAudio を何度も見てきましたが、naudio で動作する有効なイコライザーを見つけることができませんでした。数日後、私はついに @stackoverflow に来ました。C# を使用してイコライザーを作成する方法を知っていただければ幸いです。
追伸:System.Media.SoundPlayer も試してみました。しかし、そのSoundPlayerはdspに関係するものさえサポートしていません。では、外部の「純粋な」オーディオで動作する別のオーディオライブラリはあるのでしょうか?
解決
では、外部の「純粋な」オーディオで動作する別のオーディオライブラリはあるのでしょうか?
はい、1 つあります: https://cscore.codeplex.com
による イコライザーサンプル, 、次のようにイコライザーを使用できます。
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% リアルタイムで実行されるため、すべての変更が即座に適用されます。必要に応じて、各チャネルに個別にアクセスして変更することもできます。
所属していません StackOverflow