Example #1
0
    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();
    }
Example #2
0
    public uint PostOnEvent(uint in_eventID, ulong in_gameObjectID, uint in_uNumPosts, bool in_bAbsoluteOffsets)
    {
        uint ret = AkSoundEnginePINVOKE.CSharp_AkMIDIPost_PostOnEvent__SWIG_1(swigCPtr, in_eventID, in_gameObjectID, in_uNumPosts, in_bAbsoluteOffsets);

        AkCallbackManager.SetLastAddedPlayingID(ret);
        return(ret);
    }
Example #3
0
  public static uint DynamicSequenceOpen(UnityEngine.GameObject in_gameObjectID, uint in_uFlags, AkCallbackManager.EventCallback in_pfnCallback, object in_pCookie) {
    
		uint tempin_gameObjectID;
		if ( in_gameObjectID != null )
		{
			tempin_gameObjectID = (uint)in_gameObjectID.GetInstanceID();
			// Note: if AkGameObjectTracker is already attached, the following code will be bypassed.
			if (in_gameObjectID.GetComponent<AkGameObject>() == null)
			{
				in_gameObjectID.AddComponent<AkGameObject>();
			}
		}
		else
		{
			tempin_gameObjectID = unchecked((uint)-1);
		}
		
		
		in_pCookie = new AkCallbackManager.EventCallbackPackage(in_pfnCallback, in_pCookie);
    {
      uint ret = AkSoundEnginePINVOKE.CSharp_DynamicSequenceOpen__SWIG_1(tempin_gameObjectID, in_uFlags, (IntPtr)0, (IntPtr)in_pCookie.GetHashCode());

      return ret;
    }
  }
Example #4
0
 private void LateUpdate()
 {
     if (ms_Instance != null)
     {
         AkCallbackManager.PostCallbacks();
         AkSoundEngine.RenderAudio();
     }
 }
Example #5
0
 private void OnDestroy()
 {
     if (ms_Instance == this)
     {
         AkCallbackManager.SetMonitoringCallback((ErrorLevel)0, null);
         ms_Instance = null;
     }
 }
Example #6
0
 void OnDisable()
 {
     // Unregister the callback that redirects the output to the Unity console.  If not done early enough (meaning, later than Disable), AkInitializer will leak.
     if (ms_Instance != null && AkSoundEngine.IsInitialized())
     {
         AkCallbackManager.SetMonitoringCallback(0, null);
     }
 }
Example #7
0
 void OnDestroy()
 {
     if (ms_Instance == this)
     {
         AkCallbackManager.SetMonitoringCallback(0, null);
         ms_Instance = null;
     }
     // Do nothing. AkTerminator handles sound engine termination.
 }
	/// Loads a bank.  This version returns right away and loads in background. See AK::SoundEngine::LoadBank for more information
	public void LoadBankAsync(AkCallbackManager.BankCallback callback = null)
	{
		if (m_RefCount == 0)
		{
			bankCallback = callback;
			AkSoundEngine.LoadBank(bankName, AkBankManager.GlobalBankCallback, this, AkSoundEngine.AK_DEFAULT_POOL_ID, out m_BankID);
		}
		IncRef();
	}
Example #9
0
 //Use LateUpdate instead of Update() to ensure all gameobjects positions, listener positions, environements, RTPC, etc are set before finishing the audio frame.
 void LateUpdate()
 {
     //Execute callbacks that occured in last frame (not the current update)
     if (ms_Instance != null)
     {
         AkCallbackManager.PostCallbacks();
         AkSoundEngine.RenderAudio();
     }
 }
Example #10
0
 public uint PostOnEvent(uint in_eventID, ulong in_gameObjectID, uint in_uNumPosts, bool in_bAbsoluteOffsets, uint in_uFlags, AkCallbackManager.EventCallback in_pfnCallback, object in_pCookie, uint in_playingID)
 {
     in_pCookie = AkCallbackManager.EventCallbackPackage.Create(in_pfnCallback, in_pCookie, ref in_uFlags);
     {
         uint ret = AkSoundEnginePINVOKE.CSharp_AkMIDIPost_PostOnEvent__SWIG_3(swigCPtr, in_eventID, in_gameObjectID, in_uNumPosts, in_bAbsoluteOffsets, in_uFlags, in_uFlags != 0 ? (global::System.IntPtr) 1 : global::System.IntPtr.Zero, in_pCookie != null ? (global::System.IntPtr)in_pCookie.GetHashCode() : global::System.IntPtr.Zero, in_playingID);
         AkCallbackManager.SetLastAddedPlayingID(ret);
         return(ret);
     }
 }
 private void LateUpdate()
 {
     if (AkInitializer.ms_Instance != null)
     {
         AkCallbackManager.PostCallbacks();
         AkBankManager.DoUnloadBanks();
         AkSoundEngine.RenderAudio();
     }
 }
Example #12
0
    public uint PostOnEvent(uint in_eventID, UnityEngine.GameObject in_gameObjectID, uint in_uNumPosts, bool in_bAbsoluteOffsets, uint in_uFlags, AkCallbackManager.EventCallback in_pfnCallback, object in_pCookie)
    {
        var in_gameObjectID_id = AkSoundEngine.GetAkGameObjectID(in_gameObjectID);

        AkSoundEngine.PreGameObjectAPICall(in_gameObjectID, in_gameObjectID_id);

        uint ret = PostOnEvent(in_eventID, in_gameObjectID_id, in_uNumPosts, in_bAbsoluteOffsets, in_uFlags, in_pfnCallback, in_pCookie);

        AkCallbackManager.SetLastAddedPlayingID(ret);
        return(ret);
    }
Example #13
0
 //Use LateUpdate instead of Update() to ensure all gameobjects positions, listener positions, environements, RTPC, etc are set before finishing the audio frame.
 void LateUpdate()
 {
     //Execute callbacks that occured in last frame (not the current update)
     if (ms_Instance != null)
     {
         AkCallbackManager.PostCallbacks();
         AkBankManager.DoUnloadBanks();
         AkAudioListener.DefaultListeners.Refresh();
         AkSoundEngine.RenderAudio();
     }
 }
Example #14
0
    public uint PostOnEvent(uint in_eventID, UnityEngine.GameObject in_gameObjectID, uint in_uNumPosts)
    {
        var in_gameObjectID_id = AkSoundEngine.GetAkGameObjectID(in_gameObjectID);

        AkSoundEngine.PreGameObjectAPICall(in_gameObjectID, in_gameObjectID_id);

        uint ret = PostOnEvent(in_eventID, in_gameObjectID_id, in_uNumPosts);

        AkCallbackManager.SetLastAddedPlayingID(ret);
        return(ret);
    }
    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();
    }
    public void LateUpdate()
    {
        //Execute callbacks that occurred in last frame (not the current update)
        AkCallbackManager.PostCallbacks();
        AkBankManager.DoUnloadBanks();

        if (Application.isPlaying)
        {
            AkAudioListener.DefaultListeners.Refresh();
        }

        AkSoundEngine.RenderAudio();
    }
    public void LateUpdate()
    {
#if UNITY_EDITOR
        if (!IsSoundEngineLoaded)
        {
            return;
        }
#endif

        //Execute callbacks that occurred in last frame (not the current update)
        AkCallbackManager.PostCallbacks();
        AkSoundEngine.RenderAudio();
    }
Example #18
0
    void OnDestroy()
    {
        if (ms_Instance == this)
        {
#if UNITY_EDITOR
            EditorApplication.playmodeStateChanged -= OnEditorPlaymodeStateChanged;
#endif

            AkCallbackManager.SetMonitoringCallback(0, null);
            ms_Instance = null;
        }
        // Do nothing. AkTerminator handles sound engine termination.
    }
Example #19
0
    void OnEnable()
    {
        //The sound engine was not terminated normally.  Make this instance the one that will manage
        //the updates and termination.
        //This happen when Unity resets everything when a script changes.
        if (ms_Instance == null && AkSoundEngine.IsInitialized())
        {
            ms_Instance = this;
#if UNITY_EDITOR
            //Redirect Wwise error messages into Unity console.
            AkCallbackManager.SetMonitoringCallback(ErrorLevel.ErrorLevel_All, CopyMonitoringInConsole);
#endif
        }
    }
    public void LateUpdate()
    {
#if UNITY_EDITOR
        if (!IsSoundEngineLoaded)
        {
            return;
        }
#endif

        //Execute callbacks that occurred in last frame (not the current update)
        AkCallbackManager.PostCallbacks();
        AkBankManager.DoUnloadBanks();
        AkAudioListener.DefaultListeners.Refresh();
        AkSoundEngine.RenderAudio();
    }
Example #21
0
    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();
    }
    public void LateUpdate()
    {
#if UNITY_EDITOR
        if (!AkSoundEngine.EditorIsSoundEngineLoaded)
        {
            return;
        }
#endif

        //Execute callbacks that occurred in last frame (not the current update)
        AkRoomManager.Update();
        AkRoomAwareManager.UpdateRoomAwareObjects();
        AkCallbackManager.PostCallbacks();
#if !(AK_WWISE_ADDRESSABLES && UNITY_ADDRESSABLES)
        AkBankManager.DoUnloadBanks();
#endif
        AkSoundEngine.RenderAudio();
    }
Example #23
0
 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;
    }
Example #25
0
 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();
 }
  public static uint DynamicSequenceOpen(UnityEngine.GameObject in_gameObjectID, uint in_uFlags, AkCallbackManager.EventCallback in_pfnCallback, object in_pCookie) {
    
		uint tempin_gameObjectID;
		if ( in_gameObjectID != null )
		{
			tempin_gameObjectID = (uint)in_gameObjectID.GetInstanceID();
			// Note: if AkGameObjectTracker is already attached, the following code will be bypassed.
			if (in_gameObjectID.GetComponent<AkGameObject>() == null)
			{
				in_gameObjectID.AddComponent<AkGameObject>();

				// Note: We have missed AkGameObject.Awake() of this run to register. 
				// So we take over its work by inlining it here.
				AkSoundEngine.RegisterGameObj(in_gameObjectID, in_gameObjectID.name);
			
				//Set the original position
				AkSoundEngine.SetObjectPosition(
		            in_gameObjectID, 
		            in_gameObjectID.transform.position.x, 
		            in_gameObjectID.transform.position.y, 
		            in_gameObjectID.transform.position.z, 
		            in_gameObjectID.transform.forward.x,
		            in_gameObjectID.transform.forward.y, 
		            in_gameObjectID.transform.forward.z
		        	);
			}
		}
		else
		{
			tempin_gameObjectID = unchecked((uint)-1);
		}
		
		
		in_pCookie = new AkCallbackManager.EventCallbackPackage(in_pfnCallback, in_pCookie);
    {
      uint ret = AkSoundEnginePINVOKE.CSharp_DynamicSequenceOpen__SWIG_1(tempin_gameObjectID, in_uFlags, (IntPtr)0, (IntPtr)in_pCookie.GetHashCode());

      return ret;
    }
  }
  public static AKRESULT LoadBank(IntPtr in_pInMemoryBankPtr, uint in_uInMemoryBankSize, AkCallbackManager.BankCallback in_pfnBankCallback, object in_pCookie, out uint out_bankID) {
		in_pCookie = new AkCallbackManager.BankCallbackPackage(in_pfnBankCallback, in_pCookie);
    {
      AKRESULT ret = (AKRESULT)AkSoundEnginePINVOKE.CSharp_LoadBank__SWIG_5(in_pInMemoryBankPtr, in_uInMemoryBankSize, (IntPtr)0, (IntPtr)in_pCookie.GetHashCode(), out out_bankID);

      return ret;
    }
  }
  public static AKRESULT UnloadBank(uint in_bankID, IntPtr in_pInMemoryBankPtr, AkCallbackManager.BankCallback in_pfnBankCallback, object in_pCookie) {
		in_pCookie = new AkCallbackManager.BankCallbackPackage(in_pfnBankCallback, in_pCookie);
    {
      AKRESULT ret = (AKRESULT)AkSoundEnginePINVOKE.CSharp_UnloadBank__SWIG_8(in_bankID, in_pInMemoryBankPtr, (IntPtr)0, (IntPtr)in_pCookie.GetHashCode());

      return ret;
    }
  }
    public static uint DynamicSequenceOpen(UnityEngine.GameObject in_gameObjectID, uint in_uFlags, AkCallbackManager.EventCallback in_pfnCallback, object in_pCookie)
    {
        uint tempin_gameObjectID;
        if ( in_gameObjectID != null && in_gameObjectID.activeInHierarchy )
        {
            tempin_gameObjectID = (uint)in_gameObjectID.GetInstanceID();
            // Note: if AkGameObjectTracker is already attached, the following code will be bypassed.
            if (in_gameObjectID.GetComponent<AkGameObj>() == null)
            {
                in_gameObjectID.AddComponent<AkGameObj>();
            }
        }
        else
        {
            tempin_gameObjectID = unchecked((uint)-1);
        }

        in_pCookie = AkCallbackManager.EventCallbackPackage.Create(in_pfnCallback, in_pCookie, ref in_uFlags);
        {
        uint ret = AkSoundEnginePINVOKE.CSharp_DynamicSequenceOpen__SWIG_1(tempin_gameObjectID, in_uFlags, in_uFlags != 0 ? (IntPtr)1 : (IntPtr)0, in_pCookie != null ? (IntPtr)in_pCookie.GetHashCode() : (IntPtr)0);
        AkCallbackManager.SetLastAddedPlayingID(ret);
        return ret;
        }
    }
Example #30
0
    public void Initialize()
    {
        if (ms_Instance != null)
        {
            //Don't init twice
            //Check if there are 2 objects with this script.  If yes, remove this component.
            if (ms_Instance != this)
            {
                UnityEngine.Object.DestroyImmediate(this.gameObject);
            }
            return;
        }

        Debug.Log("WwiseUnity: Initialize sound engine ...");

        //Use default properties for most SoundEngine subsystem.
        //The game programmer should modify these when needed.  See the Wwise SDK documentation for the initialization.
        //These settings may very well change for each target platform.
        AkMemSettings memSettings = new AkMemSettings();

        memSettings.uMaxNumPools = 20;

        AkDeviceSettings deviceSettings = new AkDeviceSettings();

        AkSoundEngine.GetDefaultDeviceSettings(deviceSettings);

        AkStreamMgrSettings streamingSettings = new AkStreamMgrSettings();

        streamingSettings.uMemorySize = (uint)streamingPoolSize * 1024;

        AkInitSettings initSettings = new AkInitSettings();

        AkSoundEngine.GetDefaultInitSettings(initSettings);
        initSettings.uDefaultPoolSize = (uint)defaultPoolSize * 1024;

        AkPlatformInitSettings platformSettings = new AkPlatformInitSettings();

        AkSoundEngine.GetDefaultPlatformInitSettings(platformSettings);
        platformSettings.uLEngineDefaultPoolSize           = (uint)lowerPoolSize * 1024;
        platformSettings.fLEngineDefaultPoolRatioThreshold = memoryCutoffThreshold;

        AkMusicSettings musicSettings = new AkMusicSettings();

        AkSoundEngine.GetDefaultMusicSettings(musicSettings);

// Unity 5 only, UNity 4 doesn't provide a way to access the product name at runtime.
#if UNITY_5
#if UNITY_EDITOR
        AkSoundEngine.SetGameName(Application.productName + " (Editor)");
#else
        AkSoundEngine.SetGameName(Application.productName);
#endif
#endif

        AKRESULT result = AkSoundEngine.Init(memSettings, streamingSettings, deviceSettings, initSettings, platformSettings, musicSettings, (uint)preparePoolSize * 1024);
        if (result != AKRESULT.AK_Success)
        {
            Debug.LogError("WwiseUnity: Failed to initialize the sound engine. Abort.");
            return; //AkSoundEngine.Init should have logged more details.
        }

        ms_Instance = this;

        string basePathToSet = AkBasePathGetter.GetValidBasePath();
        if (string.IsNullOrEmpty(basePathToSet))
        {
            return;
        }

        result = AkSoundEngine.SetBasePath(basePathToSet);
        if (result != AKRESULT.AK_Success)
        {
            return;
        }

        AkSoundEngine.SetCurrentLanguage(language);

        result = AkCallbackManager.Init();
        if (result != AKRESULT.AK_Success)
        {
            Debug.LogError("WwiseUnity: Failed to initialize Callback Manager. Terminate sound engine.");
            AkSoundEngine.Term();
            ms_Instance = null;
            return;
        }

        AkBankManager.Reset();

        Debug.Log("WwiseUnity: Sound engine initialized.");

        //The sound engine should not be destroyed once it is initialized.
        DontDestroyOnLoad(this);

#if UNITY_EDITOR
        //Redirect Wwise error messages into Unity console.
        AkCallbackManager.SetMonitoringCallback(ErrorLevel.ErrorLevel_All, CopyMonitoringInConsole);
#endif

        //Load the init bank right away.  Errors will be logged automatically.
        uint BankID;
        result = AkSoundEngine.LoadBank("Init.bnk", AkSoundEngine.AK_DEFAULT_POOL_ID, out BankID);
        if (result != AKRESULT.AK_Success)
        {
            Debug.LogError("WwiseUnity: Failed load Init.bnk with result: " + result.ToString());
        }

#if UNITY_EDITOR
        EditorApplication.playmodeStateChanged += OnEditorPlaymodeStateChanged;
#endif
    }
  public static AKRESULT PrepareGameSyncs(PreparationType in_PreparationType, AkGroupType in_eGameSyncType, uint in_GroupID, uint[] in_paGameSyncID, uint in_uNumGameSyncs, AkCallbackManager.BankCallback in_pfnBankCallback, object in_pCookie) {
		in_pCookie = new AkCallbackManager.BankCallbackPackage(in_pfnBankCallback, in_pCookie);
    {
      AKRESULT ret = (AKRESULT)AkSoundEnginePINVOKE.CSharp_PrepareGameSyncs__SWIG_3((int)in_PreparationType, (int)in_eGameSyncType, in_GroupID, in_paGameSyncID, in_uNumGameSyncs, (IntPtr)0, (IntPtr)in_pCookie.GetHashCode());

      return ret;
    }
  }
Example #32
0
    public static uint DynamicSequenceOpen(UnityEngine.GameObject in_gameObjectID, uint in_uFlags, AkCallbackManager.EventCallback in_pfnCallback, object in_pCookie)
    {
        AkAutoObject tempObj = null;
        uint tempin_gameObjectID = (uint)AutoRegisterAkGameObj(in_gameObjectID, ref tempObj);

        in_pCookie = AkCallbackManager.EventCallbackPackage.Create(in_pfnCallback, in_pCookie, ref in_uFlags);
        {
        uint ret = AkSoundEnginePINVOKE.CSharp_DynamicSequenceOpen__SWIG_1(tempin_gameObjectID, in_uFlags, in_uFlags != 0 ? (IntPtr)1 : (IntPtr)0, in_pCookie != null ? (IntPtr)in_pCookie.GetHashCode() : (IntPtr)0);
        AkCallbackManager.SetLastAddedPlayingID(ret);
        return ret;
        }
    }
Example #33
0
    private void Awake()
    {
        if (ms_Instance != null)
        {
            if (ms_Instance != this)
            {
                UnityEngine.Object.DestroyImmediate(base.gameObject);
            }
        }
        else
        {
            Debug.Log("WwiseUnity: Initialize sound engine ...");
            AkMemSettings settings = new AkMemSettings {
                uMaxNumPools = 40
            };
            AkDeviceSettings settings2 = new AkDeviceSettings();
            AkSoundEngine.GetDefaultDeviceSettings(settings2);
            AkStreamMgrSettings settings3 = new AkStreamMgrSettings {
                uMemorySize = (uint)(this.streamingPoolSize * 0x400)
            };
            AkInitSettings settings4 = new AkInitSettings();
            AkSoundEngine.GetDefaultInitSettings(settings4);
            settings4.uDefaultPoolSize = (uint)(this.defaultPoolSize * 0x400);
            AkPlatformInitSettings settings5 = new AkPlatformInitSettings();
            AkSoundEngine.GetDefaultPlatformInitSettings(settings5);
            settings5.uLEngineDefaultPoolSize           = (uint)(this.lowerPoolSize * 0x400);
            settings5.fLEngineDefaultPoolRatioThreshold = this.memoryCutoffThreshold;
            AkMusicSettings settings6 = new AkMusicSettings();
            AkSoundEngine.GetDefaultMusicSettings(settings6);
            if (AkSoundEngine.Init(settings, settings3, settings2, settings4, settings5, settings6) != AKRESULT.AK_Success)
            {
                Debug.LogError("WwiseUnity: Failed to initialize the sound engine. Abort.");
            }
            else
            {
                ms_Instance = this;
                AkBankPathUtil.UsePlatformSpecificPath();
                string platformBasePath = AkBankPathUtil.GetPlatformBasePath();
                if (!s_loadBankFromMemory)
                {
                }
                AkSoundEngine.SetBasePath(platformBasePath);
                AkSoundEngine.SetCurrentLanguage(this.language);
                if (AkCallbackManager.Init() != AKRESULT.AK_Success)
                {
                    Debug.LogError("WwiseUnity: Failed to initialize Callback Manager. Terminate sound engine.");
                    AkSoundEngine.Term();
                    ms_Instance = null;
                }
                else
                {
                    AKRESULT akresult;
                    uint     num;
                    Debug.Log("WwiseUnity: Sound engine initialized.");
                    UnityEngine.Object.DontDestroyOnLoad(this);
                    if (s_loadBankFromMemory)
                    {
                        string        soundBankPathInResources = GetSoundBankPathInResources("Init.bytes");
                        CBinaryObject content = Singleton <CResourceManager> .GetInstance().GetResource(soundBankPathInResources, typeof(TextAsset), enResourceType.Sound, false, false).m_content as CBinaryObject;

                        GCHandle handle = GCHandle.Alloc(content.m_data, GCHandleType.Pinned);
                        IntPtr   ptr    = handle.AddrOfPinnedObject();
                        if (ptr != IntPtr.Zero)
                        {
                            akresult = AkSoundEngine.LoadBank(ptr, (uint)content.m_data.Length, -1, out num);
                            handle.Free();
                        }
                        else
                        {
                            akresult = AKRESULT.AK_Fail;
                        }
                        Singleton <CResourceManager> .GetInstance().RemoveCachedResource(soundBankPathInResources);
                    }
                    else
                    {
                        akresult = AkSoundEngine.LoadBank("Init.bnk", -1, out num);
                    }
                    if (akresult != AKRESULT.AK_Success)
                    {
                        Debug.LogError("WwiseUnity: Failed load Init.bnk with result: " + akresult.ToString());
                    }
                }
            }
        }
    }
  public static AKRESULT PrepareEvent(PreparationType in_PreparationType, uint[] in_pEventID, uint in_uNumEvent, AkCallbackManager.BankCallback in_pfnBankCallback, object in_pCookie) {
		in_pCookie = new AkCallbackManager.BankCallbackPackage(in_pfnBankCallback, in_pCookie);
    {
      AKRESULT ret = (AKRESULT)AkSoundEnginePINVOKE.CSharp_PrepareEvent__SWIG_3((int)in_PreparationType, in_pEventID, in_uNumEvent, (IntPtr)0, (IntPtr)in_pCookie.GetHashCode());

      return ret;
    }
  }
Example #35
0
    public static uint PostEvent(string in_pszEventName, UnityEngine.GameObject in_gameObjectID, uint in_uFlags, AkCallbackManager.EventCallback in_pfnCallback, object in_pCookie, uint in_cExternals)
    {
        AkAutoObject tempObj = null;
        uint tempin_gameObjectID = (uint)AutoRegisterAkGameObj(in_gameObjectID, ref tempObj);

        in_pCookie = AkCallbackManager.EventCallbackPackage.Create(in_pfnCallback, in_pCookie, ref in_uFlags);
        {
        uint ret = AkSoundEnginePINVOKE.CSharp_PostEvent__SWIG_8(in_pszEventName, tempin_gameObjectID, in_uFlags, in_uFlags != 0 ? (IntPtr)1 : (IntPtr)0, in_pCookie != null ? (IntPtr)in_pCookie.GetHashCode() : (IntPtr)0, in_cExternals);
        AkCallbackManager.SetLastAddedPlayingID(ret);
        return ret;
        }
    }
Example #36
0
    public static AKRESULT LoadBank(string in_pszString, AkCallbackManager.BankCallback in_pfnBankCallback, object in_pCookie, int in_memPoolId, out uint out_bankID)
    {
        in_pCookie = new AkCallbackManager.BankCallbackPackage(in_pfnBankCallback, in_pCookie);
        {
          AKRESULT ret = (AKRESULT)AkSoundEnginePINVOKE.CSharp_LoadBank__SWIG_4(in_pszString, (IntPtr)0, in_pCookie != null ? (IntPtr)in_pCookie.GetHashCode() : (IntPtr)0, in_memPoolId, out out_bankID);

          return ret;
        }
    }
    public void Init(AkInitializer akInitializer)
    {
        if (akInitializer == null)
        {
            UnityEngine.Debug.LogError("WwiseUnity: AkInitializer must not be null. Sound engine will not be initialized.");
            return;
        }

#if UNITY_EDITOR
        if (UnityEngine.Application.isPlaying && !IsTheSingleOwningInitializer(akInitializer))
        {
            UnityEngine.Debug.LogError("WwiseUnity: Sound engine is already initialized.");
            return;
        }

        var arguments = System.Environment.GetCommandLineArgs();
        if (System.Array.IndexOf(arguments, "-nographics") >= 0 &&
            System.Array.IndexOf(arguments, "-wwiseEnableWithNoGraphics") < 0)
        {
            return;
        }

        var isInitialized = false;
        try
        {
            isInitialized       = AkSoundEngine.IsInitialized();
            IsSoundEngineLoaded = true;
        }
        catch (System.DllNotFoundException)
        {
            IsSoundEngineLoaded = false;
            UnityEngine.Debug.LogWarning("WwiseUnity: AkSoundEngine is not loaded.");
            return;
        }
#else
        var isInitialized = AkSoundEngine.IsInitialized();
#endif

        engineLogging = akInitializer.engineLogging;

        AkLogger.Instance.Init();

        AKRESULT result;
        uint     BankID;
        if (isInitialized)
        {
#if UNITY_EDITOR
            if (UnityEngine.Application.isPlaying || UnityEditor.BuildPipeline.isBuildingPlayer)
            {
                AkSoundEngine.ClearBanks();
                AkBankManager.Reset();

                result = AkSoundEngine.LoadBank("Init.bnk", AkSoundEngine.AK_DEFAULT_POOL_ID, out BankID);
                if (result != AKRESULT.AK_Success)
                {
                    UnityEngine.Debug.LogError("WwiseUnity: Failed load Init.bnk with result: " + result);
                }
            }

            result = AkCallbackManager.Init(akInitializer.callbackManagerBufferSize * 1024);
            if (result != AKRESULT.AK_Success)
            {
                UnityEngine.Debug.LogError("WwiseUnity: Failed to initialize Callback Manager. Terminate sound engine.");
                AkSoundEngine.Term();
                return;
            }

            OnEnableEditorListener(akInitializer.gameObject);
            UnityEditor.EditorApplication.update += LateUpdate;
#else
            UnityEngine.Debug.LogError("WwiseUnity: Sound engine is already initialized.");
#endif
            return;
        }

#if UNITY_EDITOR
        if (UnityEditor.BuildPipeline.isBuildingPlayer)
        {
            return;
        }
#endif

        UnityEngine.Debug.Log("WwiseUnity: Initialize sound engine ...");
        var basePath = s_DefaultBasePath;
        language = akInitializer.language;

        //Use default properties for most SoundEngine subsystem.
        //The game programmer should modify these when needed.  See the Wwise SDK documentation for the initialization.
        //These settings may very well change for each target platform.
        var memSettings = new AkMemSettings();
        memSettings.uMaxNumPools = 20;

        var deviceSettings = new AkDeviceSettings();
        AkSoundEngine.GetDefaultDeviceSettings(deviceSettings);

        var streamingSettings = new AkStreamMgrSettings();
        streamingSettings.uMemorySize = (uint)akInitializer.streamingPoolSize * 1024;

        var initSettings = new AkInitSettings();
        AkSoundEngine.GetDefaultInitSettings(initSettings);
        initSettings.uDefaultPoolSize      = (uint)akInitializer.defaultPoolSize * 1024;
        initSettings.uMonitorPoolSize      = (uint)akInitializer.monitorPoolSize * 1024;
        initSettings.uMonitorQueuePoolSize = (uint)akInitializer.monitorQueuePoolSize * 1024;
#if (!UNITY_ANDROID && !PLATFORM_LUMIN && !UNITY_WSA) || UNITY_EDITOR // Exclude WSA. It only needs the name of the DLL, and no path.
        initSettings.szPluginDLLPath = System.IO.Path.Combine(UnityEngine.Application.dataPath,
                                                              "Plugins" + System.IO.Path.DirectorySeparatorChar);
#elif PLATFORM_LUMIN && !UNITY_EDITOR
        initSettings.szPluginDLLPath = UnityEngine.Application.dataPath.Replace("Data", "bin") + System.IO.Path.DirectorySeparatorChar;
#endif

        var platformSettings = new AkPlatformInitSettings();
        AkSoundEngine.GetDefaultPlatformInitSettings(platformSettings);
        platformSettings.uLEngineDefaultPoolSize           = (uint)akInitializer.lowerPoolSize * 1024;
        platformSettings.fLEngineDefaultPoolRatioThreshold = akInitializer.memoryCutoffThreshold;

        var musicSettings = new AkMusicSettings();
        AkSoundEngine.GetDefaultMusicSettings(musicSettings);

        var spatialAudioSettings = new AkSpatialAudioInitSettings();
        spatialAudioSettings.uPoolSize = (uint)akInitializer.spatialAudioPoolSize * 1024;
        spatialAudioSettings.uMaxSoundPropagationDepth = akInitializer.maxSoundPropagationDepth;
        spatialAudioSettings.uDiffractionFlags         = (uint)akInitializer.diffractionFlags;

#if UNITY_EDITOR
        AkSoundEngine.SetGameName(UnityEngine.Application.productName + " (Editor)");
#else
        AkSoundEngine.SetGameName(UnityEngine.Application.productName);
#endif

        result = AkSoundEngine.Init(memSettings, streamingSettings, deviceSettings, initSettings, platformSettings,
                                    musicSettings, spatialAudioSettings, (uint)akInitializer.preparePoolSize * 1024);

        if (result != AKRESULT.AK_Success)
        {
            UnityEngine.Debug.LogError("WwiseUnity: Failed to initialize the sound engine. Abort.");
            AkSoundEngine.Term();
            return;             //AkSoundEngine.Init should have logged more details.
        }

        var basePathToSet = AkBasePathGetter.GetSoundbankBasePath();
        if (string.IsNullOrEmpty(basePathToSet))
        {
            UnityEngine.Debug.LogError("WwiseUnity: Couldn't find soundbanks base path. Terminate sound engine.");
            AkSoundEngine.Term();
            return;
        }

        result = AkSoundEngine.SetBasePath(basePathToSet);
        if (result != AKRESULT.AK_Success)
        {
            UnityEngine.Debug.LogError("WwiseUnity: Failed to set soundbanks base path. Terminate sound engine.");
            AkSoundEngine.Term();
            return;
        }

#if !UNITY_SWITCH
        // Calling Application.persistentDataPath crashes Switch
        var decodedBankFullPath = GetDecodedBankFullPath();
        // AkSoundEngine.SetDecodedBankPath creates the folders for writing to (if they don't exist)
        AkSoundEngine.SetDecodedBankPath(decodedBankFullPath);
#endif

        AkSoundEngine.SetCurrentLanguage(language);

#if !UNITY_SWITCH
        // Calling Application.persistentDataPath crashes Switch
        // AkSoundEngine.AddBasePath is currently only implemented for iOS and Android; No-op for all other platforms.
        AkSoundEngine.AddBasePath(UnityEngine.Application.persistentDataPath + System.IO.Path.DirectorySeparatorChar);
        // Adding decoded bank path last to ensure that it is the first one used when writing decoded banks.
        AkSoundEngine.AddBasePath(decodedBankFullPath);
#endif

        result = AkCallbackManager.Init(akInitializer.callbackManagerBufferSize * 1024);
        if (result != AKRESULT.AK_Success)
        {
            UnityEngine.Debug.LogError("WwiseUnity: Failed to initialize Callback Manager. Terminate sound engine.");
            AkSoundEngine.Term();
            return;
        }

        AkBankManager.Reset();

        UnityEngine.Debug.Log("WwiseUnity: Sound engine initialized.");

        //Load the init bank right away.  Errors will be logged automatically.
        result = AkSoundEngine.LoadBank("Init.bnk", AkSoundEngine.AK_DEFAULT_POOL_ID, out BankID);

        if (result != AKRESULT.AK_Success)
        {
            UnityEngine.Debug.LogError("WwiseUnity: Failed load Init.bnk with result: " + result);
        }

#if UNITY_EDITOR
        OnEnableEditorListener(akInitializer.gameObject);
        UnityEditor.EditorApplication.update += LateUpdate;
#endif
    }
    public void Init(AkInitializer akInitializer)
    {
        engineLogging = akInitializer.engineLogging;

        AkLogger.Instance.Init();

        AKRESULT result;
        uint     BankID;

        if (AkSoundEngine.IsInitialized())
        {
#if UNITY_EDITOR
            if (Application.isPlaying)
            {
                AkSoundEngine.ClearBanks();
                AkBankManager.Reset();

                result = AkSoundEngine.LoadBank("Init.bnk", AkSoundEngine.AK_DEFAULT_POOL_ID, out BankID);
                if (result != AKRESULT.AK_Success)
                {
                    Debug.LogError("WwiseUnity: Failed load Init.bnk with result: " + result.ToString());
                }
            }

            result = AkCallbackManager.Init(akInitializer.callbackManagerBufferSize * 1024);
            if (result != AKRESULT.AK_Success)
            {
                Debug.LogError("WwiseUnity: Failed to initialize Callback Manager. Terminate sound engine.");
                AkSoundEngine.Term();
                return;
            }

            EditorApplication.update += LateUpdate;
#endif
            return;
        }

#if UNITY_EDITOR
        if (BuildPipeline.isBuildingPlayer)
        {
            return;
        }
#endif

        Debug.Log("WwiseUnity: Initialize sound engine ...");
        basePath = akInitializer.basePath;
        language = akInitializer.language;

        //Use default properties for most SoundEngine subsystem.
        //The game programmer should modify these when needed.  See the Wwise SDK documentation for the initialization.
        //These settings may very well change for each target platform.
        AkMemSettings memSettings = new AkMemSettings();
        memSettings.uMaxNumPools = 20;

        AkDeviceSettings deviceSettings = new AkDeviceSettings();
        AkSoundEngine.GetDefaultDeviceSettings(deviceSettings);

        AkStreamMgrSettings streamingSettings = new AkStreamMgrSettings();
        streamingSettings.uMemorySize = (uint)akInitializer.streamingPoolSize * 1024;

        AkInitSettings initSettings = new AkInitSettings();
        AkSoundEngine.GetDefaultInitSettings(initSettings);
        initSettings.uDefaultPoolSize      = (uint)akInitializer.defaultPoolSize * 1024;
        initSettings.uMonitorPoolSize      = (uint)akInitializer.monitorPoolSize * 1024;
        initSettings.uMonitorQueuePoolSize = (uint)akInitializer.monitorQueuePoolSize * 1024;
#if (!UNITY_ANDROID && !UNITY_WSA) || UNITY_EDITOR // Exclude WSA. It only needs the name of the DLL, and no path.
        initSettings.szPluginDLLPath = Path.Combine(Application.dataPath, "Plugins" + Path.DirectorySeparatorChar);
#endif

        AkPlatformInitSettings platformSettings = new AkPlatformInitSettings();
        AkSoundEngine.GetDefaultPlatformInitSettings(platformSettings);
        platformSettings.uLEngineDefaultPoolSize           = (uint)akInitializer.lowerPoolSize * 1024;
        platformSettings.fLEngineDefaultPoolRatioThreshold = akInitializer.memoryCutoffThreshold;

        AkMusicSettings musicSettings = new AkMusicSettings();
        AkSoundEngine.GetDefaultMusicSettings(musicSettings);

        AkSpatialAudioInitSettings spatialAudioSettings = new AkSpatialAudioInitSettings();
        spatialAudioSettings.uPoolSize = (uint)akInitializer.spatialAudioPoolSize * 1024;
        spatialAudioSettings.uMaxSoundPropagationDepth = akInitializer.maxSoundPropagationDepth;
        spatialAudioSettings.uDiffractionFlags         = (uint)akInitializer.diffractionFlags;

#if UNITY_EDITOR
        AkSoundEngine.SetGameName(Application.productName + " (Editor)");
#else
        AkSoundEngine.SetGameName(Application.productName);
#endif

        result = AkSoundEngine.Init(memSettings, streamingSettings, deviceSettings, initSettings, platformSettings, musicSettings, spatialAudioSettings, (uint)akInitializer.preparePoolSize * 1024);

        if (result != AKRESULT.AK_Success)
        {
            Debug.LogError("WwiseUnity: Failed to initialize the sound engine. Abort.");
            AkSoundEngine.Term();
            return;             //AkSoundEngine.Init should have logged more details.
        }

        string basePathToSet = AkBasePathGetter.GetSoundbankBasePath();
        if (string.IsNullOrEmpty(basePathToSet))
        {
            Debug.LogError("WwiseUnity: Couldn't find soundbanks base path. Terminate sound engine.");
            AkSoundEngine.Term();
            return;
        }

        result = AkSoundEngine.SetBasePath(basePathToSet);
        if (result != AKRESULT.AK_Success)
        {
            Debug.LogError("WwiseUnity: Failed to set soundbanks base path. Terminate sound engine.");
            AkSoundEngine.Term();
            return;
        }

#if !UNITY_SWITCH
        // Calling Application.persistentDataPath crashes Switch
        string decodedBankFullPath = GetDecodedBankFullPath();
        // AkSoundEngine.SetDecodedBankPath creates the folders for writing to (if they don't exist)
        AkSoundEngine.SetDecodedBankPath(decodedBankFullPath);
#endif

        AkSoundEngine.SetCurrentLanguage(language);

#if !UNITY_SWITCH
        // Calling Application.persistentDataPath crashes Switch
        // AkSoundEngine.AddBasePath is currently only implemented for iOS and Android; No-op for all other platforms.
        AkSoundEngine.AddBasePath(Application.persistentDataPath + Path.DirectorySeparatorChar);
        // Adding decoded bank path last to ensure that it is the first one used when writing decoded banks.
        AkSoundEngine.AddBasePath(decodedBankFullPath);
#endif

        result = AkCallbackManager.Init(akInitializer.callbackManagerBufferSize * 1024);
        if (result != AKRESULT.AK_Success)
        {
            Debug.LogError("WwiseUnity: Failed to initialize Callback Manager. Terminate sound engine.");
            AkSoundEngine.Term();
            return;
        }

        AkBankManager.Reset();

        Debug.Log("WwiseUnity: Sound engine initialized.");

        //Load the init bank right away.  Errors will be logged automatically.
        result = AkSoundEngine.LoadBank("Init.bnk", AkSoundEngine.AK_DEFAULT_POOL_ID, out BankID);
        if (result != AKRESULT.AK_Success)
        {
            Debug.LogError("WwiseUnity: Failed load Init.bnk with result: " + result.ToString());
        }

#if UNITY_EDITOR
#if UNITY_2017_2_OR_NEWER
        EditorApplication.pauseStateChanged += OnPauseStateChanged;
#else
        EditorApplication.playmodeStateChanged += OnEditorPlaymodeStateChanged;
#endif
        EditorApplication.update += LateUpdate;
#endif
    }
Example #39
0
    public static AKRESULT UnloadBank(string in_pszString, IntPtr in_pInMemoryBankPtr, AkCallbackManager.BankCallback in_pfnBankCallback, object in_pCookie)
    {
        in_pCookie = new AkCallbackManager.BankCallbackPackage(in_pfnBankCallback, in_pCookie);
        {
          AKRESULT ret = (AKRESULT)AkSoundEnginePINVOKE.CSharp_UnloadBank__SWIG_6(in_pszString, in_pInMemoryBankPtr, (IntPtr)0, in_pCookie != null ? (IntPtr)in_pCookie.GetHashCode() : (IntPtr)0);

          return ret;
        }
    }
  public static AKRESULT PrepareBank(PreparationType in_PreparationType, string in_pszString, AkCallbackManager.BankCallback in_pfnBankCallback, object in_pCookie) {
		in_pCookie = new AkCallbackManager.BankCallbackPackage(in_pfnBankCallback, in_pCookie);
    {
      AKRESULT ret = (AKRESULT)AkSoundEnginePINVOKE.CSharp_PrepareBank__SWIG_7((int)in_PreparationType, in_pszString, (IntPtr)0, (IntPtr)in_pCookie.GetHashCode());

      return ret;
    }
  }
Example #41
0
 /// Loads a SoundBank. This version returns right away and loads in background. See AK::SoundEngine::LoadBank for more information.
 public static void LoadBankAsync(string name, AkCallbackManager.BankCallback callback = null)
 {
     m_Mutex.WaitOne();
     AkBankHandle handle = null;
     if (!m_BankHandles.TryGetValue(name, out handle))
     {
         handle = new AkBankHandle(name, false, false);
         m_BankHandles.Add(name, handle);
         m_Mutex.ReleaseMutex();
         handle.LoadBankAsync(callback);
     }
     else
     {
         // Bank already loaded, increment its ref count.
         handle.IncRef();
         m_Mutex.ReleaseMutex();
     }
 }
  public static AKRESULT PrepareBank(PreparationType in_PreparationType, uint in_bankID, AkCallbackManager.BankCallback in_pfnBankCallback, object in_pCookie, AkBankContent in_uFlags) {
		in_pCookie = new AkCallbackManager.BankCallbackPackage(in_pfnBankCallback, in_pCookie);
    {
      AKRESULT ret = (AKRESULT)AkSoundEnginePINVOKE.CSharp_PrepareBank__SWIG_10((int)in_PreparationType, in_bankID, (IntPtr)0, (IntPtr)in_pCookie.GetHashCode(), (int)in_uFlags);

      return ret;
    }
  }
Example #43
0
    public void Initialize()
    {
        if (ms_Instance != null)
        {
            //Don't init twice
            //Check if there are 2 objects with this script.  If yes, remove this component.
            if (ms_Instance != this)
            {
                UnityEngine.Object.DestroyImmediate(this.gameObject);
            }
            return;
        }

        Debug.Log("WwiseUnity: Initialize sound engine ...");

        //Use default properties for most SoundEngine subsystem.
        //The game programmer should modify these when needed.  See the Wwise SDK documentation for the initialization.
        //These settings may very well change for each target platform.
        AkMemSettings memSettings = new AkMemSettings();

        memSettings.uMaxNumPools = 20;

        AkDeviceSettings deviceSettings = new AkDeviceSettings();

        AkSoundEngine.GetDefaultDeviceSettings(deviceSettings);

        AkStreamMgrSettings streamingSettings = new AkStreamMgrSettings();

        streamingSettings.uMemorySize = (uint)streamingPoolSize * 1024;

        AkInitSettings initSettings = new AkInitSettings();

        AkSoundEngine.GetDefaultInitSettings(initSettings);
        initSettings.uDefaultPoolSize      = (uint)defaultPoolSize * 1024;
        initSettings.uMonitorPoolSize      = (uint)monitorPoolSize * 1024;
        initSettings.uMonitorQueuePoolSize = (uint)monitorQueuePoolSize * 1024;
#if (!UNITY_ANDROID && !UNITY_WSA) || UNITY_EDITOR // Exclude WSA. It only needs the name of the DLL, and no path.
        initSettings.szPluginDLLPath = Path.Combine(Application.dataPath, "Plugins" + Path.DirectorySeparatorChar);
#endif

        AkPlatformInitSettings platformSettings = new AkPlatformInitSettings();
        AkSoundEngine.GetDefaultPlatformInitSettings(platformSettings);
        platformSettings.uLEngineDefaultPoolSize           = (uint)lowerPoolSize * 1024;
        platformSettings.fLEngineDefaultPoolRatioThreshold = memoryCutoffThreshold;

        AkMusicSettings musicSettings = new AkMusicSettings();
        AkSoundEngine.GetDefaultMusicSettings(musicSettings);

#if UNITY_EDITOR
        AkSoundEngine.SetGameName(Application.productName + " (Editor)");
#else
        AkSoundEngine.SetGameName(Application.productName);
#endif

        AKRESULT result = AkSoundEngine.Init(memSettings, streamingSettings, deviceSettings, initSettings, platformSettings, musicSettings, (uint)preparePoolSize * 1024);
        if (result != AKRESULT.AK_Success)
        {
            Debug.LogError("WwiseUnity: Failed to initialize the sound engine. Abort.");
            return;             //AkSoundEngine.Init should have logged more details.
        }

        ms_Instance = this;

        string basePathToSet = AkBasePathGetter.GetSoundbankBasePath();
        if (string.IsNullOrEmpty(basePathToSet))
        {
            return;
        }

        result = AkSoundEngine.SetBasePath(basePathToSet);
        if (result != AKRESULT.AK_Success)
        {
            return;
        }

#if !UNITY_SWITCH
        // Calling Application.persistentDataPath crashes Switch
        AkSoundEngine.SetDecodedBankPath(GetDecodedBankFullPath());
#endif

        AkSoundEngine.SetCurrentLanguage(language);

#if !UNITY_SWITCH
        // Calling Application.persistentDataPath crashes Switch
        // AkSoundEngine.AddBasePath is currently only implemented for iOS and Android; No-op for all other platforms.
        AkSoundEngine.AddBasePath(Application.persistentDataPath + Path.DirectorySeparatorChar);
#endif

        result = AkCallbackManager.Init(callbackManagerBufferSize * 1024);
        if (result != AKRESULT.AK_Success)
        {
            Debug.LogError("WwiseUnity: Failed to initialize Callback Manager. Terminate sound engine.");
            AkSoundEngine.Term();
            ms_Instance = null;
            return;
        }

        AkBankManager.Reset();

        Debug.Log("WwiseUnity: Sound engine initialized.");

        //The sound engine should not be destroyed once it is initialized.
        DontDestroyOnLoad(this);

#if UNITY_EDITOR
        //Redirect Wwise error messages into Unity console.
        AkCallbackManager.SetMonitoringCallback(ErrorLevel.ErrorLevel_All, CopyMonitoringInConsole);
#endif

        //Load the init bank right away.  Errors will be logged automatically.
        uint BankID;
        result = AkSoundEngine.LoadBank("Init.bnk", AkSoundEngine.AK_DEFAULT_POOL_ID, out BankID);
        if (result != AKRESULT.AK_Success)
        {
            Debug.LogError("WwiseUnity: Failed load Init.bnk with result: " + result.ToString());
        }

#if UNITY_EDITOR
        EditorApplication.playmodeStateChanged += OnEditorPlaymodeStateChanged;
#endif
    }
  public static AKRESULT PrepareGameSyncs(PreparationType in_PreparationType, AkGroupType in_eGameSyncType, string in_pszGroupName, string [] in_ppszGameSyncName, uint in_uNumGameSyncs, AkCallbackManager.BankCallback in_pfnBankCallback, object in_pCookie) {
			
		//Find the required size
		int size = 0;
		foreach(string s in in_ppszGameSyncName)
			size += s.Length + 1;
				
		int sizeofChar = 2;	//Unicode
		IntPtr pMem = Marshal.AllocHGlobal(size * sizeofChar);
		
		//Write the length of array
		Marshal.WriteInt16(pMem, (short)in_ppszGameSyncName.Length);
		IntPtr pCurrent = (IntPtr)(pMem.ToInt64() + sizeofChar);
		
		//Copy the strings one after the other.
		foreach(string s in in_ppszGameSyncName)
		{
			Marshal.Copy(s.ToCharArray(), 0, pCurrent, s.Length);
			pCurrent = (IntPtr)(pCurrent.ToInt64() + sizeofChar * s.Length);
			Marshal.WriteInt16(pCurrent, 0);	//Null-terminated string
			pCurrent = (IntPtr)(pCurrent.ToInt64() + sizeofChar);
		}		
		
		in_pCookie = new AkCallbackManager.BankCallbackPackage(in_pfnBankCallback, in_pCookie);
    try {
      AKRESULT ret = (AKRESULT)AkSoundEnginePINVOKE.CSharp_PrepareGameSyncs__SWIG_2((int)in_PreparationType, (int)in_eGameSyncType, in_pszGroupName, pMem, in_uNumGameSyncs, (IntPtr)0, (IntPtr)in_pCookie.GetHashCode());

      return ret;
    } finally {
	Marshal.FreeHGlobal(pMem);
    }
  }
Example #45
0
    public static uint PostEvent(string in_pszEventName, ComponentBind.Entity in_gameObjectID, uint in_uFlags, AkCallbackManager.EventCallback in_pfnCallback, object in_pCookie)
    {
        uint tempin_gameObjectID;
                if ( in_gameObjectID != null )
                {
                        tempin_gameObjectID = getGameObjectID(in_gameObjectID);
                        // Note: if AkGameObjectTracker is already attached, the following code will be bypassed.
                        if (in_gameObjectID.Get<AkGameObject>() == null)
                        {
                                in_gameObjectID.Add(new AkGameObject());
                        }
                }
                else
                {
                        tempin_gameObjectID = unchecked((uint)-1);
                }

                in_pCookie = new AkCallbackManager.EventCallbackPackage(in_pfnCallback, in_pCookie);
        {
            uint ret = AkSoundEnginePINVOKE.CSharp_PostEvent__SWIG_9(in_pszEventName, tempin_gameObjectID, in_uFlags, (IntPtr)0, (IntPtr)in_pCookie.GetHashCode());

            return ret;
        }
    }
Example #46
0
    /// Loads a bank.  This version returns right away and loads in background. See AK::SoundEngine::LoadBank for more information
    public void LoadBankAsync(AkCallbackManager.BankCallback callback = null)
    {
        if (m_RefCount == 0)
        {
            // There might be a case where we were asked to unload the SoundBank, but then asked immediately after to load that bank.
            // If that happens, there will be a short amount of time where the ref count will be 0, but the bank will still be in memory.
            // In that case, we do not want to unload the bank, so we have to remove it from the list of pending bank unloads.
            if(AkBankManager.BanksToUnload.Contains(this))
            {
                AkBankManager.BanksToUnload.Remove(this);
                IncRef();
                return;
            }

            bankCallback = callback;
            AkSoundEngine.LoadBank(bankName, AkBankManager.GlobalBankCallback, this, AkSoundEngine.AK_DEFAULT_POOL_ID, out m_BankID);
        }
        IncRef();
    }
    public static uint PostEvent(string in_pszEventName, UnityEngine.GameObject in_gameObjectID, uint in_uFlags, AkCallbackManager.EventCallback in_pfnCallback, object in_pCookie, uint in_cExternals, AkExternalSourceInfo in_pExternalSources, uint in_PlayingID)
    {
        uint tempin_gameObjectID;
        if ( in_gameObjectID != null && in_gameObjectID.activeInHierarchy )
        {
            tempin_gameObjectID = (uint)in_gameObjectID.GetInstanceID();
            // Note: if AkGameObjectTracker is already attached, the following code will be bypassed.
            if (in_gameObjectID.GetComponent<AkGameObj>() == null)
            {
                in_gameObjectID.AddComponent<AkGameObj>();
            }
        }
        else
        {
            tempin_gameObjectID = unchecked((uint)-1);
        }

        in_pCookie = AkCallbackManager.EventCallbackPackage.Create(in_pfnCallback, in_pCookie, ref in_uFlags);
        {
        uint ret = AkSoundEnginePINVOKE.CSharp_PostEvent__SWIG_6(in_pszEventName, tempin_gameObjectID, in_uFlags, in_uFlags != 0 ? (IntPtr)1 : (IntPtr)0, in_pCookie != null ? (IntPtr)in_pCookie.GetHashCode() : (IntPtr)0, in_cExternals, AkExternalSourceInfo.getCPtr(in_pExternalSources), in_PlayingID);
        AkCallbackManager.SetLastAddedPlayingID(ret);
        return ret;
        }
    }
    public static uint DynamicSequenceOpen(UnityEngine.GameObject in_gameObjectID, uint in_uFlags, AkCallbackManager.EventCallback in_pfnCallback, object in_pCookie)
    {
        AkAutoObject tempObj = null;
        uint tempin_gameObjectID;
        if ( in_gameObjectID != null )
        {
            tempin_gameObjectID = (uint)in_gameObjectID.GetInstanceID();
            if (in_gameObjectID.activeInHierarchy)
            {
                if (in_gameObjectID.GetComponent<AkGameObj>() == null)
                {
                    in_gameObjectID.AddComponent<AkGameObj>();
                }
            }
            else
            {
                //Object not active. AkGameObj will not work.  Use a temporary game object.
                //This will automatically unregister at the end of this scope.
                tempObj = new AkAutoObject(in_gameObjectID);
                tempin_gameObjectID = (uint)tempObj.m_id;	//Silence warning
            }
        }
        else
        {
            tempin_gameObjectID = unchecked((uint)-1);
        }

        in_pCookie = AkCallbackManager.EventCallbackPackage.Create(in_pfnCallback, in_pCookie, ref in_uFlags);
        {
        uint ret = AkSoundEnginePINVOKE.CSharp_DynamicSequenceOpen__SWIG_1(tempin_gameObjectID, in_uFlags, in_uFlags != 0 ? (IntPtr)1 : (IntPtr)0, in_pCookie != null ? (IntPtr)in_pCookie.GetHashCode() : (IntPtr)0);
        AkCallbackManager.SetLastAddedPlayingID(ret);
        return ret;
        }
    }
Example #49
0
    void Awake()
    {
        if (ms_Instance != null)
        {
            return; //Don't init twice
        }
#if UNITY_ANDROID
        InitalizeAndroidSoundBankIO();
#endif

        Debug.Log("WwiseUnity: Initialize sound engine ...");

        //Use default properties for most SoundEngine subsystem.
        //The game programmer should modify these when needed.  See the Wwise SDK documentation for the initialization.
        //These settings may very well change for each target platform.
        AkMemSettings memSettings = new AkMemSettings();
        memSettings.uMaxNumPools = 20;

        AkDeviceSettings deviceSettings = new AkDeviceSettings();
        AkSoundEngine.GetDefaultDeviceSettings(deviceSettings);

        AkStreamMgrSettings streamingSettings = new AkStreamMgrSettings();
        streamingSettings.uMemorySize = (uint)streamingPoolSize * 1024;

        AkInitSettings initSettings = new AkInitSettings();
        AkSoundEngine.GetDefaultInitSettings(initSettings);
        initSettings.uDefaultPoolSize = (uint)defaultPoolSize * 1024;

        AkPlatformInitSettings platformSettings = new AkPlatformInitSettings();
        AkSoundEngine.GetDefaultPlatformInitSettings(platformSettings);
        platformSettings.uLEngineDefaultPoolSize           = (uint)lowerPoolSize * 1024;
        platformSettings.fLEngineDefaultPoolRatioThreshold = memoryCutoffThreshold;
#if UNITY_IOS && !UNITY_EDITOR
        platformSettings.bAppListensToInterruption = true;
#endif // #if UNITY_IOS && !UNITY_EDITOR

        AkMusicSettings musicSettings = new AkMusicSettings();
        AkSoundEngine.GetDefaultMusicSettings(musicSettings);

        AKRESULT result = AkSoundEngine.Init(memSettings, streamingSettings, deviceSettings, initSettings, platformSettings, musicSettings);
        if (result != AKRESULT.AK_Success)
        {
            Debug.LogError("WwiseUnity: Failed to initialize the sound engine. Abort.");
            return; //AkSoundEngine.Init should have logged more details.
        }

        AkBankPath.UsePlatformSpecificPath();
        string platformBasePath = AkBankPath.GetPlatformBasePath();
// Note: Android low-level IO uses relative path to "assets" folder of the apk as SoundBank folder.
// Unity uses full paths for general path checks. We thus don't use DirectoryInfo.Exists to test
// our SoundBank folder for Android.
#if !UNITY_ANDROID && !UNITY_METRO
        if (!AkBankPath.Exists(platformBasePath))
        {
            string errorMsg = string.Format("WwiseUnity: Failed to find soundbank folder: {0}. Abort.", platformBasePath);
            Debug.LogError(errorMsg);
            return;
        }
#endif // #if !UNITY_ANDROID

        AkSoundEngine.SetBasePath(platformBasePath);
        AkSoundEngine.SetCurrentLanguage(language);

        result = AkCallbackManager.Init();
        if (result != AKRESULT.AK_Success)
        {
            Debug.LogError("WwiseUnity: Failed to initialize Callback Manager. Terminate sound engine.");
            AkSoundEngine.Term();
            return;
        }

        AkCallbackManager.SetMonitoringCallback(ErrorLevel.ErrorLevel_All, null);


        Debug.Log("WwiseUnity: Sound engine initialized.");

        //The sound engine should not be destroyed once it is initialized.
        DontDestroyOnLoad(this);
        ms_Instance = this;

        //Load the init bank right away.  Errors will be logged automatically.
        uint BankID;
        result = AkSoundEngine.LoadBank("Init.bnk", AkSoundEngine.AK_DEFAULT_POOL_ID, out BankID);
        if (result != AKRESULT.AK_Success)
        {
            Debug.LogError("WwiseUnity: Failed load Init.bnk with result: " + result.ToString());
        }
    }
 //Methode pour jouer un event Wwise ayant une durée finie, en appelant une methode de callback quand il se termine
 // eventName : le nom de l'event
 // gObject : l'objet sur lequel il sera positionné dans l'espace ( si il s'agit  d'un son 3d )
 // callBackFunction : la fonction a appellé à la fin de l'event
 public static void PlayFiniteEvent(string eventName, GameObject gObject, AkCallbackManager.EventCallback callBackFunction )
 {
     AkSoundEngine.PostEvent(eventName, gObject, (uint)AkCallbackType.AK_EndOfEvent, callBackFunction, gObject);
 }
  public static AKRESULT LoadBank(uint in_bankID, AkCallbackManager.BankCallback in_pfnBankCallback, object in_pCookie, int in_memPoolId) {
		in_pCookie = new AkCallbackManager.BankCallbackPackage(in_pfnBankCallback, in_pCookie);
    {
      AKRESULT ret = (AKRESULT)AkSoundEnginePINVOKE.CSharp_LoadBank__SWIG_4(in_bankID, (IntPtr)0, (IntPtr)in_pCookie.GetHashCode(), in_memPoolId);

      return ret;
    }
  }
Example #52
0
    void Awake()
    {
        if (ms_Instance != null)
        {
            //Don't init twice
            //Check if there are 2 objects with this script.  If yes, remove this component.
            if (ms_Instance != this)
            {
                UnityEngine.Object.DestroyImmediate(this.gameObject);
            }
            return;
        }

        Debug.Log("WwiseUnity: Initialize sound engine ...");

        //Use default properties for most SoundEngine subsystem.
        //The game programmer should modify these when needed.  See the Wwise SDK documentation for the initialization.
        //These settings may very well change for each target platform.
        AkMemSettings memSettings = new AkMemSettings();

        memSettings.uMaxNumPools = 20;

        AkDeviceSettings deviceSettings = new AkDeviceSettings();

        AkSoundEngine.GetDefaultDeviceSettings(deviceSettings);

        AkStreamMgrSettings streamingSettings = new AkStreamMgrSettings();

        streamingSettings.uMemorySize = (uint)streamingPoolSize * 1024;

        AkInitSettings initSettings = new AkInitSettings();

        AkSoundEngine.GetDefaultInitSettings(initSettings);
        initSettings.uDefaultPoolSize = (uint)defaultPoolSize * 1024;

        AkPlatformInitSettings platformSettings = new AkPlatformInitSettings();

        AkSoundEngine.GetDefaultPlatformInitSettings(platformSettings);
        platformSettings.uLEngineDefaultPoolSize           = (uint)lowerPoolSize * 1024;
        platformSettings.fLEngineDefaultPoolRatioThreshold = memoryCutoffThreshold;

        AkMusicSettings musicSettings = new AkMusicSettings();

        AkSoundEngine.GetDefaultMusicSettings(musicSettings);

        AKRESULT result = AkSoundEngine.Init(memSettings, streamingSettings, deviceSettings, initSettings, platformSettings, musicSettings);

        if (result != AKRESULT.AK_Success)
        {
            Debug.LogError("WwiseUnity: Failed to initialize the sound engine. Abort.");
            return; //AkSoundEngine.Init should have logged more details.
        }

        ms_Instance = this;

        AkBankPathUtil.UsePlatformSpecificPath();
        string platformBasePath = AkBankPathUtil.GetPlatformBasePath();

// Note: Android low-level IO uses relative path to "assets" folder of the apk as SoundBank folder.
// Unity uses full paths for general path checks. We thus don't use DirectoryInfo.Exists to test
// our SoundBank folder for Android.
#if !UNITY_ANDROID && !UNITY_METRO && !UNITY_PSP2
        if (!AkBankPathUtil.Exists(platformBasePath))
        {
            string errorMsg = string.Format("WwiseUnity: Failed to find soundbank folder: {0}. Abort.", platformBasePath);
            Debug.LogError(errorMsg);
            ms_Instance = null;
            return;
        }
#endif // #if !UNITY_ANDROID

        AkSoundEngine.SetBasePath(platformBasePath);
        AkSoundEngine.SetCurrentLanguage(language);

        result = AkCallbackManager.Init();
        if (result != AKRESULT.AK_Success)
        {
            Debug.LogError("WwiseUnity: Failed to initialize Callback Manager. Terminate sound engine.");
            AkSoundEngine.Term();
            ms_Instance = null;
            return;
        }

        AkBankManager.Reset();

        Debug.Log("WwiseUnity: Sound engine initialized.");

        //The sound engine should not be destroyed once it is initialized.
        DontDestroyOnLoad(this);

#if UNITY_EDITOR
        //Redirect Wwise error messages into Unity console.
        AkCallbackManager.SetMonitoringCallback(ErrorLevel.ErrorLevel_All, CopyMonitoringInConsole);
#endif

        //Load the init bank right away.  Errors will be logged automatically.
        uint BankID;
#if UNITY_ANDROID && !UNITY_METRO && AK_LOAD_BANK_IN_MEMORY
        result = AkInMemBankLoader.LoadNonLocalizedBank("Init.bnk");
#else
        result = AkSoundEngine.LoadBank("Init.bnk", AkSoundEngine.AK_DEFAULT_POOL_ID, out BankID);
#endif // #if UNITY_ANDROID && !UNITY_METRO && AK_ANDROID_BANK_IN_OBB
        if (result != AKRESULT.AK_Success)
        {
            Debug.LogError("WwiseUnity: Failed load Init.bnk with result: " + result.ToString());
        }
    }
Example #53
0
  public static uint PostEvent(string in_pszEventName, UnityEngine.GameObject in_gameObjectID, uint in_uFlags, AkCallbackManager.EventCallback in_pfnCallback, object in_pCookie, uint in_cExternals, AkExternalSourceInfo in_pExternalSources) {
    
		uint tempin_gameObjectID;
		if ( in_gameObjectID != null )
		{
			tempin_gameObjectID = (uint)in_gameObjectID.GetInstanceID();
			// Note: if AkGameObjectTracker is already attached, the following code will be bypassed.
			if (in_gameObjectID.GetComponent<AkGameObject>() == null)
			{
				in_gameObjectID.AddComponent<AkGameObject>();
			}
		}
		else
		{
			tempin_gameObjectID = unchecked((uint)-1);
		}
		
		
		in_pCookie = new AkCallbackManager.EventCallbackPackage(in_pfnCallback, in_pCookie);
    {
      uint ret = AkSoundEnginePINVOKE.CSharp_PostEvent__SWIG_7(in_pszEventName, tempin_gameObjectID, in_uFlags, (IntPtr)0, (IntPtr)in_pCookie.GetHashCode(), in_cExternals, AkExternalSourceInfo.getCPtr(in_pExternalSources));

      return ret;
    }
  }