# Equivalent to Unity Audio Source - Android Build

**URL:** <https://qa.fmod.com/t/equivalent-to-unity-audio-source-android-build/15838>\
**Category:** Unity\
**Tags:** android\
**Created:** [June 3, 2020, 7:43am UTC](https://qa.fmod.com/t/equivalent-to-unity-audio-source-android-build/15838 "2020-06-03T07:43:34Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![MisterIX](https://avatars.discourse-cdn.com/v4/letter/m/eada6e/32.png) [@MisterIX](https://qa.fmod.com/u/MisterIX)\
**Post date:** [June 3, 2020, 7:43am UTC](https://qa.fmod.com/t/equivalent-to-unity-audio-source-android-build/15838/1 "2020-06-03T07:43:34Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![joseph](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/joseph/32/264_2.png) [@joseph](https://qa.fmod.com/u/joseph)\
**Post date:** [June 4, 2020, 1:18am UTC](https://qa.fmod.com/t/equivalent-to-unity-audio-source-android-build/15838/2 "2020-06-04T01:18:01Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![MisterIX](https://avatars.discourse-cdn.com/v4/letter/m/eada6e/32.png) [@MisterIX](https://qa.fmod.com/u/MisterIX)\
**Post date:** [June 22, 2020, 6:38pm UTC](https://qa.fmod.com/t/equivalent-to-unity-audio-source-android-build/15838/3 "2020-06-22T18:38:38Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![brett](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/brett/32/261_2.png) [@brett](https://qa.fmod.com/u/brett)\
**Post date:** [June 23, 2020, 12:15am UTC](https://qa.fmod.com/t/equivalent-to-unity-audio-source-android-build/15838/4 "2020-06-23T00:15:45Z")

</div>

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](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.

---

<div class="post-metadata">

**Author:** ![MisterIX](https://avatars.discourse-cdn.com/v4/letter/m/eada6e/32.png) [@MisterIX](https://qa.fmod.com/u/MisterIX)\
**Post date:** [June 23, 2020, 5:36pm UTC](https://qa.fmod.com/t/equivalent-to-unity-audio-source-android-build/15838/5 "2020-06-23T17:36:04Z")

</div>

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](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](https://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);

---

<div class="post-metadata">

**Author:** ![brett](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/brett/32/261_2.png) [@brett](https://qa.fmod.com/u/brett)\
**Post date:** [June 24, 2020, 1:29am UTC](https://qa.fmod.com/t/equivalent-to-unity-audio-source-android-build/15838/6 "2020-06-24T01:29:07Z")

</div>

Hi, if you look at [https://fmod.com/resources/documentation-api?version=2.1&page=core-api-system.html#system\_createdsp](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](https://fmod.com/resources/documentation-api?version=2.1&page=white-papers-dsp-plugin-api.html#the-plug-in-descriptor) for more on this.
