Coder Social home page Coder Social logo

supersonicsound's Introduction

Supersonic Sound

C# Wrapper For FMOD Studio Programmers API

FMOD Studio is a game changing Pro Audio content creation pipeline for sound designers and musicians. FMOD Studio programmer’s API is the interface for programmers to load FMOD Studio projects and play them back in realtime. Also includes a low level API for simple sounds/channels/dsp/geometry.

SupersonicSound is a C# wrapper for the FMOD studio API. There are a few wrappers for FMOD ex, the legacy sound system, but as far as I am aware SupersonicSound is the only C# wrapper for the modern FMOD Studio programmers API.

The aim of the SupersonicSound is to present a much more C# friendly experience for using FMOD studio programmers API.

Licensing

I do not control licensing of any FMOD technologies! You should go here to the FMOD sales page and check what the licensing conditions are before proceeding any further! As of January 1st 2015 the licensing conditions are very friendly to indies, non-commercial and educational uses.

This library itself is MIT licensed, see the LICENSE.md file for more details.

Compatibility

SupersonicSound is currently built with compatibility for FMOD 1.10.08 (latest as of August 28th 2018).

Upgrading or downgrading to other versions is relatively easy - just drag in the new C# wrapper and a new set of binaries (shipped with FMOD API). Methods which have been removed in FMOD will trigger a compile error as SupersonicSound tries to reference the now non-existant methods. New methods can be added on an as-needed basis (PRs much appreciated). The unit tests in the project will check all of the Enums in SupersonicSound to ensure they have equivalent values to the underlying FMOD enums.

Installation Instructions

The easiest way to get started using SupersonicSound is to use the nuget package. Run:

Install-Package SupersonicSound

at the nuget package manager console. Currently this package requires .Net 4.5 (due to a dependency on System.Numerics).

Unfortunately FMOD licensing does not allow for the FMOD dlls to be distributed with the nuget package and you will need to download these yourself.

Examples

SupersonicSound is almost a direct translation from the C++ API but instead does things in C# style. For example to get a parameter from an event instance in C++ is:

FMOD.Studio.ParameterInstance instance;
ERRCHECK(_eventInstance.getParameter(name, &instance));
return instance;

Doing the same in C# is:

return _eventInstance.Parameters[name]; //throws an exception if there is an error

Because the two APIs are so similar you should be able to follow along with the documentation supplied with the C++ API without any trouble. If you find any places where SupersonicSound is inconsistent then please create an issue here. Here's a more complete example of how to load banks, get an event from them and then play back a sound with a varying parameter:

using (System system = new System())
{
    // Load bank from disk
    var master = system.LoadBankFromFile("Master Bank.bank", BankLoadingFlags.Normal);
    var strings = system.LoadBankFromFile("Master Bank.strings.bank", BankLoadingFlags.Normal);
    var bank = system.LoadBankFromFile("Surround_Ambience.bank", BankLoadingFlags.Normal);

    // Get a single playback event
    var loopingAmbienceDescription = system.GetEvent("event:/Ambience/Country");

    //Create an instance of it
    var loopingAmbienceInstance = loopingAmbienceDescription.CreateInstance();

    // Get a parameter from this playback instance
    var timeParam = loopingAmbienceInstance.Parameters["Time"];

    // Start playing it
    loopingAmbienceInstance.Start();

    // Loop forever, playing the sound
    while (true)
    {
        Thread.Sleep(1);
        
        // Update the playback system
        system.Update();

        // Vary the parameter we fetched earlier
        timeParam.Value = (float)(DateTime.Now.TimeOfDay.TotalSeconds * 0.025f) % 1;
    }
}

Implementation Notes

Wrapping The Wrapper

Supplied with the FMOD Studio API is a C# wrapper which is almost a direct translation of the C++ API. SupersonicSound is built around this wrapper and acts as a translation layer from C# conventions to the C++ conventions.

The supplied FMOD C++ wrapper is included almost unchanged in SupersonicSound/Wrapper/Fmod (some very minor changes were required to expose some private fields as internal - this seems to have been an implementation mistakes by the FMOD wrapper programmers). This means that when a new FMOD version is released (with a new FMOD wrapper) it should be very simple to update SupersonicSound to the new version - simply drop in the new wrapper and the new DLLs.

Native DLLs

Obviously a wrapper around a native API requires some native DLLs! SupersonicSound DLLs are loaded as soon as you try to create a "System" (a core part of the FMOD API). You can load the DLLs early by calling Native.Load(). If you have already loaded the fmod DLLs yourself, you can instead call Native.SuppressLoad() - be warned this will cause a System.DllNotFoundException if you have not loaded the correct DLLs.

The required DLLs are:

  • fmod.dll
  • fmodstudio.dll

Structs

The wrapper supplied with FMOD allocates objects to wrap up C++ handles in C# objects. If SupersonicSound also allocated objects to wrap these objects that would make this wrapper excessively allocation heavy. Instead all the SupersonicSound wrappers are structs which have been optimised to be very small (the most commonly used ones are pointer sized). This makes using SupersonicSound almost a zero cost abstraction.

Contributions

  • Martin Evans - Project Owner
  • Hakan Lindestaf - FMOD upgrades, examples and other improvements

Contributions are welcome! Please open up an issue before you write any code though, just in case I'm already working on something similar.

Known Issues

  • Async file systems are not supported. There seems to be a problem with the underlying FMOD wrapper being incorrectly structured.

supersonicsound's People

Contributors

hakanl avatar hozuki avatar martindevans 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

Watchers

 avatar  avatar  avatar  avatar  avatar

supersonicsound's Issues

Add Unit Tests

Investigate adding unit testing to the project. Possibly with the NoSoundNotRealtime or WavWriterNotRealtime outputs modes set.

Discuss: What are the benefits of using structs vs classes?

For example in my app I want to keep a reference to the current playing channel and stop it before playing a new sound. Since the Channel (in SSS) is a struct that means I can't check on null and calling Stop() will not work since it's not actually assigned to a FMOD-channel. The memory overhead for a class vs struct is literally 4 bytes so can't see that it would be a deciding factor, IMHO.

Discuss: Is it right to throw FmodInvalidHandleException when a channel has finished playing

If I change the PlaySound sample to not loop and GetPosition or Stop is called after the sound has finished playing then I'm thrown a FmodInvalidHandleException. Obviously the handle is invalid (the channel has been stolen), but I wonder if it's correct to throw the exception, the C# code gets rather cluttered if we have to have a try/catch around all those just to see if the sample has finished. Suggestions?

Need to remove FMOD binaries, violates EULA

From FMOD:

I've had a quick look at the GitHub page and I can see the FMOD binaries are checked in.
This is a violation of our license, could you please remove them?

We are happy to see developers extending the usefulness of FMOD through an enhanced C# interface, but it is important that the binaries are sourced directly from us including full EULA.
If you could instead direct people to our downloads page for the dependencies that would be ideal.

Update fmod to the 2.0 version

Is possible do a direct update of the wraper to make it compatible with the new 2.0 fmods api?

I tried to use it with the new dlls (without recompiling it) but supersonicsound throws an invalid parameter exception when you try to initialize the lowlevelSystem instance.

So if is possible update it without mutch work, please do it, or tell me if is possible recompiling it :)

:)

thanks in advance!

Windows x64 support

Currently the DLL loader on windows does not load the 64 bit dependencies when loaded into a 64 bit process.

This code always throws when the process is compiled as x64:

var ptr = LoadLibrary(path);
if (ptr == IntPtr.Zero)
    throw new DllNotFoundException(string.Format("Failed to load DLL '{0}'. See https://github.com/martindevans/SupersonicSound#installation-instructions", path));

Even when it is being pointed at 64 bit DLLs. Loader has been modified to throw a NotImplementedException when loaded in a 64 bit process until this is resolved.

Low Level Initialization

The FMOD.Studio.System contains a FMOD.LowLevel.System internally. When the studio system is initialized this automatically initializes the low level system.

The LowLevelSystem property exposed on Studio.System exposes a low level system which a user could, incorrectly, call initialize on. Instead we should expose an interface ILowLevelSystem which contains only the things we want the user to access (probably everything except init and disposal).

Nuget Package

I have no idea how to release a nuget package with native dependencies, investigate this and then release a nuget package.

.NET Framework version can be reduced to v4.0

I'm working on a project which uses .NET Framework 4.0. I tried to install SupersonicSound via NuGet and received a 'Not supported' error. So I checked the source code and found out this solution uses .NET Framework 4.6.

I try to build SupersonicSound under v4.0 and there are errors: IReadOnlyList (introduced in v4.5) and Vector3 (using System.Numerics, this assembly has a v4.0 version but the type was introduced in v4.6).

Since v4.0 is pre-installed in Windows 7 and it is forward-compatible, I think if SupersonicSound can run under v4.0 it can be more widely used. To achieve this, I suggest writing our own implementation for IReadOnlyList (which is only used on arrays in this solution) and Vector3.

What do you think?

Add note to documentation that .NET 4.6 is required

I tried to go to 4.5 but Vector3 isn't available so I assume .NET 4.6 is required (which is fine with me, still works fine in Mono), but we should probably have a note on the first documentation page as it may be an issue for some.

Automatic output mode selection

By default the OutputMode of the sound system is automatically selected. However, this causes strange lockups of the sound system on windows 10 (it seems as though FMOD takes exclusive use of the sound device and never releases it).

Current hack to fix this is:

if (!SupersonicSound.Wrapper.Util.IsLinux)
    ll.Output = OutputMode.DirectSound;

Low Level Validity Checking

Low level types can become invalid at any time, the only way to check is to check the return result of calls to see if it is FMOD_ERR_INVALID_HANDLE or FMOD_ERR_CHANNEL_STOLEN. This is problematic in SSS because these become exceptions which makes handling this case extremely ugly (all calling code must be wrapped in a try block with a handler for these exceptions).

Discussion in this thread eventually settled on a solution for this problem:

  • By default suppress these two errors, have two per struct flags to toggle suppression.
    • SuppressInvalidHandle
    • SuppressChannelStolen
  • In setters there is no additional special handling; either the error is ignored entirely or an exception is thrown (depending on the flag values)
  • In getters return nullable values; and also throw if the flags require it

Error file not found LoadPlugin()

I've set the plugin path with SetPluginPath() but then I can't load properly the plugin fmod_distance_filter.dll and then the bank doesn't load because of this plugin

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.