# Adding effects to real-time recorded audio

**URL:** <https://qa.fmod.com/t/adding-effects-to-real-time-recorded-audio/21265>\
**Category:** Unity\
**Tags:** unity, csharp\
**Created:** [February 20, 2024, 5:25am UTC](https://qa.fmod.com/t/adding-effects-to-real-time-recorded-audio/21265 "2024-02-20T05:25:17Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Connor\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/connor_fmod/32/3685_2.png) [@Connor\_FMOD](https://qa.fmod.com/u/Connor_FMOD)\
**Post date:** [February 22, 2024, 1:11am UTC](https://qa.fmod.com/t/adding-effects-to-real-time-recorded-audio/21265/2 "2024-02-22T01:11:55Z")

</div>

Hi,

This can certainly be done using a [Programmer Instrument](https://fmod.com/docs/2.02/studio/instrument-reference.html#programmer-instrument). We have a scripting example: [Unity Integration | Scripting Examples - Programmer Sound](https://fmod.com/docs/2.02/unity/examples-programmer-sounds.html) which outlines using [Audio Tables](https://fmod.com/docs/2.02/studio/dialogue-and-localization.html#audio-tables) with a programmer sound. However, since you already have a sound, rather than using a table or a file you’d just pass the sound to the programmer instrument.

Here is the updated `switch` statement:

> **Switch**
>
> ```switch
> {
> case FMOD.Studio.EVENT_CALLBACK_TYPE.CREATE_PROGRAMMER_SOUND:
> {
> // We can remove all this since we already have the sound
> //FMOD.MODE soundMode = FMOD.MODE.LOOP_NORMAL | FMOD.MODE.CREATECOMPRESSEDSAMPLE | FMOD.MODE.NONBLOCKING;
> 
> // We need to keep this
> var parameter = (FMOD.Studio.PROGRAMMER_SOUND_PROPERTIES)Marshal.PtrToStructure(parameterPtr, typeof(FMOD.Studio.PROGRAMMER_SOUND_PROPERTIES));
> 
> // Remove this
> // if (key.Contains("."))
> // {
> // FMOD.Sound dialogueSound;
> // var soundResult = FMODUnity.RuntimeManager.CoreSystem.createSound(Application.streamingAssetsPath + "/" + key, soundMode, out dialogueSound);
> // if (soundResult == FMOD.RESULT.OK)
> // {
> // parameter.sound = dialogueSound.handle;
> // parameter.subsoundIndex = -1;
> // Marshal.StructureToPtr(parameter, parameterPtr, false);
> // }
> // }
> // else
> // {
> // FMOD.Studio.SOUND_INFO dialogueSoundInfo;
> // var keyResult = FMODUnity.RuntimeManager.StudioSystem.getSoundInfo(key, out dialogueSoundInfo);
> // if (keyResult != FMOD.RESULT.OK)
> // {
> // break;
> // }
> // FMOD.Sound dialogueSound;
> // var soundResult = FMODUnity.RuntimeManager.CoreSystem.createSound(dialogueSoundInfo.name_or_data, soundMode | dialogueSoundInfo.mode, ref dialogueSoundInfo.exinfo, out dialogueSound);
> // if (soundResult == FMOD.RESULT.OK)
> // {
> // parameter.sound = dialogueSound.handle;
> // parameter.subsoundIndex = dialogueSoundInfo.subsoundindex;
> // Marshal.StructureToPtr(parameter, parameterPtr, false);
> // }
> // }
> 
> // We now need to pass the sound to the programmer instrument
> parameter.sound = dialogueSound.handle;
> parameter.subsoundIndex = dialogueSoundInfo.subsoundindex;
> Marshal.StructureToPtr(parameter, parameterPtr, false);
> // Thats it!
> break;
> }
> case FMOD.Studio.EVENT_CALLBACK_TYPE.DESTROY_PROGRAMMER_SOUND:
> {
> var parameter = (FMOD.Studio.PROGRAMMER_SOUND_PROPERTIES)Marshal.PtrToStructure(parameterPtr, typeof(FMOD.Studio.PROGRAMMER_SOUND_PROPERTIES));
> var sound = new FMOD.Sound(parameter.sound);
> sound.release();
> 
> break;
> }
> case FMOD.Studio.EVENT_CALLBACK_TYPE.DESTROYED:
> {
> // Now the event has been destroyed, unpin the string memory so it can be garbage collected
> stringHandle.Free();
> 
> break;
> }
> }
> 
> ```

Remember to pass in the sound as the event instances [User Data](https://fmod.com/docs/2.02/api/glossary.html#user-data) . To do this I create a simple class to hold the sound for me:

```auto
public class UserDataClass
{
	public FMOD.Sound sound;
}

```

But you may wish to do this another way.

Hope this helps!

---

_[View the full topic](https://qa.fmod.com/t/adding-effects-to-real-time-recorded-audio/21265)._
