Search Unity

Audio Unity can play an audio source backwards, FMOD Studio can't. Why?

Discussion in 'Audio & Video' started by Mlizana, Sep 5, 2019.

  1. Mlizana


    Jun 6, 2017
    Hi, I'm trying to understand why Unity can play audioSources backwards, setting the "pitch" attribute to negative. I know Unity uses FMOD, and I'm trying to use FMOD to play an eventInstance playing backwards too.

    First, audio source can modify the pitch value using this extern variable declared, using extern getters and setters:

    Code (CSharp):
    1. public extern float pitch { [GeneratedByOldBindingsGenerator, MethodImpl(MethodImplOptions.InternalCall)] get; [GeneratedByOldBindingsGenerator, MethodImpl(MethodImplOptions.InternalCall)] set; }
    The pitch setter is implemented externally on the fmod.dll

    Code (CSharp):
    1. [DllImport(VERSION.dll)]
    2. private static extern RESULT FMOD_ChannelGroup_SetPitch(IntPtr channelgroup, float pitch);
    So I understand you need a reference to a channelGroup to set the pitch. But I don't see any eventInstance reference, so this could mean (I don't know how it works) that unity does not use eventInstances to play the sounds.

    I'm trying to reproduce the same behaviour on unity using the FMODStudio library, so I want to change the pitch to play FMOD Events backwards.

    This is my simple FMOD Event:

    I've tried two things:
    1) Setting the pitch directly to the eventInstance (it doesn't work because there's an assertion error that says pitch must be between 0 and ~3.5)

    Code (CSharp):
    1. _eventInstance.setPitch(-1);
    2) Setting the pitch to the channelGroup of the eventInstance ()

    Code (CSharp):
    1. _eventInstance.getChannelGroup(out ChannelGroup channelGroup);
    2. channelGroup.setPitch(-1);
    3) Setting the pitch to the channel on the channelGroup
    Code (CSharp):
    1. channelGroup.getChannel(0, out Channel channel);
    2. channel.setPitch(-1);
    On this last one, setting the pitch on the channel does not throw any error, but it plays normally (not backwards).

    I'm assuming unity doesn't use eventInstances to change the pitch, then, how it works using FMOD? I'm trying to realize how can I achive reproducing FMOD sounds backwards, can someone help with this issue?

    Thanks a lot, hope this can bring some discussion here.