# Having trouble to reproduce audio from a Programmer Instrument

**URL:** <https://qa.fmod.com/t/having-trouble-to-reproduce-audio-from-a-programmer-instrument/22896>\
**Category:** Unity\
**Created:** [May 6, 2025, 2:12pm UTC](https://qa.fmod.com/t/having-trouble-to-reproduce-audio-from-a-programmer-instrument/22896 "2025-05-06T14:12:49Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sirevanac](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/sirevanac/32/480_2.png) [@Sirevanac](https://qa.fmod.com/u/Sirevanac)\
**Post date:** [May 6, 2025, 2:12pm UTC](https://qa.fmod.com/t/having-trouble-to-reproduce-audio-from-a-programmer-instrument/22896/1 "2025-05-06T14:12:49Z")

</div>

Hi! My team is having trouble reproducing an injected .wav into a Programmer instrument. Here’s the code:

```auto
 public static FMOD.Studio.EventInstance PlayCutsceneDialogue(string route, string key, Transform transform)
 {
     FMOD.Studio.EventInstance dialogueInstance = RuntimeManager.CreateInstance(route);

     GCHandle stringHandle = GCHandle.Alloc(key, GCHandleType.Pinned);
     dialogueInstance.setUserData(GCHandle.ToIntPtr(stringHandle));

     dialogueInstance.set3DAttributes(RuntimeUtils.To3DAttributes(transform));
     RuntimeManager.AttachInstanceToGameObject(dialogueInstance, transform, false);

     return dialogueInstance;
 }

```

No error on console. Working with 2.02.24. What they think it’s happening is that the path assigned to “key” is wrongly put. So I came here asking how is the path is written. And of course if you see any other problem, please do tell!

---

<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:** [May 7, 2025, 4:51am UTC](https://qa.fmod.com/t/having-trouble-to-reproduce-audio-from-a-programmer-instrument/22896/2 "2025-05-07T04:51:16Z")

</div>

Hi,

Thanks for the info and code.

Can I confirm the issue is not hearing any audio from the programmer sound?

Would it be possible to apply the following settings:

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/fmod/original/2X/d/db0e4e53317faec076dd0f48cfc97e0db4903b8d.png)  
And let me know if there are any additional logs in the console?

Could I grab an example of a `key` you are passing in. When using in conjunction with an audio table, the keys can be found in studio:

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/fmod/original/2X/7/768074afae2f4418b3759ad8d31a93b8bf5a506f.png)

We also have a scripting example here: [Unity Integration | Scripting Examples - Programmer Instrument](https://fmod.com/docs/2.02/unity/examples-programmer-sounds.html)

---

<div class="post-metadata">

**Author:** ![Sirevanac](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/sirevanac/32/480_2.png) [@Sirevanac](https://qa.fmod.com/u/Sirevanac)\
**Post date:** [May 7, 2025, 9:13pm UTC](https://qa.fmod.com/t/having-trouble-to-reproduce-audio-from-a-programmer-instrument/22896/3 "2025-05-07T21:13:34Z")

</div>

Yes, the problem is that the audio is not being reproduced. We’re not using keys per se, but directly calling the wav itself in the folder (cause we’ll be using thousands of files so it’d impractical for them to have keys). Inside the audio table, it’s located on a folder that says “../Dialogue”. But we are not sure how to call each wav.

On log, this appears:

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/fmod/original/2X/8/85875dc415c8695b67765cf82d26045ab324268f.png)

---

<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:** [May 8, 2025, 1:05am UTC](https://qa.fmod.com/t/having-trouble-to-reproduce-audio-from-a-programmer-instrument/22896/4 "2025-05-08T01:05:17Z")

</div>

> [@Sirevanac](#):
>
> cause we’ll be using thousands of files so it’d impractical for them to have keys

Would it be possible to elaborate on this issue? FMOD generates the keys for you if that is the issue?

I have a example of playing a file using a programmer instrument here: [General advice on user-friendly process for players to upload audio assets then pipe them through FMOD-powered Unity? - #2 by Connor\_FMOD](https://qa.fmod.com/t/general-advice-on-user-friendly-process-for-players-to-upload-audio-assets-then-pipe-them-through-fmod-powered-unity/19005/2)

Hope this helps!

---

<div class="post-metadata">

**Author:** ![Sirevanac](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/sirevanac/32/480_2.png) [@Sirevanac](https://qa.fmod.com/u/Sirevanac)\
**Post date:** [May 8, 2025, 2:36pm UTC](https://qa.fmod.com/t/having-trouble-to-reproduce-audio-from-a-programmer-instrument/22896/5 "2025-05-08T14:36:42Z")

</div>

What we think is the problem is that we are not setting the path correctly. So if I don’t assign a manual key, it’d be the path to where the file is, am I correct?

So, for a example, the path would be “ProjectName/Assets/Dialogue/NameFile”? Would there be anything we are missing?

---

<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:** [May 9, 2025, 6:16am UTC](https://qa.fmod.com/t/having-trouble-to-reproduce-audio-from-a-programmer-instrument/22896/6 "2025-05-09T06:16:37Z")

</div>

Correct, you would just have to update the callback to correctly handle file paths:

```c
[AOT.MonoPInvokeCallback(typeof(FMOD.Studio.EVENT_CALLBACK))]
    static FMOD.RESULT YourCallBackFunction(FMOD.Studio.EVENT_CALLBACK_TYPE type, IntPtr instancePtr, IntPtr parameterPtr)
    {
        FMOD.Studio.EventInstance instance = new FMOD.Studio.EventInstance(instancePtr);

        if (instance.isValid() == false)
        {
            UnityEngine.Debug.Log("Failed to create instance, instance invalid");
            return FMOD.RESULT.ERR_EVENT_NOTFOUND;
        }

        //Retrive the user data 
        IntPtr stringPtr;
        instance.getUserData(out stringPtr);

        // Retrieving the path of the audio source from the user data
        GCHandle stringHandle = GCHandle.FromIntPtr(stringPtr);
        String location = stringHandle.Target as String;

        switch (type)
        {
            case FMOD.Studio.EVENT_CALLBACK_TYPE.CREATE_PROGRAMMER_SOUND:
                {
                    FMOD.MODE soundMode = FMOD.MODE.LOOP_NORMAL | FMOD.MODE.CREATECOMPRESSEDSAMPLE | FMOD.MODE.NONBLOCKING;
                    var parameter = (FMOD.Studio.PROGRAMMER_SOUND_PROPERTIES)Marshal.PtrToStructure(parameterPtr, typeof(FMOD.Studio.PROGRAMMER_SOUND_PROPERTIES));
		
                    FMOD.Sound audioSound;
                    FMOD.RESULT result;

                    // Creating the sound using the location of the audio source 
                    result = FMODUnity.RuntimeManager.CoreSystem.createSound(location, soundMode, out audioSound);

                    if (result == FMOD.RESULT.OK)
                    {
                        parameter.sound = audioSound.handle;
                        parameter.subsoundIndex = -1;
                        Marshal.StructureToPtr(parameter, parameterPtr, false);
                    }
                    break;
                }
            case FMOD.Studio.EVENT_CALLBACK_TYPE.DESTROY_PROGRAMMER_SOUND:
                {
                    var paramerter = (FMOD.Studio.PROGRAMMER_SOUND_PROPERTIES)Marshal.PtrToStructure(parameterPtr, typeof(FMOD.Studio.PROGRAMMER_SOUND_PROPERTIES));
                    var sound = new FMOD.Sound(paramerter.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 garbaged collected
                    stringHandle.Free();
                    break;
                }
        }
        return FMOD.RESULT.OK;
    }

```
