0

I can play wav files just fine using a SoundEffectInstance but I can't find any way to play compressed audio with these libraries on the phone.

The way I've found to do this with XNA is to use the XACT creation tool as outlined here but the AudioEngine, WaveBank, and SoundBank classes aren't available on the phone as far as I can tell. Through various resources I've found I've seen people using the content loader to load directly into a sound effect:

SoundEffect soundEffect = Content.Load<SoundEffect>(@"Content\Audio\LaserShot");
soundEffect.Play();

but I can't seem to get that to work either.

It seems to me there must be a way to do this because having all your sound effects be uncompressed wav's is a bit ridiculous.

Mick N
  • 14,892
  • 2
  • 35
  • 41
DShook
  • 14,833
  • 9
  • 45
  • 55

1 Answers1

1

You need to add the uncompressed files to your content project. The content pipeline can compress them individually and let you load them up as SoundEffect (the same way you might load a Texture2D). The default setting is uncompressed ("Best") but you can set it to use lossy compression ("Low" or "Medium") for a very good compression ratio.

There's a newer answer of mine here that includes more information and detailed instructions.

Community
  • 1
  • 1
Andrew Russell
  • 26,924
  • 7
  • 58
  • 104
  • I can't figure out how to set up the content manager since my class doesn't derive from the base XNA game class. – DShook Nov 04 '10 at 23:21
  • My answer to another question http://stackoverflow.com/questions/2863575#2873609 might help. Basically: the WinForms sample (http://create.msdn.com/en-US/education/catalog/sample/winforms_series_1) has code for setting up a GraphicsDevice and ContentManager without needing `Game`. – Andrew Russell Nov 05 '10 at 01:04
  • I have to create a form, GraphicsDeviceService, and ServiceContainer just to initialize the content manager for loading only audio? – DShook Nov 05 '10 at 06:11
  • Ah - if you're not loading in any graphics-related content you should be able to just pass in ServiceContainer without needing an `IGraphicsDeviceService`-implementing object in there (and therefore you do not need a Form). Indeed you could write an essentially blank implementation of `IServiceProvider`. – Andrew Russell Nov 05 '10 at 10:15
  • Well, I got it to compile but now I can't get it to find any files to load. I've tried putting wav files in different directories, in the solution itself, tried loading the .xap file created by XACT also. Why is this so difficult and why isn't there any documentation how to do this? – DShook Nov 05 '10 at 20:56
  • I don't really see where the difficulty is. You're probably just missing a step somewhere. Have you tried making a small game that *does* use `Game`, and tried to load and play a sound that way? (the normal way). – Andrew Russell Nov 06 '10 at 02:45
  • I really don't think this all is available at all on the WP7 platform. Andrew, if you really know how to do it, it would be helpful to show the exact code/project files it takes since I've seen no other hint about how to do it, and I've been looking around for some time now. – Jonny Aug 31 '11 at 16:59
  • @Jonny I've modified my answer to [your question over here](http://stackoverflow.com/questions/7022360/wp7-play-many-compressed-mp3-wma-etc-audio-files-simultaneously-dynamically/7025544#7025544) to include screenshots. Hopefully you will get it now. – Andrew Russell Sep 01 '11 at 15:07
  • If you want to use ogg files, I made a codeplex project at http://xnaogg.codeplex.com that uses DynamicSoundEffectInstance to stream an ogg file. But the CPU usage hasn't fully been tested on WP7. – jjxtra Dec 29 '11 at 16:39