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(); }
/// 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(); } }
private static bool SafeExtractCallbackPackages(AkCommonCallback commonCB, out EventCallbackPackage eventPkg, out BankCallbackPackage bankPkg) { eventPkg = null; bankPkg = null; if (((commonCB.eType == AkCallbackType.AK_AudioInterruption) || (commonCB.eType == AkCallbackType.AK_AudioSourceChange)) || (commonCB.eType == AkCallbackType.AK_Monitoring)) { return(true); } if (m_mapEventCallbacks.TryGetValue((int)commonCB.pPackage, out eventPkg)) { return(true); } if (m_mapBankCallbacks.TryGetValue((int)commonCB.pPackage, out bankPkg)) { m_mapBankCallbacks.Remove((int)commonCB.pPackage); return(true); } return(false); }
/// 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); }
static private bool SafeExtractCallbackPackages(AkCommonCallback commonCB, out EventCallbackPackage eventPkg, out BankCallbackPackage bankPkg) { eventPkg = null; bankPkg = null; // Callbacks without packages are always valid. if (commonCB.eType == AkCallbackType.AK_AudioInterruption) { return(true); } bool isValidCallback = m_mapEventCallbacks.TryGetValue((int)commonCB.pPackage, out eventPkg); if (!isValidCallback) { isValidCallback = m_mapBankCallbacks.TryGetValue((int)commonCB.pPackage, out bankPkg); if (!isValidCallback) { return(false); } } return(true); }
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(); }
/// 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(); } }
static private bool SafeExtractCallbackPackages(AkCommonCallback commonCB, out EventCallbackPackage eventPkg, out BankCallbackPackage bankPkg) { eventPkg = null; bankPkg = null; // Callbacks without packages are always valid. if (commonCB.eType == AkCallbackType.AK_AudioInterruption || commonCB.eType == AkCallbackType.AK_Monitoring) { return(true); } if (m_mapEventCallbacks.TryGetValue((int)commonCB.pPackage, out eventPkg)) { return(true); } if (m_mapBankCallbacks.TryGetValue((int)commonCB.pPackage, out bankPkg)) { m_mapBankCallbacks.Remove((int)commonCB.pPackage); return(true); } return(false); }