void Terminate() { if (ms_Instance == null || ms_Instance != this || !AkSoundEngine.IsInitialized()) { return; //Don't term twice } // Mop up the last callbacks that will be sent from Term with blocking. // It may happen that the term sends so many callbacks that it will use up // all the callback memory buffer and lock the calling thread. // WG-25356 Thread is unsupported in Windows Store App API. AkSoundEngine.StopAll(); AkSoundEngine.RenderAudio(); const double IdleMs = 1.0; const uint IdleTryCount = 50; for (uint i = 0; i < IdleTryCount; i++) { AkCallbackManager.PostCallbacks(); using (EventWaitHandle tmpEvent = new ManualResetEvent(false)) { tmpEvent.WaitOne(System.TimeSpan.FromMilliseconds(IdleMs)); } } AkSoundEngine.Term(); ms_Instance = null; AkCallbackManager.Term(); }
public void Terminate() { #if UNITY_EDITOR ClearInitializeState(); if (!IsSoundEngineLoaded) { return; } #endif if (!AkSoundEngine.IsInitialized()) { return; } // Stop everything, and make sure the callback buffer is empty. We try emptying as much as possible, and wait 10 ms before retrying. // Callbacks can take a long time to be posted after the call to RenderAudio(). AkSoundEngine.StopAll(); AkSoundEngine.ClearBanks(); AkSoundEngine.RenderAudio(); var retry = 5; do { var numCB = 0; do { numCB = AkCallbackManager.PostCallbacks(); // This is a WSA-friendly sleep using (System.Threading.EventWaitHandle tmpEvent = new System.Threading.ManualResetEvent(false)) { tmpEvent.WaitOne(System.TimeSpan.FromMilliseconds(1)); } }while (numCB > 0); // This is a WSA-friendly sleep using (System.Threading.EventWaitHandle tmpEvent = new System.Threading.ManualResetEvent(false)) { tmpEvent.WaitOne(System.TimeSpan.FromMilliseconds(10)); } retry--; }while (retry > 0); AkSoundEngine.Term(); // Make sure we have no callbacks left after Term. Some might be posted during termination. AkCallbackManager.PostCallbacks(); AkCallbackManager.Term(); AkBankManager.Reset(); }
void Terminate() { if (ms_Instance == null || ms_Instance != this || !AkSoundEngine.IsInitialized()) { return; //Don't term twice } // Stop everything, and make sure the callback buffer is empty. We try emptying as much as possible, and wait 10 ms before retrying. // Callbacks can take a long time to be posted after the call to RenderAudio(). AkCallbackManager.SetMonitoringCallback(0, null); AkSoundEngine.StopAll(); AkSoundEngine.ClearBanks(); AkSoundEngine.RenderAudio(); int retry = 5; do { int numCB = 0; do { numCB = AkCallbackManager.PostCallbacks(); // This is a WSA-friendly sleep using (EventWaitHandle tmpEvent = new ManualResetEvent(false)) { tmpEvent.WaitOne(System.TimeSpan.FromMilliseconds(1)); } }while(numCB > 0); // This is a WSA-friendly sleep using (EventWaitHandle tmpEvent = new ManualResetEvent(false)) { tmpEvent.WaitOne(System.TimeSpan.FromMilliseconds(10)); } retry--; }while (retry > 0); AkSoundEngine.Term(); // Make sure we have no callbacks left after Term. Some might be posted during termination. AkCallbackManager.PostCallbacks(); ms_Instance = null; AkCallbackManager.Term(); AkBankManager.Reset(); }
private void Terminate() { if (((ms_Instance != null) && (ms_Instance == this)) && AkSoundEngine.IsInitialized()) { AkSoundEngine.StopAll(); AkSoundEngine.RenderAudio(); for (uint i = 0; i < 50; i++) { AkCallbackManager.PostCallbacks(); using (EventWaitHandle handle = new ManualResetEvent(false)) { handle.WaitOne(TimeSpan.FromMilliseconds(1.0)); } } AkSoundEngine.Term(); ms_Instance = null; AkCallbackManager.Term(); } }
void Terminate() { if (ms_Instance == null) { return; //Don't term twice } // NOTE: Do not check AkGlobalSoundEngine.IsInitialized() // since its OnDestroy() has been called first in the project exec priority list. if (AkSoundEngine.IsInitialized()) { AkSoundEngine.Term(); // NOTE: AkCallbackManager needs to handle last few events after sound engine terminates // So it has to terminate after sound engine does. AkCallbackManager.Term(); } ms_Instance = null; }
private void Terminate() { if (AkTerminator.ms_Instance == null || AkTerminator.ms_Instance != this || !AkSoundEngine.IsInitialized()) { return; } AkSoundEngine.StopAll(); AkSoundEngine.RenderAudio(); for (uint num = 0u; num < 50u; num += 1u) { AkCallbackManager.PostCallbacks(); using (EventWaitHandle eventWaitHandle = new ManualResetEvent(false)) { eventWaitHandle.WaitOne(TimeSpan.FromMilliseconds(1.0)); } } AkSoundEngine.Term(); AkTerminator.ms_Instance = null; AkCallbackManager.Term(); }