如何在 .Net/Mono 中解码 wav、mp3 和/或 ogg?
我正在寻找一种跨平台(Windows、MacOSX 和 Linux 上的 .Net 和 Mono)方法来解码 wav、mp3 或 ogg 文件,以便我可以根据需要通过 DirectSound 或 OpenAL 播放解码的流。
一个可以解码 mp3 或 ogg 的解决方案就足够了——不需要解码两者。 如果它(或其他解决方案)也可以解码 wav,那将是理想的选择,但并不是绝对必要的,因为我可能会将我的 wav 文件转换为 mp3 或 ogg。
只能解码 wav 文件的解决方案只是部分解决方案,但我会采取我能得到的。 ;-)
这是我已经看过的内容:
- DirectSound 和 Alut 都支持 WAV 解码,但 Alut 已被弃用。
- ffmpeg 几乎可以解码任何内容,但它似乎没有跨平台的通用稳定版本?
- 我还没有尝试过 csvorbis,但它已经很旧了,我不确定它当前的状态是什么。
非常欢迎您尝试说服我上述解决方案之一实际上是最佳选择。
谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
为了部分回答我自己的问题,事实证明编写自己的 WAV 加载器非常容易。 我使用这篇文章描述了 wav 文件格式:
http://www.sonicspot.com/guide /wavefiles.html
To partially answer my own question, it turns out that it's pretty easy to write your own WAV loader. I used this article that describes the wav file format:
http://www.sonicspot.com/guide/wavefiles.html
一如既往,fmod 就是你的答案......
请随时在 http://www.fmod.org 上获取所有问题的解决方案/index.php/download#FMODExProgrammersAPI
as always, fmod is your answer...
please feel free to get solution to all your problems on http://www.fmod.org/index.php/download#FMODExProgrammersAPI
wav 文件有结构
44字节起始音频信号。 如果读取 44 到结束文件音频数据(wav 文件),您可以在 .NET(openl)中播放您的音乐
https://dpaste.com/8VNKMAUU5
wav file have structure
44 byte start audio signal. if read 44-to end file audio data(wav file)your have playing in .NET(opeanl) your music
https://dpaste.com/8VNKMAUU5
https://sites.google.com/site/cobnut3d/
SlimDX.DirectSound - 是一个C# 代码示例。
https://sites.google.com/site/cobnut3d/
SlimDX.DirectSound - is an example of code to C #.
您还没有提到您正在寻找的许可类型。 我使用 FMOD 取得了出色的效果,该软件可免费用于非商业用途项目。 它可以播放多种格式,包括 ogg 和 mp3,并具有广泛的 API 来控制如何播放它们。 它是跨平台的,正如您所需要的。
FMOD很大程度上是针对游戏的; 如果它已经具备出色的 3D 功能,我不会感到惊讶(尽管我不确定)。
正如您所见,我是它的忠实粉丝,这主要是因为第一次获得一个空白的 C# 项目来播放 OGG 文件非常轻松。
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.
对于 WAV 文件的简单支持,您可以在 mcs/class/System/System.Media/AudioData.cs (http://anonsvn.mono-project.com/viewvc/trunk/mcs/class/System/System.Media/)。
要解码 ogg 音频文件,您可以查看 mono 的 sn 服务器中的 csvorbis 模块:
http://anonsvn.mono-project.com/viewvc/trunk/csvorbis/< /a>
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/
您应该能够直接使用 System.Media.SoundPlayer 播放 .wav 文件。 不确定这是否对您的用例有帮助。
You should be able to play back .wav files directly with System.Media.SoundPlayer. Not sure if that helps your use case.
我使用 ffmpeg 工作,到目前为止我很喜欢它。 是的,各个版本之间几乎没有问题,但它是所有版本中最有效的。
I worked with ffmpeg and so far I like it. Yea there are few issues across releases, but it is the most efficient of all.