简体   繁体   English

使用FMOD进行C#?

[英]Using FMOD for C#?

I'm working with FMOD in C#. 我在C#中使用FMOD。 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: 我已经试过进口fmodex.dll通过选择项目- >添加引用和浏览该文件fmodex.dll ,但我得到一个错误:

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 请确保该文件是可访问的,并且它是有效的程序集或COM组件

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. 我阅读指导,并表示使用fmodex_vc.lib链接到时fmodex.dll文件。 So I try, but I can't seem to find on how to link to .lib files in Visual Studio; 所以我尝试,但我似乎无法找到如何链接到Visual Studio中的.lib文件; searching Google always leads me to linking to .dll files. 搜索Google总是引导我链接到.dll文件。

Fmod is written in unmanaged C++ so you cannot reference it directly from a .Net application. Fmod是用非托管C ++编写的,因此您无法直接从.Net应用程序中引用它。 There is ac# 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. 如果我没有弄错你可以添加到你的项目中并且将负责为你做P / Invoking,那么在fmod包中的fmodex.dll下有一个名为“fmod_wrapper”的目录的ac#包装器。

Try https://github.com/madrang/FmodSharp been working for a little while on it. 尝试https://github.com/madrang/FmodSharp已经工作了一段时间。 It should be better than the current Fmod wrapper. 它应该比当前的Fmod包装更好。

Instead of using Handles and coding like you are using C++ in C#. 而不是像在C#中使用C ++那样使用Handles和编码。 The FmodSharp wrapper is object oriented and there is no need to think about using handles. FmodSharp包装器是面向对象的,不需要考虑使用句柄。

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();
}

In order to use FMOD in C# you need to wrap FMOD functions and structures using p/Invoke. 为了在C#中使用FMOD,您需要使用p / Invoke包装FMOD函数和结构。 This task has been taken care of for you in the open source project fmodnet 在开源项目fmodnet中已经为您完成了这项任务

To add a COM item to a VS project perform the following steps: 要将COM项添加到VS项目,请执行以下步骤:

  • Register the COM 注册COM

  • Select "Add Reference" 选择“添加参考”

  • Select COM tab 选择COM选项卡

  • Browse to item and select it. 浏览到项目并选择它。

You should see (after a build) that VS has created an Interopt DLL library in your BIN dir. 你应该看到(在构建之后)VS在你的BIN目录中创建了一个Interopt DLL库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM