Reputation: 11
How can i load an Audio File from FileOpenPicker
with NAudio
or SharpDX
and add an Audio FX
like Flanger, Phaser, Echo, Gate, Bit Crusher.
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();
Upvotes: 0
Views: 703
Reputation: 11
This is my Solution for a FX Sound Effect on my Audio File.
Before we can start, you need the following packages, that you get easily with 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());
The AudioPlayer Class come from Alexandre Mutel https://github.com/sharpdx/SharpDX-Samples/tree/master/Desktop/XAudio2/AudioPlayerApp . In the AudioPlayer Class you change the Constructor from:
public AudioPlayer(XAudio2 xaudio2, Stream audioStream)
To:
public AudioPlayer(XAudio2 xaudio2, IRandomAccessStreamWithContentType audioStream)
Now, you can control the Audio File with audioPlayer.Play();
audioPlayer.Stop();
You can add an Effect so:
SourceVoice sourceVoice = audioPlayer.SourceVoice;
Reverb reverb = new SharpDX.XAPO.Fx.Reverb();
EffectDescriptor effectDescriptor = new EffectDescriptor(reverb);
sourceVoice.SetEffectChain(effectDescriptor);
sourceVoice.EnableEffect(0);
Upvotes: 1