Search Unity

Audio Unity Audio Native Plugin - FluidSynthLite

Discussion in 'Audio & Video' started by Foriero, Mar 20, 2019.

  1. Foriero

    Foriero

    Joined:
    Jan 24, 2012
    Posts:
    584
    Hello,

    This https://github.com/divideconcept/FluidLite midi synthesiser outputs audio floa[] data and assumes that this data is passed to audio system.

    We have compiled FluidSynthLite into libraries for OSX, iOS, WIN, WSA and ANDROID and looking how to pass this float[] data into unity audio system.

    It looks like we have two options.

    1) we need to marshal the data between C# and Native and pass them into OnAudioFilterRead
    2) we write Unity Audio Native Plugin SDK plugin and keep the data passing only on native side

    I know how to make 1) but want to avoid OnAudioFilterRead.

    So my question is can anyone point me how to write Audio Native Plugins SDK plugin and pass the float[] data into it?

    Thank you, Marek.
     
  2. AndyJB_Unity

    AndyJB_Unity

    Unity Technologies

    Joined:
    Apr 2, 2019
    Posts:
    4
    Hi Marek,

    The NativeAudioPluginSDK bundle ( https://bitbucket.org/Unity-Technologies/nativeaudioplugins ) referenced on the manual page ( https://docs.unity3d.com/Manual/AudioMixerNativeAudioPlugin.html ) contains source and projects demonstrating the procedure.

    In particular the Plugin_Synthesize.cpp file should match your use-case very closely, with the plugin function ProcessCallback() filling in a float buffer with data generated from the included synthesizer code. Note that the ProcessCallback indicates how many samples you should supply. A quick look at FluidSynth seems to suggest this will be fine as it generates data at per sample granularity too.

    The example comes with projects for Windows and OS X. Setting up plugins for iOS and Android require a little more work on your part but use exactly the same code.

    I tested the example on iOS and can confirm it works as expected.
     
    spakment likes this.
  3. manassehclifford

    manassehclifford

    Joined:
    Sep 20, 2021
    Posts:
    8
    Hi where can i find more information on how to write the plugins for android ios and other platforms, i managed to build native audio plugins for mac and windows using the juce library (it has a good audio api and a wrapper for building plugins), i presume i can make some changes to the wrapper ang get things going , but i am unsure where to start