Coder Social home page Coder Social logo

fmodforfoxes's Introduction

header

nuget

Current FMOD version target: 2.02.19

Join our Discord

The time has come. You're finally witnessing a high-level cross-platform C# library, which makes Monogame and FMOD best friends.

In case you've come here and the only thing you've understood so far was the doge meme, FMOD is a powerful cross-platform audio engine, which is pretty much the only hope to have any decent audio in Monogame.

The catch is - FMOD is written in C++, and unless you're using Unity, you're only getting a bare-bones C# wrapper. No tutorials, no setup guides. Only you and DllImport.

send help

That's why this library exists. It does the tough part for you and provides a basic high-level interface.

Also note that even though the primary target of this library is Monogame, you can easily adapt it for any other C#-based project.

Setup

The initial setup is a little fiddly. Here's the thing - the FMOD license prohibits me from distributing their libraries in my Nuget package - so you have to download them yourself. But fear not, I've put together a detailed guide. With pictures.

Preparations

Visit the FMOD Download page (accessing it requires registration), find the FMOD Studio API downloads and get APIs for Windows, Linux and Android (in case you want all three). If you're going to set up all three, of course.

NOTE: Current version of the library was tested on FMOD v2.02.19. I really recommend getting it. Later versions will probably also work, but I have no guarantee.

Windows API requires installation, Linux and Android don't. You can drop them near the Windows API just to have everything in one place.

setup1

Common logic

In your crossplatform project, install 2. Install FmodForFoxes NuGet package. It contains the API.

Windows & Linux

  1. Open your DesktopGL or WindowsDX Monogame project.
  2. Install the NuGet package FmodForFoxes.Desktop. Alternatively, you can plug this repo as a submodule and reference projects directly.
  3. Navigate to your FMOD Windows API installation. From there navigate to \api\core\lib. You will see two directories: x64 and x86. Each one will contain this:

setup2

Out of all the files you'll need only fmod.dll and fmodL.dll from either x86 or x64 directories (x64 highly recommended). The files engine with L mean that the library supports logging. They are used for debugging andf shoudl not be included into the final release. Copy fmod.dll and fmodL.dll to the root of your DesktopGL or WindowsDX project. Do the same for \api\studio\lib libs and you should end up with it looking like this:

setup3

Make sure dll files will be copied to the output directory:

setup4

  1. Navigate to your FMOD Linux API installation. From there navigate to \api\core\lib. This time you will see four directories:

setup5

You'll need only x64 or x86.

Each directory contains this:

setup6

You will need all libfmod files from here. Copy fmod files from x86 or x64 directory the root of your project, same as on Windows. Do the same for \api\studio\lib libs and you'll end up with this:

setup7

NOTE: DesktopGL project works on both Linux and Windows, so you need to add the dll files there too.

Again, make sure all the files you've just added will be copied to the output directory:

setup4

And that's it - you've gotten yourself cross-platform desktop FMOD!

Android

  1. Open your Monogame Android project.
  2. Install NuGet package FmodForFoxes.Android. Alternatively, you can plug repo as a submodule and reference projects directly.
  3. Create libs directory in the root of your project.
  4. Navigate to your FMOD Android API installation. From there navigate to \api\core\lib. You will see this:

setup8

  1. Each folder contains libfmod.so and libfmodL.so. Copy everything except .jar file over to your libs directory. Don't lose this jar, tho. We'll need it later. Do the same for \api\studio\lib libs and you should end up with this:

setup9

  1. Select each .so file you've just copied, open their Properties and set their Build Action to AndroidNativeLibrary.

setup10

  1. Create an NET6 Android Bindings Project.

    setup12

    Remember that jar from earlier? Now you need to copy it into the Jars directory and make sure its Build Action is set to AndroidLibrary.

    setup13

    Now reference Bindings project to your main Android project - and you're golden.

    setup14

Studio setup

FMOD Studio setup process is exactly the same, but you'll need to look into studio instead of core directories. It's also extremely important that ALL your binaries are the exact same version. FMOD doesn't like version mixup. Foxes don't like version mixup. Nobody does.

If you still have questions, take a look at the Samples project that has everything set up for all platforms.

Playing some tunes!

So, after you've set everything up, it's time to bop some pops, as kids say these days.

  1. Find a sound file and import it into the Content Pipeline.
  2. Select the sound file and set its Build Action to Copy.

setup11

  1. Include the FmodForFoxes namespace and paste the following code into your Initialize() method:
FmodManager.Init(_nativeLibrary, FMODMode.CoreAndStudio, "Content");

var sound = CoreSystem.LoadStreamedSound("test.mp3");
var channel = sound.Play();
channel.Looping = true;

_nativeLibrary is an instance of INativeFmodLibrary that you have to create separately in your platform-specific projects. Samples project already has this set up.

And lastly, do note that FmodManager has to be properly updated and unloaded. Your main gameloop class has to have this added:

/// <summary>
/// UnloadContent will be called once per game and is the place to unload
/// game-specific content.
/// </summary>
protected override void UnloadContent()
{
	FmodManager.Unload();
}

/// <summary>
/// Allows the game to run logic such as updating the world,
/// checking for collisions, gathering input, and playing audio.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Update(GameTime gameTime)
{
	FmodManager.Update();
	base.Update(gameTime);
}
  1. Compile and hope that you (and me) did everything right.

You can also check out the included Samples project.

But what about other platforms?

I'd like to make console versions of the library - but currently I have no ability to do so, and probably won't have for a long time. As for UWP and Apple platforms, I just don't care about them enough.

If you want to be a hero and expand the library with any of those platforms yourself - contact me and we'll figure something out.

License and legal stuffs

This library is licensed under MIT, so you can use it and its code in any shenanigans you want. Free games, commercial games, anything - no payment or royalties required. Just leave a credit. ; - )

But the show's main star is a bit different. FMOD has its own license, which is much less permissive than mine.

Demo music is provided by Agrofox and FMOD team.

Also big thanque to StinkBrigade who helped a ton in adding FMOD Studio support.

don't forget to pet your foxes

fmodforfoxes's People

Contributors

chaifoxes avatar extdeniss avatar jeffgamedev avatar kimeraroyal avatar martenfur avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

fmodforfoxes's Issues

UWP support?

Hi, I was wondering, is UWP support for FmodForFoxes planned/in the works?

How to check if Muting/Looping/sound file exists

I just found your amazing plugin, but I was wondering how to check if a song exists in a folder, how to mute the soundchannel on which the song plays (and how to check if it's muted) and how to check if a song is looping. Also I'd like each song to have a seperate intro song file that only plays once and then plays the regular song. Do you have an idea of how to do that?

Suggestion: Add FMODManager.Update to readme

I never really post or comment stuff on github, so this might not be how an issue should be posted exactly. So apologies in advance, but I had a silly problem that can easily be prevented for future users I think.

I followed the whole setup guide and got it working perfectly, but after some testing of my game I realized the sound stopped working eventually. It took me quite a while to realize that I didn't use
FMODManager.Update();
Which I think is responsible for clearing used channels that became free? (And probably more important stuff)
It wasn't mentioned in the readme, and I'm the kind of person to not dive into the demo's haha. (I noticed it in a demo I checked after I was out of ideas)

I know this repo hasn't been updated in a while, but it seems so powerful to me that I think a lot of people use it, and maybe just adding that extra pretty important explanation can help some idiots like me save a few hours haha

Thanks for making my game make sound <3

For extra info: I'm now using MonoGame 3.8 and works perfectly!

EDIT:
I found out how to propose a change, and submitted it. Hope it's useful!

MAUI - Android FMOD Studio - Loads Banks but doesn't play anything

I know this might be a bit of a stretch but I've your library FMODForFoxes to work with MAUI using the FMOD Core services and things work fine (Nice library). But when I attempt to use the FMOD studio capabilities, all the RC codes indicate things worked but I never get any audio.

I've essentially implemented the same code in MAUI as the reference included in your samples.

 `FMODManager.Init(new AndroidNativeLibrary(), FMODMode.CoreAndStudio, "content");
    List<Bank> _banks = new List<Bank>();
    _banks.Add(await StudioSystem.LoadBank("Master.bank"));
    _banks.Add(await StudioSystem.LoadBank("Master.strings.bank"));
    _banks.Add(await StudioSystem.LoadBank("Vehicles.bank"));



      var _engineDescription = StudioSystem.GetEvent("event:/Vehicles/Car Engine");
    

    FMOD.Studio.Util.parseID("{0c8363b4-23af-4f9c-af4b-0951bfd37d84}", out var sfxGuid);
    _engineDescription.LoadSampleData();

     _engineInstance = _engineDescription.CreateInstance();

    //// If you have any parameters set within FMOD Studio, you can change them within the code.
    _engineInstance.SetParameterValue("RPM", 1000);
    _engineInstance.SetParameterValue("Load", -1f);
    _engineInstance.Volume = 1;
    if (_engineInstance.PlaybackState == FMOD.Studio.PLAYBACK_STATE.PLAYING)
    {

        _engineInstance.Stop();
    }
    else
    {

        _engineInstance.Start();
    }`

Any idea's what might be happening?

Setting 3D audio attributes doesn't work.

Trying to implement 3D audio into my project. I've created a listener and I'm setting its position every frame.

var position = GameManager.Instance.Player.Position.ToVector3();
listener.Position3D = position;

And I'm setting the 3D position of EventInstances when they play.

var attr = new Attributes3D()
{
    Position = srcPosition.ToVector3(),
};
i.Attributes = attr;

If I log to the console the value of either of these attribute positions, it reveals that they're still set to 0, 0, 0. Not sure why it's not updating but it seems like a bug.

Setting root FMOD directory doesn't support parent directories.

When I attempt to set the main directory on AudioMgr.Init(), it appears to ignore relative parent paths, such as ".."

So when attempting to set the parent folder above where the exe is stored to be the main path it fails:
AudioMgr.Init(".."). It also appears to not support specific paths, like "C:\My Projects\Content".

Any insight on how to work through this would be appreciated!

does it have support for FMOD dsp Plugins?

So, the question on the title :)

Can you add to the library and easily use plugins for FMOD?

Specificically how hard is implement with the lib spatial audio, using plugins like oculus spatialicer, steam audio or resonance audio by google.

A few days ago, I got to use the regular FMOD headers for c# with resonance audio in a small monogame test project, but of course bot are separated libs, and aren't integrated one into the other, like your pluging does, incorporing fmod with the content pipeline of monogame and other awesome stuff.

So... can you do that in the current state of the lib? :P

thanks!

Add link to sample project under the "Getting started" section of the documentation.

In the "Getting Started" section of the documentation, it recommends to the user that they should install nuget packages locally in the project, and then links to Microsoft's documentation about NuGet configuration. However MS's docs aren't always so clear. Adding a link to the sample project, or more specifically the nuget.config file within the sample project might make setup smoother for users who aren't as experienced with NuGet configuration (read: me), or are otherwise running into issue with configuring NuGet to install packages locally.

https://github.com/AristurtleDev/monogame-aseprite-examples/tree/main

Monogame.DestktopGL.Core Compatiblilty

Hello gnFur,

Thanks for this great helper library.

I'm currently working with the DesktopGL.Core version of Monogame, using .netcore ( hence the name ! )
As this is not relying anymore on the Mono logic to load native library, your library does not manage to load fmod native libraries, using the nuget packages and the instructions you provided.

Any idea on how to make it work ?
I'm far out my comfort zone when it comes to native library loading.
Maybe this lib could help : https://github.com/mellinoe/nativelibraryloader

Thanks in advance for your answer.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.