如何使用FileOpenPicker
或NAudio
从SharpDX
加载音频文件,并添加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轻松获得以下软件包:
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);