c# - 具有效果的Windows 8.1应用程序音频(NAudio或SharpDX)

标签 c# windows audio naudio sharpdx

如何使用FileOpenPickerNAudioSharpDX加载音频文件,并添加flat,Phaser,Echo,Gate,Bit Crusher等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();

最佳答案

这是我对音频文件上的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类中,将构造函数从以下位置更改:
    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);
    

    关于c# - 具有效果的Windows 8.1应用程序音频(NAudio或SharpDX),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29994394/

    相关文章:

    java - 如何以正确的时机将音频数据发送到 Icecast?

    jquery - HTML5音频m4a

    c# - IEnumerable<T, int>、Arity 和通用类型定义

    C# - SQLClient - 最简单的 INSERT

    windows - window 崩溃的原因

    android - 在Android中支持对视频文件进行编码/解码

    c# - 从泛型方法返回 null

    c# - 如果我用 c sharp 写 static public void 而不是 public static void 会怎么样?

    windows - 当涉及文件权限时,是否可以在Windows上构建相同的Linux docker镜像?

    c# - 使用 Powershell 自动禁用 Windows 更新