Pregunta

Desde hace unos días, estoy tratando de crear un ecualizador usando C#.He visto NAudio bastante tiempo, pero no pude encontrar ningún ecualizador que funcionara con naudio.Ahora, después de unos días, finalmente estoy aquí @stackoverflow y, con suerte, conoces una forma de crear un ecualizador usando c#.

PS:También probé el Sistema.Medios de comunicación.Reproductor de sonido.Pero ese reproductor de sonido ni siquiera admite nada que tenga que ver con dsp.Entonces, ¿hay otra biblioteca de audio que funcione con audio "puro" afuera?

¿Fue útil?

Solución

Entonces, ¿hay otra biblioteca de audio que funcione con audio "puro" afuera?

Sí, hay una: https://cscore.codeplex.com

Según el Ecualizadoresmuestra, puedes usar el ecualizador así:

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

Puedes configurar el ecualizador a lo que quieras.Y dado que se ejecuta al 100% en tiempo real, todos los cambios se aplican instantáneamente.Si es necesario, también existe la posibilidad de acceder a modificar cada canal por separado.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top