diff --git a/VAURendererController.cs b/VAUAudioRenderer.cs similarity index 54% rename from VAURendererController.cs rename to VAUAudioRenderer.cs index 6b2ffac070913a666138622f49a4cf2602a8298e..912c656152bae10f2471d91938db9948f8f4f79f 100644 --- a/VAURendererController.cs +++ b/VAUAudioRenderer.cs @@ -2,10 +2,15 @@ using System.Collections.Generic; using UnityEngine; -public class VAURendererController : MonoBehaviour +public class VAUAudioRenderer : MonoBehaviour { - public string RendererID = ""; + [Tooltip("Rendering module identifier")] + public string ID = ""; + + [Tooltip("Mute/unmute rendering output")] public bool OutputMuted = false; + + [Tooltip("Control rendering output gain")] public double OutputGain = 1.0; private bool OutputMutedShadow; @@ -13,8 +18,8 @@ public class VAURendererController : MonoBehaviour void Start () { - VAUAdapter.VA.SetRenderingModuleMuted( RendererID, OutputMuted ); - VAUAdapter.VA.SetRenderingModuleGain( RendererID, OutputGain ); + VAUAdapter.VA.SetRenderingModuleMuted( ID, OutputMuted ); + VAUAdapter.VA.SetRenderingModuleGain( ID, OutputGain ); OutputMutedShadow = OutputMuted; OutputGainShadow = OutputGain; @@ -24,12 +29,12 @@ public class VAURendererController : MonoBehaviour { if( OutputMuted != OutputMutedShadow ) { - VAUAdapter.VA.SetRenderingModuleMuted( RendererID, OutputMuted ); + VAUAdapter.VA.SetRenderingModuleMuted( ID, OutputMuted ); OutputMutedShadow = OutputMuted; } if( OutputGain != OutputGainShadow ) { - VAUAdapter.VA.SetRenderingModuleGain( RendererID, OutputGain ); + VAUAdapter.VA.SetRenderingModuleGain( ID, OutputGain ); OutputGainShadow = OutputGain; } } diff --git a/VAUReproductionController.cs b/VAUAudioReproduction.cs similarity index 52% rename from VAUReproductionController.cs rename to VAUAudioReproduction.cs index 951216cb3156b0df3c9123e8a57c81497e754d68..ed2f61e0e9999cd287067b5bb7629dd8855e8b21 100644 --- a/VAUReproductionController.cs +++ b/VAUAudioReproduction.cs @@ -2,19 +2,24 @@ using System.Collections.Generic; using UnityEngine; -public class VAUReproductionController : MonoBehaviour +public class VAUAudioReproduction : MonoBehaviour { - public string ReproductionID = ""; + [Tooltip("Reproduction module identifier")] + public string ID = ""; + + [Tooltip("Mute/unmute reproduction output")] public bool OutputMuted = false; + + [Tooltip("Control reproduction output gain")] public double OutputGain = 1.0; - + private bool OutputMutedShadow; private double OutputGainShadow; void Start () { - VAUAdapter.VA.SetReproductionModuleMuted( ReproductionID, OutputMuted ); - VAUAdapter.VA.SetReproductionModuleGain( ReproductionID, OutputGain ); + VAUAdapter.VA.SetReproductionModuleMuted( ID, OutputMuted ); + VAUAdapter.VA.SetReproductionModuleGain( ID, OutputGain ); OutputMutedShadow = OutputMuted; OutputGainShadow = OutputGain; @@ -24,12 +29,12 @@ public class VAUReproductionController : MonoBehaviour { if( OutputMuted != OutputMutedShadow ) { - VAUAdapter.VA.SetReproductionModuleMuted( ReproductionID, OutputMuted ); + VAUAdapter.VA.SetReproductionModuleMuted( ID, OutputMuted ); OutputMutedShadow = OutputMuted; } if( OutputGain != OutputGainShadow ) { - VAUAdapter.VA.SetReproductionModuleGain( ReproductionID, OutputGain ); + VAUAdapter.VA.SetReproductionModuleGain( ID, OutputGain ); OutputGainShadow = OutputGain; } } diff --git a/VAUAuralizationMode.cs b/VAUAuralizationMode.cs index 6c4de0595c5b63a2ca581888a3437c7a62d302df..201f4c586fc72d0c63c093f61e2cf8021337a078 100644 --- a/VAUAuralizationMode.cs +++ b/VAUAuralizationMode.cs @@ -4,19 +4,40 @@ using System.Collections; public class VAUAuralizationMode : MonoBehaviour { + [Tooltip("Toggle direct sound")] public bool DirectSound = true; - public bool EarlyReflections = false; - public bool DiffuseDecay = false; - public bool SourceDirectivity = true; - public bool AirAbsorption = false; - public bool AtmosphericTemporalVariations = false; - public bool Scattering = false; - public bool Diffraction = false; - public bool NearFieldEffects = false; - public bool DopplerShifts = true; + + [Tooltip("Toggle early reflections")] + public bool EarlyReflections = false; + + [Tooltip("Toggle diffuse decay")] + public bool DiffuseDecay = false; + + [Tooltip("Toggle source directivity")] + public bool SourceDirectivity = true; + + [Tooltip("Toggle air absorption")] + public bool AirAbsorption = false; + + [Tooltip("Toggle atmospheric temporal variations")] + public bool AtmosphericTemporalVariations = false; + + [Tooltip("Toggle scattering")] + public bool Scattering = false; + + [Tooltip("Toggle diffraction")] + public bool Diffraction = false; + + [Tooltip("Toggle hear-field effects")] + public bool NearFieldEffects = false; + + [Tooltip("Toggle Doppler shifts")] + public bool DopplerShifts = true; + + [Tooltip("Toggle spherical spreading loss")] public bool SphericalSpreadingLoss = true; - private class AuralizationMode : System.Object + protected class AuralizationMode : System.Object { public bool DirectSound = true; public bool EarlyReflections = true; @@ -195,7 +216,7 @@ public class VAUAuralizationMode : MonoBehaviour AuraStringChanged(externAuraString); } - AuralizationMode UpdateAuraModeSettings() + protected AuralizationMode UpdateAuraModeSettings() { AuralizationMode am = new AuralizationMode(); am.DirectSound = DirectSound; diff --git a/VAUController.cs b/VAUController.cs index 4a49f38c0d38133bea96eb888c59ceef44f61f58..af6b7e4f7e8541faee9240fed8c9de8e6eeec905 100644 --- a/VAUController.cs +++ b/VAUController.cs @@ -4,9 +4,16 @@ using UnityEngine; public class VAUController : MonoBehaviour { + [Tooltip("Mute global input")] public bool InputMuted = false; + + [Tooltip("Control global input gain")] public double InputGain = 1.0; + + [Tooltip("Mute global output")] public bool OutputMuted = false; + + [Tooltip("Control global output gain")] public double OutputGain = 1.0; private bool InputMutedShadow; diff --git a/VAUListener.cs b/VAUListener.cs index 59b5f2c70fab9ebcf9886a275723686bbc93294f..f47ff5e93a4d211315a8433ffe74b7cb7acc2c5b 100644 --- a/VAUListener.cs +++ b/VAUListener.cs @@ -4,17 +4,12 @@ using System.Collections; using VA; -[Tooltip("A human listener that can receive sound and will be rendered by an audio renderer")] -public class VAUListener : MonoBehaviour { - - [Tooltip("Descriptive name")] - public string Name = "HumanListener"; - +public class VAUListener : VAUSoundReceiver { + [Tooltip("Number of reverbzones used for determining the current reverb.")] public int NumMaxReverbZones = 2; + public string VAAudioRenderer = "MyBinauralArtificialReverb"; - [Tooltip("Add custom VAUHRIR dataset.")] - public VAUDirectivity HRIR = null; [Tooltip("Anthropometric head width, for HRIR individualization or generic binaural cues")] public double HeadWidth = 0.12; @@ -26,10 +21,7 @@ public class VAUListener : MonoBehaviour { private double ShadowHeadWidth; private double ShadowHeadHeight; private double ShadowHeadDepth; - - private int _ID; - private VANet _VA = null; - + private Quaternion q; private Transform t; private AudioReverbZone[] reverbZones; @@ -37,33 +29,24 @@ public class VAUListener : MonoBehaviour { public delegate void ReverbTimeChangedDelegate(double reverbTime); public event ReverbTimeChangedDelegate ReverbTimeChanged; - - public int ID - { - get - { - return _ID; - } - } - + void Start() { - _VA = VAUAdapter.VA; - _ID = _VA.CreateSoundReceiver(Name); - _VA.SetSoundReceiverAuralizationMode(_ID, "all"); - if (HRIR) - _VA.SetSoundReceiverDirectivity(_ID, HRIR.ID); + _ID = VAUAdapter.VA.CreateSoundReceiver(Name); + VAUAdapter.VA.SetSoundReceiverAuralizationMode(_ID, "all"); + if (Directivity) + VAUAdapter.VA.SetSoundReceiverDirectivity(_ID, Directivity.ID); else if( VAUAdapter.DefaultHRIRID != -1 ) - _VA.SetSoundReceiverDirectivity(_ID, VAUAdapter.DefaultHRIRID); + VAUAdapter.VA.SetSoundReceiverDirectivity(_ID, VAUAdapter.DefaultHRIRID); - _VA.SetSoundReceiverAnthropometricData(_ID, HeadWidth, HeadHeight, HeadDepth); + VAUAdapter.VA.SetSoundReceiverAnthropometricData(_ID, HeadWidth, HeadHeight, HeadDepth); ShadowHeadWidth = HeadWidth; ShadowHeadHeight = HeadHeight; ShadowHeadDepth = HeadDepth; SetSoundReceiverPositionOrientation(); - _VA.SetArtificialReverberationTime(VAAudioRenderer, 0.3f); + VAUAdapter.VA.SetArtificialReverberationTime(VAAudioRenderer, 0.3f); reverbZones = FindObjectsOfType(typeof(AudioReverbZone)) as AudioReverbZone[]; } @@ -80,27 +63,13 @@ public class VAUListener : MonoBehaviour { if( HeadWidth != ShadowHeadWidth || HeadHeight != ShadowHeadHeight || HeadDepth != ShadowHeadDepth ) { - _VA.SetSoundReceiverAnthropometricData(_ID, HeadWidth, HeadHeight, HeadDepth); + VAUAdapter.VA.SetSoundReceiverAnthropometricData(_ID, HeadWidth, HeadHeight, HeadDepth); ShadowHeadWidth = HeadWidth; ShadowHeadHeight = HeadHeight; ShadowHeadDepth = HeadDepth; } } - // Uses the View- and Up-Vector to transmit the position of the listener to VA - void SetSoundReceiverPositionOrientation() - { - _VA = VAUAdapter.VA; - t = GetComponent(); - q = t.rotation; - Vector3 up = q * Vector3.up; - Vector3 view = q * Vector3.forward; - Vector3 view_ogl = new Vector3(view.x, view.y, -view.z); - Vector3 up_ogl = new Vector3(up.x, up.y, -up.z); - _VA.SetSoundReceiverPosition(_ID, new VAVec3( t.transform.position.x, t.transform.position.y, -t.transform.position.z )); - _VA.SetSoundReceiverOrientationVU(_ID, new VAVec3( view_ogl.x, view_ogl.y, view_ogl.z ), new VAVec3( up_ogl.x, up_ogl.y, up_ogl.z )); - } - void SetActiveReverbZones() { if (reverbZones == null) @@ -131,9 +100,9 @@ public class VAUListener : MonoBehaviour { if (actReverbTime < 0.3f) - _VA.SetRenderingModuleMuted("MyBinauralArtificialReverb", true); + VAUAdapter.VA.SetRenderingModuleMuted("MyBinauralArtificialReverb", true); else - _VA.SetRenderingModuleMuted("MyBinauralArtificialReverb", false); + VAUAdapter.VA.SetRenderingModuleMuted("MyBinauralArtificialReverb", false); shadowReverbTime = actReverbTime; @@ -143,20 +112,7 @@ public class VAUListener : MonoBehaviour { if (ReverbTimeChanged != null) ReverbTimeChanged(actReverbTime); - _VA.SetArtificialReverberationTime(VAAudioRenderer, actReverbTime); - - } - - void OnSoundReceiverAuralizationModeChanged(string AuraMode) - { - _VA.SetSoundReceiverAuralizationMode(_ID, AuraMode); - } - - private void OnDestroy() - { - if (GetComponent() != null) - GetComponent().AuraStringChanged -= OnSoundReceiverAuralizationModeChanged; + VAUAdapter.VA.SetArtificialReverberationTime(VAAudioRenderer, actReverbTime); - _VA.DeleteSoundReceiver(_ID); } } diff --git a/VAURendererArtificialReverb.cs b/VAURendererArtificialReverb.cs index 84f4710b0435f62b9f530b3afc9d22ab1d593544..16abb9c4c60dd921822faf48fd6af6c4d6788b0b 100644 --- a/VAURendererArtificialReverb.cs +++ b/VAURendererArtificialReverb.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using UnityEngine; -public class VAURendererArtificialReverb : VAURendererController +public class VAURendererArtificialReverb : VAUAudioRenderer { public double RoomReverberationTime = 1.2; // s public double RoomSurfaceArea = 220.0; // m^2 @@ -14,9 +14,9 @@ public class VAURendererArtificialReverb : VAURendererController void Start () { - VAUAdapter.VA.SetArtificialReverberationTime( RendererID, RoomReverberationTime ); - VAUAdapter.VA.SetArtificialSurfaceArea( RendererID, RoomSurfaceArea ); - VAUAdapter.VA.SetArtificialRoomVolume( RendererID, RoomVolume ); + VAUAdapter.VA.SetArtificialReverberationTime( ID, RoomReverberationTime ); + VAUAdapter.VA.SetArtificialSurfaceArea( ID, RoomSurfaceArea ); + VAUAdapter.VA.SetArtificialRoomVolume( ID, RoomVolume ); RoomReverberationTimeShadow = RoomReverberationTime; RoomSurfaceAreaShadow = RoomSurfaceArea; @@ -27,17 +27,17 @@ public class VAURendererArtificialReverb : VAURendererController { if( RoomReverberationTime != RoomReverberationTimeShadow ) { - VAUAdapter.VA.SetArtificialReverberationTime( RendererID, RoomReverberationTime ); + VAUAdapter.VA.SetArtificialReverberationTime( ID, RoomReverberationTime ); RoomReverberationTimeShadow = RoomReverberationTime; } if( RoomSurfaceArea != RoomSurfaceAreaShadow ) { - VAUAdapter.VA.SetArtificialSurfaceArea( RendererID, RoomSurfaceArea ); + VAUAdapter.VA.SetArtificialSurfaceArea( ID, RoomSurfaceArea ); RoomSurfaceAreaShadow = RoomSurfaceArea; } if( RoomVolume != RoomVolumeShadow ) { - VAUAdapter.VA.SetArtificialRoomVolume( RendererID, RoomVolume ); + VAUAdapter.VA.SetArtificialRoomVolume( ID, RoomVolume ); RoomVolumeShadow = RoomVolume; } } diff --git a/VAUSoundReceiver.cs b/VAUSoundReceiver.cs index 25f549145a0dfb4fd21be5bd3b022caefc87fa28..95caede08791ad04ea508e36dd0fbf3798755817 100644 --- a/VAUSoundReceiver.cs +++ b/VAUSoundReceiver.cs @@ -4,7 +4,6 @@ using System.Collections; using VA; -[Tooltip("Entity that can receive sound and will be rendered by an audio renderer")] public class VAUSoundReceiver : MonoBehaviour { [Tooltip("Descriptive name")] @@ -16,8 +15,8 @@ public class VAUSoundReceiver : MonoBehaviour { [Tooltip("Connect an directivity to this receiver")] public VAUDirectivity Directivity = null; - private int _ID; - private VANet _VA = null; + [Tooltip("Internal VA identifier")] + protected int _ID; private Quaternion q; private Transform t; @@ -32,13 +31,12 @@ public class VAUSoundReceiver : MonoBehaviour { void Start() { - _VA = VAUAdapter.VA; - _ID = _VA.CreateSoundReceiver(Name); - _VA.SetSoundReceiverAuralizationMode(_ID, "all"); - if (HRIR) - _VA.SetSoundReceiverDirectivity(_ID, HRIR.ID); + _ID = VAUAdapter.VA.CreateSoundReceiver(Name); + VAUAdapter.VA.SetSoundReceiverAuralizationMode(_ID, "all"); + if (Directivity) + VAUAdapter.VA.SetSoundReceiverDirectivity(_ID, Directivity.ID); else if( VAUAdapter.DefaultHRIRID != -1 ) - _VA.SetSoundReceiverDirectivity(_ID, VAUAdapter.DefaultHRIRID); + VAUAdapter.VA.SetSoundReceiverDirectivity(_ID, VAUAdapter.DefaultHRIRID); SetSoundReceiverPositionOrientation(); } @@ -55,22 +53,21 @@ public class VAUSoundReceiver : MonoBehaviour { } // Uses the View- and Up-Vector to transmit the position of the listener to VA - void SetSoundReceiverPositionOrientation() + protected void SetSoundReceiverPositionOrientation() { - _VA = VAUAdapter.VA; t = GetComponent(); q = t.rotation; Vector3 up = q * Vector3.up; Vector3 view = q * Vector3.forward; Vector3 view_ogl = new Vector3(view.x, view.y, -view.z); Vector3 up_ogl = new Vector3(up.x, up.y, -up.z); - _VA.SetSoundReceiverPosition(_ID, new VAVec3( t.transform.position.x, t.transform.position.y, -t.transform.position.z )); - _VA.SetSoundReceiverOrientationVU(_ID, new VAVec3( view_ogl.x, view_ogl.y, view_ogl.z ), new VAVec3( up_ogl.x, up_ogl.y, up_ogl.z )); + VAUAdapter.VA.SetSoundReceiverPosition(_ID, new VAVec3(t.transform.position.x, t.transform.position.y, -t.transform.position.z)); + VAUAdapter.VA.SetSoundReceiverOrientationVU(_ID, new VAVec3(view_ogl.x, view_ogl.y, view_ogl.z), new VAVec3(up_ogl.x, up_ogl.y, up_ogl.z)); } - void OnSoundReceiverAuralizationModeChanged(string AuraMode) + protected void OnSoundReceiverAuralizationModeChanged(string AuraMode) { - _VA.SetSoundReceiverAuralizationMode(_ID, AuraMode); + VAUAdapter.VA.SetSoundReceiverAuralizationMode(_ID, AuraMode); } private void OnDestroy() @@ -78,6 +75,6 @@ public class VAUSoundReceiver : MonoBehaviour { if (GetComponent() != null) GetComponent().AuraStringChanged -= OnSoundReceiverAuralizationModeChanged; - _VA.DeleteSoundReceiver(_ID); + VAUAdapter.VA.DeleteSoundReceiver(_ID); } }