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); } }
public bool BinaryEquivalent(Q3DAudioRoomSettings q3dAudioRoomSettings)//because we don't need all the HashCode(), etc C# machinery { return(gainAdjust == q3dAudioRoomSettings.gainAdjust && brightAdjust == q3dAudioRoomSettings.brightAdjust && timeAdjust == q3dAudioRoomSettings.timeAdjust && wetMix == q3dAudioRoomSettings.wetMix && roomDimensionsX_meters == q3dAudioRoomSettings.roomDimensionsX_meters && roomDimensionsY_meters == q3dAudioRoomSettings.roomDimensionsY_meters && roomDimensionsZ_meters == q3dAudioRoomSettings.roomDimensionsZ_meters && roomMaterialWalls == q3dAudioRoomSettings.roomMaterialWalls && roomMaterialCeiling == q3dAudioRoomSettings.roomMaterialCeiling && roomMaterialFloor == q3dAudioRoomSettings.roomMaterialFloor); }
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 }