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); } }
public AKRESULT SetExternalSources(uint in_nExternalSrc, AkExternalSourceInfo in_pExternalSrc) { AKRESULT ret = (AKRESULT)AkSoundEnginePINVOKE.CSharp_PlaylistItem_SetExternalSources(swigCPtr, in_nExternalSrc, AkExternalSourceInfo.getCPtr(in_pExternalSrc)); return(ret); }
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 }
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()); } }
void BankCallback(uint in_bankID, IntPtr in_pInMemoryBankPtr, AKRESULT in_eLoadResult, uint in_memPoolId, object in_Cookie) { //The bank has completed loading or unloading. This trigger doesn't care about that, but you could do something... }
private bool DoLoadBankFromImage(string in_bankPath, CBankEntry bankEntry) { uint in_uInMemoryBankSize = 0; GCHandle ms_pinnedArray = new GCHandle(); IntPtr ms_pInMemoryBankPtr = IntPtr.Zero; uint ms_bankID = AkSoundEngine.AK_INVALID_BANK_ID; byte[] bytes = Util.ReadFile(in_bankPath); if (bytes == null) { Common.HobaDebuger.LogErrorFormat("WwiseUnity: AkMemBankLoader: bank loading failed: {0}", in_bankPath); return(false); } try { ms_pinnedArray = GCHandle.Alloc(bytes, GCHandleType.Pinned); ms_pInMemoryBankPtr = ms_pinnedArray.AddrOfPinnedObject(); in_uInMemoryBankSize = (uint)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[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(bytes, 0, alignedBytes, alignedOffset, bytes.Length); ms_pInMemoryBankPtr = new_pInMemoryBankPtr; ms_pinnedArray.Free(); ms_pinnedArray = new_pinnedArray; } } catch (Exception) { if (ms_pInMemoryBankPtr != IntPtr.Zero) { ms_pinnedArray.Free(); } return(false); } bankEntry.InMemoryBankSize = in_uInMemoryBankSize; bankEntry.PinnedArray = ms_pinnedArray; bankEntry.InMemoryBankPtr = ms_pInMemoryBankPtr; AKRESULT result = AkSoundEngine.LoadBank(ms_pInMemoryBankPtr, in_uInMemoryBankSize, out ms_bankID); if (result != AKRESULT.AK_Success) { HobaDebuger.LogErrorFormat("DoLoadBankFromImage failed with result: {0} {1}", result, in_bankPath); return(false); } bankEntry.BankID = ms_bankID; return(true); }
private static void GlobalBankCallback(uint in_bankID, System.IntPtr in_pInMemoryBankPtr, AKRESULT in_eLoadResult, object in_Cookie) { var handle = (AsyncBankHandle)in_Cookie; var callback = handle.bankCallback; if (in_eLoadResult != AKRESULT.AK_Success) { handle.LogLoadResult(in_eLoadResult); if (in_eLoadResult != AKRESULT.AK_BankAlreadyLoaded) { lock (m_BankHandles) m_BankHandles.Remove(handle.bankName); } } if (callback != null) { callback(in_bankID, in_pInMemoryBankPtr, in_eLoadResult, null); } }
public static BankLoadResponseStruct Create(string bnkName, AKRESULT loadReuslt) { return(Create(bnkName, loadReuslt, null, null)); }
public static AKRESULT Init(IntPtr in_pMemory, uint in_uSize) { AKRESULT ret = (AKRESULT)AkSoundEnginePINVOKE.CSharp_AkCallbackSerializer_Init(in_pMemory, in_uSize); return(ret); }
public static AKRESULT AudioSourceChangeCallbackFunc(bool in_bOtherAudioPlaying, object in_pCookie) { AKRESULT ret = (AKRESULT)AkSoundEnginePINVOKE.CSharp_AkCallbackSerializer_AudioSourceChangeCallbackFunc(in_bOtherAudioPlaying, in_pCookie != null ? (IntPtr)in_pCookie.GetHashCode() : (IntPtr)0); return(ret); }
public AKRESULT SetState(int stateGroupID, int stateValueID) { AKRESULT result = AkSoundEngine.SetState((uint)stateGroupID, (uint)stateValueID); return(result); }
public AKRESULT SetState(string stateGroup, string state) { AKRESULT result = AkSoundEngine.SetState(stateGroup, state); return(result); }
public AKRESULT SetRTPC(string name, float value) { AKRESULT result = AkSoundEngine.SetRTPCValue(name, value); return(result); }
public AKRESULT Reserve(uint in_ulReserve) { AKRESULT ret = (AKRESULT)AkSoundEnginePINVOKE.CSharp_AkPlaylistArray_Reserve(swigCPtr, in_ulReserve); return(ret); }
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()); } }
//全局异步回调处理 private void OnAsyncBnkLoadHandler(uint in_bankID, System.IntPtr in_InMemoryBankPtr, AKRESULT in_eLoadResult, uint in_memPoolId, object in_Cookie) { LoadResultCallback_Data callbackData = in_Cookie != null ? (LoadResultCallback_Data)in_Cookie : null; handlerAgent.BroadcastBankLoadResult(callbackData.Name, in_eLoadResult); if (callbackData != null) { callbackData.Call(in_eLoadResult); } }
public static bool Prefix(LoadedAudioBank __instance, ref AKRESULT __result, ref uint ___id) { RLog.M.TWL(0, "LoadedAudioBank.LoadBankExternal " + __instance.name); if (ModTek.soundBanks.ContainsKey(__instance.name) == false) { return(false); } var uri = new System.Uri(ModTek.soundBanks[__instance.name].filename).AbsoluteUri; RLog.M.WL(1, uri); WWW www = new WWW(uri); while (!www.isDone) { Thread.Sleep(25); } RLog.M.WL(1, "'" + uri + "' loaded"); ProcessParameters pparams = SoundBanksProcessHelper.GetRegistredProcParams(__instance.name); GCHandle? handle = null; uint dataLength = (uint)www.bytes.Length; if (pparams != null) { RLog.M.WL(1, "found post-process parameters " + pparams.param1 + " " + pparams.param2); Aes aes = Aes.Create(); aes.Mode = CipherMode.CBC; aes.KeySize = 256; aes.BlockSize = 128; aes.FeedbackSize = 128; aes.Padding = PaddingMode.PKCS7; aes.Key = Convert.FromBase64String(pparams.param1); aes.IV = Convert.FromBase64String(pparams.param2); ICryptoTransform encryptor = aes.CreateDecryptor(aes.Key, aes.IV); byte[] result = null; using (MemoryStream msEncrypt = new MemoryStream()) { using (CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write)) { csEncrypt.Write(www.bytes, 0, www.bytes.Length); } result = msEncrypt.ToArray(); } handle = GCHandle.Alloc((object)result, GCHandleType.Pinned); dataLength = (uint)result.Length; } else { handle = GCHandle.Alloc((object)www.bytes, GCHandleType.Pinned); dataLength = (uint)www.bytes.Length; } if (handle.HasValue == false) { return(false); } try { uint id = uint.MaxValue; __result = AkSoundEngine.LoadBank(handle.Value.AddrOfPinnedObject(), dataLength, out id); ___id = id; if (__result == AKRESULT.AK_Success) { ModTek.soundBanks[__instance.name].registerEvents(); ModTek.soundBanks[__instance.name].setVolume(); } ; } catch { __result = AKRESULT.AK_Fail; } RLog.M.WL(1, "Result:" + __result + " id:" + ___id + " length:" + dataLength); return(false); }
private static void GlobalBankCallback(uint in_bankID, System.IntPtr in_pInMemoryBankPtr, AKRESULT in_eLoadResult, uint in_memPoolId, object in_Cookie) { m_Mutex.WaitOne(); var handle = (AsyncBankHandle)in_Cookie; var callback = handle.bankCallback; if (in_eLoadResult != AKRESULT.AK_Success) { handle.LogLoadResult(in_eLoadResult); m_BankHandles.Remove(handle.bankName); } m_Mutex.ReleaseMutex(); if (callback != null) { callback(in_bankID, in_pInMemoryBankPtr, in_eLoadResult, in_memPoolId, null); } }
public BankLoadInfo(AKRESULT result, string name) { this.result = result; this.bname = name; }
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); }
public void Call(AKRESULT result) { callbackObj(result, Name, customData); }
public static AKRESULT AppInterruptCallback(int in_iEnterInterruption, AKRESULT in_prevEngineStepResult, object in_Cookie) { if (in_iEnterInterruption != 0) { ms_isAudioSessionInterrupted = true; Debug.Log("Wwise: iOS audio session is interrupted by another app. Tap device screen to restore app's audio."); } return AKRESULT.AK_Success; }
public void Initialize() { if (AkInitializer.ms_Instance != null) { if (AkInitializer.ms_Instance != this) { UnityEngine.Object.DestroyImmediate(base.gameObject); } return; } 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; string validBasePath = AkBasePathGetter.GetValidBasePath(); if (string.IsNullOrEmpty(validBasePath)) { return; } aKRESULT = AkSoundEngine.SetBasePath(validBasePath); if (aKRESULT != AKRESULT.AK_Success) { return; } AkSoundEngine.SetCurrentLanguage("Chinese(PRC)"); aKRESULT = AkCallbackManager.Init(); if (aKRESULT != AKRESULT.AK_Success) { ClientLogger.Error("WwiseUnity: Failed to initialize Callback Manager. Terminate sound engine."); AkSoundEngine.Term(); AkInitializer.ms_Instance = null; return; } AkBankManager.Reset(); UnityEngine.Object.DontDestroyOnLoad(this); }
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; } GetAllDerivedTypes(); Debug.Log("WwiseUnity: Initialize sound engine ..."); AkBasePathGetter.Initialize(); //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 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(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 #if UNITY_2017_2_OR_NEWER EditorApplication.playModeStateChanged += OnPlayModeStateChanged; EditorApplication.pauseStateChanged += OnPauseStateChanged; #else EditorApplication.playmodeStateChanged += OnEditorPlaymodeStateChanged; #endif #endif }
public AKRESULT Enqueue(uint in_audioNodeID, int in_msDelay, IntPtr in_pCustomInfo, uint in_cExternals, AkExternalSourceInfo in_pExternalSources) { AKRESULT ret = (AKRESULT)AkSoundEnginePINVOKE.CSharp_Playlist_Enqueue__SWIG_0(swigCPtr, in_audioNodeID, in_msDelay, in_pCustomInfo, in_cExternals, AkExternalSourceInfo.getCPtr(in_pExternalSources)); return(ret); }
public static bool Sucess(this AKRESULT result) { return(result == AKRESULT.AK_Success || result == AKRESULT.AK_BankAlreadyLoaded); }
public AKRESULT Enqueue(uint in_audioNodeID, int in_msDelay, IntPtr in_pCustomInfo) { AKRESULT ret = (AKRESULT)AkSoundEnginePINVOKE.CSharp_Playlist_Enqueue__SWIG_2(swigCPtr, in_audioNodeID, in_msDelay, in_pCustomInfo); return(ret); }
private void SwitchStateFinalHandler(AKSwitchAtom atom, GameObject target) { AKRESULT result = AkSoundEngine.SetSwitch(atom.config.Group, atom.currState, target); // DebugUtil.MyLog( "Real set switch {1} {0}", atom.currState,target.name); }
public AKRESULT Enqueue(uint in_audioNodeID) { AKRESULT ret = (AKRESULT)AkSoundEnginePINVOKE.CSharp_Playlist_Enqueue__SWIG_4(swigCPtr, in_audioNodeID); return(ret); }
public AKRESULT RemoveSwap(PlaylistItem in_rItem) { AKRESULT ret = (AKRESULT)AkSoundEnginePINVOKE.CSharp_AkPlaylistArray_RemoveSwap(swigCPtr, PlaylistItem.getCPtr(in_rItem)); return(ret); }
/// 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(); }
/// <summary> /// User hook called after RegisterGameObj(). An example use could be to add the id and gameObject to a dictionary upon /// AK_Success. /// </summary> /// <param name="result">The result from calling RegisterGameObj() on gameObject.</param> /// <param name="gameObject">The GameObject that RegisterGameObj() was called on.</param> /// <param name="id">The ulong returned from GameObjectHash that represents this GameObject in Wwise.</param> static partial void PostRegisterGameObjUserHook(AKRESULT result, UnityEngine.GameObject gameObject, ulong id);
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()); } }