Beispiel #1
0
    /// Loads a bank.  This version blocks until the bank is loaded.  See AK::SoundEngine::LoadBank for more information
    public void LoadBank()
    {
        if (m_RefCount == 0)
        {
            AKRESULT res = AkSoundEngine.LoadBank(bankName, AkSoundEngine.AK_DEFAULT_POOL_ID, out m_BankID);
            if (res != AKRESULT.AK_Success)
            {
                Debug.LogWarning("Wwise: Bank " + bankName + " failed to load (" + res.ToString() + ")");
            }
        }

        IncRef();
    }
    IEnumerator LoadFile()
    {
        ms_www = new WWW(m_bankPath);

        yield return(ms_www);

        uint in_uInMemoryBankSize = 0;

        // Allocate an aligned buffer
        try
        {
            ms_pinnedArray       = GCHandle.Alloc(ms_www.bytes, GCHandleType.Pinned);
            ms_pInMemoryBankPtr  = ms_pinnedArray.AddrOfPinnedObject();
            in_uInMemoryBankSize = (uint)ms_www.bytes.Length;

            // Array inside the WWW object is not aligned. Allocate a new array for which we can guarantee the alignment.
            if ((ms_pInMemoryBankPtr.ToInt64() & AK_BANK_PLATFORM_DATA_ALIGNMENT_MASK) != 0)
            {
                byte[]   alignedBytes         = new byte[ms_www.bytes.Length + AK_BANK_PLATFORM_DATA_ALIGNMENT];
                GCHandle new_pinnedArray      = GCHandle.Alloc(alignedBytes, GCHandleType.Pinned);
                IntPtr   new_pInMemoryBankPtr = new_pinnedArray.AddrOfPinnedObject();
                int      alignedOffset        = 0;

                // New array is not aligned, so we will need to use an offset inside it to align our data.
                if ((new_pInMemoryBankPtr.ToInt64() & AK_BANK_PLATFORM_DATA_ALIGNMENT_MASK) != 0)
                {
                    Int64 alignedPtr = (new_pInMemoryBankPtr.ToInt64() + AK_BANK_PLATFORM_DATA_ALIGNMENT_MASK) & ~AK_BANK_PLATFORM_DATA_ALIGNMENT_MASK;
                    alignedOffset        = (int)(alignedPtr - new_pInMemoryBankPtr.ToInt64());
                    new_pInMemoryBankPtr = new IntPtr(alignedPtr);
                }

                // Copy the bank's bytes in our new array, at the correct aligned offset.
                Array.Copy(ms_www.bytes, 0, alignedBytes, alignedOffset, ms_www.bytes.Length);

                ms_pInMemoryBankPtr = new_pInMemoryBankPtr;
                ms_pinnedArray.Free();
                ms_pinnedArray = new_pinnedArray;
            }
        }
        catch
        {
            yield break;
        }

        AKRESULT result = AkSoundEngine.LoadBank(ms_pInMemoryBankPtr, in_uInMemoryBankSize, out ms_bankID);

        if (result != AKRESULT.AK_Success)
        {
            Debug.LogError("AkMemBankLoader: bank loading failed with result " + result.ToString());
        }
    }
    private void SetMusic(MusicState state)
    {
        string   stateName = System.Enum.GetName(typeof(MusicState), state);
        AKRESULT result    = AKRESULT.AK_Cancelled;
        int      i         = 0;

        do
        {
            if (i >= 4)
            {
                Debug.LogError("Set Music State Fail : " + result.ToString());
            }
            result = AkSoundEngine.SetState("Music", stateName);
            i++;
        } while (result != AKRESULT.AK_Success);
        m_currentState = state;
    }
Beispiel #4
0
 public void LoadBank()
 {
     if (this.m_RefCount == 0)
     {
         AKRESULT aKRESULT = AkSoundEngine.LoadBank(this.bankName, -1, out this.m_BankID);
         if (aKRESULT != AKRESULT.AK_Success)
         {
             Debug.LogWarning(string.Concat(new string[]
             {
                 "Wwise: Bank ",
                 this.bankName,
                 " failed to load (",
                 aKRESULT.ToString(),
                 ")"
             }));
         }
     }
     this.IncRef();
 }
Beispiel #5
0
 public void DecRef()
 {
     this.m_RefCount--;
     if (this.m_RefCount == 0 && this.m_BankID > 0u)
     {
         AKRESULT aKRESULT = AkSoundEngine.UnloadBank(this.m_BankID, IntPtr.Zero);
         if (aKRESULT != AKRESULT.AK_Success)
         {
             Debug.LogWarning(string.Concat(new string[]
             {
                 "Wwise: Bank ",
                 this.bankName,
                 " failed to unload (",
                 aKRESULT.ToString(),
                 ")"
             }));
         }
         this.m_BankID = 0u;
     }
 }
 public void PlayTrigger(GameObject from, params string[] names)
 {
     if (names.Length > 0)
     {
         foreach (string name in names)
         {
             AKRESULT result = AKRESULT.AK_Cancelled;
             int      i      = 0;
             do
             {
                 if (i >= 4)
                 {
                     Debug.LogError("Post Trigger Fail : " + result.ToString());
                 }
                 result = AkSoundEngine.PostTrigger(name, musicObject);
                 i++;
             } while (result != AKRESULT.AK_Success);
         }
     }
 }
Beispiel #7
0
 public bool LoadBank(bool ignoreError = false)
 {
     if (this.m_RefCount == 0)
     {
         AKRESULT aKRESULT = AkSoundEngine.LoadBank(this.bankName, -1, out this.m_BankID);
         if (aKRESULT != AKRESULT.AK_Success)
         {
             if (!ignoreError)
             {
                 Debug.LogError(string.Concat(new string[]
                 {
                     "WwiseUnity: Bank ",
                     this.bankName,
                     " failed to load (",
                     aKRESULT.ToString(),
                     ")"
                 }));
             }
             return(false);
         }
     }
     return(true);
 }
Beispiel #8
0
    static public void GlobalBankCallback(uint in_bankID, IntPtr in_pInMemoryBankPtr, AKRESULT in_eLoadResult, uint in_memPoolId, object in_Cookie)
    {
        m_Mutex.WaitOne();
        AkBankHandle handle = (AkBankHandle)in_Cookie;

        AkCallbackManager.BankCallback cb = handle.bankCallback;
        if (in_eLoadResult != AKRESULT.AK_Success)
        {
            Debug.LogWarning("Wwise: Bank " + handle.bankName + " failed to load (" + in_eLoadResult.ToString() + ")");
            m_BankHandles.Remove(handle.bankName);
        }
        m_Mutex.ReleaseMutex();

        if (cb != null)
        {
            cb(in_bankID, in_pInMemoryBankPtr, in_eLoadResult, in_memPoolId, null);
        }
    }
Beispiel #9
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());
        }
    }
Beispiel #10
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
    }
Beispiel #11
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());
        }
    }
Beispiel #12
0
 public void LoadBank(byte[] data)
 {
     if (this.m_RefCount == 0)
     {
         GCHandle handle = GCHandle.Alloc(data, GCHandleType.Pinned);
         IntPtr   zero   = handle.AddrOfPinnedObject();
         if (zero != IntPtr.Zero)
         {
             AKRESULT akresult = AkSoundEngine.LoadBank(zero, (uint)data.Length, -1, out this.m_BankID);
             if (akresult != AKRESULT.AK_Success)
             {
                 this.m_BankID = 0;
                 Debug.LogWarning("Wwise: Bank " + this.bankName + " failed to load (" + akresult.ToString() + ")");
             }
             handle.Free();
             zero = IntPtr.Zero;
         }
         else
         {
             Debug.LogWarning("Wwise: Bank " + this.bankName + " failed to Alloc Memory");
         }
     }
     this.IncRef();
 }
Beispiel #13
0
        /// Loads a bank. This version blocks until the bank is loaded. See AK::SoundEngine::LoadBank for more information.
        public void LoadBank()
        {
            if (m_RefCount == 0)
            {
                AKRESULT res = AKRESULT.AK_Fail;

                // 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 (BanksToUnload.Contains(this))
                {
                    BanksToUnload.Remove(this);
                    IncRef();
                    return;
                }

                if (!decodeBank)
                {
                    string basePathToSet = null;

                    if (!string.IsNullOrEmpty(relativeBasePath))
                    {
                        basePathToSet = AkBasePathGetter.GetSoundbankBasePath();
                        if (string.IsNullOrEmpty(basePathToSet))
                        {
                            Debug.LogWarning("WwiseUnity: Bank " + bankName + " failed to load (could not obtain base path to set).");
                            return;
                        }

                        res = AkSoundEngine.SetBasePath(System.IO.Path.Combine(basePathToSet, relativeBasePath));
                    }
                    else
                    {
                        res = AKRESULT.AK_Success;
                    }

                    if (res == AKRESULT.AK_Success)
                    {
                        res = AkSoundEngine.LoadBank(bankName, AkSoundEngine.AK_DEFAULT_POOL_ID, out m_BankID);

                        if (!string.IsNullOrEmpty(basePathToSet))
                        {
                            AkSoundEngine.SetBasePath(basePathToSet);
                        }
                    }
                }
                else
                {
                    res = AkSoundEngine.LoadAndDecodeBank(bankName, saveDecodedBank, out m_BankID);
                }

                if (res != AKRESULT.AK_Success)
                {
                    Debug.LogWarning("WwiseUnity: Bank " + bankName + " failed to load (" + res.ToString() + ")");
                }
            }
            IncRef();
        }
    private void Awake()
    {
        if (AkInitializer.ms_Instance != null)
        {
            if (AkInitializer.ms_Instance != this)
            {
                Object.DestroyImmediate(base.gameObject);
            }
            return;
        }
        Debug.Log("WwiseUnity: Initialize sound engine ...");
        AkMemSettings akMemSettings = new AkMemSettings();

        akMemSettings.uMaxNumPools = 40u;
        AkDeviceSettings akDeviceSettings = new AkDeviceSettings();

        AkSoundEngine.GetDefaultDeviceSettings(akDeviceSettings);
        AkStreamMgrSettings akStreamMgrSettings = new AkStreamMgrSettings();

        akStreamMgrSettings.uMemorySize = (uint)(this.streamingPoolSize * 1024);
        AkInitSettings akInitSettings = new AkInitSettings();

        AkSoundEngine.GetDefaultInitSettings(akInitSettings);
        akInitSettings.uDefaultPoolSize = (uint)(this.defaultPoolSize * 1024);
        AkPlatformInitSettings akPlatformInitSettings = new AkPlatformInitSettings();

        AkSoundEngine.GetDefaultPlatformInitSettings(akPlatformInitSettings);
        akPlatformInitSettings.uLEngineDefaultPoolSize           = (uint)(this.lowerPoolSize * 1024);
        akPlatformInitSettings.fLEngineDefaultPoolRatioThreshold = this.memoryCutoffThreshold;
        AkMusicSettings akMusicSettings = new AkMusicSettings();

        AkSoundEngine.GetDefaultMusicSettings(akMusicSettings);
        AKRESULT aKRESULT = AkSoundEngine.Init(akMemSettings, akStreamMgrSettings, akDeviceSettings, akInitSettings, akPlatformInitSettings, akMusicSettings);

        if (aKRESULT != AKRESULT.AK_Success)
        {
            Debug.LogError("WwiseUnity: Failed to initialize the sound engine. Abort.");
            return;
        }
        AkInitializer.ms_Instance = this;
        AkBankPathUtil.UsePlatformSpecificPath();
        string platformBasePath = AkBankPathUtil.GetPlatformBasePath();

        if (!AkInitializer.s_loadBankFromMemory)
        {
        }
        AkSoundEngine.SetBasePath(platformBasePath);
        AkSoundEngine.SetCurrentLanguage(this.language);
        aKRESULT = AkCallbackManager.Init();
        if (aKRESULT != AKRESULT.AK_Success)
        {
            Debug.LogError("WwiseUnity: Failed to initialize Callback Manager. Terminate sound engine.");
            AkSoundEngine.Term();
            AkInitializer.ms_Instance = null;
            return;
        }
        Debug.Log("WwiseUnity: Sound engine initialized.");
        Object.DontDestroyOnLoad(this);
        if (AkInitializer.s_loadBankFromMemory)
        {
            string        soundBankPathInResources = AkInitializer.GetSoundBankPathInResources("Init.bytes");
            CBinaryObject cBinaryObject            = Singleton <CResourceManager> .GetInstance().GetResource(soundBankPathInResources, typeof(TextAsset), enResourceType.Sound, false, false).m_content as CBinaryObject;

            GCHandle gCHandle = GCHandle.Alloc(cBinaryObject.m_data, 3);
            IntPtr   intPtr   = gCHandle.AddrOfPinnedObject();
            if (intPtr != IntPtr.Zero)
            {
                uint num;
                aKRESULT = AkSoundEngine.LoadBank(intPtr, (uint)cBinaryObject.m_data.Length, -1, out num);
                gCHandle.Free();
            }
            else
            {
                aKRESULT = AKRESULT.AK_Fail;
            }
            Singleton <CResourceManager> .GetInstance().RemoveCachedResource(soundBankPathInResources);
        }
        else
        {
            uint num2;
            aKRESULT = AkSoundEngine.LoadBank("Init.bnk", -1, out num2);
        }
        if (aKRESULT != AKRESULT.AK_Success)
        {
            Debug.LogError("WwiseUnity: Failed load Init.bnk with result: " + aKRESULT.ToString());
        }
    }
Beispiel #15
0
    /// Loads a bank.  This version blocks until the bank is loaded.  See AK::SoundEngine::LoadBank for more information
    public void LoadBank()
    {
        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(m_BankID))
            {
                AkBankManager.BanksToUnload.Remove(m_BankID);
                IncRef();
                return;
            }

            AKRESULT res = AkSoundEngine.LoadBank(bankName, AkSoundEngine.AK_DEFAULT_POOL_ID, out m_BankID);
            if (res != AKRESULT.AK_Success)
            {
                Debug.LogWarning("WwiseUnity: Bank " + bankName + " failed to load (" + res.ToString() + ")");
            }
        }

        IncRef();
    }
Beispiel #16
0
 public void DecRef()
 {
     this.m_RefCount--;
     if ((this.m_RefCount == 0) && (this.m_BankID > 0))
     {
         AKRESULT akresult = AkSoundEngine.UnloadBank(this.m_BankID, IntPtr.Zero);
         if (akresult != AKRESULT.AK_Success)
         {
             Debug.LogWarning("Wwise: Bank " + this.bankName + " failed to unload (" + akresult.ToString() + ")");
         }
         this.m_BankID = 0;
     }
 }
Beispiel #17
0
 public void LoadBank()
 {
     if (this.m_RefCount == 0)
     {
         AKRESULT akresult = AkSoundEngine.LoadBank(this.bankName, -1, out this.m_BankID);
         if (akresult != AKRESULT.AK_Success)
         {
             Debug.LogWarning("Wwise: Bank " + this.bankName + " failed to load (" + akresult.ToString() + ")");
         }
     }
     this.IncRef();
 }
Beispiel #18
0
    /// Loads a bank.  This version blocks until the bank is loaded.  See AK::SoundEngine::LoadBank for more information
    public void LoadBank()
    {
        if (m_RefCount == 0)
        {
            AKRESULT res = AKRESULT.AK_Fail;

            // 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;
            }

#if UNITY_EDITOR
            res = AkSoundEngine.LoadBank(bankName, AkSoundEngine.AK_DEFAULT_POOL_ID, out m_BankID);
#else
            if (decodeBank == false)
            {
                string basePathToSet = null;

                if (!string.IsNullOrEmpty(relativeBasePath))
                {
                    basePathToSet = AkBasePathGetter.GetValidBasePath();
                    if (string.IsNullOrEmpty(basePathToSet))
                    {
                        Debug.LogWarning("WwiseUnity: Bank " + bankName + " failed to load (could not obtain base path to set).");
                        return;
                    }

                    res = AkSoundEngine.SetBasePath(System.IO.Path.Combine(basePathToSet, relativeBasePath));
                }
                else
                {
                    res = AKRESULT.AK_Success;
                }

                if (res == AKRESULT.AK_Success)
                {
                    res = AkSoundEngine.LoadBank(bankName, AkSoundEngine.AK_DEFAULT_POOL_ID, out m_BankID);

                    if (!string.IsNullOrEmpty(basePathToSet))
                    {
                        AkSoundEngine.SetBasePath(basePathToSet);
                    }
                }
            }
            else
            {
                if (saveDecodedBank == true)
                {
                    if (!System.IO.Directory.Exists(AkInitializer.GetDecodedBankFullPath()))
                    {
                        try
                        {
                            System.IO.Directory.CreateDirectory(AkInitializer.GetDecodedBankFullPath());
                            System.IO.Directory.CreateDirectory(System.IO.Path.Combine(AkInitializer.GetDecodedBankFullPath(), AkInitializer.GetCurrentLanguage()));
                        }
                        catch
                        {
                            Debug.LogWarning("Could not create decoded SoundBank directory, decoded SoundBank will not be saved.");
                            saveDecodedBank = false;
                        }
                    }
                }
                res = AkSoundEngine.LoadAndDecodeBank(bankName, saveDecodedBank, out m_BankID);
            }
#endif
            if (res != AKRESULT.AK_Success)
            {
                Debug.LogWarning("WwiseUnity: Bank " + bankName + " failed to load (" + res.ToString() + ")");
            }
        }
        IncRef();
    }
Beispiel #19
0
 protected void LogLoadResult(AKRESULT result)
 {
     if (result != AKRESULT.AK_Success)
     {
         Debug.LogWarning("WwiseUnity: Bank " + bankName + " failed to load (" + result.ToString() + ")");
     }
 }
 protected void LogLoadResult(AKRESULT result)
 {
     if (result != AKRESULT.AK_Success && AkSoundEngine.IsInitialized())
     {
         Debug.LogWarning("WwiseUnity: Bank " + bankName + " failed to load (" + result.ToString() + ")");
     }
 }
Beispiel #21
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 void GlobalBankCallback(uint in_bankID, IntPtr in_pInMemoryBankPtr, AKRESULT in_eLoadResult, uint in_memPoolId, object in_Cookie)
    {
        m_Mutex.WaitOne();
        AkBankHandle handle = (AkBankHandle)in_Cookie ;
        AkCallbackManager.BankCallback cb = handle.bankCallback;
        if (in_eLoadResult != AKRESULT.AK_Success)
        {
            Debug.LogWarning("WwiseUnity: Bank " + handle.bankName + " failed to load (" + in_eLoadResult.ToString() + ")");
            m_BankHandles.Remove(handle.bankName);
        }
        m_Mutex.ReleaseMutex();

        if (cb != null)
            cb(in_bankID, in_pInMemoryBankPtr, in_eLoadResult, in_memPoolId, null);
    }