2014-02-25 4 views
6

며칠 후로 C#을 사용하여 이퀄라이저를 만들려고합니다. NAudio는 꽤 많은 시간이 걸렸지 만 naudio에서 작동하는 작업 이퀄라이저를 찾을 수 없었습니다. 며칠 후, 마침내 여기 @stackoverflow가되었으므로 희망적으로 C#을 사용하여 이퀄라이저를 만드는 방법을 알았습니다.이퀄라이저가있는 사운드

추신 : System.Media.SoundPlayer도 사용해 보았습니다. 그러나 SoundPlayer는 dsp와 관련이있는 것은 지원하지 않습니다. 그래서 "순수한"오디오와 함께 작동하는 또 다른 오디오 라이브러리가 있습니까?

답변

12

"순수한"오디오와 함께 작동하는 다른 오디오 라이브러리가 있습니까?

예 중 하나가 :

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); 
    } 
} 

당신은 이제까지 당신이 원하는 이퀄라이저를 구성 할 수 있습니다 https://cscore.codeplex.com

EqualizerSample에 따르면, 당신은 그런 이퀄라이저를 사용할 수 있습니다. 또한 실시간으로 100 % 실행되기 때문에 모든 변경 사항이 즉시 적용됩니다. 필요한 경우 각 채널을 개별적으로 수정할 수있는 가능성도 있습니다.

+1

안녕하세요! 오늘 CSCORE를 업데이트했지만 문제가 해결되었지만 또 다른 문제가 발생했습니다. 이제 문제는 이퀄라이저를 사용하는 것이 이전 (이 코드)과 같지 않고 사용 방법을 파악할 수 없다는 것입니다. 제발 나를 도울 수 있니? – ACE