Equivalent to Unity Audio Source - Android Build

Hi there!

I’m a rookie to fmod, but I’m starting to get an idea of the great functionality of it. Fantastic! OK, enough schmoozing ;). Here my questions:

I’m building an Android music composer app, with a step sequencer, arranger a.s.o.
Therefore I use the MIDI Player Toolkit from Thierry Bachman which is a FluidSynth integration and therefore a soundfont player. That gives me the possibility of having a real sampler in the background including keyboard splits and velocity zones.

So if I could bring this together with FMOD Core functionality, I’d have the big advantage of AAudio (OpenSL ES) integration and I’m really keen on integrating the sound effects like compressor, EQ, distortion a.s.o.

For that I’d need some equivalent of an Audio Source from the native Unity sound integration, as the MTPK Scripts pass their audio through to those.

Is it possible to script an equivalent for that, and also using effects and influencing their parameters directly from a script?

FMOD Studio does not currently support streaming the output of third-party samplers into FMOD Studio events. The FMOD Core API can handle streams outside of events, but as of the time of writing (June of 2020) the FMOD Unity integration requires the use of events to produce audio, making the particular combination you describe impossible to achieve in the current FMOD Unity integration.

Dear joseph,

thank you for your reply. Actually I get an audio stream from the sampler that looks approx. like this:

(int i = 0; i < buffersize; i++)

{
int j = (block + i) * 2;

        data[j + 0] = left_buf[i] * Volume;

       data[j + 1] = right_buf[i] *Volume;

}

Could you please describe to me, how I can pass the stream to FMOD Core API, or is there maybe a sample code that I could review?

Kind regards, MisterIX.

Hi,
The function you should use in the core API is
https://fmod.com/resources/documentation-api?version=2.1&page=core-api-system.html#system_createdsp

Then you would add it to somewhere in the mix graph. If you want to add it to a ‘channel’ (to modify existing data) you can use Channel::addDSP to insert it into a channel stream (ie a channel handle returned from System::playSound)

Another way to actually play it on its own channel, is to use System::playDSP if it is a generator/instrument type of DSP.

The 3rd way is to avoid channels, and just play it on a channelgroup so it is always running in the background regardless of what channels are doing. This can be done with ChannelGroup::addDSP

For an example of a DSP implementation, look in the example folder for dsp_custom where it simply modifies a signal by multiplying it by a gain value.

Hi brett,
thank you very much for your answer. As I work in Unity, I have to code it in C# using the FMOD Core API - C# wrapper (fmod.cs). So first things first, I unfortunatly didn’t find an example folder (also not in the FMOD Studio installation Examples file) to take a look a the dsp_custom file as recommended…

The only working reference was from PeteDE here in the forum: https://qa.fmod.com/t/core-api-playing-a-sound/15532

So I tried to use this as a role model:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using FMOD;

public class FMOD_Test : MonoBehaviour
{
uint s_byte = new uint[512];
uint version;

// Start is called before the first frame update
void Start()
{
var coreSystem = FMODUnity.RuntimeManager.CoreSystem;
coreSystem.getVersion(out version);

UnityEngine.Debug.Log("FMOD Core Version "+version);

//corSystem.createSound(“filename.wav”, MODE.DEFAULT, out sound);

Sound sound;
coreSystem.createSound("Assets/file_example.wav", MODE.DEFAULT, out sound);

ChannelGroup channelgroup;
coreSystem.createChannelGroup("master", out channelgroup);

Channel channel;
coreSystem.playSound(sound, channelgroup, false, out channel);

}

And: it’s working fine so far.

So now, when I add following lines:

DSP my_dsp;
coreSystem.createDSP(out my_dsp);

I get an error message saying: There is no argument given that corresponds to the required formal parameter ‘dsp’ of ‘System.createDSP(ref DSP_DESCRIPTION, out DSP)’

I wanted to proceed approx. like this:

channel.addDSP(1, my_dsp);
(What value should I set for index?)
coreSystem.playDSP(my_dsp, channelgroup, false, out channel);

Hi, if you look at https://fmod.com/resources/documentation-api?version=2.1&page=core-api-system.html#system_createdsp again it has the parameters required for the function.

For the DSP_DESCRIPTION structure start by zeroing it out. Then just set what you need.
This just might be nothing but the ‘read’ callback to get started, and pluginsdkversion is FMOD.PLUGIN_SDK_VERSION

See https://fmod.com/resources/documentation-api?version=2.1&page=white-papers-dsp-plugin-api.html#the-plug-in-descriptor for more on this.