Jump to content

  • Log In with Google      Sign In   
  • Create Account

Calling all IT Pros from Canada and Australia.. we need your help! Support our site by taking a quick sponsored surveyand win a chance at a $50 Amazon gift card. Click here to get started!


AxPet

Member Since 13 Feb 2012
Offline Last Active Feb 20 2012 04:04 PM

Posts I've Made

In Topic: XAudio2 - Playing Ogg, Mp3, Midi, etc.

13 February 2012 - 05:01 PM

For Ogg try this:http://www.codeproje...g-Vorbis-Player

"What do I need to do?"
Go to the link I gave you, download the source files and extract them. You'll have two directories: VS2003 and VS2005. Go to the latter and access OggPlayer Demo and pick-up the file TgPlayOgg_vorbisfile.dll and copy it in the same directory where you have the executable for your C# program. This dll file is actually a native C++ library and you'll have to import its functions in your C# application. Here is how you do it: Open the OggPlayer Sample directory, locate the file NativeMethods.cs and copy the code from it in a code file in your application. What that code does is that it imports the native functions from the dll into your managed application and now you'll be able to use them as if they are part of your code. An important note here: in order for this to work you'll have to check Allow Unsafe Code in your project's properties. Next take a look at the file OggPlayer.cs from that same directory to find out how to play streaming music. Sound effects are played by writing the decoded PCM data entirely in the sound buffer.

"Also - should "sounds" (effects: rain, walking, etc) be preloaded into memory and music be streamed from the harddisk?"
Sound effects are short enough and small enough even decoded into PCM that they can fit in the memory. Music, however, in decoded PCM format can be extremely large, so it has to be streamed. You can stream it either from the file located on the harddsik, or from a copy of that file loaded in a memory stream. I use the latter.

PARTNERS