Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to decode wav, mp3, and/or ogg in .Net/Mono?

Tags:

I am looking for a cross-platform (.Net and Mono on Windows, MacOSX, and Linux) way to decode wav, mp3, or ogg files such that I can then play the decoded streams through DirectSound or OpenAL as desired.

A solution that can decode either mp3 or ogg would be sufficient -- decoding both is not necessary. If it (or another solution) can decode wav as well, that would be ideal, but isn't strictly necessary since I could potentially convert my wav files to mp3 or ogg.

A solution that can only decode wav files is only a partial solution, but I'll take what I can get. ;-)

Here's what I've already looked at:

  • DirectSound and Alut both support WAV decoding, but Alut has been deprecated.
  • ffmpeg will decode just about anything, but it doesn't seem to have a common stable release across platforms?
  • I have not tried csvorbis yet, but it's very old and I'm not sure what its current status is.

You are more than welcome to try to pursuade me that one of these above solutions is actually the best option.

Thanks.

like image 644
Walt D Avatar asked Apr 10 '09 19:04

Walt D


People also ask

Which is better MP3 or WAV or OGG?

Since OGG is a lossy audio format, some data from the original is irretrievably lost after the compression, so it's no match to FLAC, WAV or AIFF. However, in comparison to MP3, OGG is superior in sound quality and file size alike.

What is the difference between WAV and OGG?

Wav is a raw format, while mp3 is a compressed format for audio. ogg is more of wrapper format. it can wrap Speex compressed audio, Speex (www speex org)is a very efficient compression technique based on CELP.


2 Answers

You haven't mentioned the sort of licensing you're looking for. I've had excellent results with FMOD, which is available for free for non-commercial projects. It plays a diverse variety of formats, including ogg and mp3, and has an extensive API for controlling how to play them. It's cross-platform, like you require.

FMOD targets games to a large extent; I wouldn't be surprised if it already comes with excellent 3D features (though I don't know for sure).

As you can tell I'm quite a fan, which is mostly because it was surprisingly painless to get a blank C# project to play an OGG file for the first time.

like image 155
Roman Starkov Avatar answered Oct 12 '22 00:10

Roman Starkov


For simple support for WAV files you can look at mono's implementation in mcs/class/System/System.Media/AudioData.cs (http://anonsvn.mono-project.com/viewvc/trunk/mcs/class/System/System.Media/).

For decoding ogg audio files you can look at the csvorbis module in mono's sn server: http://anonsvn.mono-project.com/viewvc/trunk/csvorbis/

like image 23
lupus Avatar answered Oct 12 '22 00:10

lupus