Open AlbatorLaho opened 2 years ago
Hey there @Albator11, did you find a fix, or by a chance some good cross platform c# audio library? I just ported my game engine to MacOS and NAudio no longer works... Thank you :')
Hey @hexiy!
I recently found LibVLCSharp which seems to work pretty well!
I tried OpenTK.OpenAL but it's pretty low-level. Which I'm more or less ok with, and it's (maybe) better if you're trying to do 3D audio effects as it (I think) was made with 3D space in mind. But it doesn't have any way to load audio files, so you're on your own for that... or you could use an audio file parser someone else has made. (most I've seen are only for .wav
though) I'm not sure if/how you could get the raw audio in bytes to send to OpenAL from LibVLCSharp... I'm sure it should support that, but I haven't really looked yet.
There is also SFML.Audio and SDL2 (there's a lot of C# bindings for SDL2... so take your pick I guess) but I haven't tried either yet. SFML (as far as I know) just uses OpenAL for the backend, but (I think) should be a bit higher-level. I have no idea about SDL2... I actually didn't realize it did audio until just recently. I'm pretty sure both SFML and SDL2 would need an external solution to load audio files.
So anyway, LibVLCSharp seems to be the only C# option to load multiple different kinds of audio/video files quite easily... although the first file I tested was a .aiff
which I guess it doesn't support? So I was confused for a bit when trying to get it to work. You'll also have to add packages for platform-specific binaries like Mac or Windows. (no Linux binaries are provided, so you're users will need to install them manually) Note that the size of the LibVLC binaries for Mac are about 42 MB, and for both Windows x64 and x86 it's about 344 MB. I'm not sure what kind of audio/video effects are build-in to LibVLCSharp... but there's a (I think unofficial) sample repository.
Here's some LibVLCSharp pseudo code:
using LibVLCSharp.Shared;
Core.Initialize();
using (var lib_vlc = new LibVLC()) {
using (var media = new Media(lib_vlc, new Uri("/example/audio_file.m4a"), ":no-video")) {
using (var media_player = new MediaPlayer(lib_vlc)) {
media_player.Media = media;
media_player.Play();
while (media_player.WillPlay || media_player.IsPlaying) { Thread.Sleep(100); }
}
}
}
Hopefully this is helpful in some way... I probably went a bit too in-depth... I don't know. Good luck!
Hey, i recently got a Macbook myself - i'll test this and push a fix
hmm @Albator11 Do you have an intel or M1 mac? I'm having troubles making LibVLC work on my M1 macbook, and in their repo readme it says LibVLC.Mac only supports x86_64 platform...
I use an Intel... I hadn't thought about ARM... sorry @hexiy. I guess you could try to build it, or find prebuilt binaries somewhere? Although it would probably be a hassle to get it working properly. I guess as long as you're only concerned about playing one or two types of audio files, than you could find parsers for them and use OpenAL or (probably a lot easier) SFML.Audio or something. I have done that with NAudio.Core to parse wav files and then sending the data to OpenAL to be played.
Hello there, any updates for m1 macs ? I'm on MacBook Pro 2021 m1 pro
and SharpAudio 1.0.65-beta
, AudioEngine.CreateDefault()
returns null.
Should be fixed with the latest version to be honest. See #70
[m1 air, latest os] Didn't work out of the box and once i installed openal through brew, following instructions from here https://github.com/feliwir/SharpAudio/issues/43, still didn't work, so i copied libopenal.dylib to the build folder and it works now.
I have a problem with
AudioEngine.CreateDefault()
trying to find the OpenAL library. (I'm using a Mac) I think a simple enough fix would be to add/System/Library/Frameworks/OpenAL.framework/OpenAL
to the library search path like OpenTK.OpenAL does... or maybe you just want to use OpenTK.OpenAL (or some other OpenAL bindings) instead to avoid manually binding OpenAL yourself? P.S.AudioEngine.CreateDefault()
doesn't tell you/warn that it can return null.