Project DescriptionWant to stream compressed audio for music or sound effects in your Windows, XBOX 360 or Windows Phone 7 Game? Look no further!
OggSharp allows playing OGG files using pure C# WITHOUT PInvoke. OggSharp decompresses an OGG stream and stuffs it into a PCM buffer. OggSharp is currently bundled with an example using XNA and DynamicSoundEffectInstance.
Of course if you aren't using XNA, this code is still useful if you require a managed sound solution that does not use PInvoke.
Example:
OggSong menuMusic = new OggSong(TitleContainer.OpenStream("Content/Music/MainMenuMusic.ogg"));
menuMusic.Play();
menuMusic.Pitch = 1.0f; // speed it up!
menuMusic.Pan = 0.1f; // move it from left to right speakers
float lengthInSeconds = menuMusic.Length; // how many seconds long is this song?
float position = menuMusic.Position; // where in the song are we?
menuMusic.Position = 5.0f; // seek 5 seconds into the song
// for sound effects, does not support playing multiple simultaneous times with the same OggSong yet...
OggSong explosion = new OggSong(TitleContainer.OpenStream("Content/Sounds/Explosion.ogg"));
explosion.Play();
Note much of this code is taken from the csvorbis code that was taken from JVorbis.
See more: https://github.com/mono/csvorbis