tags:

views:

146

answers:

3

Hi Everyone,

I want to do some slightly advanced audio playing using a standard WPF application.

Here is what I need:

  • ability to smoothly loop
  • change pitch
  • play multiple sounds at once

I know the SoundPlayer class in not sufficient because it cannot play multiple sounds at once, so I began looking into the XNA SoundEffect class (and similar) but Im not sure how exactly the interoperability between XNA and WPF works.

Can someone shed some light here for me?

Cheers Mark

+1  A: 

Take a look at the BASS library.

It has a .NET wrapper that will work for WPF, and can do all those things you are looking for. (Although looping requires some coding, I think you can find example of this in their discussion forums)

Magnus Johansson
Sadly I need something that can be used in a commercial state... any thoughts?
Mark
You could buy it? ;)
RobS
@Mark, then buy a license from them. Read more about their pricing plans on their home page.
Magnus Johansson
So there is no way to do this without paying money for a license?
Mark
Also, dont get me wrong, I pay for software that is worth it, but only if necessary... :)
Mark
SoundEffect won't be enough for what you need. You can control volume, pitch, pan, and something else that I don't remember but not more. It's usually used to play... sounds effects in a game :)
Jodi
+1  A: 

You can achieve all of this with NAudio, although you will need to write a some custom code on top of the core library.

  1. Create a WaveStream derived class that in its Read method goes back to the start of its source stream whenever it runs out.
  2. This is your hardest request. Do you wish for the audio to play faster, or just have its pitch increased? Have a look at Skype Voice Changer for an example of using NAudio to perform realtime pitch shifting DSP.
  3. Use the WaveMixerStream to mix several WaveStreams together.
Mark Heath
A: 

So thanks very much for the library help everyone, but I ended up solving the problem by using the XNA XACT tool and the Audio framework that comes with XNA.

I did end up simply being able to add a reference to the XNA .Net Libraries and using them. There was a bit of initial confusion at first, but at the end, as long as you call Update() on your AudioEngine object every now and then, it works very well.

You can set programmable variables in your audio project (within XACT) that you manually manipulate using c#, I did this by adjusting the volume and pitch using the mouse x and y coords on the screen.

Here is a link to the tutorial that shows this nicely: http://blogs.msdn.com/coding4fun/archive/2007/04/27/2307521.aspx

-- Mark

Mark