Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using FMOD for C#?

Tags:

c#

fmod

I'm working with FMOD in C#. I've tried importing the fmodex.dll file by selecting Project->Add Reference and browsing for the fmodex.dll, but I am getting an error:

A reference to ... could not be added. Please make sure that the file is accessible, and that it is a valid assembly or COM component

It is accessible, but I still get the error. I read the guide and it says to use the fmodex_vc.lib when linking to the fmodex.dll file. So I try, but I can't seem to find on how to link to .lib files in Visual Studio; searching Google always leads me to linking to .dll files.

like image 719
user488792 Avatar asked May 16 '11 16:05

user488792


People also ask

Is fmod used in C?

In the C Programming Language, the fmod function returns the remainder when x is divided by y.

What does fmod function do in C?

The fmod function calculates the floating-point remainder f of x / y such that x = i * y + f , where i is an integer, f has the same sign as x , and the absolute value of f is less than the absolute value of y . C++ allows overloading, so you can call overloads of fmod that take and return float and long double values.

What library is fmod in C?

C library function - fmod() The C library function double fmod(double x, double y) returns the remainder of x divided by y.

Can you use modulus with floats in C?

Yes, %(modulo) operator isn't work with floats and double.. if you want to do the modulo operation on large number you can check long long int(64bits) might this help you. still the range grater than 64 bits then in that case you need to store the data in .. string and do the modulo operation algorithmically.


2 Answers

Fmod is written in unmanaged C++ so you cannot reference it directly from a .Net application. There is a c# wrapper to the fmodex.dll in the fmod package under a directory called "fmod_wrapper" if I am not mistaken that you can add to your project and which will take care of making the P/Invoking for you.

like image 96
jeremy-george Avatar answered Oct 29 '22 00:10

jeremy-george


Try https://github.com/madrang/FmodSharp been working for a little while on it. It should be better than the current Fmod wrapper.

Instead of using Handles and coding like you are using C++ in C#. The FmodSharp wrapper is object oriented and there is no need to think about using handles.

public static void Main (string[] args)
{
    Console.WriteLine ("Fmod Play File Test");

    Xpod.FmodSharp.Debug.Level = Xpod.FmodSharp.DebugLevel.Error;
    var SoundSystem = new Xpod.FmodSharp.SoundSystem.SoundSystem();

    Console.WriteLine ("Default Output: {0}", SoundSystem.Output);

    SoundSystem.Init();
    SoundSystem.ReverbProperties = Xpod.FmodSharp.Reverb.Presets.Room;

    if (args.Length > 0) {
        foreach (string StringItem in args) {
            Xpod.FmodSharp.Sound.Sound SoundFile;
            SoundFile = SoundSystem.CreateSound (StringItem);

            Xpod.FmodSharp.Channel.Channel Chan;
            Chan = SoundSystem.PlaySound(SoundFile);

            while(Chan.IsPlaying) {
                System.Threading.Thread.Sleep(10);
            }

            SoundFile.Dispose();
            Chan.Dispose();
        }

    } else {
        Console.WriteLine ("No File to play.");
    }

    SoundSystem.CloseSystem();
    SoundSystem.Dispose();
}
like image 26
madrang Avatar answered Oct 28 '22 22:10

madrang