Archived

This topic is now archived and is closed to further replies.

robpearmain

How to play OGG file in Managed C# DirectX

Recommended Posts

My best bet would be to use Managed DirectShow with C#. However, since DirectShow actually uses those filters/plugins/codecs/whatever installed on the machine, you would not be able to play the OGG until you install the relevent codecs.

Share this post


Link to post
Share on other sites
Use the OGG File Format specification to write your own loader/decompresser, write out the sound data into a Microsoft.DirectX.DirectSound.Buffer object, and play it.

Alternatively, you could try the Microsoft.DirectX.AudioVideoPlayback.Audio class.

Share this post


Link to post
Share on other sites
It is usually inefficient to buffer the whole ogg, especially if it is a music track, since the raw sound will require a relatively huge amount of memory. Instead, create a buffer that can hold, for example, a second of sound - and read a little bit from the ogg file every second to fill the buffer again.
The latter is the way DirectShow does it

-Nik

EDIT: You can't really go more "real-time" than that, since at least the sound card needs some kind of actual buffer for the data.

[edited by - Nik02 on April 21, 2004 9:19:26 AM]

Share this post


Link to post
Share on other sites
The other way is a good programming excercise, but I think that DirectShow is enough for most cases, including yours.
Only bad thing in DShow approach is that you have to get the ogg/vorbis codec to the target machine.

-Nik

Share this post


Link to post
Share on other sites
Yes it can, but you need dshow-compatible ogg codec in the system

-Nik

EDIT: I would've posted a link to the codec download page, but noticed that the site is down: Vorbis

EDIT 2: However, here is the codec download!

[edited by - Nik02 on April 21, 2004 10:24:50 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by noVum
I really doubt that DirectShow can playback Ogg files per default


That''s the whole idea of DirectShow, it uses filters. If a user installs a filter for xyzzy music format or supermpeg88 video, then if he tries to play an AVI or WMV with the video stream in supermpeg88 and the audio in xyzzy, with ANY player, then it will work. DirectShow will identify the stream format, notice that it has a decompressor, and load it.

This way the possibilities are not hardcoded in DirectShow, and anyone can write filters for new formats. So if you have an ogg playback filter, then even your own game can play ogg files as background music.

Share this post


Link to post
Share on other sites