What is the structure of audio playback in WPF?

I know this may sound like a subjective question, but I need some reasonable opinions on this topic:

In the C # / WPF GUI, I need to play short wave files in response to user interaction.
The specifications are as follows:

  • low latency (immediate start of playback)
  • code must be native C # (.Net 4.0)
  • should be combined with WPF
  • multiple simultaneous playbacks
  • no restrictions on sound buffer manipulation
  • guaranteed future (I want to use something that will support in a few years.)
  • the sound player module should be a simple class (= c # code) and not an encapsulated dll

So far, I got along well with DirectSound (using the Microsoft DirectX SDK), it meets all the requirements mentioned above. Since Visual Studio 2010 (.Net 4.0), Managed DirectX (MDX) is no longer supported, it also disappeared from the latest DirectX SDK.

What are my options now?

  • XNA seems redundant (too big) for me, as I am not developing a game, but an application. See this question for more information.
    It was supposed to be a replacement for MDX, but I read a lot of scary stories about its implementation. Or is it all fairy tales?
  • SlimDX may be an option, but it is a third-party product and again a rather large project.
  • There are several β€œsmaller” solutions that I know of, each of which has its drawbacks:
    • MediaElement (only with WMP10 +)
    • P / Invoke with WinMM
    • Playound
    • Soundplayer
    • Mediaplayer
  • In the wild, there are many custom audio libraries that work more or less well.
    (NAudio, BASS, waveOut ...)

I am really puzzled by what I should use for a new project. I do not want to delve into a completely new structure to find out that its limitations do not allow me to use it.

Thanks in advance!

+4
source share
1 answer

It looks like some of the options will do what you need, but I will answer your requirements for NAudio

low latency (immediate start of playback)

No audio library will start immediately. NAudio can easily work with delays of about 50 ms using the WaveOut API. Perhaps faster if you use WASAPI

code must be native C # (.Net 4.0)

NAudio code is native C # and contains shells for the Windows API

should be combined with WPF

NAudio works great with WPF

multiple simultaneous playbacks

Multiple playbacks supported. You can additionally create a mixer to have one playback and mix different inputs and outputs.

no restrictions on sound buffer manipulation

This is a great advantage of NAudio over some of your other options. You have full access to the data samples and you can manipulate the way you like.

guaranteed future (I want to use something that will support in a few years.)

There are no guarantees in open source software. But with its open source code, nothing prevents you from fixing bugs yourself. NAudio has been around for 10 years.

the sound player module should be a simple class (= c # code) and not an encapsulated dll

Well, you can copy the code into your own project, but there are quite a few helper classes, so it may be easier for you to just use the DLL.

+5
source

Source: https://habr.com/ru/post/1339648/


All Articles