【问题标题】:Windows 8.1 App Audio with Effects (NAudio or SharpDX)带有效果的 Windows 8.1 应用音频(NAudio 或 SharpDX)
【发布时间】:2015-05-01 20:12:46
【问题描述】:

如何使用NAudioSharpDXFileOpenPicker 加载音频文件并添加Audio FX,如镶边、移相器、回声、门、位破碎机。

FileOpenPicker openPicker = new FileOpenPicker();
openPicker.FileTypeFilter.Add(".mp3");
openPicker.FileTypeFilter.Add(".wav");
openPicker.FileTypeFilter.Add(".m4a");
openPicker.FileTypeFilter.Add(".wma");
openPicker.FileTypeFilter.Add(".aac");
StorageFile file = await openPicker.PickSingleFileAsync();

【问题讨论】:

    标签: c# windows audio naudio sharpdx


    【解决方案1】:

    这是我为音频文件添加 FX 音效的解决方案。

    播放声音

    在我们开始之前,您需要以下包,您可以使用 NuGet-Package 轻松获得:

    • SharpDX
    • SharpDX.MediaFoundation
    • SharpDX.XAudio2

    C#

    FileOpenPicker openPicker = new FileOpenPicker();
    openPicker.FileTypeFilter.Add(".mp3");
    openPicker.FileTypeFilter.Add(".wav");
    openPicker.FileTypeFilter.Add(".m4a");
    openPicker.FileTypeFilter.Add(".wma");
    openPicker.FileTypeFilter.Add(".aac");
    StorageFile audioFile = await openPicker.PickSingleFileAsync();
    
    MediaManager.Startup();
    XAudio2 xaudio2 = new XAudio2();
    xaudio2.StartEngine();
    MasteringVoice masteringVoice = new MasteringVoice(xaudio2);
    AudioPlayer audioPlayer = new AudioPlayer(xaudio2, await audioFile.OpenReadAsync());
    

    AudioPlayer 类来自 Alexandre Mutel https://github.com/sharpdx/SharpDX-Samples/tree/master/Desktop/XAudio2/AudioPlayerApp . 在 AudioPlayer 类中,您将 Constructor 更改为:

    public AudioPlayer(XAudio2 xaudio2, Stream audioStream)
    

    收件人:

    public AudioPlayer(XAudio2 xaudio2, IRandomAccessStreamWithContentType audioStream)
    

    现在,您可以使用audioPlayer.Play(); audioPlayer.Stop(); 控制音频文件

    添加效果

    您可以这样添加效果:

    SourceVoice sourceVoice = audioPlayer.SourceVoice;
    Reverb reverb = new SharpDX.XAPO.Fx.Reverb();
    EffectDescriptor effectDescriptor = new EffectDescriptor(reverb);
    sourceVoice.SetEffectChain(effectDescriptor);
    sourceVoice.EnableEffect(0);
    

    【讨论】:

    • 您在 Reverb() 构造函数中缺少 xaudio2 引用
    猜你喜欢
    • 1970-01-01
    • 2012-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-19
    相关资源
    最近更新 更多