Exemple #1
0
    private static FMOD.RESULT BeatEventCallback(EVENT_CALLBACK_TYPE type, EventInstance instance, IntPtr parameterPtr)
    {
        //IntPtr timelineInfoPtr;
        //FMOD.RESULT result = instance.getUserData(out timelineInfoPtr);
        //if(result != FMOD.RESULT.OK) {
        //    Debug.LogError("Timeline Callback error: " + result);
        //    return result;
        //}
        if (type == EVENT_CALLBACK_TYPE.TIMELINE_BEAT)
        {
            //TIMELINE_MARKER_PROPERTIES parameter = (TIMELINE_MARKER_PROPERTIES)Marshal.PtrToStructure(parameterPtr, typeof(TIMELINE_MARKER_PROPERTIES));

            //GCHandle gch = GCHandle.Alloc(parameter.name);
            //IntPtr ptr = Marshal.UnsafeAddrOfPinnedArrayElement(gch.ToString().ToCharArray(), 0);
            //int nameLen = 0;
            //while(Marshal.ReadByte(ptr, nameLen) != 0) ++nameLen;
            //byte[] buffer = new byte[nameLen];
            //Marshal.Copy(ptr, buffer, 0, buffer.Length);
            //string name = Encoding.UTF8.GetString(buffer, 0, nameLen);

            print("Beat happened");

            OnBeat?.Invoke();
            //gch.Free();
        }
        return(FMOD.RESULT.OK);
    }
    private FMOD.RESULT VoiceEventCallback(EVENT_CALLBACK_TYPE callbackType, EventInstance eventInstance, IntPtr parameters)
    {
        IntPtr voiceStatePtr;

        FMOD.RESULT result = eventInstance.getUserData(out voiceStatePtr);

        if (result != FMOD.RESULT.OK)
        {
            Debug.LogError("FMOD error: " + result);
        }
        else
        {
            if (voiceStatePtr != IntPtr.Zero)
            {
                GCHandle       voiceInfoHandle = GCHandle.FromIntPtr(voiceStatePtr);
                VoiceStateInfo voiceInfo       = (VoiceStateInfo)voiceInfoHandle.Target;

                switch (callbackType)
                {
                case EVENT_CALLBACK_TYPE.START_FAILED:
                case EVENT_CALLBACK_TYPE.STOPPED:
                    eventInstance.setUserData(IntPtr.Zero);
                    eventInstance.setCallback(null);
                    eventInstance.release();
                    voiceInfo.State = VoiceState.Silent;
                    break;
                }
            }
        }

        return(FMOD.RESULT.OK);
    }
Exemple #3
0
    private RESULT audioFinishedCallback(EVENT_CALLBACK_TYPE type, EventInstance eventInstance, IntPtr parameters)
    {
        dialogRunning = false;
        UnityEngine.Debug.Log("dialog finished");

        return(RESULT.OK);
    }
            private RESULT wrapperCallback(EVENT_CALLBACK_TYPE type, IntPtr parameters)
            {
                if (onPlaybackStateChange != null)
                {
                    onPlaybackStateChange(type, this);
                }

                return(RESULT.OK);
            }
Exemple #5
0
 private static FMOD.RESULT BeatEventCallback(EVENT_CALLBACK_TYPE type, EventInstance instance, IntPtr parameterPtr)
 {
     if (type == EVENT_CALLBACK_TYPE.TIMELINE_BEAT)
     {
         Debug.Log("0");
         OnBeat?.Invoke();
     }
     Debug.Log("1");
     return(FMOD.RESULT.OK);
 }
        // Handles creation and destructin of the programmer sound
        static RESULT ProgrammerEventCallback(EVENT_CALLBACK_TYPE type, EventInstance studioEvent, IntPtr parameterPtr)
        {
            EventInstance eventInstance = studioEvent;

            IntPtr pointer;

            eventInstance.getUserData(out pointer);

            // This gets the user data we just gave to the event
            GCHandle handle = GCHandle.FromIntPtr(pointer);
            ProgrammerSoundContext context = handle.Target as ProgrammerSoundContext;

            switch (type)
            {
            case EVENT_CALLBACK_TYPE.CREATE_PROGRAMMER_SOUND:

                UnityEngine.Debug.Log("FMOD Extensions: Creating Programmer Sound");
                PROGRAMMER_SOUND_PROPERTIES props = (PROGRAMMER_SOUND_PROPERTIES)Marshal.PtrToStructure(parameterPtr, typeof(PROGRAMMER_SOUND_PROPERTIES));

                RESULT result = RESULT.OK;

                Sound sound;
                result = Instance.LowLevelSystem.createSound(context.file, context.mode, out sound);
                Instance.CheckResult(result, "FMOD.CreateSound");

                if (result == RESULT.OK)
                {
                    props.sound = sound.handle;
                    Marshal.StructureToPtr(props, parameterPtr, false);
                }
                break;

            case EVENT_CALLBACK_TYPE.DESTROY_PROGRAMMER_SOUND:
                UnityEngine.Debug.Log("FMOD Extensions: Destroying Programmer Sound");
                RESULT resultTwo = RESULT.OK;
                PROGRAMMER_SOUND_PROPERTIES properties = (PROGRAMMER_SOUND_PROPERTIES)Marshal.PtrToStructure(parameterPtr, typeof(PROGRAMMER_SOUND_PROPERTIES));
                Sound destroyingSound = new Sound {
                    handle = properties.sound
                };

                result = destroyingSound.release();
                Instance.CheckResult(resultTwo, "Sound.Release");
                break;

            case EVENT_CALLBACK_TYPE.DESTROYED:
                UnityEngine.Debug.Log("FMOD Extensions: Destroying Event");
                handle.Free();
                break;
            }
            return(RESULT.OK);
        }
Exemple #7
0
        FMOD.RESULT EventInstanceCreatedCallback(EVENT_CALLBACK_TYPE type, IntPtr instancePtr, IntPtr parameterPtr)
        {
            EventInstance instance = new EventInstance(instancePtr);

            IntPtr registreePointer;

            instance.getUserData(out registreePointer);
            GCHandle registreeHandle = GCHandle.FromIntPtr(registreePointer);
            DelayedSpatialAudioRegistree delayedRegistree = registreeHandle.Target as DelayedSpatialAudioRegistree;

            switch (type)
            {
            case EVENT_CALLBACK_TYPE.CREATED:
            {
                float maxDistance = ResonanceAudioSourceUtility.GetResonanceAudioSourceMaxDistance(instance);

                if (maxDistance == -1)
                {
                    if (delayedRegistree != null)
                    {
                        delayedRegistree.isInvalid = true;
                    }
                }
                else
                {
                    if (instance.isValid() && delayedRegistree != null)
                    {
                        delayedRegistree.maxDistance = maxDistance;
                        delayedRegistree.instanceCreationComplete = true;
                    }
                    else if (delayedRegistree != null)
                    {
                        delayedRegistree.isInvalid = true;
                    }
                }
            }
            break;

            case EVENT_CALLBACK_TYPE.DESTROYED:
            {
                registreeHandle.Free();
            }
            break;

            default:
                break;
            }

            return(FMOD.RESULT.OK);
        }
        static RESULT MusicEventCallback(EVENT_CALLBACK_TYPE type, EventInstance instance, IntPtr parameterPtr)
        {
            switch (type)
            {
            case EVENT_CALLBACK_TYPE.CREATE_PROGRAMMER_SOUND: {
                MODE soundMode = MODE.LOOP_NORMAL | MODE.CREATECOMPRESSEDSAMPLE | MODE.NONBLOCKING;
                var  parameter = (PROGRAMMER_SOUND_PROPERTIES)Marshal.PtrToStructure(parameterPtr, typeof(PROGRAMMER_SOUND_PROPERTIES));
                parameter.sound         = audioClipSound.handle;
                parameter.subsoundIndex = -1;
                Marshal.StructureToPtr(parameter, parameterPtr, false);
                break;
            }

            case EVENT_CALLBACK_TYPE.SOUND_PLAYED: {
                awaitingCallback = false;
                break;
            }
            }
            return(RESULT.OK);
        }
    /*
     * Used to set a callback on an event instance that returns a EventCallbackData instance.
     * EventCallbackData can be used to simplify the process  of getting data from the callbacks.
     */
    public static void setCallback(
        EventInstance instance,
        Action <EventCallbackData> callback,
        EVENT_CALLBACK_TYPE callbackMask = EVENT_CALLBACK_TYPE.ALL)
    {
        EVENT_CALLBACK evCallback = (EVENT_CALLBACK_TYPE type, IntPtr eventInstance, IntPtr parameters) =>
        {
            try
            {
                EventCallbackData data = new EventCallbackData(type, eventInstance, parameters);
                callback(data);
            }
            catch (Exception ex)
            {
                UnityEngine.Debug.LogError("Error occurred during event callback: " + ex.Message);
            }
            return(RESULT.OK);
        };

        evCallbacks.Add(evCallback);

        //set callback to lambda instance (whose lifetime SHOULD be the same as this class (forever))
        instance.setCallback(evCallback, callbackMask);
    }
 private static extern RESULT FMOD_Studio_EventDescription_SetCallback(IntPtr eventdescription, EVENT_CALLBACK callback, EVENT_CALLBACK_TYPE callbackmask);
            private RESULT wrapperCallback(EVENT_CALLBACK_TYPE type, IntPtr parameters)
            {
                if (onPlaybackStateChange != null)
                onPlaybackStateChange(type, this);

                return RESULT.OK;
            }
Exemple #12
0
 private static extern RESULT FMOD_Studio_EventInstance_SetCallback(IntPtr _event, EVENT_CALLBACK callback, EVENT_CALLBACK_TYPE callbackmask);
Exemple #13
0
        public static RESULT GNHEventCallback(EVENT_CALLBACK_TYPE type, EventInstance _event, IntPtr parameters)
        {
            RESULT      result;
            FmodService service = _latestService;

            if (service == null)
            {
                return(RESULT.ERR_UNSUPPORTED);
            }

            //lock(service.eventInstanceLock)
            //{
            if (type == EVENT_CALLBACK_TYPE.STOPPED || type == EVENT_CALLBACK_TYPE.START_FAILED)
            {
                for (int i = 0; i < GHConstants.MaxNormalImmediateSoundInstances; i++)
                {
                    if (i >= service.immediateInstances.Count)
                    {
                        break;
                    }

                    if (service.immediateInstances[i].instance.handle == _event.handle)
                    {
                        service.immediateInstances[i].stopped = true;
                        for (int j = i - 1; j >= 0; j--)
                        {
                            if (service.immediateInstances[j].queued)
                            {
                                service.immediateInstances[j].queued = false;
                                result = service.immediateInstances[j].instance.start();
                                result = _system.update();
                                return(RESULT.OK);
                            }
                        }
                    }
                }
                for (int i = 0; i < GHConstants.MaxLongImmediateSoundInstances; i++)
                {
                    if (i >= service.longImmediateInstances.Count)
                    {
                        break;
                    }

                    if (service.longImmediateInstances[i].instance.handle == _event.handle)
                    {
                        service.longImmediateInstances[i].stopped = true;
                        for (int j = i - 1; j >= 0; j--)
                        {
                            if (service.longImmediateInstances[j].queued)
                            {
                                service.longImmediateInstances[j].queued = false;
                                result = service.longImmediateInstances[j].instance.start();
                                result = _system.update();
                                return(RESULT.OK);
                            }
                        }
                    }
                }
            }
            return(RESULT.OK);
            //}
        }
 public EventCallbackData(EVENT_CALLBACK_TYPE type, IntPtr instance, IntPtr parameters)
 {
     this.type       = type;
     this.instance   = instance;
     this.parameters = parameters;
 }
Exemple #15
0
 public RESULT setCallback(EVENT_CALLBACK callback, EVENT_CALLBACK_TYPE callbackmask = EVENT_CALLBACK_TYPE.ALL)
 {
     return(FMOD_Studio_EventDescription_SetCallback(handle, callback, callbackmask));
 }
 public RESULT setCallback(EVENT_CALLBACK callback, EVENT_CALLBACK_TYPE callbackmask = EVENT_CALLBACK_TYPE.ALL)
 {
     return FMOD_Studio_EventInstance_SetCallback(rawPtr, callback, callbackmask);
 }
 private static extern RESULT FMOD_Studio_EventInstance_SetCallback          (IntPtr _event, EVENT_CALLBACK callback, EVENT_CALLBACK_TYPE callbackmask);
 public RESULT setCallback(EVENT_CALLBACK callback, EVENT_CALLBACK_TYPE callbackmask = EVENT_CALLBACK_TYPE.ALL)
 {
     return(EventDescription.FMOD_Studio_EventDescription_SetCallback(this.rawPtr, callback, callbackmask));
 }
 private static extern RESULT FMOD_Studio_EventDescription_SetCallback(IntPtr eventdescription, EVENT_CALLBACK callback, EVENT_CALLBACK_TYPE callbackmask);
Exemple #20
0
 public RESULT setCallback(EVENT_CALLBACK callback, EVENT_CALLBACK_TYPE callbackmask = EVENT_CALLBACK_TYPE.ALL)
 {
     return(EventInstance.FMOD_Studio_EventInstance_SetCallback(this.rawPtr, callback, callbackmask));
 }