public static void Term()
 {
     if (m_pNotifMem != System.IntPtr.Zero)
     {
         AkCallbackSerializer.Term();
         System.Runtime.InteropServices.Marshal.FreeHGlobal(m_pNotifMem);
         m_pNotifMem = System.IntPtr.Zero;
     }
 }
 static public void Term()
 {
     if (m_pNotifMem != IntPtr.Zero)
     {
         AkCallbackSerializer.Term();
         Marshal.FreeHGlobal(m_pNotifMem);
         m_pNotifMem = IntPtr.Zero;
     }
 }
    static public AKRESULT Init(int BufferSize)
    {
        m_pNotifMem = (BufferSize > 0) ? Marshal.AllocHGlobal(BufferSize) : IntPtr.Zero;

#if UNITY_EDITOR
        AkCallbackSerializer.SetLocalOutput((uint)AkMonitorErrorLevel.ErrorLevel_All);
#endif

        return(AkCallbackSerializer.Init(m_pNotifMem, (uint)BufferSize));
    }
Exemple #4
0
    public static void Init(InitializationSettings settings)
    {
        IsLoggingEnabled = settings.IsLoggingEnabled;

#if UNITY_EDITOR
        AkCallbackSerializer.SetLocalOutput((uint)AkMonitorErrorLevel.ErrorLevel_All);
#endif

        AkCallbackSerializer.Init();
    }
    public static AKRESULT Init(InitializationSettings settings)
    {
        IsLoggingEnabled = settings.IsLoggingEnabled;

        m_pNotifMem = settings.BufferSize > 0 ? System.Runtime.InteropServices.Marshal.AllocHGlobal(settings.BufferSize) : System.IntPtr.Zero;

#if UNITY_EDITOR
        AkCallbackSerializer.SetLocalOutput((uint)AkMonitorErrorLevel.ErrorLevel_All);
#endif

        return(AkCallbackSerializer.Init(m_pNotifMem, (uint)settings.BufferSize));
    }
Exemple #6
0
    public virtual void Dispose()
    {
        AkCallbackSerializer serializer = this;

        lock (serializer)
        {
            if (this.swigCPtr != IntPtr.Zero)
            {
                if (this.swigCMemOwn)
                {
                    this.swigCMemOwn = false;
                    AkSoundEnginePINVOKE.CSharp_delete_AkCallbackSerializer(this.swigCPtr);
                }
                this.swigCPtr = IntPtr.Zero;
            }
            GC.SuppressFinalize(this);
        }
    }
Exemple #7
0
    /// This funcition dispatches all the accumulated callbacks from the native sound engine.
    /// It must be called regularly.  By default this is called in AkInitializer.cs.
    static public int PostCallbacks()
    {
        int numCallbacks = 0;

        if (m_pNotifMem == IntPtr.Zero)
        {
            return(numCallbacks);
        }

        IntPtr pData = AkCallbackSerializer.Lock();

        if (pData == IntPtr.Zero)
        {
            AkCallbackSerializer.Unlock();
            return(numCallbacks);
        }

        AkCommonCallback commonCB;

        commonCB.eType    = 0;
        commonCB.pPackage = IntPtr.Zero;
        commonCB.pNext    = IntPtr.Zero;

        IntPtr callbacksStart = pData;

        commonCB = new AkCommonCallback();

        commonCB.pPackage = Marshal.ReadIntPtr(pData);
        GotoEndOfCurrentStructMember_IntPtr(ref pData);

        commonCB.pNext = Marshal.ReadIntPtr(pData);
        GotoEndOfCurrentStructMember_IntPtr(ref pData);

        commonCB.eType = (AkCallbackType)Marshal.ReadInt32(pData);
        GotoEndOfCurrentStructMember_EnumType <AkCallbackType>(ref pData);

        EventCallbackPackage eventPkg = null;
        BankCallbackPackage  bankPkg  = null;

        if (!SafeExtractCallbackPackages(commonCB, out eventPkg, out bankPkg))
        {
            AkCallbackSerializer.Unlock();
            return(numCallbacks);
        }

        pData = callbacksStart;

        do
        {
            // Point to start of the next callback after commonCallback.
            pData = (IntPtr)(pData.ToInt64() + Marshal.SizeOf(typeof(AkCommonCallback)));

            if (commonCB.eType == AkCallbackType.AK_Monitoring)
            {
                AkMonitoringMsg monitorMsg = new AkMonitoringMsg();

                monitorMsg.errorCode = (ErrorCode)Marshal.ReadInt32(pData);
                // WG-25449
                GotoEndOfCurrentStructMember_ValueType <int>(ref pData);

                monitorMsg.errorLevel = (ErrorLevel)Marshal.ReadInt32(pData);
                // WG-25449
                GotoEndOfCurrentStructMember_ValueType <int>(ref pData);

                monitorMsg.playingID = (uint)Marshal.ReadInt32(pData);
                GotoEndOfCurrentStructMember_ValueType <uint>(ref pData);

                monitorMsg.gameObjID = (IntPtr)Marshal.ReadIntPtr(pData);
                GotoEndOfCurrentStructMember_IntPtr(ref pData);

                // C# implementation of the struct does not include the tail string member, so as we skip sizes, pData is now at the actual start of the string member.
                monitorMsg.msg = SafeMarshalString(pData);
                if (m_MonitoringCB != null)
                {
                    m_MonitoringCB(monitorMsg.errorCode, monitorMsg.errorLevel, monitorMsg.playingID, monitorMsg.gameObjID, monitorMsg.msg);
                }
            }
            else if (commonCB.eType == AkCallbackType.AK_Bank)
            {
                AkBankInfo bankCB = new AkBankInfo();

                bankCB.bankID = (uint)Marshal.ReadInt32(pData);
                GotoEndOfCurrentStructMember_ValueType <uint>(ref pData);

                bankCB.inMemoryBankPtr = Marshal.ReadIntPtr(pData);
                GotoEndOfCurrentStructMember_ValueType <IntPtr>(ref pData);

                bankCB.eLoadResult = (AKRESULT)Marshal.ReadInt32(pData);
                GotoEndOfCurrentStructMember_EnumType <AKRESULT>(ref pData);

                bankCB.memPoolId = (uint)Marshal.ReadInt32(pData);
                GotoEndOfCurrentStructMember_ValueType <uint>(ref pData);

                if (bankPkg != null && bankPkg.m_Callback != null)
                {
                    bankPkg.m_Callback(bankCB.bankID, bankCB.inMemoryBankPtr, bankCB.eLoadResult, bankCB.memPoolId, bankPkg.m_Cookie);
                }
            }
#if UNITY_IOS && !UNITY_EDITOR
            else if (commonCB.eType == AkCallbackType.AK_AudioInterruption)
            {
                AkAudioInterruptionInfo cbInfo = new AkAudioInterruptionInfo();

                cbInfo.bEnterInterruption = Marshal.ReadInt32(pData);
                GotoEndOfCurrentStructMember_ValueType <Int32>(ref pData);

                if (ms_interruptCallbackPkg != null && ms_interruptCallbackPkg.m_Callback != null)
                {
                    ms_interruptCallbackPkg.m_Callback(cbInfo.bEnterInterruption, ms_interruptCallbackPkg.m_Cookie);
                }
            }
#endif // #if UNITY_IOS && ! UNITY_EDITOR
            else if (commonCB.eType == AkCallbackType.AK_AudioSourceChange)
            {
                AkBGMInfo cbInfo = new AkBGMInfo();

                cbInfo.bOtherAudioPlaying = Marshal.ReadInt32(pData);
                GotoEndOfCurrentStructMember_ValueType <Int32>(ref pData);

                if (ms_sourceChangeCallbackPkg != null && ms_sourceChangeCallbackPkg.m_Callback != null)
                {
                    ms_sourceChangeCallbackPkg.m_Callback(cbInfo.bOtherAudioPlaying, ms_sourceChangeCallbackPkg.m_Cookie);
                }
            }
            else
            {
                //Get the other parameters
                switch (commonCB.eType)
                {
                case AkCallbackType.AK_EndOfEvent:
                    AkEventCallbackInfo eventCB = new AkEventCallbackInfo();

                    eventCB.pCookie = Marshal.ReadIntPtr(pData);
                    GotoEndOfCurrentStructMember_IntPtr(ref pData);

                    eventCB.gameObjID = Marshal.ReadIntPtr(pData);
                    GotoEndOfCurrentStructMember_IntPtr(ref pData);

                    eventCB.playingID = (uint)Marshal.ReadInt32(pData);
                    GotoEndOfCurrentStructMember_ValueType <uint>(ref pData);

                    eventCB.eventID = (uint)Marshal.ReadInt32(pData);
                    GotoEndOfCurrentStructMember_ValueType <uint>(ref pData);

                    if (eventPkg.m_bNotifyEndOfEvent)
                    {
                        eventPkg.m_Callback(eventPkg.m_Cookie, commonCB.eType, eventCB);
                    }
                    m_mapEventCallbacks.Remove(eventPkg.GetHashCode());
                    break;

                case AkCallbackType.AK_EndOfDynamicSequenceItem:
                    AkDynamicSequenceItemCallbackInfo dynSeqInfoCB = new AkDynamicSequenceItemCallbackInfo();

                    dynSeqInfoCB.pCookie = Marshal.ReadIntPtr(pData);
                    GotoEndOfCurrentStructMember_IntPtr(ref pData);

                    dynSeqInfoCB.playingID = (uint)Marshal.ReadInt32(pData);
                    GotoEndOfCurrentStructMember_ValueType <uint>(ref pData);

                    dynSeqInfoCB.audioNodeID = (uint)Marshal.ReadInt32(pData);
                    GotoEndOfCurrentStructMember_ValueType <uint>(ref pData);

                    dynSeqInfoCB.pCustomInfo = Marshal.ReadIntPtr(pData);
                    GotoEndOfCurrentStructMember_IntPtr(ref pData);

                    eventPkg.m_Callback(eventPkg.m_Cookie, commonCB.eType, dynSeqInfoCB);
                    break;

                case AkCallbackType.AK_MIDIEvent:
                    AkMidiEventCallbackInfo midiEventInfo = new AkMidiEventCallbackInfo();

                    midiEventInfo.pCookie = Marshal.ReadIntPtr(pData);
                    GotoEndOfCurrentStructMember_IntPtr(ref pData);

                    midiEventInfo.gameObjID = Marshal.ReadIntPtr(pData);
                    GotoEndOfCurrentStructMember_IntPtr(ref pData);

                    midiEventInfo.playingID = (uint)Marshal.ReadInt32(pData);
                    GotoEndOfCurrentStructMember_ValueType <uint>(ref pData);

                    midiEventInfo.eventID = (uint)Marshal.ReadInt32(pData);
                    GotoEndOfCurrentStructMember_ValueType <uint>(ref pData);

                    midiEventInfo.byType = (byte)Marshal.ReadByte(pData);
                    GotoEndOfCurrentStructMember_ValueType <byte>(ref pData);

                    midiEventInfo.byChan = (byte)Marshal.ReadByte(pData);
                    GotoEndOfCurrentStructMember_ValueType <byte>(ref pData);

                    switch (midiEventInfo.byType)
                    {
                    case AkSoundEngine.AK_MIDI_EVENT_TYPE_NOTE_OFF:                                     //Deliberate fall-through
                    case AkSoundEngine.AK_MIDI_EVENT_TYPE_NOTE_ON:
                        midiEventInfo.byOnOffNote = (byte)Marshal.ReadByte(pData);
                        GotoEndOfCurrentStructMember_ValueType <byte>(ref pData);
                        midiEventInfo.byVelocity = (byte)Marshal.ReadByte(pData);
                        GotoEndOfCurrentStructMember_ValueType <byte>(ref pData);
                        break;

                    case AkSoundEngine.AK_MIDI_EVENT_TYPE_NOTE_AFTERTOUCH:
                        midiEventInfo.byAftertouchNote = (byte)Marshal.ReadByte(pData);
                        GotoEndOfCurrentStructMember_ValueType <byte>(ref pData);
                        midiEventInfo.byNoteAftertouchValue = (byte)Marshal.ReadByte(pData);
                        GotoEndOfCurrentStructMember_ValueType <byte>(ref pData);
                        break;

                    case AkSoundEngine.AK_MIDI_EVENT_TYPE_CONTROLLER:
                        // tCc
                        midiEventInfo.byCc = (byte)Marshal.ReadByte(pData);
                        GotoEndOfCurrentStructMember_ValueType <byte>(ref pData);
                        midiEventInfo.byCcValue = (byte)Marshal.ReadByte(pData);
                        GotoEndOfCurrentStructMember_ValueType <byte>(ref pData);
                        break;

                    case AkSoundEngine.AK_MIDI_EVENT_TYPE_PROGRAM_CHANGE:
                        midiEventInfo.byProgramNum = (byte)Marshal.ReadByte(pData);
                        GotoEndOfCurrentStructMember_ValueType <byte>(ref pData);
                        GotoEndOfCurrentStructMember_ValueType <byte>(ref pData);                                        // skip unused 2nd member
                        break;

                    case AkSoundEngine.AK_MIDI_EVENT_TYPE_CHANNEL_AFTERTOUCH:
                        midiEventInfo.byChanAftertouchValue = (byte)Marshal.ReadByte(pData);
                        GotoEndOfCurrentStructMember_ValueType <byte>(ref pData);
                        GotoEndOfCurrentStructMember_ValueType <byte>(ref pData);                                        // skip unused 2nd member
                        break;

                    case AkSoundEngine.AK_MIDI_EVENT_TYPE_PITCH_BEND:
                        midiEventInfo.byValueLsb = (byte)Marshal.ReadByte(pData);
                        GotoEndOfCurrentStructMember_ValueType <byte>(ref pData);
                        midiEventInfo.byValueMsb = (byte)Marshal.ReadByte(pData);
                        GotoEndOfCurrentStructMember_ValueType <byte>(ref pData);
                        break;

                    // mcooper quote: "You won't get these"
                    case AkSoundEngine.AK_MIDI_EVENT_TYPE_SYSEX:
                    case AkSoundEngine.AK_MIDI_EVENT_TYPE_ESCAPE:
                    case AkSoundEngine.AK_MIDI_EVENT_TYPE_META:
                    case AkSoundEngine.AK_MIDI_EVENT_TYPE_INVALID:
                    default:
                        // Do nothing except skip the next two members
                        GotoEndOfCurrentStructMember_ValueType <byte>(ref pData);
                        GotoEndOfCurrentStructMember_ValueType <byte>(ref pData);
                        break;
                    }

                    eventPkg.m_Callback(eventPkg.m_Cookie, commonCB.eType, midiEventInfo);
                    break;

                case AkCallbackType.AK_Marker:
                    AkMarkerCallbackInfo markerInfo = new AkMarkerCallbackInfo();

                    markerInfo.pCookie = Marshal.ReadIntPtr(pData);
                    GotoEndOfCurrentStructMember_IntPtr(ref pData);

                    markerInfo.gameObjID = Marshal.ReadIntPtr(pData);
                    GotoEndOfCurrentStructMember_IntPtr(ref pData);

                    markerInfo.playingID = (uint)Marshal.ReadInt32(pData);
                    GotoEndOfCurrentStructMember_ValueType <uint>(ref pData);

                    markerInfo.eventID = (uint)Marshal.ReadInt32(pData);
                    GotoEndOfCurrentStructMember_ValueType <uint>(ref pData);

                    markerInfo.uIdentifier = (uint)Marshal.ReadInt32(pData);
                    GotoEndOfCurrentStructMember_ValueType <uint>(ref pData);

                    markerInfo.uPosition = (uint)Marshal.ReadInt32(pData);
                    GotoEndOfCurrentStructMember_ValueType <uint>(ref pData);

                    markerInfo.strLabel = SafeMarshalMarkerString(pData);

                    eventPkg.m_Callback(eventPkg.m_Cookie, commonCB.eType, markerInfo);
                    break;

                case AkCallbackType.AK_Duration:
                    AkDurationCallbackInfo durInfoCB = new AkDurationCallbackInfo();

                    durInfoCB.pCookie = Marshal.ReadIntPtr(pData);
                    GotoEndOfCurrentStructMember_IntPtr(ref pData);

                    durInfoCB.gameObjID = Marshal.ReadIntPtr(pData);
                    GotoEndOfCurrentStructMember_IntPtr(ref pData);

                    durInfoCB.playingID = (uint)Marshal.ReadInt32(pData);
                    GotoEndOfCurrentStructMember_ValueType <uint>(ref pData);

                    durInfoCB.eventID = (uint)Marshal.ReadInt32(pData);
                    GotoEndOfCurrentStructMember_ValueType <uint>(ref pData);

                    durInfoCB.fDuration = MarshalFloat32(pData);
                    GotoEndOfCurrentStructMember_ValueType <float>(ref pData);

                    durInfoCB.fEstimatedDuration = MarshalFloat32(pData);
                    GotoEndOfCurrentStructMember_ValueType <float>(ref pData);

                    durInfoCB.audioNodeID = (uint)Marshal.ReadInt32(pData);
                    GotoEndOfCurrentStructMember_ValueType <uint>(ref pData);

                    durInfoCB.mediaID = (uint)Marshal.ReadInt32(pData);
                    GotoEndOfCurrentStructMember_ValueType <uint>(ref pData);

                    durInfoCB.bStreaming = Convert.ToBoolean(Marshal.ReadInt32(pData));
                    GotoEndOfCurrentStructMember_ValueType <uint>(ref pData);

                    eventPkg.m_Callback(eventPkg.m_Cookie, commonCB.eType, durInfoCB);
                    break;

                case AkCallbackType.AK_MusicSyncUserCue:
                case AkCallbackType.AK_MusicPlayStarted:
                case AkCallbackType.AK_MusicSyncBar:
                case AkCallbackType.AK_MusicSyncBeat:
                case AkCallbackType.AK_MusicSyncEntry:
                case AkCallbackType.AK_MusicSyncExit:
                case AkCallbackType.AK_MusicSyncGrid:
                case AkCallbackType.AK_MusicSyncPoint:
                    AkMusicSyncCallbackInfo pInfo = new AkMusicSyncCallbackInfo();

                    pInfo.pCookie = Marshal.ReadIntPtr(pData);
                    GotoEndOfCurrentStructMember_IntPtr(ref pData);

                    pInfo.gameObjID = Marshal.ReadIntPtr(pData);
                    GotoEndOfCurrentStructMember_IntPtr(ref pData);

                    pInfo.playingID = (uint)Marshal.ReadInt32(pData);
                    GotoEndOfCurrentStructMember_ValueType <uint>(ref pData);

                    pInfo.segmentInfo.iCurrentPosition = Marshal.ReadInt32(pData);
                    GotoEndOfCurrentStructMember_ValueType <int>(ref pData);

                    pInfo.segmentInfo.iPreEntryDuration = Marshal.ReadInt32(pData);
                    GotoEndOfCurrentStructMember_ValueType <int>(ref pData);

                    pInfo.segmentInfo.iActiveDuration = Marshal.ReadInt32(pData);
                    GotoEndOfCurrentStructMember_ValueType <int>(ref pData);

                    pInfo.segmentInfo.iPostExitDuration = Marshal.ReadInt32(pData);
                    GotoEndOfCurrentStructMember_ValueType <int>(ref pData);

                    pInfo.segmentInfo.iRemainingLookAheadTime = Marshal.ReadInt32(pData);
                    GotoEndOfCurrentStructMember_ValueType <int>(ref pData);

                    pInfo.segmentInfo.fBeatDuration = MarshalFloat32(pData);
                    GotoEndOfCurrentStructMember_ValueType <float>(ref pData);

                    pInfo.segmentInfo.fBarDuration = MarshalFloat32(pData);
                    GotoEndOfCurrentStructMember_ValueType <float>(ref pData);

                    pInfo.segmentInfo.fGridDuration = MarshalFloat32(pData);
                    GotoEndOfCurrentStructMember_ValueType <float>(ref pData);

                    pInfo.segmentInfo.fGridOffset = MarshalFloat32(pData);
                    GotoEndOfCurrentStructMember_ValueType <float>(ref pData);

                    pInfo.musicSyncType = (AkCallbackType)Marshal.ReadInt32(pData);
                    GotoEndOfCurrentStructMember_EnumType <AkCallbackType>(ref pData);

                    // WG-22334: User cues are always ANSI char*.
                    pInfo.pszUserCueName = Marshal.PtrToStringAnsi(pData);

                    eventPkg.m_Callback(eventPkg.m_Cookie, commonCB.eType, pInfo);
                    break;

                default:
                    string log = string.Format("WwiseUnity: PostCallbacks aborted due to error: Undefined callback type found. Callback object possibly corrupted.");
                    Debug.LogError(log);
                    AkCallbackSerializer.Unlock();
                    return(numCallbacks);
                }
                ;
            }

            numCallbacks++;
            if (commonCB.pNext == IntPtr.Zero)
            {
                break;
            }

            // Note: At the end of each callback case above, pData points to either end of the callback struct, or right before the tail string member of the struct.
            pData = commonCB.pNext;

            callbacksStart = pData;

            commonCB = new AkCommonCallback();

            commonCB.pPackage = (IntPtr)Marshal.ReadIntPtr(pData);
            GotoEndOfCurrentStructMember_IntPtr(ref pData);

            commonCB.pNext = (IntPtr)Marshal.ReadIntPtr(pData);
            GotoEndOfCurrentStructMember_IntPtr(ref pData);

            commonCB.eType = (AkCallbackType)Marshal.ReadInt32(pData);
            GotoEndOfCurrentStructMember_EnumType <AkCallbackType>(ref pData);

            eventPkg = null;
            bankPkg  = null;

            if (!SafeExtractCallbackPackages(commonCB, out eventPkg, out bankPkg))
            {
                AkCallbackSerializer.Unlock();
                return(numCallbacks);
            }

            pData = callbacksStart;
        } while (true);

        AkCallbackSerializer.Unlock();
        return(numCallbacks);
    }
Exemple #8
0
 static public AKRESULT Init()
 {
     //Allocate 4k for notifications that will happen during one game frame.
     m_pNotifMem = Marshal.AllocHGlobal(4096);
     return(AkCallbackSerializer.Init(m_pNotifMem, 4096));
 }
 internal static global::System.IntPtr getCPtr(AkCallbackSerializer obj)
 {
     return((obj == null) ? global::System.IntPtr.Zero : obj.swigCPtr);
 }
Exemple #10
0
    static public void PostCallbacks()
    {
        if (!AkSoundEngine.IsInitialized())
        {
            return;
        }


        if (m_pNotifMem == IntPtr.Zero)
        {
            return;
        }

        IntPtr pData = AkCallbackSerializer.Lock();

        if (pData == IntPtr.Zero)
        {
            AkCallbackSerializer.Unlock();
            return;
        }

        AkCommonCallback commonCB;

        commonCB.eType    = 0;
        commonCB.pPackage = IntPtr.Zero;
        commonCB.pNext    = IntPtr.Zero;

        IntPtr callbacksStart = pData;

        commonCB = new AkCommonCallback();

        commonCB.pPackage = Marshal.ReadIntPtr(pData);
        GotoEndOfCurrentStructMember_IntPtr(ref pData);

        commonCB.pNext = Marshal.ReadIntPtr(pData);
        GotoEndOfCurrentStructMember_IntPtr(ref pData);

        commonCB.eType = (AkCallbackType)Marshal.ReadInt32(pData);
        GotoEndOfCurrentStructMember_EnumType <AkCallbackType>(ref pData);

        EventCallbackPackage eventPkg = null;
        BankCallbackPackage  bankPkg  = null;

        if (!SafeExtractCallbackPackages(commonCB, out eventPkg, out bankPkg))
        {
            AkCallbackSerializer.Unlock();
            return;
        }

        pData = callbacksStart;

        do
        {
            // Point to start of the next callback after commonCallback.
            pData = (IntPtr)(pData.ToInt64() + Marshal.SizeOf(typeof(AkCommonCallback)));

            if (commonCB.eType == AkCallbackType.AK_Monitoring)
            {
                AkMonitoringMsg monitorMsg = new AkMonitoringMsg();

                monitorMsg.errorCode = (ErrorCode)Marshal.ReadInt32(pData);
                GotoEndOfCurrentStructMember_EnumType <ErrorCode>(ref pData);

                monitorMsg.errorLevel = (ErrorLevel)Marshal.ReadInt32(pData);
                GotoEndOfCurrentStructMember_EnumType <ErrorLevel>(ref pData);

                monitorMsg.playingID = (uint)Marshal.ReadInt32(pData);
                GotoEndOfCurrentStructMember_ValueType <uint>(ref pData);

                monitorMsg.gameObjID = (IntPtr)Marshal.ReadIntPtr(pData);
                GotoEndOfCurrentStructMember_IntPtr(ref pData);

                // C# implementation of the struct does not include the tail string member, so as we skip sizes, pData is now at the actual start of the string member.
                monitorMsg.msg = SafeMarshalString(pData);
                if (m_MonitoringCB != null)
                {
                    m_MonitoringCB(monitorMsg.errorCode, monitorMsg.errorLevel, monitorMsg.playingID, monitorMsg.gameObjID, monitorMsg.msg);
                }
                else
                {
#if UNITY_EDITOR
                    string msg = "Wwise: " + monitorMsg.msg;
                    if (monitorMsg.gameObjID != (IntPtr)AkSoundEngine.AK_INVALID_GAME_OBJECT)
                    {
                        GameObject obj  = EditorUtility.InstanceIDToObject((int)monitorMsg.gameObjID) as GameObject;
                        string     name = obj != null?obj.ToString() : monitorMsg.gameObjID.ToString();

                        msg += "(Object: " + name + ")";
                    }

                    if (monitorMsg.errorLevel == ErrorLevel.ErrorLevel_Error)
                    {
                        Debug.LogError(msg);
                    }
                    else
                    {
                        Debug.Log(msg);
                    }
#endif
                }
            }
            else if (commonCB.eType == AkCallbackType.AK_Bank)
            {
                AkBankInfo bankCB = new AkBankInfo();

                bankCB.bankID = (uint)Marshal.ReadInt32(pData);
                GotoEndOfCurrentStructMember_ValueType <uint>(ref pData);

                bankCB.inMemoryBankPtr = Marshal.ReadIntPtr(pData);
                GotoEndOfCurrentStructMember_ValueType <IntPtr>(ref pData);

                bankCB.eLoadResult = (AKRESULT)Marshal.ReadInt32(pData);
                GotoEndOfCurrentStructMember_EnumType <AKRESULT>(ref pData);

                bankCB.memPoolId = (uint)Marshal.ReadInt32(pData);
                GotoEndOfCurrentStructMember_ValueType <uint>(ref pData);

                if (bankPkg != null)
                {
                    bankPkg.m_Callback(bankCB.bankID, bankCB.inMemoryBankPtr, bankCB.eLoadResult, bankCB.memPoolId, bankPkg.m_Cookie);
                }
            }
#if UNITY_IOS && !UNITY_EDITOR
            else if (commonCB.eType == AkCallbackType.AK_AudioInterruption)
            {
                AkAudioInterruptionInfo cbInfo = new AkAudioInterruptionInfo();

                cbInfo.bEnterInterruption = Marshal.ReadInt32(pData);
                GotoEndOfCurrentStructMember_ValueType <Int32>(ref pData);

                cbInfo.prevEngineStepResult = (AKRESULT)Marshal.ReadInt32(pData);
                GotoEndOfCurrentStructMember_EnumType <AKRESULT>(ref pData);

                ms_interruptCallbackPkg.m_Callback(cbInfo.bEnterInterruption, cbInfo.prevEngineStepResult, ms_interruptCallbackPkg.m_Cookie);
            }
#endif // #if UNITY_IOS && ! UNITY_EDITOR
            else
            {
                //Get the other parameters
                switch (commonCB.eType)
                {
                case AkCallbackType.AK_EndOfEvent:
                    AkEventCallbackInfo eventCB = new AkEventCallbackInfo();

                    eventCB.pCookie = Marshal.ReadIntPtr(pData);
                    GotoEndOfCurrentStructMember_IntPtr(ref pData);

                    eventCB.gameObjID = Marshal.ReadIntPtr(pData);
                    GotoEndOfCurrentStructMember_IntPtr(ref pData);

                    eventCB.playingID = (uint)Marshal.ReadInt32(pData);
                    GotoEndOfCurrentStructMember_ValueType <uint>(ref pData);

                    eventCB.eventID = (uint)Marshal.ReadInt32(pData);
                    GotoEndOfCurrentStructMember_ValueType <uint>(ref pData);

                    eventPkg.m_Callback(eventPkg.m_Cookie, commonCB.eType, eventCB);
                    break;

                case AkCallbackType.AK_EndOfDynamicSequenceItem:
                    AkDynamicSequenceItemCallbackInfo dynSeqInfoCB = new AkDynamicSequenceItemCallbackInfo();

                    dynSeqInfoCB.pCookie = Marshal.ReadIntPtr(pData);
                    GotoEndOfCurrentStructMember_IntPtr(ref pData);

                    dynSeqInfoCB.playingID = (uint)Marshal.ReadInt32(pData);
                    GotoEndOfCurrentStructMember_ValueType <uint>(ref pData);

                    dynSeqInfoCB.audioNodeID = (uint)Marshal.ReadInt32(pData);
                    GotoEndOfCurrentStructMember_ValueType <uint>(ref pData);

                    dynSeqInfoCB.pCustomInfo = Marshal.ReadIntPtr(pData);
                    GotoEndOfCurrentStructMember_IntPtr(ref pData);

                    eventPkg.m_Callback(eventPkg.m_Cookie, commonCB.eType, dynSeqInfoCB);
                    break;

                case AkCallbackType.AK_Marker:
                    AkMarkerCallbackInfo markerInfo = new AkMarkerCallbackInfo();

                    markerInfo.pCookie = Marshal.ReadIntPtr(pData);
                    GotoEndOfCurrentStructMember_IntPtr(ref pData);

                    markerInfo.gameObjID = Marshal.ReadIntPtr(pData);
                    GotoEndOfCurrentStructMember_IntPtr(ref pData);

                    markerInfo.playingID = (uint)Marshal.ReadInt32(pData);
                    GotoEndOfCurrentStructMember_ValueType <uint>(ref pData);

                    markerInfo.eventID = (uint)Marshal.ReadInt32(pData);
                    GotoEndOfCurrentStructMember_ValueType <uint>(ref pData);

                    markerInfo.uIdentifier = (uint)Marshal.ReadInt32(pData);
                    GotoEndOfCurrentStructMember_ValueType <uint>(ref pData);

                    markerInfo.uPosition = (uint)Marshal.ReadInt32(pData);
                    GotoEndOfCurrentStructMember_ValueType <uint>(ref pData);

                    markerInfo.strLabel = SafeMarshalMarkerString(pData);

                    eventPkg.m_Callback(eventPkg.m_Cookie, commonCB.eType, markerInfo);
                    break;

                case AkCallbackType.AK_Duration:
                    AkDurationCallbackInfo durInfoCB = new AkDurationCallbackInfo();

                    durInfoCB.pCookie = Marshal.ReadIntPtr(pData);
                    GotoEndOfCurrentStructMember_IntPtr(ref pData);

                    durInfoCB.gameObjID = Marshal.ReadIntPtr(pData);
                    GotoEndOfCurrentStructMember_IntPtr(ref pData);

                    durInfoCB.playingID = (uint)Marshal.ReadInt32(pData);
                    GotoEndOfCurrentStructMember_ValueType <uint>(ref pData);

                    durInfoCB.eventID = (uint)Marshal.ReadInt32(pData);
                    GotoEndOfCurrentStructMember_ValueType <uint>(ref pData);

                    durInfoCB.fDuration = MarshalFloat32(pData);
                    GotoEndOfCurrentStructMember_ValueType <float>(ref pData);

                    durInfoCB.fEstimatedDuration = MarshalFloat32(pData);
                    GotoEndOfCurrentStructMember_ValueType <float>(ref pData);

                    durInfoCB.audioNodeID = (uint)Marshal.ReadInt32(pData);
                    GotoEndOfCurrentStructMember_ValueType <uint>(ref pData);

                    eventPkg.m_Callback(eventPkg.m_Cookie, commonCB.eType, durInfoCB);
                    break;

                case AkCallbackType.AK_MusicSyncUserCue:
                case AkCallbackType.AK_MusicPlayStarted:
                case AkCallbackType.AK_MusicSyncBar:
                case AkCallbackType.AK_MusicSyncBeat:
                case AkCallbackType.AK_MusicSyncEntry:
                case AkCallbackType.AK_MusicSyncExit:
                case AkCallbackType.AK_MusicSyncGrid:
                case AkCallbackType.AK_MusicSyncPoint:
                    AkMusicSyncCallbackInfo pInfo = new AkMusicSyncCallbackInfo();

                    pInfo.pCookie = Marshal.ReadIntPtr(pData);
                    GotoEndOfCurrentStructMember_IntPtr(ref pData);

                    pInfo.gameObjID = Marshal.ReadIntPtr(pData);
                    GotoEndOfCurrentStructMember_IntPtr(ref pData);

                    pInfo.playingID = (uint)Marshal.ReadInt32(pData);
                    GotoEndOfCurrentStructMember_ValueType <uint>(ref pData);

                    pInfo.musicSyncType = (AkCallbackType)Marshal.ReadInt32(pData);
                    GotoEndOfCurrentStructMember_EnumType <AkCallbackType>(ref pData);

                    pInfo.fBeatDuration = MarshalFloat32(pData);
                    GotoEndOfCurrentStructMember_ValueType <float>(ref pData);

                    pInfo.fBarDuration = MarshalFloat32(pData);
                    GotoEndOfCurrentStructMember_ValueType <float>(ref pData);

                    pInfo.fGridDuration = MarshalFloat32(pData);
                    GotoEndOfCurrentStructMember_ValueType <float>(ref pData);

                    pInfo.fGridOffset = MarshalFloat32(pData);
                    GotoEndOfCurrentStructMember_ValueType <float>(ref pData);

                    // WG-22334: User cues are always ANSI char*.
                    pInfo.pszUserCueName = Marshal.PtrToStringAnsi(pData);

                    eventPkg.m_Callback(eventPkg.m_Cookie, commonCB.eType, pInfo);
                    break;

                default:
                    string log = string.Format("WwiseUnity: PostCallbacks aborted due to error: Undefined callback type found. Callback object possiblly corrupted.");
                    Log.d(log);
                    AkCallbackSerializer.Unlock();
                    return;
                }
                ;
            }

            if (commonCB.pNext == IntPtr.Zero)
            {
                break;
            }

            // Note: At the end of each callback case above, pData points to either end of the callback struct, or right before the tail string member of the struct.
            pData = commonCB.pNext;

            callbacksStart = pData;

            commonCB = new AkCommonCallback();

            commonCB.pPackage = (IntPtr)Marshal.ReadIntPtr(pData);
            GotoEndOfCurrentStructMember_IntPtr(ref pData);

            commonCB.pNext = (IntPtr)Marshal.ReadIntPtr(pData);
            GotoEndOfCurrentStructMember_IntPtr(ref pData);

            commonCB.eType = (AkCallbackType)Marshal.ReadInt32(pData);
            GotoEndOfCurrentStructMember_EnumType <AkCallbackType>(ref pData);

            eventPkg = null;
            bankPkg  = null;

            if (!SafeExtractCallbackPackages(commonCB, out eventPkg, out bankPkg))
            {
                AkCallbackSerializer.Unlock();
                return;
            }

            pData = callbacksStart;
        } while (true);

        AkCallbackSerializer.Unlock();
    }
Exemple #11
0
 public static void Term()
 {
     AkCallbackSerializer.Term();
 }
    public static void PostCallbacks()
    {
        AkCommonCallback        callback;
        AkMidiEventCallbackInfo info4;

        if (m_pNotifMem == IntPtr.Zero)
        {
            return;
        }
        IntPtr pNext = AkCallbackSerializer.Lock();

        if (pNext == IntPtr.Zero)
        {
            AkCallbackSerializer.Unlock();
            return;
        }
        callback.eType    = (AkCallbackType)0;
        callback.pPackage = IntPtr.Zero;
        callback.pNext    = IntPtr.Zero;
        IntPtr ptr2 = pNext;

        callback = new AkCommonCallback {
            pPackage = Marshal.ReadIntPtr(pNext)
        };
        GotoEndOfCurrentStructMember_IntPtr(ref pNext);
        callback.pNext = Marshal.ReadIntPtr(pNext);
        GotoEndOfCurrentStructMember_IntPtr(ref pNext);
        callback.eType = (AkCallbackType)Marshal.ReadInt32(pNext);
        GotoEndOfCurrentStructMember_EnumType <AkCallbackType>(ref pNext);
        EventCallbackPackage eventPkg = null;
        BankCallbackPackage  bankPkg  = null;

        if (!SafeExtractCallbackPackages(callback, out eventPkg, out bankPkg))
        {
            AkCallbackSerializer.Unlock();
            return;
        }
        pNext = ptr2;
Label_00B3:
        pNext = (IntPtr)(pNext.ToInt64() + Marshal.SizeOf(typeof(AkCommonCallback)));
        switch (callback.eType)
        {
        case AkCallbackType.AK_EndOfEvent:
        {
            AkEventCallbackInfo info2 = new AkEventCallbackInfo {
                pCookie = Marshal.ReadIntPtr(pNext)
            };
            GotoEndOfCurrentStructMember_IntPtr(ref pNext);
            info2.gameObjID = Marshal.ReadIntPtr(pNext);
            GotoEndOfCurrentStructMember_IntPtr(ref pNext);
            info2.playingID = (uint)Marshal.ReadInt32(pNext);
            GotoEndOfCurrentStructMember_ValueType <uint>(ref pNext);
            info2.eventID = (uint)Marshal.ReadInt32(pNext);
            GotoEndOfCurrentStructMember_ValueType <uint>(ref pNext);
            if (eventPkg.m_bNotifyEndOfEvent)
            {
                eventPkg.m_Callback(eventPkg.m_Cookie, callback.eType, info2);
            }
            m_mapEventCallbacks.Remove(eventPkg.GetHashCode());
            goto Label_087E;
        }

        case AkCallbackType.AK_EndOfDynamicSequenceItem:
        {
            AkDynamicSequenceItemCallbackInfo info3 = new AkDynamicSequenceItemCallbackInfo {
                pCookie = Marshal.ReadIntPtr(pNext)
            };
            GotoEndOfCurrentStructMember_IntPtr(ref pNext);
            info3.playingID = (uint)Marshal.ReadInt32(pNext);
            GotoEndOfCurrentStructMember_ValueType <uint>(ref pNext);
            info3.audioNodeID = (uint)Marshal.ReadInt32(pNext);
            GotoEndOfCurrentStructMember_ValueType <uint>(ref pNext);
            info3.pCustomInfo = Marshal.ReadIntPtr(pNext);
            GotoEndOfCurrentStructMember_IntPtr(ref pNext);
            eventPkg.m_Callback(eventPkg.m_Cookie, callback.eType, info3);
            goto Label_087E;
        }

        case AkCallbackType.AK_Marker:
        {
            AkMarkerCallbackInfo info5 = new AkMarkerCallbackInfo {
                pCookie = Marshal.ReadIntPtr(pNext)
            };
            GotoEndOfCurrentStructMember_IntPtr(ref pNext);
            info5.gameObjID = Marshal.ReadIntPtr(pNext);
            GotoEndOfCurrentStructMember_IntPtr(ref pNext);
            info5.playingID = (uint)Marshal.ReadInt32(pNext);
            GotoEndOfCurrentStructMember_ValueType <uint>(ref pNext);
            info5.eventID = (uint)Marshal.ReadInt32(pNext);
            GotoEndOfCurrentStructMember_ValueType <uint>(ref pNext);
            info5.uIdentifier = (uint)Marshal.ReadInt32(pNext);
            GotoEndOfCurrentStructMember_ValueType <uint>(ref pNext);
            info5.uPosition = (uint)Marshal.ReadInt32(pNext);
            GotoEndOfCurrentStructMember_ValueType <uint>(ref pNext);
            info5.strLabel = SafeMarshalMarkerString(pNext);
            eventPkg.m_Callback(eventPkg.m_Cookie, callback.eType, info5);
            goto Label_087E;
        }

        case AkCallbackType.AK_Duration:
        {
            AkDurationCallbackInfo info6 = new AkDurationCallbackInfo {
                pCookie = Marshal.ReadIntPtr(pNext)
            };
            GotoEndOfCurrentStructMember_IntPtr(ref pNext);
            info6.gameObjID = Marshal.ReadIntPtr(pNext);
            GotoEndOfCurrentStructMember_IntPtr(ref pNext);
            info6.playingID = (uint)Marshal.ReadInt32(pNext);
            GotoEndOfCurrentStructMember_ValueType <uint>(ref pNext);
            info6.eventID = (uint)Marshal.ReadInt32(pNext);
            GotoEndOfCurrentStructMember_ValueType <uint>(ref pNext);
            info6.fDuration = MarshalFloat32(pNext);
            GotoEndOfCurrentStructMember_ValueType <float>(ref pNext);
            info6.fEstimatedDuration = MarshalFloat32(pNext);
            GotoEndOfCurrentStructMember_ValueType <float>(ref pNext);
            info6.audioNodeID = (uint)Marshal.ReadInt32(pNext);
            GotoEndOfCurrentStructMember_ValueType <uint>(ref pNext);
            eventPkg.m_Callback(eventPkg.m_Cookie, callback.eType, info6);
            goto Label_087E;
        }

        case AkCallbackType.AK_MusicPlayStarted:
        case AkCallbackType.AK_MusicSyncBeat:
        case AkCallbackType.AK_MusicSyncBar:
        case AkCallbackType.AK_MusicSyncEntry:
        case AkCallbackType.AK_MusicSyncExit:
        case AkCallbackType.AK_MusicSyncGrid:
        case AkCallbackType.AK_MusicSyncUserCue:
        case AkCallbackType.AK_MusicSyncPoint:
        {
            AkMusicSyncCallbackInfo info7 = new AkMusicSyncCallbackInfo {
                pCookie = Marshal.ReadIntPtr(pNext)
            };
            GotoEndOfCurrentStructMember_IntPtr(ref pNext);
            info7.gameObjID = Marshal.ReadIntPtr(pNext);
            GotoEndOfCurrentStructMember_IntPtr(ref pNext);
            info7.playingID = (uint)Marshal.ReadInt32(pNext);
            GotoEndOfCurrentStructMember_ValueType <uint>(ref pNext);
            info7.musicSyncType = (AkCallbackType)Marshal.ReadInt32(pNext);
            GotoEndOfCurrentStructMember_EnumType <AkCallbackType>(ref pNext);
            info7.fBeatDuration = MarshalFloat32(pNext);
            GotoEndOfCurrentStructMember_ValueType <float>(ref pNext);
            info7.fBarDuration = MarshalFloat32(pNext);
            GotoEndOfCurrentStructMember_ValueType <float>(ref pNext);
            info7.fGridDuration = MarshalFloat32(pNext);
            GotoEndOfCurrentStructMember_ValueType <float>(ref pNext);
            info7.fGridOffset = MarshalFloat32(pNext);
            GotoEndOfCurrentStructMember_ValueType <float>(ref pNext);
            info7.pszUserCueName = Marshal.PtrToStringAnsi(pNext);
            eventPkg.m_Callback(eventPkg.m_Cookie, callback.eType, info7);
            goto Label_087E;
        }

        case AkCallbackType.AK_MidiEvent:
            info4 = new AkMidiEventCallbackInfo {
                pCookie = Marshal.ReadIntPtr(pNext)
            };
            GotoEndOfCurrentStructMember_IntPtr(ref pNext);
            info4.gameObjID = Marshal.ReadIntPtr(pNext);
            GotoEndOfCurrentStructMember_IntPtr(ref pNext);
            info4.playingID = (uint)Marshal.ReadInt32(pNext);
            GotoEndOfCurrentStructMember_ValueType <uint>(ref pNext);
            info4.eventID = (uint)Marshal.ReadInt32(pNext);
            GotoEndOfCurrentStructMember_ValueType <uint>(ref pNext);
            info4.byType = Marshal.ReadByte(pNext);
            GotoEndOfCurrentStructMember_ValueType <byte>(ref pNext);
            info4.byChan = Marshal.ReadByte(pNext);
            GotoEndOfCurrentStructMember_ValueType <byte>(ref pNext);
            switch (info4.byType)
            {
            case 0x80:
            case 0x90:
                info4.byOnOffNote = Marshal.ReadByte(pNext);
                GotoEndOfCurrentStructMember_ValueType <byte>(ref pNext);
                info4.byVelocity = Marshal.ReadByte(pNext);
                GotoEndOfCurrentStructMember_ValueType <byte>(ref pNext);
                goto Label_05FF;

            case 160:
                info4.byAftertouchNote = Marshal.ReadByte(pNext);
                GotoEndOfCurrentStructMember_ValueType <byte>(ref pNext);
                info4.byNoteAftertouchValue = Marshal.ReadByte(pNext);
                GotoEndOfCurrentStructMember_ValueType <byte>(ref pNext);
                goto Label_05FF;

            case 0xb0:
                info4.byCc = Marshal.ReadByte(pNext);
                GotoEndOfCurrentStructMember_ValueType <byte>(ref pNext);
                info4.byCcValue = Marshal.ReadByte(pNext);
                GotoEndOfCurrentStructMember_ValueType <byte>(ref pNext);
                goto Label_05FF;

            case 0xc0:
                info4.byProgramNum = Marshal.ReadByte(pNext);
                GotoEndOfCurrentStructMember_ValueType <byte>(ref pNext);
                GotoEndOfCurrentStructMember_ValueType <byte>(ref pNext);
                goto Label_05FF;

            case 0xd0:
                info4.byChanAftertouchValue = Marshal.ReadByte(pNext);
                GotoEndOfCurrentStructMember_ValueType <byte>(ref pNext);
                GotoEndOfCurrentStructMember_ValueType <byte>(ref pNext);
                goto Label_05FF;

            case 0xe0:
                info4.byValueLsb = Marshal.ReadByte(pNext);
                GotoEndOfCurrentStructMember_ValueType <byte>(ref pNext);
                info4.byValueMsb = Marshal.ReadByte(pNext);
                GotoEndOfCurrentStructMember_ValueType <byte>(ref pNext);
                goto Label_05FF;
            }
            GotoEndOfCurrentStructMember_ValueType <byte>(ref pNext);
            GotoEndOfCurrentStructMember_ValueType <byte>(ref pNext);
            break;

        case AkCallbackType.AK_Bank:
        {
            AkBankInfo info = new AkBankInfo {
                bankID = (uint)Marshal.ReadInt32(pNext)
            };
            GotoEndOfCurrentStructMember_ValueType <uint>(ref pNext);
            info.inMemoryBankPtr = Marshal.ReadIntPtr(pNext);
            GotoEndOfCurrentStructMember_ValueType <IntPtr>(ref pNext);
            info.eLoadResult = (AKRESULT)Marshal.ReadInt32(pNext);
            GotoEndOfCurrentStructMember_EnumType <AKRESULT>(ref pNext);
            info.memPoolId = (uint)Marshal.ReadInt32(pNext);
            GotoEndOfCurrentStructMember_ValueType <uint>(ref pNext);
            if ((bankPkg != null) && (bankPkg.m_Callback != null))
            {
                bankPkg.m_Callback(info.bankID, info.inMemoryBankPtr, info.eLoadResult, info.memPoolId, bankPkg.m_Cookie);
            }
            goto Label_087E;
        }

        case AkCallbackType.AK_Monitoring:
        {
            AkMonitoringMsg msg = new AkMonitoringMsg {
                errorCode = (ErrorCode)Marshal.ReadInt32(pNext)
            };
            GotoEndOfCurrentStructMember_ValueType <int>(ref pNext);
            msg.errorLevel = (ErrorLevel)Marshal.ReadInt32(pNext);
            GotoEndOfCurrentStructMember_ValueType <int>(ref pNext);
            msg.playingID = (uint)Marshal.ReadInt32(pNext);
            GotoEndOfCurrentStructMember_ValueType <uint>(ref pNext);
            msg.gameObjID = Marshal.ReadIntPtr(pNext);
            GotoEndOfCurrentStructMember_IntPtr(ref pNext);
            msg.msg = SafeMarshalString(pNext);
            if (m_MonitoringCB != null)
            {
                m_MonitoringCB(msg.errorCode, msg.errorLevel, msg.playingID, msg.gameObjID, msg.msg);
            }
            goto Label_087E;
        }

        default:
            Debug.LogError(string.Format("WwiseUnity: PostCallbacks aborted due to error: Undefined callback type found. Callback object possibly corrupted.", new object[0]));
            AkCallbackSerializer.Unlock();
            return;
        }
Label_05FF:
        eventPkg.m_Callback(eventPkg.m_Cookie, callback.eType, info4);
Label_087E:
        if (callback.pNext != IntPtr.Zero)
        {
            pNext    = callback.pNext;
            ptr2     = pNext;
            callback = new AkCommonCallback {
                pPackage = Marshal.ReadIntPtr(pNext)
            };
            GotoEndOfCurrentStructMember_IntPtr(ref pNext);
            callback.pNext = Marshal.ReadIntPtr(pNext);
            GotoEndOfCurrentStructMember_IntPtr(ref pNext);
            callback.eType = (AkCallbackType)Marshal.ReadInt32(pNext);
            GotoEndOfCurrentStructMember_EnumType <AkCallbackType>(ref pNext);
            eventPkg = null;
            bankPkg  = null;
            if (!SafeExtractCallbackPackages(callback, out eventPkg, out bankPkg))
            {
                AkCallbackSerializer.Unlock();
                return;
            }
            pNext = ptr2;
            goto Label_00B3;
        }
        AkCallbackSerializer.Unlock();
    }
 internal static IntPtr getCPtr(AkCallbackSerializer obj) {
   return (obj == null) ? IntPtr.Zero : obj.swigCPtr;
 }
 /// Call this to set a function to call whenever Wwise prints a message (warnings or errors).
 static public void SetMonitoringCallback(AkMonitorErrorLevel in_Level, MonitoringCallback in_CB)
 {
     AkCallbackSerializer.SetLocalOutput(in_CB != null ? (uint)in_Level : 0);
     m_MonitoringCB = in_CB;
 }
    public static void PostCallbacks()
    {
        if (AkCallbackManager.m_pNotifMem == IntPtr.Zero)
        {
            return;
        }
        IntPtr intPtr = AkCallbackSerializer.Lock();

        if (intPtr == IntPtr.Zero)
        {
            AkCallbackSerializer.Unlock();
            return;
        }
        AkCallbackManager.AkCommonCallback commonCB;
        commonCB.eType    = (AkCallbackType)0;
        commonCB.pPackage = IntPtr.Zero;
        commonCB.pNext    = IntPtr.Zero;
        IntPtr intPtr2 = intPtr;

        commonCB          = default(AkCallbackManager.AkCommonCallback);
        commonCB.pPackage = Marshal.ReadIntPtr(intPtr);
        AkCallbackManager.GotoEndOfCurrentStructMember_IntPtr(ref intPtr);
        commonCB.pNext = Marshal.ReadIntPtr(intPtr);
        AkCallbackManager.GotoEndOfCurrentStructMember_IntPtr(ref intPtr);
        commonCB.eType = (AkCallbackType)Marshal.ReadInt32(intPtr);
        AkCallbackManager.GotoEndOfCurrentStructMember_EnumType <AkCallbackType>(ref intPtr);
        AkCallbackManager.EventCallbackPackage eventCallbackPackage = null;
        AkCallbackManager.BankCallbackPackage  bankCallbackPackage  = null;
        if (!AkCallbackManager.SafeExtractCallbackPackages(commonCB, out eventCallbackPackage, out bankCallbackPackage))
        {
            AkCallbackSerializer.Unlock();
            return;
        }
        intPtr = intPtr2;
        while (true)
        {
            intPtr = (IntPtr)(intPtr.ToInt64() + (long)Marshal.SizeOf(typeof(AkCallbackManager.AkCommonCallback)));
            AkCallbackType eType = commonCB.eType;
            switch (eType)
            {
            case AkCallbackType.AK_EndOfEvent:
            {
                AkCallbackManager.AkEventCallbackInfo akEventCallbackInfo = default(AkCallbackManager.AkEventCallbackInfo);
                akEventCallbackInfo.pCookie = Marshal.ReadIntPtr(intPtr);
                AkCallbackManager.GotoEndOfCurrentStructMember_IntPtr(ref intPtr);
                akEventCallbackInfo.gameObjID = Marshal.ReadIntPtr(intPtr);
                AkCallbackManager.GotoEndOfCurrentStructMember_IntPtr(ref intPtr);
                akEventCallbackInfo.playingID = (uint)Marshal.ReadInt32(intPtr);
                AkCallbackManager.GotoEndOfCurrentStructMember_ValueType <uint>(ref intPtr);
                akEventCallbackInfo.eventID = (uint)Marshal.ReadInt32(intPtr);
                AkCallbackManager.GotoEndOfCurrentStructMember_ValueType <uint>(ref intPtr);
                if (eventCallbackPackage.m_bNotifyEndOfEvent)
                {
                    eventCallbackPackage.m_Callback(eventCallbackPackage.m_Cookie, commonCB.eType, akEventCallbackInfo);
                }
                AkCallbackManager.m_mapEventCallbacks.Remove(eventCallbackPackage.GetHashCode());
                goto IL_84D;
            }

            case AkCallbackType.AK_EndOfDynamicSequenceItem:
            {
                AkCallbackManager.AkDynamicSequenceItemCallbackInfo akDynamicSequenceItemCallbackInfo = default(AkCallbackManager.AkDynamicSequenceItemCallbackInfo);
                akDynamicSequenceItemCallbackInfo.pCookie = Marshal.ReadIntPtr(intPtr);
                AkCallbackManager.GotoEndOfCurrentStructMember_IntPtr(ref intPtr);
                akDynamicSequenceItemCallbackInfo.playingID = (uint)Marshal.ReadInt32(intPtr);
                AkCallbackManager.GotoEndOfCurrentStructMember_ValueType <uint>(ref intPtr);
                akDynamicSequenceItemCallbackInfo.audioNodeID = (uint)Marshal.ReadInt32(intPtr);
                AkCallbackManager.GotoEndOfCurrentStructMember_ValueType <uint>(ref intPtr);
                akDynamicSequenceItemCallbackInfo.pCustomInfo = Marshal.ReadIntPtr(intPtr);
                AkCallbackManager.GotoEndOfCurrentStructMember_IntPtr(ref intPtr);
                eventCallbackPackage.m_Callback(eventCallbackPackage.m_Cookie, commonCB.eType, akDynamicSequenceItemCallbackInfo);
                goto IL_84D;
            }

            case (AkCallbackType)3:
            case (AkCallbackType)5:
            case (AkCallbackType)6:
            case (AkCallbackType)7:
            {
IL_104:
                if (eType == AkCallbackType.AK_MusicPlayStarted || eType == AkCallbackType.AK_MusicSyncBeat || eType == AkCallbackType.AK_MusicSyncBar || eType == AkCallbackType.AK_MusicSyncEntry || eType == AkCallbackType.AK_MusicSyncExit || eType == AkCallbackType.AK_MusicSyncGrid || eType == AkCallbackType.AK_MusicSyncUserCue || eType == AkCallbackType.AK_MusicSyncPoint)
                {
                    AkCallbackManager.AkMusicSyncCallbackInfo akMusicSyncCallbackInfo = new AkCallbackManager.AkMusicSyncCallbackInfo();
                    akMusicSyncCallbackInfo.pCookie = Marshal.ReadIntPtr(intPtr);
                    AkCallbackManager.GotoEndOfCurrentStructMember_IntPtr(ref intPtr);
                    akMusicSyncCallbackInfo.gameObjID = Marshal.ReadIntPtr(intPtr);
                    AkCallbackManager.GotoEndOfCurrentStructMember_IntPtr(ref intPtr);
                    akMusicSyncCallbackInfo.playingID = (uint)Marshal.ReadInt32(intPtr);
                    AkCallbackManager.GotoEndOfCurrentStructMember_ValueType <uint>(ref intPtr);
                    akMusicSyncCallbackInfo.musicSyncType = (AkCallbackType)Marshal.ReadInt32(intPtr);
                    AkCallbackManager.GotoEndOfCurrentStructMember_EnumType <AkCallbackType>(ref intPtr);
                    akMusicSyncCallbackInfo.fBeatDuration = AkCallbackManager.MarshalFloat32(intPtr);
                    AkCallbackManager.GotoEndOfCurrentStructMember_ValueType <float>(ref intPtr);
                    akMusicSyncCallbackInfo.fBarDuration = AkCallbackManager.MarshalFloat32(intPtr);
                    AkCallbackManager.GotoEndOfCurrentStructMember_ValueType <float>(ref intPtr);
                    akMusicSyncCallbackInfo.fGridDuration = AkCallbackManager.MarshalFloat32(intPtr);
                    AkCallbackManager.GotoEndOfCurrentStructMember_ValueType <float>(ref intPtr);
                    akMusicSyncCallbackInfo.fGridOffset = AkCallbackManager.MarshalFloat32(intPtr);
                    AkCallbackManager.GotoEndOfCurrentStructMember_ValueType <float>(ref intPtr);
                    akMusicSyncCallbackInfo.pszUserCueName = Marshal.PtrToStringAnsi(intPtr);
                    eventCallbackPackage.m_Callback(eventCallbackPackage.m_Cookie, commonCB.eType, akMusicSyncCallbackInfo);
                    goto IL_84D;
                }
                if (eType == AkCallbackType.AK_MidiEvent)
                {
                    AkCallbackManager.AkMidiEventCallbackInfo akMidiEventCallbackInfo = default(AkCallbackManager.AkMidiEventCallbackInfo);
                    akMidiEventCallbackInfo.pCookie = Marshal.ReadIntPtr(intPtr);
                    AkCallbackManager.GotoEndOfCurrentStructMember_IntPtr(ref intPtr);
                    akMidiEventCallbackInfo.gameObjID = Marshal.ReadIntPtr(intPtr);
                    AkCallbackManager.GotoEndOfCurrentStructMember_IntPtr(ref intPtr);
                    akMidiEventCallbackInfo.playingID = (uint)Marshal.ReadInt32(intPtr);
                    AkCallbackManager.GotoEndOfCurrentStructMember_ValueType <uint>(ref intPtr);
                    akMidiEventCallbackInfo.eventID = (uint)Marshal.ReadInt32(intPtr);
                    AkCallbackManager.GotoEndOfCurrentStructMember_ValueType <uint>(ref intPtr);
                    akMidiEventCallbackInfo.byType = Marshal.ReadByte(intPtr);
                    AkCallbackManager.GotoEndOfCurrentStructMember_ValueType <byte>(ref intPtr);
                    akMidiEventCallbackInfo.byChan = Marshal.ReadByte(intPtr);
                    AkCallbackManager.GotoEndOfCurrentStructMember_ValueType <byte>(ref intPtr);
                    byte byType = akMidiEventCallbackInfo.byType;
                    if (byType != 128 && byType != 144)
                    {
                        if (byType != 160)
                        {
                            if (byType != 176)
                            {
                                if (byType != 192)
                                {
                                    if (byType != 208)
                                    {
                                        if (byType != 224)
                                        {
                                            AkCallbackManager.GotoEndOfCurrentStructMember_ValueType <byte>(ref intPtr);
                                            AkCallbackManager.GotoEndOfCurrentStructMember_ValueType <byte>(ref intPtr);
                                        }
                                        else
                                        {
                                            akMidiEventCallbackInfo.byValueLsb = Marshal.ReadByte(intPtr);
                                            AkCallbackManager.GotoEndOfCurrentStructMember_ValueType <byte>(ref intPtr);
                                            akMidiEventCallbackInfo.byValueMsb = Marshal.ReadByte(intPtr);
                                            AkCallbackManager.GotoEndOfCurrentStructMember_ValueType <byte>(ref intPtr);
                                        }
                                    }
                                    else
                                    {
                                        akMidiEventCallbackInfo.byChanAftertouchValue = Marshal.ReadByte(intPtr);
                                        AkCallbackManager.GotoEndOfCurrentStructMember_ValueType <byte>(ref intPtr);
                                        AkCallbackManager.GotoEndOfCurrentStructMember_ValueType <byte>(ref intPtr);
                                    }
                                }
                                else
                                {
                                    akMidiEventCallbackInfo.byProgramNum = Marshal.ReadByte(intPtr);
                                    AkCallbackManager.GotoEndOfCurrentStructMember_ValueType <byte>(ref intPtr);
                                    AkCallbackManager.GotoEndOfCurrentStructMember_ValueType <byte>(ref intPtr);
                                }
                            }
                            else
                            {
                                akMidiEventCallbackInfo.byCc = Marshal.ReadByte(intPtr);
                                AkCallbackManager.GotoEndOfCurrentStructMember_ValueType <byte>(ref intPtr);
                                akMidiEventCallbackInfo.byCcValue = Marshal.ReadByte(intPtr);
                                AkCallbackManager.GotoEndOfCurrentStructMember_ValueType <byte>(ref intPtr);
                            }
                        }
                        else
                        {
                            akMidiEventCallbackInfo.byAftertouchNote = Marshal.ReadByte(intPtr);
                            AkCallbackManager.GotoEndOfCurrentStructMember_ValueType <byte>(ref intPtr);
                            akMidiEventCallbackInfo.byNoteAftertouchValue = Marshal.ReadByte(intPtr);
                            AkCallbackManager.GotoEndOfCurrentStructMember_ValueType <byte>(ref intPtr);
                        }
                    }
                    else
                    {
                        akMidiEventCallbackInfo.byOnOffNote = Marshal.ReadByte(intPtr);
                        AkCallbackManager.GotoEndOfCurrentStructMember_ValueType <byte>(ref intPtr);
                        akMidiEventCallbackInfo.byVelocity = Marshal.ReadByte(intPtr);
                        AkCallbackManager.GotoEndOfCurrentStructMember_ValueType <byte>(ref intPtr);
                    }
                    eventCallbackPackage.m_Callback(eventCallbackPackage.m_Cookie, commonCB.eType, akMidiEventCallbackInfo);
                    goto IL_84D;
                }
                if (eType == AkCallbackType.AK_Monitoring)
                {
                    AkCallbackManager.AkMonitoringMsg akMonitoringMsg = default(AkCallbackManager.AkMonitoringMsg);
                    akMonitoringMsg.errorCode = (AkErrorCode)Marshal.ReadInt32(intPtr);
                    AkCallbackManager.GotoEndOfCurrentStructMember_ValueType <int>(ref intPtr);
                    akMonitoringMsg.errorLevel = (ErrorLevel)Marshal.ReadInt32(intPtr);
                    AkCallbackManager.GotoEndOfCurrentStructMember_ValueType <int>(ref intPtr);
                    akMonitoringMsg.playingID = (uint)Marshal.ReadInt32(intPtr);
                    AkCallbackManager.GotoEndOfCurrentStructMember_ValueType <uint>(ref intPtr);
                    akMonitoringMsg.gameObjID = Marshal.ReadIntPtr(intPtr);
                    AkCallbackManager.GotoEndOfCurrentStructMember_IntPtr(ref intPtr);
                    akMonitoringMsg.msg = AkCallbackManager.SafeMarshalString(intPtr);
                    if (AkCallbackManager.m_MonitoringCB != null)
                    {
                        AkCallbackManager.m_MonitoringCB(akMonitoringMsg.errorCode, akMonitoringMsg.errorLevel, akMonitoringMsg.playingID, akMonitoringMsg.gameObjID, akMonitoringMsg.msg);
                    }
                    goto IL_84D;
                }
                if (eType != AkCallbackType.AK_Bank)
                {
                    goto Block_14;
                }
                AkCallbackManager.AkBankInfo akBankInfo = default(AkCallbackManager.AkBankInfo);
                akBankInfo.bankID = (uint)Marshal.ReadInt32(intPtr);
                AkCallbackManager.GotoEndOfCurrentStructMember_ValueType <uint>(ref intPtr);
                akBankInfo.inMemoryBankPtr = Marshal.ReadIntPtr(intPtr);
                AkCallbackManager.GotoEndOfCurrentStructMember_ValueType <IntPtr>(ref intPtr);
                akBankInfo.eLoadResult = (AKRESULT)Marshal.ReadInt32(intPtr);
                AkCallbackManager.GotoEndOfCurrentStructMember_EnumType <AKRESULT>(ref intPtr);
                akBankInfo.memPoolId = (uint)Marshal.ReadInt32(intPtr);
                AkCallbackManager.GotoEndOfCurrentStructMember_ValueType <uint>(ref intPtr);
                if (bankCallbackPackage != null && bankCallbackPackage.m_Callback != null)
                {
                    bankCallbackPackage.m_Callback(akBankInfo.bankID, akBankInfo.inMemoryBankPtr, akBankInfo.eLoadResult, akBankInfo.memPoolId, bankCallbackPackage.m_Cookie);
                }
                goto IL_84D;
            }

            case AkCallbackType.AK_Marker:
            {
                AkCallbackManager.AkMarkerCallbackInfo akMarkerCallbackInfo = default(AkCallbackManager.AkMarkerCallbackInfo);
                akMarkerCallbackInfo.pCookie = Marshal.ReadIntPtr(intPtr);
                AkCallbackManager.GotoEndOfCurrentStructMember_IntPtr(ref intPtr);
                akMarkerCallbackInfo.gameObjID = Marshal.ReadIntPtr(intPtr);
                AkCallbackManager.GotoEndOfCurrentStructMember_IntPtr(ref intPtr);
                akMarkerCallbackInfo.playingID = (uint)Marshal.ReadInt32(intPtr);
                AkCallbackManager.GotoEndOfCurrentStructMember_ValueType <uint>(ref intPtr);
                akMarkerCallbackInfo.eventID = (uint)Marshal.ReadInt32(intPtr);
                AkCallbackManager.GotoEndOfCurrentStructMember_ValueType <uint>(ref intPtr);
                akMarkerCallbackInfo.uIdentifier = (uint)Marshal.ReadInt32(intPtr);
                AkCallbackManager.GotoEndOfCurrentStructMember_ValueType <uint>(ref intPtr);
                akMarkerCallbackInfo.uPosition = (uint)Marshal.ReadInt32(intPtr);
                AkCallbackManager.GotoEndOfCurrentStructMember_ValueType <uint>(ref intPtr);
                akMarkerCallbackInfo.strLabel = AkCallbackManager.SafeMarshalMarkerString(intPtr);
                eventCallbackPackage.m_Callback(eventCallbackPackage.m_Cookie, commonCB.eType, akMarkerCallbackInfo);
                goto IL_84D;
            }

            case AkCallbackType.AK_Duration:
            {
                AkCallbackManager.AkDurationCallbackInfo akDurationCallbackInfo = default(AkCallbackManager.AkDurationCallbackInfo);
                akDurationCallbackInfo.pCookie = Marshal.ReadIntPtr(intPtr);
                AkCallbackManager.GotoEndOfCurrentStructMember_IntPtr(ref intPtr);
                akDurationCallbackInfo.gameObjID = Marshal.ReadIntPtr(intPtr);
                AkCallbackManager.GotoEndOfCurrentStructMember_IntPtr(ref intPtr);
                akDurationCallbackInfo.playingID = (uint)Marshal.ReadInt32(intPtr);
                AkCallbackManager.GotoEndOfCurrentStructMember_ValueType <uint>(ref intPtr);
                akDurationCallbackInfo.eventID = (uint)Marshal.ReadInt32(intPtr);
                AkCallbackManager.GotoEndOfCurrentStructMember_ValueType <uint>(ref intPtr);
                akDurationCallbackInfo.fDuration = AkCallbackManager.MarshalFloat32(intPtr);
                AkCallbackManager.GotoEndOfCurrentStructMember_ValueType <float>(ref intPtr);
                akDurationCallbackInfo.fEstimatedDuration = AkCallbackManager.MarshalFloat32(intPtr);
                AkCallbackManager.GotoEndOfCurrentStructMember_ValueType <float>(ref intPtr);
                akDurationCallbackInfo.audioNodeID = (uint)Marshal.ReadInt32(intPtr);
                AkCallbackManager.GotoEndOfCurrentStructMember_ValueType <uint>(ref intPtr);
                eventCallbackPackage.m_Callback(eventCallbackPackage.m_Cookie, commonCB.eType, akDurationCallbackInfo);
                goto IL_84D;
            }
            }
            goto IL_104;
IL_84D:
            if (!(commonCB.pNext != IntPtr.Zero))
            {
                goto IL_8D3;
            }
            intPtr            = commonCB.pNext;
            intPtr2           = intPtr;
            commonCB          = default(AkCallbackManager.AkCommonCallback);
            commonCB.pPackage = Marshal.ReadIntPtr(intPtr);
            AkCallbackManager.GotoEndOfCurrentStructMember_IntPtr(ref intPtr);
            commonCB.pNext = Marshal.ReadIntPtr(intPtr);
            AkCallbackManager.GotoEndOfCurrentStructMember_IntPtr(ref intPtr);
            commonCB.eType = (AkCallbackType)Marshal.ReadInt32(intPtr);
            AkCallbackManager.GotoEndOfCurrentStructMember_EnumType <AkCallbackType>(ref intPtr);
            eventCallbackPackage = null;
            bankCallbackPackage  = null;
            if (!AkCallbackManager.SafeExtractCallbackPackages(commonCB, out eventCallbackPackage, out bankCallbackPackage))
            {
                goto Block_27;
            }
            intPtr = intPtr2;
        }
Block_14:
        Debug.LogError(string.Format("WwiseUnity: PostCallbacks aborted due to error: Undefined callback type found. Callback object possibly corrupted.", new object[0]));
        AkCallbackSerializer.Unlock();
        return;

Block_27:
        AkCallbackSerializer.Unlock();
        return;

IL_8D3:
        AkCallbackSerializer.Unlock();
    }
 public static void Term()
 {
     AkCallbackSerializer.Term();
     Marshal.FreeHGlobal(AkCallbackManager.m_pNotifMem);
     AkCallbackManager.m_pNotifMem = IntPtr.Zero;
 }
 public static AKRESULT Init()
 {
     AkCallbackManager.m_pNotifMem = Marshal.AllocHGlobal(4096);
     return(AkCallbackSerializer.Init(AkCallbackManager.m_pNotifMem, 4096u));
 }
Exemple #18
0
 internal static IntPtr getCPtr(AkCallbackSerializer obj)
 {
     return((obj != null) ? obj.swigCPtr : IntPtr.Zero);
 }
 public static AKRESULT Init()
 {
     m_pNotifMem = Marshal.AllocHGlobal(0x1000);
     return(AkCallbackSerializer.Init(m_pNotifMem, 0x1000));
 }
 internal static HandleRef getCPtr(AkCallbackSerializer obj)
 {
     return((obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr);
 }
    /// This function dispatches all the accumulated callbacks from the native sound engine.
    /// It must be called regularly.  By default this is called in AkInitializer.cs.
    static public int PostCallbacks()
    {
        if (m_pNotifMem == IntPtr.Zero)
        {
            return(0);
        }

        try
        {
            int numCallbacks = 0;

            for (IntPtr pNext = AkCallbackSerializer.Lock(); pNext != IntPtr.Zero; pNext = AkSoundEnginePINVOKE.CSharp_AkSerializedCallbackHeader_pNext_get(pNext), ++numCallbacks)
            {
                IntPtr         pPackage = AkSoundEnginePINVOKE.CSharp_AkSerializedCallbackHeader_pPackage_get(pNext);
                AkCallbackType eType    = (AkCallbackType)AkSoundEnginePINVOKE.CSharp_AkSerializedCallbackHeader_eType_get(pNext);
                IntPtr         pData    = AkSoundEnginePINVOKE.CSharp_AkSerializedCallbackHeader_GetData(pNext);

                switch (eType)
                {
                case AkCallbackType.AK_AudioInterruption:
#if UNITY_IOS && !UNITY_EDITOR
                    if (ms_interruptCallbackPkg != null && ms_interruptCallbackPkg.m_Callback != null)
                    {
                        AkAudioInterruptionCallbackInfo.setCPtr(pData);
                        ms_interruptCallbackPkg.m_Callback(AkAudioInterruptionCallbackInfo.bEnterInterruption, ms_interruptCallbackPkg.m_Cookie);
                    }
#endif // #if UNITY_IOS && ! UNITY_EDITOR
                    break;

                case AkCallbackType.AK_AudioSourceChange:
                    if (ms_sourceChangeCallbackPkg != null && ms_sourceChangeCallbackPkg.m_Callback != null)
                    {
                        AkAudioSourceChangeCallbackInfo.setCPtr(pData);
                        ms_sourceChangeCallbackPkg.m_Callback(AkAudioSourceChangeCallbackInfo.bOtherAudioPlaying, ms_sourceChangeCallbackPkg.m_Cookie);
                    }
                    break;

                case AkCallbackType.AK_Monitoring:
                    if (m_MonitoringCB != null)
                    {
                        AkMonitoringCallbackInfo.setCPtr(pData);
                        m_MonitoringCB(AkMonitoringCallbackInfo.errorCode, AkMonitoringCallbackInfo.errorLevel, AkMonitoringCallbackInfo.playingID,
                                       AkMonitoringCallbackInfo.gameObjID, AkMonitoringCallbackInfo.message);
                    }
#if UNITY_EDITOR
                    else if (AkSoundEngineController.Instance.engineLogging)
                    {
                        AkMonitoringCallbackInfo.setCPtr(pData);

                        string msg = "Wwise: " + AkMonitoringCallbackInfo.message;
                        if (AkMonitoringCallbackInfo.gameObjID != AkSoundEngine.AK_INVALID_GAME_OBJECT)
                        {
                            var obj = EditorUtility.InstanceIDToObject((int)AkMonitoringCallbackInfo.gameObjID) as GameObject;
                            if (obj != null)
                            {
                                msg += " (GameObject: " + obj.ToString() + ")";
                            }

                            msg += " (Instance ID: " + AkMonitoringCallbackInfo.gameObjID.ToString() + ")";
                        }

                        if (AkMonitoringCallbackInfo.errorLevel == AkMonitorErrorLevel.ErrorLevel_Error)
                        {
                            Debug.LogError(msg);
                        }
                        else
                        {
                            Debug.Log(msg);
                        }
                    }
#endif
                    break;

                case AkCallbackType.AK_Bank:
                    BankCallbackPackage bankPkg = null;
                    if (!m_mapBankCallbacks.TryGetValue((int)pPackage, out bankPkg))
                    {
                        Debug.LogError("WwiseUnity: BankCallbackPackage not found for <" + pPackage + ">.");
                        return(numCallbacks);
                    }
                    else
                    {
                        m_mapBankCallbacks.Remove((int)pPackage);

                        if (bankPkg != null && bankPkg.m_Callback != null)
                        {
                            AkBankCallbackInfo.setCPtr(pData);
                            bankPkg.m_Callback(AkBankCallbackInfo.bankID, AkBankCallbackInfo.inMemoryBankPtr, AkBankCallbackInfo.loadResult,
                                               (uint)AkBankCallbackInfo.memPoolId, bankPkg.m_Cookie);
                        }
                    }
                    break;

                default:
                    EventCallbackPackage eventPkg = null;
                    if (!m_mapEventCallbacks.TryGetValue((int)pPackage, out eventPkg))
                    {
                        Debug.LogError("WwiseUnity: EventCallbackPackage not found for <" + pPackage + ">.");
                        return(numCallbacks);
                    }
                    else
                    {
                        AkCallbackInfo info = null;

                        switch (eType)
                        {
                        case AkCallbackType.AK_EndOfEvent:
                            m_mapEventCallbacks.Remove(eventPkg.GetHashCode());
                            if (eventPkg.m_bNotifyEndOfEvent)
                            {
                                AkEventCallbackInfo.setCPtr(pData);
                                info = AkEventCallbackInfo;
                            }
                            break;

                        case AkCallbackType.AK_MusicPlayStarted:
                            AkEventCallbackInfo.setCPtr(pData);
                            info = AkEventCallbackInfo;
                            break;

                        case AkCallbackType.AK_EndOfDynamicSequenceItem:
                            AkDynamicSequenceItemCallbackInfo.setCPtr(pData);
                            info = AkDynamicSequenceItemCallbackInfo;
                            break;

                        case AkCallbackType.AK_MIDIEvent:
                            AkMIDIEventCallbackInfo.setCPtr(pData);
                            info = AkMIDIEventCallbackInfo;
                            break;

                        case AkCallbackType.AK_Marker:
                            AkMarkerCallbackInfo.setCPtr(pData);
                            info = AkMarkerCallbackInfo;
                            break;

                        case AkCallbackType.AK_Duration:
                            AkDurationCallbackInfo.setCPtr(pData);
                            info = AkDurationCallbackInfo;
                            break;

                        case AkCallbackType.AK_MusicSyncUserCue:
                        case AkCallbackType.AK_MusicSyncBar:
                        case AkCallbackType.AK_MusicSyncBeat:
                        case AkCallbackType.AK_MusicSyncEntry:
                        case AkCallbackType.AK_MusicSyncExit:
                        case AkCallbackType.AK_MusicSyncGrid:
                        case AkCallbackType.AK_MusicSyncPoint:
                            AkMusicSyncCallbackInfo.setCPtr(pData);
                            info = AkMusicSyncCallbackInfo;
                            break;

                        case AkCallbackType.AK_MusicPlaylistSelect:
                            AkMusicPlaylistCallbackInfo.setCPtr(pData);
                            info = AkMusicPlaylistCallbackInfo;
                            break;

                        default:
                            Debug.LogError("WwiseUnity: PostCallbacks aborted due to error: Undefined callback type <" + eType + "> found. Callback object possibly corrupted.");
                            return(numCallbacks);
                        }

                        if (info != null)
                        {
                            eventPkg.m_Callback(eventPkg.m_Cookie, eType, info);
                        }
                    }
                    break;
                }
            }

            return(numCallbacks);
        }
        finally
        {
            AkCallbackSerializer.Unlock();
        }
    }
 static public AKRESULT Init(int BufferSize)
 {
     m_pNotifMem = (BufferSize > 0) ? Marshal.AllocHGlobal(BufferSize) : IntPtr.Zero;
     return(AkCallbackSerializer.Init(m_pNotifMem, (uint)BufferSize));
 }
 public static void SetMonitoringCallback(ErrorLevel in_Level, MonitoringCallback in_CB)
 {
     AkCallbackSerializer.SetLocalOutput((uint)in_Level);
     m_MonitoringCB = in_CB;
 }
    /// This function dispatches all the accumulated callbacks from the native sound engine.
    /// It must be called regularly.  By default this is called in AkInitializer.cs.
    static public int PostCallbacks()
    {
        if (m_pNotifMem == IntPtr.Zero)
        {
            return(0);
        }

        try
        {
            int numCallbacks = 0;

            for (IntPtr pNext = AkCallbackSerializer.Lock(); pNext != IntPtr.Zero; pNext = AkSoundEnginePINVOKE.CSharp_AkSerializedCallbackHeader_pNext_get(pNext), ++numCallbacks)
            {
                IntPtr         pPackage = AkSoundEnginePINVOKE.CSharp_AkSerializedCallbackHeader_pPackage_get(pNext);
                AkCallbackType eType    = (AkCallbackType)AkSoundEnginePINVOKE.CSharp_AkSerializedCallbackHeader_eType_get(pNext);
                IntPtr         pData    = AkSoundEnginePINVOKE.CSharp_AkSerializedCallbackHeader_GetData(pNext);

                switch (eType)
                {
                case AkCallbackType.AK_AudioInterruption:
#if UNITY_IOS && !UNITY_EDITOR
                    if (ms_interruptCallbackPkg != null && ms_interruptCallbackPkg.m_Callback != null)
                    {
                        using (AkAudioInterruptionCallbackInfo info = new AkAudioInterruptionCallbackInfo(pData, false))
                            ms_interruptCallbackPkg.m_Callback(info.bEnterInterruption, ms_interruptCallbackPkg.m_Cookie);
                    }
#endif // #if UNITY_IOS && ! UNITY_EDITOR
                    break;

                case AkCallbackType.AK_AudioSourceChange:
                    if (ms_sourceChangeCallbackPkg != null && ms_sourceChangeCallbackPkg.m_Callback != null)
                    {
                        using (AkAudioSourceChangeCallbackInfo info = new AkAudioSourceChangeCallbackInfo(pData, false))
                            ms_sourceChangeCallbackPkg.m_Callback(info.bOtherAudioPlaying, ms_sourceChangeCallbackPkg.m_Cookie);
                    }
                    break;

                case AkCallbackType.AK_Monitoring:
                    if (m_MonitoringCB != null)
                    {
                        using (AkMonitoringCallbackInfo info = new AkMonitoringCallbackInfo(pData, false))
                            m_MonitoringCB(info.errorCode, info.errorLevel, info.playingID, info.gameObjID, info.message);
                    }
                    break;

                case AkCallbackType.AK_Bank:
                    BankCallbackPackage bankPkg = null;
                    if (!m_mapBankCallbacks.TryGetValue((int)pPackage, out bankPkg))
                    {
                        Debug.LogError("WwiseUnity: BankCallbackPackage not found for <" + pPackage + ">.");
                        return(numCallbacks);
                    }
                    else
                    {
                        m_mapBankCallbacks.Remove((int)pPackage);

                        if (bankPkg != null && bankPkg.m_Callback != null)
                        {
                            using (AkBankCallbackInfo info = new AkBankCallbackInfo(pData, false))
                                bankPkg.m_Callback(info.bankID, info.inMemoryBankPtr, info.loadResult, (uint)info.memPoolId, bankPkg.m_Cookie);
                        }
                    }
                    break;

                default:
                    EventCallbackPackage eventPkg = null;
                    if (!m_mapEventCallbacks.TryGetValue((int)pPackage, out eventPkg))
                    {
                        Debug.LogError("WwiseUnity: EventCallbackPackage not found for <" + pPackage + ">.");
                        return(numCallbacks);
                    }
                    else
                    {
                        AkCallbackInfo info = null;

                        switch (eType)
                        {
                        case AkCallbackType.AK_EndOfEvent:
                            m_mapEventCallbacks.Remove(eventPkg.GetHashCode());
                            if (eventPkg.m_bNotifyEndOfEvent)
                            {
                                info = new AkEventCallbackInfo(pData, false);
                            }
                            break;

                        case AkCallbackType.AK_MusicPlayStarted:
                            info = new AkEventCallbackInfo(pData, false);
                            break;

                        case AkCallbackType.AK_EndOfDynamicSequenceItem:
                            info = new AkDynamicSequenceItemCallbackInfo(pData, false);
                            break;

                        case AkCallbackType.AK_MIDIEvent:
                            info = new AkMIDIEventCallbackInfo(pData, false);
                            break;

                        case AkCallbackType.AK_Marker:
                            info = new AkMarkerCallbackInfo(pData, false);
                            break;

                        case AkCallbackType.AK_Duration:
                            info = new AkDurationCallbackInfo(pData, false);
                            break;

                        case AkCallbackType.AK_MusicSyncUserCue:
                        case AkCallbackType.AK_MusicSyncBar:
                        case AkCallbackType.AK_MusicSyncBeat:
                        case AkCallbackType.AK_MusicSyncEntry:
                        case AkCallbackType.AK_MusicSyncExit:
                        case AkCallbackType.AK_MusicSyncGrid:
                        case AkCallbackType.AK_MusicSyncPoint:
                            info = new AkMusicSyncCallbackInfo(pData, false);
                            break;

                        case AkCallbackType.AK_MusicPlaylistSelect:
                            info = new AkMusicPlaylistCallbackInfo(pData, false);
                            break;

                        default:
                            Debug.LogError("WwiseUnity: PostCallbacks aborted due to error: Undefined callback type <" + eType + "> found. Callback object possibly corrupted.");
                            return(numCallbacks);
                        }

                        if (info != null)
                        {
                            eventPkg.m_Callback(eventPkg.m_Cookie, eType, info);
                        }
                    }
                    break;
                }
            }

            return(numCallbacks);
        }
        finally
        {
            AkCallbackSerializer.Unlock();
        }
    }
 internal static HandleRef getCPtr(AkCallbackSerializer obj) {
   return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
 }
 internal static IntPtr getCPtr(AkCallbackSerializer obj)
 {
     return((obj == null) ? IntPtr.Zero : obj.swigCPtr);
 }