Coder Social home page Coder Social logo

fmodaudio's Introduction

FmodAudio

NuGet Version Join FmodAudio's Discord

Welcome to FmodAudio, a C# Wrapper for the FMOD audio library.

This library has been written for .NET 5 and above.

In order to use this library, you will need to download the FMOD native binaries from https://www.fmod.com/download

If you find a bug, or have a feature request, please file an issue on github, and I'll review it as soon as possible. Alternatively you can now join FmodAudio's Discord server, and talk with me directly. (Link Above)

If you wish to contribute, see CONTRIBUTING.md

How to use FmodAudio

First off, this wrapper allows you to choose a location to look for the native library through the Fmod.SetLibraryLocation() method. Use this if you have a non-standard place you put the library.

Now you have two options for calling into FMOD. The first and recommended way is to use the Object Oriented wrapper Types (FmodSystem, Sound, Channel, etc.) beginning with calling Fmod.CreateSystem().

Alternatively, you have direct access to the binding through the Fmod.Library property for situations where FMOD gives you a OOP handle directly via callbacks. All FMOD API methods are exposed through the class this property returns.

All API methods and structures are documented in https://www.fmod.com/resources/documentation-api?version=2.1&page=core-api.html

Example usage found in the Examples directory of this repository.

fmodaudio's People

Contributors

sunkin351 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

fmodaudio's Issues

Example Project unable to find Native Fmod DLL

Hello:
I want to try to run the example project in this repo.
I downloaded the repo souce code, unzip it, and open it with Visual Studio 2022.
I set up Example project as the "Set as Startup project", I can see the console window displayed.
But when I press return key, I got the following error:
System.DllNotFoundException: Unable to load DLL 'fmod.dll' or one of its dependencies: The specified module could not be found. (0x8007007E)
at System.Runtime.InteropServices.NativeLibrary.LoadFromPath(String libraryName, Boolean throwOnError)
at System.Runtime.InteropServices.NativeLibrary.Load(String libraryPath)
at FmodAudio.Fmod.<>c.<.cctor>b__35_0() in D:\GitHubRepos\FmodAudio-master\FmodAudio\Fmod.cs:line 114
at System.Lazy1.ViaFactory(LazyThreadSafetyMode mode) at System.Lazy1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
at System.Lazy1.CreateValue() at System.Lazy1.get_Value()
at FmodAudio.Fmod.get_Library() in D:\GitHubRepos\FmodAudio-master\FmodAudio\Fmod.cs:line 117
at FmodAudio.Fmod.CreateSystem() in D:\GitHubRepos\FmodAudio-master\FmodAudio\Fmod.cs:line 200
at Examples.Base.Example.Initialize() in D:\GitHubRepos\FmodAudio-master\Examples\Base\LibraryExample.cs:line 32
at Examples._3DExample.Initialize() in D:\GitHubRepos\FmodAudio-master\Examples_3D_Example.cs:line 41
at Examples.Program.StartExample(Type exampleType) in D:\GitHubRepos\FmodAudio-master\Examples\Program.cs:line 158

D:\GitHubRepos\FmodAudio-master\Examples\bin\Debug\net5.0\Examples.exe (process 36340) exited with code 0.
To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops.
Press any key to close this window . . .

Let me know how I can fix this issue.
By the way, I am using Windows 10 (Version 21H2).
Besides, can I use the repo to merge/concat mutliple audio files (aac format)?
Thanks,

Callback implementation

Not finding the abstractions for channel callbacks.

In the native C# Language, you would implement the call back function this way:
// Define the channel callback function
private static RESULT ChannelCallback(IntPtr channelControlRaw,
CHANNELCONTROL_TYPE controlType,
CHANNELCONTROL_CALLBACK_TYPE callbackType,
IntPtr commandData1,
IntPtr commandData2)
{
if (controlType == CHANNELCONTROL_TYPE.CHANNEL &&
callbackType == CHANNELCONTROL_CALLBACK_TYPE.END)
{
// The sound has reached its end point

            // Write your notification logic here
            Console.WriteLine("The sound has completed playing.");

            return RESULT.OK;
        }

        return RESULT.OK;
    }

Looking through your lib, I'm not finding the corollary types. Of course, you could have implemented this in a different manner like Events but don't see that either.

Loading Fmod Studio Bank files?

Not finding a way in the lib to load Fmod bank files.

In my case, l'd like to use the Bank file with a "Programmer Instrument" so I can load the audio stream on demand during program execution and apply the appropriate audio effects.

Background:
In my case, I'm apply audio effects to dynamically generated speech. I can certainly craft the effects via code but was hoping to take advantage to a Bank file that can be updated outside the code.

FFT Value Interpretation and Complex Numbers

In many cases we want to take the raw values from the object ParameterFFT* fftData = (ParameterFFT*) ptr; and extrapolate them into another format. I didn't feel that it is clear if the values from this call already come processed using Complex number class, or if it has to be done manually.

In the case of manually, the current design recommends we first store the value in the base Complex class (double), then use that as a parameter for the Fmod_Complex (float).
When we get the FFT spectrum using floatspectrum = fftData->GetSpectrum(channel); it's in float, however since Fmod_Complex is made to work with Base Complex, no constructor taking the raw float values, there are some extra operations that probably can be bypassed if the Fmod_Complex class receive some updates such as constructor for taking the float, method for getting Magnitude etc.

Or, am I totally misunderstanding the use of this interface?

Use with FMOD version 2.02

Hi, I wanted to ask if there are big changes necessary to get it to work with 2.02.
Right now it throws a version mismatch with the DLLs. If its possible to remove the version check, do you know if it will run with 2.02?
Btw I need 2.02 since I am working on armv8 and 2.01 only supports up to armv6 as far as I know.

I also know about the default included wrapper but I would really like to use yours.

DSP.GetParameterInfo throws ArgumentOutOfRangeException

Bug description

There's a problem with optaining parameter descriptions of a nested DSP plugin. It should contain 13 parameters but I can get descriptions just for parameter 0 to parameter 10. When I access parameter 11 then exception is thrown. I used FMOD 2.0 and Resonance Audio DSP plugin and I was exploring a nested plugin called Source.

Code causing the exception

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Windows;

using FmodAudio;
using FmodAudio.Dsp;

namespace FmodResonanceExperiment
{
    public static class ResonanceAudio
    {
        public static readonly ReadOnlyDictionary<string, Sound> Sounds;

        private static readonly Dictionary<string, Sound> _sounds;

        private static Plugin _basePlugin;

        private static FmodSystem _fmodSystem;

        private static DSP _listenerDSP;

        private static Plugin _listenerPlugin;

        private static ChannelGroup _masterChannelGroup;

        private static Plugin _nearFieldPlugin;

        private static Plugin _sourcePlugin;

        private static ChannelGroup _spatialChannelGroup;

        static ResonanceAudio()
        {
            _sounds = new Dictionary<string, Sound>();
            Sounds = new ReadOnlyDictionary<string, Sound>(_sounds);
        }/*mtd*/

        public static void AddSound(string fileName, bool loop = false)
        {
            Sound sound = new Sound(fileName, loop, _sourcePlugin, _nearFieldPlugin, _fmodSystem, _spatialChannelGroup);
            _sounds[sound.Name] = sound;
        }

        public static void Free()
            => _fmodSystem.Release();

        public static void Init()
        {
            _fmodSystem = Fmod.CreateSystem();
            _fmodSystem.Init(32);

            _basePlugin = _fmodSystem.LoadPlugin("resonanceaudio.dll");

            _listenerPlugin = _fmodSystem.GetNestedPlugin(_basePlugin, 0);
            _listenerDSP = _fmodSystem.CreateDSPByPlugin(_listenerPlugin);
            _nearFieldPlugin = _fmodSystem.GetNestedPlugin(_basePlugin, 1);
            _sourcePlugin = _fmodSystem.GetNestedPlugin(_basePlugin, 2);

            _masterChannelGroup = _fmodSystem.MasterChannelGroup;
            _spatialChannelGroup = _fmodSystem.CreateChannelGroup("spatial");
            _masterChannelGroup.AddGroup(_spatialChannelGroup, false);

            _spatialChannelGroup.AddDSP(ChannelControlDSPIndex.DSPTail, _listenerDSP);
        }

        public static void ShowPluginsInfo()
        {
            // Local function
            void pluginInfo(DSP plugin)
            {
                Span<char> pluginName = new Span<char>();
                plugin.GetInfo(pluginName, out FmodVersion a, out int b, out int c, out int d);
                string msg = $"Displaying parameters of {new string(pluginName)} plugin.{Environment.NewLine} Parameter count: {plugin.ParameterCount.ToString()}{Environment.NewLine}";

                for (int paramIndex = 0; paramIndex < plugin.ParameterCount; paramIndex++)
                {
                    ParameterDescription description = plugin.GetParameterInfo(paramIndex);
                    msg += $"Parameter index: {paramIndex.ToString() + Environment.NewLine}";
                    msg += $"Name: {description.Name + Environment.NewLine}";
                    msg += $"Short description: {description.Label + Environment.NewLine}";
                }/*for*/

                Clipboard.SetText(msg);

                MessageBox.Show(msg);
            }/*fnc*/

            pluginInfo(_fmodSystem.CreateDSPByPlugin(_sourcePlugin));
        }/*mtd*/

        /*mtd*/
        /*mtd*/
    } /*cls*/
}/*nspc*/

Illegal to use on iOS platforms

Just thought I'd let you know that the ADL license doesn't allow static linking, which means that iOS can't be supported without breaching the license. If this is an issue, please contact Firwood Softwar eto discuss purchasing a commercial license/open-source grant similar to those given to OpenTK and Silk.NET.

How to use and configure DSP of type FFT?

Couldn't find any examples that showed how to do this in the Examples or general source.
I need to access the spectral data e.g. fftDsp.GetParameterData(..) -> to find ParameterFFT.Spectrum, but the examples from the official FMOD source does not match the syntax of the FmodAudio implementation, so I wanted to ask directly.
Any help would be appreciated, thanks.

MAUI Cross Platform Support

First off, very cool library!

Wondering if you've explored generating the necessary abstractions for FMOD to support a cross platform implementation?

I've seen posts that talk about using the native FMOD Libs in that manner.

Should this work an android?

Hi, I try to use this lib with .NET6 MAUI
It works fine in windows, but on android it says
System.PlatformNotSupportedException: 'Operation is not supported on this platform.'
Could this be because it can't find the fmod libs for android?

FmodSystem Acts Strange With Certain Channel Counts

Below are a couple of snippets in my code.

    internal SfxSystem()
    {
        _fmodSystem = Fmod.CreateSystem();
        _fmodSystem.Init(MaxChannels);
    }
            Channel? channel = _fmodSystem.PlaySound(sfx.Sound);
            if (channel is null) throw new Exception("Sound channel wasn't properly created");
            if (randomPitch) channel.Pitch = _rng.Range(0.9f, 1.1f);

When I play the same sound repeatedly, what I hear is different depending on the MaxChannels value. If it's 16, I hear the sound effect playing repeatedly just fine. If it's 64, the sound will play normally at first, but it will eventually stop overlapping with itself and only play when the previous sound is done playing. When I set MaxChannels to 128, the sound plays fine for a few seconds and then cuts out completely, leaving me with total silence.

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.