Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could not find the native OpenAL library on MacOS #68

Open
Albator11 opened this issue Sep 23, 2022 · 8 comments
Open

Could not find the native OpenAL library on MacOS #68

Albator11 opened this issue Sep 23, 2022 · 8 comments

Comments

@Albator11
Copy link

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.

@hexiy
Copy link

hexiy commented Sep 25, 2022

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 :')

@Albator11
Copy link
Author

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!

@feliwir
Copy link
Owner

feliwir commented Sep 29, 2022

Hey, i recently got a Macbook myself - i'll test this and push a fix

@hexiy
Copy link

hexiy commented Sep 30, 2022

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...

@Albator11
Copy link
Author

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.

@theramzay
Copy link

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.

@feliwir
Copy link
Owner

feliwir commented Nov 29, 2022

Should be fixed with the latest version to be honest. See #70

@hexiy
Copy link

hexiy commented Nov 29, 2022

[m1 air, latest os] Didn't work out of the box and once i installed openal through brew, following instructions from here #43, still didn't work, so i copied libopenal.dylib to the build folder and it works now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants