# Load an AudioClip as fmod sound

**URL:** <https://qa.fmod.com/t/load-an-audioclip-as-fmod-sound/11741>\
**Category:** Unity\
**Created:** [December 2, 2014, 10:21am UTC](https://qa.fmod.com/t/load-an-audioclip-as-fmod-sound/11741 "2014-12-02T10:21:25Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![fsilvestrim](https://avatars.discourse-cdn.com/v4/letter/f/aeb1de/32.png) [@fsilvestrim](https://qa.fmod.com/u/fsilvestrim)\
**Post date:** [December 2, 2014, 10:21am UTC](https://qa.fmod.com/t/load-an-audioclip-as-fmod-sound/11741/1 "2014-12-02T10:21:25Z")

</div>

Hey guys,

is there any way to load and Unity AudioClip as an fmod sound like we do with FMOD.System.createSound(“sound.wav”) ? I was trying to convert the audio clip to a bytearray and get just the raw data, but it hasn’t work.

Any other approaches suggested?

Thanks.

---

<div class="post-metadata">

**Author:** ![nick1](https://avatars.discourse-cdn.com/v4/letter/n/47e85d/32.png) [@nick1](https://qa.fmod.com/u/nick1)\
**Post date:** [December 3, 2014, 5:59am UTC](https://qa.fmod.com/t/load-an-audioclip-as-fmod-sound/11741/2 "2014-12-03T05:59:38Z")

</div>

```
using UnityEngine;
using System.Collections;
using System;
using System.Runtime.InteropServices;

public class clip_to_sound : MonoBehaviour 
{
    public AudioClip audioclip;
    FMOD.Channel channel;

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

        FMOD.System lowlevel = null;
        FMOD_StudioSystem.instance.System.getLowLevelSystem(out lowlevel);

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

        FMOD.CREATESOUNDEXINFO soundinfo = new FMOD.CREATESOUNDEXINFO();
        soundinfo.length = lenbytes;
        soundinfo.format = FMOD.SOUND_FORMAT.PCMFLOAT;
        soundinfo.defaultfrequency = audioclip.frequency;
        soundinfo.numchannels = audioclip.channels;

        FMOD.RESULT result;
        FMOD.Sound sound;
        result = lowlevel.createSound("", FMOD.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(FMOD.MODE.LOOP_NORMAL);

        result = lowlevel.playSound(sound, null, false, out channel);
	}
}
```

---

<div class="post-metadata">

**Author:** ![Xuan](https://avatars.discourse-cdn.com/v4/letter/x/a87d85/32.png) [@Xuan](https://qa.fmod.com/u/Xuan)\
**Post date:** [January 9, 2018, 10:34am UTC](https://qa.fmod.com/t/load-an-audioclip-as-fmod-sound/11741/3 "2018-01-09T10:34:46Z")

</div>

> [@](#):
>
> ```
> using UnityEngine;
> using System.Collections;
> using System;
> using System.Runtime.InteropServices;
> 
> public class clip_to_sound : MonoBehaviour 
> {
> public AudioClip audioclip;
> FMOD.Channel channel;
> 
> void Start ()
> {
> float[] samples = new float[audioclip.samples * audioclip.channels];
> audioclip.GetData(samples, 0);
> 
> FMOD.System lowlevel = null;
> FMOD_StudioSystem.instance.System.getLowLevelSystem(out lowlevel);
> 
> uint lenbytes = (uint)(audioclip.samples * audioclip.channels * sizeof(float));
> 
> FMOD.CREATESOUNDEXINFO soundinfo = new FMOD.CREATESOUNDEXINFO();
> soundinfo.length = lenbytes;
> soundinfo.format = FMOD.SOUND_FORMAT.PCMFLOAT;
> soundinfo.defaultfrequency = audioclip.frequency;
> soundinfo.numchannels = audioclip.channels;
> 
> FMOD.RESULT result;
> FMOD.Sound sound;
> result = lowlevel.createSound("", FMOD.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(FMOD.MODE.LOOP_NORMAL);
> 
> result = lowlevel.playSound(sound, null, false, out channel);
> }
> }
> 
> ```

I have a confuse that why not use “Factory.System\_Create(out lowlevel)” but “getLowLevelSystem(out lowlevel)”

---

<div class="post-metadata">

**Author:** ![cameron-fmod](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/cameron-fmod/32/261_2.png) [@cameron-fmod](https://qa.fmod.com/u/cameron-fmod)\
**Post date:** [January 9, 2018, 11:41pm UTC](https://qa.fmod.com/t/load-an-audioclip-as-fmod-sound/11741/4 "2018-01-09T23:41:44Z")

</div>

The StudioSystem will already contain a LowLevel System and this will give you a reference to it, System\_Create will make a new LowLevel System separate from the one you are already using.

---

<div class="post-metadata">

**Author:** ![Xuan](https://avatars.discourse-cdn.com/v4/letter/x/a87d85/32.png) [@Xuan](https://qa.fmod.com/u/Xuan)\
**Post date:** [January 10, 2018, 3:01am UTC](https://qa.fmod.com/t/load-an-audioclip-as-fmod-sound/11741/5 "2018-01-10T03:01:33Z")

</div>

Thanks!But I can’t create the current sound,it’s handle’s value always equals 0,I don’t know why.

---

<div class="post-metadata">

**Author:** ![Xuan](https://avatars.discourse-cdn.com/v4/letter/x/a87d85/32.png) [@Xuan](https://qa.fmod.com/u/Xuan)\
**Post date:** [January 10, 2018, 3:06am UTC](https://qa.fmod.com/t/load-an-audioclip-as-fmod-sound/11741/6 "2018-01-10T03:06:38Z")

</div>

ps:The parametric “name” of createSound is the path of music likes “d:/AAA/touch.mp3”, Is’t correct ?

---

<div class="post-metadata">

**Author:** ![cameron-fmod](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/cameron-fmod/32/261_2.png) [@cameron-fmod](https://qa.fmod.com/u/cameron-fmod)\
**Post date:** [January 10, 2018, 4:01am UTC](https://qa.fmod.com/t/load-an-audioclip-as-fmod-sound/11741/7 "2018-01-10T04:01:34Z")

</div>

That is correct.  
This Q&A is for the older legacy Unity Integration for FMOD Ex and will be different for the latest versions, although not a lot will need to change.  
To get the LowLevel system use:

```
FMOD.System lowlevelsystem = FMODUnity.RuntimeManager.LowlevelSystem;
```

---

<div class="post-metadata">

**Author:** ![Xuan](https://avatars.discourse-cdn.com/v4/letter/x/a87d85/32.png) [@Xuan](https://qa.fmod.com/u/Xuan)\
**Post date:** [January 10, 2018, 4:12am UTC](https://qa.fmod.com/t/load-an-audioclip-as-fmod-sound/11741/8 "2018-01-10T04:12:12Z")

</div>

THANKS!!!
