# Issue with playing an audio clip as a FMOD sound

**URL:** <https://qa.fmod.com/t/issue-with-playing-an-audio-clip-as-a-fmod-sound/18983>\
**Category:** Unity\
**Tags:** unity, csharp\
**Created:** [July 8, 2022, 7:01am UTC](https://qa.fmod.com/t/issue-with-playing-an-audio-clip-as-a-fmod-sound/18983 "2022-07-08T07:01:19Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![G\_S\_R](https://avatars.discourse-cdn.com/v4/letter/g/ce7236/32.png) [@G\_S\_R](https://qa.fmod.com/u/G_S_R)\
**Post date:** [July 8, 2022, 7:01am UTC](https://qa.fmod.com/t/issue-with-playing-an-audio-clip-as-a-fmod-sound/18983/1 "2022-07-08T07:01:19Z")

</div>

Hello,

I have been looking for a way to play an unity audio clip as a FMOD sound.

There are solution for this query from the previous versions of FMOD : -  
[https://qa.fmod.com/t/load-an-audioclip-as-fmod-sound/11741](https://qa.fmod.com/t/load-an-audioclip-as-fmod-sound/11741)  
[https://qa.fmod.com/t/err-invalid-param-when-converting-audioclip-to-fmod-sound/11776](https://qa.fmod.com/t/err-invalid-param-when-converting-audioclip-to-fmod-sound/11776)

But none of these solution are working for me I updated the the code according to the  
current APIs please check my script attached in which you will find both the methods  
I referred from the links above.  
What should I do?

PLEASE HELP!!!  
[My Script.txt](https://qa.fmod.com/uploads/short-url/kzOgOEsHbtdEdtitJO2VTFT1pJQ.txt) (3.3 KB)

---

<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:** [July 13, 2022, 1:50am UTC](https://qa.fmod.com/t/issue-with-playing-an-audio-clip-as-a-fmod-sound/18983/2 "2022-07-13T01:50:00Z")

</div>

Hi,

There are a few things that will need to be fixed before you can use Unity Audio Clips.

Firstly enable Unity Audio again under the Unity toolbar Edit drop-down → Project Settings → Audio → Disable Unity Audio. Keep in mind with Unity Audio re-enabled the FMOD audio will no longer be heard on PS5 and Xbox.

Currently `channel_group` isn’t part of the FMOD signal chain so when we are calling `RuntimeManager.CoreSystem.playSound()` with the `channel_group` as it is, it won’t be heard. The easier way to fix this is to assign `channel_group` to the MasterChannelGroup as this is where all sound eventually goes. To do this we will call `FMODUnity.RuntimeManager.CoreSystem.getMasterChannelGroup(out channel_Group)`. So now when we call `playSound()` the audio from the clip will be heard as it is part of the `MasterChannelGroup`.

A tip, call `Debug.Log()` on the output of `result` each time it is assigned, rather than just at the end of the function. Logging the `results` value at the end of the function will just be its most recent assignment.

Lastly, make sure that `channel.setPaused()` is set to false to allow the sound to play.

Hopefully, this will allow the Audio Clip to play!

---

<div class="post-metadata">

**Author:** ![G\_S\_R](https://avatars.discourse-cdn.com/v4/letter/g/ce7236/32.png) [@G\_S\_R](https://qa.fmod.com/u/G_S_R)\
**Post date:** [July 13, 2022, 8:06am UTC](https://qa.fmod.com/t/issue-with-playing-an-audio-clip-as-a-fmod-sound/18983/3 "2022-07-13T08:06:22Z")

</div>

Thanks @Connor_FMOD  
It’s working now!!!

---

<div class="post-metadata">

**Author:** ![d23](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/d23/32/5824_2.png) [@d23](https://qa.fmod.com/u/d23)\
**Post date:** [May 17, 2024, 12:35am UTC](https://qa.fmod.com/t/issue-with-playing-an-audio-clip-as-a-fmod-sound/18983/4 "2024-05-17T00:35:40Z")

</div>

For ease to anyone else who may find this in the future, here’s the merged code that worked for me:

```auto
using UnityEngine;
using System.Collections;
using System;
using System.Runtime.InteropServices;
using FMOD;
using FMODUnity;

public class ClipToSound : Singleton<ClipToSound>
{
    public AudioClip audioclip;
    Channel channel;
    private ChannelGroup channelGroup;

    public void Start()
    {
        float[] samples = new float[audioclip.samples * audioclip.channels];
        audioclip.GetData(samples, 0);

        uint lenbytes = (uint)(audioclip.samples * audioclip.channels * sizeof(float));

        CREATESOUNDEXINFO soundinfo = new CREATESOUNDEXINFO();
        soundinfo.cbsize = Marshal.SizeOf(typeof(CREATESOUNDEXINFO));
        soundinfo.length = lenbytes;
        soundinfo.format = SOUND_FORMAT.PCMFLOAT;
        soundinfo.defaultfrequency = audioclip.frequency;
        soundinfo.numchannels = audioclip.channels;

        RESULT result;
        Sound sound;
        result = RuntimeManager.CoreSystem.createSound("abc", MODE.OPENUSER, ref soundinfo, out sound);

        IntPtr ptr1, ptr2;
        uint len1, len2;
        result = sound.@lock(0, lenbytes, out ptr1, out ptr2, out len1, out len2);
        Marshal.Copy(samples, 0, ptr1, (int)(len1 / sizeof(float)));
        if (len2 > 0)
        {
            Marshal.Copy(samples, (int)(len1 / sizeof(float)), ptr2, (int)(len2 / sizeof(float)));
        }
        result = sound.unlock(ptr1, ptr2, len1, len2);
        result = sound.setMode(MODE.LOOP_NORMAL);

        FMODUnity.RuntimeManager.CoreSystem.getMasterChannelGroup(out channelGroup);
        result = RuntimeManager.CoreSystem.playSound(sound, channelGroup, false, out channel);
        channel.setPaused(false);
        UnityEngine.Debug.LogError("RESULT => " + result);
    }
}

```

`Singleton` is a custom class I have (presumably similar to OP) and is optional.

---

<div class="post-metadata">

**Author:** ![Eendhoorn](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/eendhoorn/32/890_2.png) [@Eendhoorn](https://qa.fmod.com/u/Eendhoorn)\
**Post date:** [November 12, 2024, 11:17pm UTC](https://qa.fmod.com/t/issue-with-playing-an-audio-clip-as-a-fmod-sound/18983/5 "2024-11-12T23:17:18Z")

</div>

I know it’s an old topic, but I’m completely stuck on this. I tried using d23’s code above, it runs fine, and I can see a sound channel playing but there’s no volume (neither from the speakers or in the debug panel).

The sound file works fine if I use FMODUnity.RuntimeManager.CoreSystem.createSound(path, FMOD.MODE.DEFAULT, out fmodSound).

But this doesn’t work on android, so it would be better to create it from an audioclip.

The sound file is .wav file with the following settings;

- Decompress on load
- Preload Audio data
- PCM

Any clues what could be wrong?

---

<div class="post-metadata">

**Author:** ![jeff\_fmod](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/jeff_fmod/32/1766_2.png) [@jeff\_fmod](https://qa.fmod.com/u/jeff_fmod)\
**Post date:** [November 19, 2024, 1:26am UTC](https://qa.fmod.com/t/issue-with-playing-an-audio-clip-as-a-fmod-sound/18983/6 "2024-11-19T01:26:53Z")

</div>

Linking to this case [Playing FMOD.Sound from Audioclip has no volume - #8 by jeff\_fmod](https://qa.fmod.com/t/playing-fmod-sound-from-audioclip-has-no-volume/22088/8)
