Using FMOD for C#?
Asked Answered
A

4

7

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.

Ammoniac answered 16/5, 2011 at 16:13 Comment(0)
B
7

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.

Bercy answered 16/5, 2011 at 16:25 Comment(1)
Yes, the C# wrapper is provided with the FMOD SDK to handle the P/Invoke. Just to clarify it is located in <install dir>\api\csharpArchaeozoic
O
2

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();
}
Orianna answered 12/12, 2011 at 4:46 Comment(4)
Okay to get this to work I had to manually copy the fmodex.dll into the bin folder it creates after building in the root of the project.Incarnation
Been a long time since i worked on this project. There are some of the more advanced features that are not implemented, if you need some of them, you can always help me by sending a commit after implementing them. When i have more free time i should send a few updates for this. I hope it helps you develop your project.Orianna
they seem to have removed it.Hightower
Forgot to update the link. Now at github.com/madrang/FmodSharp But i havent had the time to update it to work with the latest FMod version. I should do that at some point.....Orianna
J
1

In order to use FMOD in C# you need to wrap FMOD functions and structures using p/Invoke. This task has been taken care of for you in the open source project fmodnet

Jauch answered 16/5, 2011 at 16:26 Comment(5)
I believe the fmodnet project is quite out of date, I would recommend sticking to the C# wrapper provided with the FMOD SDK.Archaeozoic
It's been a while since the last time I used it. So you are problably right and using the one provided with FMOD should be better.Jauch
It doesn't work either. Visual Studio reports it's missing the FMDOnet reference, and it's not in the downloaded zip file.Incarnation
@Matthew Lock You do realize this answer is 3 years old... right?Jauch
Sure, but someone's got to say it doesn't work to help others.Incarnation
P
-1

To add a COM item to a VS project perform the following steps:

  • Register the COM

  • Select "Add Reference"

  • Select COM tab

  • Browse to item and select it.

You should see (after a build) that VS has created an Interopt DLL library in your BIN dir.

Peripheral answered 16/5, 2011 at 16:20 Comment(1)
@Jauch - as you say; the question implied he was trying to add a COM, I've no knowledge of FMOD specifically.Peripheral

© 2022 - 2024 — McMap. All rights reserved.