Monday, September 12, 2016

c# - Loading sound in XNA without the Content Pipeline



I'm working on a "Game Maker"-type of application for Windows where the user imports his own assets to be used in the game. I need to be able to load this content at runtime on the engine side.


However I don't want the user to have to install anything more than the XNA runtime, so calling the content pipeline at runtime is out.


For images I'm doing fine using Texture2D.FromStream.


I've also noticed that XNA 4.0 added a FromStream method to the SoundEffect class but it only accepts PCM wave files.


I'd like to support more than wave files though, at least MP3.


Any recommendations? Perhaps some C# library that would do the decoding to PCM wave format.



Answer



I hadn't noticed the FromStream method, that's a good one to remember. I'm now curious about using FromStream vs DynamicSoundEffectInstance, since you could theoretically accomplish a lot of the same work with both methods.


Google turned up this library: http://robburke.net/mle/mp3sharp/ And you could also conceivably call lame.exe from within your app to decode the sound.


I'd be wary of MP3 though, it's a legal can of worms. Adobe pays a hefty fee to Fraunhofer for the right to use it in Flash. Ogg Vorbis is a superior format, easily converted from mp3 using free and open-source software, and there seem to be many more C#/.Net decoder libraries for it.




No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...