Playing FMOD.Sound from Audioclip has no volume

Hello! I’ve used FMOD previous for monogame, and I’m porting the project over to Unity. I’m using a .wav file as an instrument in the game. It’s the same file that I used and worked in the monogame project.
Load Type : Decompress on Load
Preload Audio Data : True (would prefer not, but for testing).
Compression format: PCM

I made sure to initialize fmod first;
FMODUnity.RuntimeManager.CoreSystem.init(32, FMOD.INITFLAGS.NORMAL, (IntPtr)0);

I’ve converted an audioclip to FMOD.Sound using this code. This probably where I mess up. It’s a bit low level for me too be honest!

            unityClip.GetData(samples, 0);

            byte[] byteArray = new byte[samples.Length * sizeof(float)];
            System.Buffer.BlockCopy(samples, 0, byteArray, 0, byteArray.Length);

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

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

            RESULT result;
            FMOD.Sound sound;
            
            //doesn't work
            //result = RuntimeManager.CoreSystem.createSound(byteArray, FMOD.MODE.OPENMEMORY | FMOD.MODE.CREATESAMPLE, ref soundinfo, out sound);
            
            //I'm not sure where to actually pass the float array
            result = RuntimeManager.CoreSystem.createSound(unityClip.name, FMOD.MODE.OPENUSER | FMOD.MODE.CREATESAMPLE, ref soundinfo, out sound);

            if (result != FMOD.RESULT.OK)
                Debug.LogError($"error creating sound {result}" );
            else
                Debug.Log($"converted sound {result} : sound");

I then try to play this sound as followed;

    {
        sound = FmodSound.LoadSound(instrumentPlayer.audioClip);
        RuntimeManager.CoreSystem.createChannelGroup(" test", out channelGroup);
        channelGroup.setVolumeRamp(false);
        channelGroup.setVolume(1);
    }

    // Update is called once per frame
    void Update()
    {
        Keyboard keyboard = playerInput.GetDevice<Keyboard>();
        if (keyboard == null) return;

        if (keyboard.dKey.wasPressedThisFrame)
        {

            RuntimeManager.CoreSystem.playSound( sound, channelGroup, false, out FMOD.Channel fmodChannel);
            fmodChannel.setVolume(1);
            fmodChannel.setVolumeRamp(false);
            //instrumentPlayer.instrument.Play(Note.C3);
        }
}

I can see a channel is created, but the volume remains at -80.
image

I’m sure I’m just forgetting a very basic thing, help is appreciated!

Hi,

What version of the FMOD integration are you using?
image

Are you manually calling this? This is called as part of the integration. It is possible to modify the flags passed to the core system if you wish on line: RuntimeManger.cs 376. ’

I would suggest having a look at our API example user_created_sound.cpp which is included with our engine download: "C:\Program Files (x86)\FMOD SoundSystem\FMOD Studio API Windows\api\core\examples\vs2019\examples.sln" which outlines how to pass PCM data to a sound to be played via a callback.

Hope this helps!

That’s the same version I’m using!

As a temporary work around both of these are working;

path = Path.Combine(Application.streamingAssetsPath, eventName);
path = Path.Combine("Assets/Audio/" + eventName);
FMOD.RESULT result = FMODUnity.RuntimeManager.CoreSystem.createSound(path, FMOD.MODE.DEFAULT, out fmodSound);

So I know I’ve set up FMOD correctly and that the audio file is fine.
That narrowed it down to incorrectly converting the audioclip to FMOD.Sound.

The problem is specific to the Audioclip, so I don’t think looking at the .cpp will help!

1 Like

Good to hear it is fixed. Thanks for sharing the solution.