public void SetAudioRoomSettings(Q3DAudioRoomSettings currentSettings) { if (!currentSettings.BinaryEquivalent(mQ3DAudioRoomSettingsLast)) { mQ3DAudioRoomSettingsLast = currentSettings; Q3DAudioManager.DebugLog("Q3DAudioRoom:Set=[" + currentSettings.gainAdjust + ";" + currentSettings.brightAdjust + ";" + currentSettings.timeAdjust + ";" + currentSettings.wetMix + ";" + currentSettings.roomDimensionsX_meters + ";" + currentSettings.roomDimensionsY_meters + ";" + currentSettings.roomDimensionsZ_meters + ";" + currentSettings.roomMaterialWalls + ";" + currentSettings.roomMaterialCeiling + ";" + currentSettings.roomMaterialFloor + "]"); Q3DAudioRoom.SetReverb( currentSettings.gainAdjust, currentSettings.brightAdjust, currentSettings.timeAdjust, currentSettings.wetMix, currentSettings.roomDimensionsX_meters, currentSettings.roomDimensionsY_meters, currentSettings.roomDimensionsZ_meters, (int)currentSettings.roomMaterialWalls, (int)currentSettings.roomMaterialCeiling, (int)currentSettings.roomMaterialFloor); } }
void OnDestroy() { if (!Q3DAudioManager.DisableIfQ3DNotActive(this)) { UpdatePlayingThisFrame();//release q3d_audio resources } }
public static void CopyAndroidLibrary(string sourceFullPath, string destinationFullPath) { Q3DAudioManager.DebugLogAlways("Copying " + sourceFullPath + " to " + destinationFullPath); File.SetAttributes(destinationFullPath, FileAttributes.Normal); File.Copy(sourceFullPath, destinationFullPath, true); }
private void DisableBecauseUninitialized() { enabled = false; if (!mAudioReverbZone) { Q3DAudioManager.DebugLog("Q3DAudioRoom found no AudioReverbZone on its GameObject -- disabling."); } }
static public void LogIfQ3DAudioSourceNumIsNotCorrect(int q3dAudioSourcesLength, int audioSourcesLength, string gameObjectName) { if (q3dAudioSourcesLength != audioSourcesLength) { Q3DAudioManager.DebugLogAlways( "Authoring error: there should either be no Q3DAudioSource's on a GameObject, or there should be as many Q3DAudioSource's on the " + "GameObject as there are AudioSource's. However, on " + gameObjectName + " there are " + audioSourcesLength + " AudioSource(s) and " + q3dAudioSourcesLength + " Q3DAudioSource(s). Spatialization of these AudioSource's may be inconsistent"); } }
static void AudioSourcesToQ3DAudioRooms() { string Q3DAudioSource = "Q3DAudioSource"; AudioSource[] audioSources = Q3DAudioManager.FindObjectsOfTypeAllWrapper<AudioSource>(); foreach (AudioSource audioSource in audioSources) { if (!audioSource.GetComponent<Q3DAudioSource>()) { Undo.RegisterCreatedObjectUndo(audioSource, "Created " + Q3DAudioSource);//this must be done before adding the component for undo to work! audioSource.gameObject.AddComponent<Q3DAudioSource>(); } } }
static void ReverbZonesToQ3DAudioRooms() { string Q3DAudioRoom = "Q3DAudioRoom"; AudioReverbZone[] reverbZones = Q3DAudioManager.FindObjectsOfTypeAllWrapper<AudioReverbZone>(); foreach(AudioReverbZone reverbZone in reverbZones) { if(!reverbZone.GetComponent<Q3DAudioRoom>()) { Undo.RegisterCreatedObjectUndo(reverbZone, "Created " + Q3DAudioRoom);//this must be done before adding the component for undo to work! reverbZone.gameObject.AddComponent<Q3DAudioRoom>(); } } }
void Awake() { if (Q3DAudioManager.DisableIfQ3DNotActive(this)) { return; } //create singleton if necessary -- do this as early as possible so logging mechanism on Windows can be setup if (!smQ3DAudioManagerInstance) { GameObject go = new GameObject("Q3DAudioManager"); smQ3DAudioManagerInstance = go.AddComponent <Q3DAudioManager>(); } GetComponent <AudioListener>().enabled = enabled; }
void Awake() { if (Q3DAudioManager.DisableIfQ3DNotActive(this)) { return; } mAudioReverbZone = GetComponent <AudioReverbZone>(); if (!mAudioReverbZone) { DisableBecauseUninitialized(); } else { Q3DAudioListener.mQ3DAudioRoomList.Add(this); } }
static public void SpatializeMonoAudioSources(bool log) { AudioSource[] audioSources = FindObjectsOfTypeAllWrapper <AudioSource>(); foreach (AudioSource audioSource in audioSources) { AudioClip clip = audioSource.clip; if (clip && clip.channels == 1 && audioSource.GetComponent <Q3DAudioSource>() == null) { audioSource.gameObject.AddComponent(typeof(Q3DAudioSource)); audioSource.spatialize = true; if (log) { Q3DAudioManager.DebugLogAlways("AudioSource " + audioSource.gameObject.name + " with mono clip " + clip.name + " found without a Q3DAudioSource; adding Q3DAudioSource and setting Spatialize=true"); } } } }
static Q3DAudioGlobalSettings smQ3DAudioGlobalSettings;///note that this value will remain resident even if the underlying GameObject is destroyed, so the last set global settings will persist forever void Awake() { if (Q3DAudioManager.DisableIfUnsupportedPlatform(this)) { return; } /* setup the global settings even if the user has disabled Q3DAudio on this supported platform; this allows the rest of Q3DAudio to disable * with minimal startup processing */ if (smQ3DAudioGlobalSettings) { Q3DAudioManager.DebugLog("There is already another Q3DAudioGlobalSettings; this Q3DAudioGlobalSettings replaces and destroys it. Multiple Q3DAudioGlobalSetting's in one scene is not recommended practice, since " + "this original Q3DAudioGlobalSettings will not be restored, even if this Q3DAudioGlobalSettings is destroyed. We recommend you " + "instantiate one Q3DAudioGlobalSettings at startup; it will remain resident for the entire lifetime of the application, even if its " + "GameObject is destroyed when a new scene is loaded. If you place one Q3DAudioGlobalSettings object in each scene, then each time " + "a new scene is loaded the latest Q3DAudioGlobalSettings will replace the previous one without emitting this message."); GameObject.Destroy(smQ3DAudioGlobalSettings.gameObject); } smQ3DAudioGlobalSettings = this; }
void Awake() { if (Q3DAudioManager.DisableIfQ3DNotActive(this)) { return; } int idInt; do { //Unity's audio interface only passes floats; use 23-bit mantissa of IEEE 32bit float to keep things simple with non-fractional float ids idInt = smRandom.Next(2 << 23); } while (smIdHashMap.ContainsKey(idInt)); mId = (float)idInt; smIdHashMap.Add(idInt, mId); if (!InitializeAudioSource()) { return; } }
private void DisableBecauseUninitialized() { Q3DAudioManager.DebugLog("Q3DAudioSource " + gameObject.name + " found no AudioSource on its GameObject -- disabling. (Q3DAudioSource must have an AudioSource that references an AudioClip of 1 or 4 channels to work as a sound object or First Order Ambisonics soundfield, respectively). Soundfields are supported by Unity 2017.1.0f3 and later versions"); enabled = false; }
void OnApplicationQuit() { Q3DAudioManager.DebugLog("OnApplicationQuit called!"); OnApplicationQuit(InEditor()); }
void Awake() { //Q3DAudioManager should never be constructed by Q3DAudioListener if we are running a platform Q3DAudio does not support or the user has disabled //allow C++ plugin can emit to Unity's debug logs -- call as soon as possible! DebugLogCallbackDelegate callbackDelegate = new DebugLogCallbackDelegate(DebugLogCallBackFunction); System.IntPtr intptrDelegate = Marshal.GetFunctionPointerForDelegate(callbackDelegate); //convert callback_delegate into a function pointer that can be used in unmanaged code SetDebugLogCallback(intptrDelegate); // Call the API passing along the function pointer Q3DAudioGlobalSettings.vr_audio_shoebox_mode firstChoiceReverbProcessor = Q3DAudioGlobalSettings.vr_audio_shoebox_mode.COMPUTE_DSP; Q3DAudioGlobalSettings.vr_audio_shoebox_mode secondChoiceReverbProcessor = Q3DAudioGlobalSettings.vr_audio_shoebox_mode.HEXAGON_ADSP; Q3DAudioGlobalSettings globalSettings = Q3DAudioGlobalSettings.GetQ3DAudioGlobalSettings(); if (globalSettings) { firstChoiceReverbProcessor = globalSettings.mAndroidReverbProcessorFirstChoice; secondChoiceReverbProcessor = globalSettings.mAndroidReverbProcessorSecondChoice; } /* * command line arguments (Windows) and intents (Android) override global settings * command line arguments are case-insensitive and are expected to be formatted: NAME_OF_EXE Q3DAudio1stChoiceReverbProcessor=COMPUTE_DSP * the equivalent Android intent has a case-sensitive key (due to Android's requirements) and a case-insensitive value: * adb shell am start -n NAME_OF_PACKAGE/com.unity3d.player.UnityPlayerActivity -e Q3DAudio1stChoiceReverbProcessor COMPUTE_CPU */ string firstChoiceReverbProcessorString = "1stChoiceReverbProcessor"; string secondChoiceReverbProcessorString = "2ndChoiceReverbProcessor"; string q3dAudioString = "Q3DAudio"; #if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN //Windows is case-insensitive for convenience, because (unlike some other platforms) we can make it so q3dAudioString = q3dAudioString.ToLower(); firstChoiceReverbProcessorString = firstChoiceReverbProcessorString.ToLower(); secondChoiceReverbProcessorString = secondChoiceReverbProcessorString.ToLower(); string[] commandLineArgs = Environment.GetCommandLineArgs(); foreach (string c in commandLineArgs) { string commandLineArg = c.ToLower(); if (StringIsInString(q3dAudioString, commandLineArg)) { if (StringIsInString(firstChoiceReverbProcessorString, commandLineArg)) { ParseAndroidReverbProcessorIfItExists(ref firstChoiceReverbProcessor, commandLineArg); } else if (StringIsInString(secondChoiceReverbProcessorString, commandLineArg)) { ParseAndroidReverbProcessorIfItExists(ref secondChoiceReverbProcessor, commandLineArg); } } } #elif UNITY_ANDROID AndroidJavaClass UnityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); AndroidJavaObject currentActivity = UnityPlayer.GetStatic <AndroidJavaObject>("currentActivity"); AndroidJavaObject intent = currentActivity.Call <AndroidJavaObject>("getIntent"); ParseAndroidReverbProcessorIfItExists(ref firstChoiceReverbProcessor, q3dAudioString + firstChoiceReverbProcessorString, intent); ParseAndroidReverbProcessorIfItExists(ref secondChoiceReverbProcessor, q3dAudioString + secondChoiceReverbProcessorString, intent); #endif//#if UNITY_STANDALONE_WIN #elif UNITY_ANDROID Q3DAudioManager.DebugLog("Reverb: 1stChoiceProcessor=" + firstChoiceReverbProcessor + ";2ndChoiceProcessor=" + secondChoiceReverbProcessor); SetReverbProcessorPreferences((int)firstChoiceReverbProcessor, (int)secondChoiceReverbProcessor); //point C++ plugin to the directory where q3d_audio dll's are deployed Q3DAudioManager.SetApplicationDataPath(Application.dataPath, InEditor()); //the user is not allowed to set the default parameters on the mixer effect at runtime, so this can be done here once int roomMatWalls, roomMatCeiling, roomMatFloor; GetDefaultReverb( out mQ3DAudioRoomSettingsDefault.gainAdjust, out mQ3DAudioRoomSettingsDefault.brightAdjust, out mQ3DAudioRoomSettingsDefault.timeAdjust, out mQ3DAudioRoomSettingsDefault.wetMix, out mQ3DAudioRoomSettingsDefault.roomDimensionsX_meters, out mQ3DAudioRoomSettingsDefault.roomDimensionsY_meters, out mQ3DAudioRoomSettingsDefault.roomDimensionsZ_meters, out roomMatWalls, out roomMatCeiling, out roomMatFloor); mQ3DAudioRoomSettingsDefault.roomMaterialWalls = (Q3DAudioRoom.vr_audio_room_material_type)roomMatWalls; mQ3DAudioRoomSettingsDefault.roomMaterialCeiling = (Q3DAudioRoom.vr_audio_room_material_type)roomMatCeiling; mQ3DAudioRoomSettingsDefault.roomMaterialFloor = (Q3DAudioRoom.vr_audio_room_material_type)roomMatFloor; #if UNITY_EDITOR //after the first "play", the editor doesn't recreate the mixer effects, so the default settings are not necessarily what q3d_audio is using SetAudioRoomSettings(mQ3DAudioRoomSettingsDefault);//q3d_audio uses default settings #else //for standalone players, the default settings are by definition what is set immediately after creating the mixer effects mQ3DAudioRoomSettingsLast = mQ3DAudioRoomSettingsDefault; #endif//#if UNITY_EDITOR DontDestroyOnLoad(this);//persist until the game is shut down //BEG_CONFIG /* as of Unity 2017.1.0f3 this cannot be done. Executing the code below appears to cause Unity to destroy all * mixer effects, and the spatializer effect and ambisonic decoder effect (correct), and then recreate all of * these except for the ambisonic decoder effect (wrong) and then proceeds to play silence on Android (wrong) */ ///@todo: warn if overriding values //AudioConfiguration audioConfiguration = AudioSettings.GetConfiguration(); //audioConfiguration.dspBufferSize = 192; ////audioConfiguration.sampleRate = 48000; ////audioConfiguration.speakerMode = AudioSpeakerMode.Stereo; ////AudioSettings.Reset(audioConfiguration);///@todo: if false, then log epic failure //END_CONFIG }