Updating internal class names and using more object-oriented approach

parent c0690de0
...@@ -2,10 +2,15 @@ ...@@ -2,10 +2,15 @@
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; 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; public bool OutputMuted = false;
[Tooltip("Control rendering output gain")]
public double OutputGain = 1.0; public double OutputGain = 1.0;
private bool OutputMutedShadow; private bool OutputMutedShadow;
...@@ -13,8 +18,8 @@ public class VAURendererController : MonoBehaviour ...@@ -13,8 +18,8 @@ public class VAURendererController : MonoBehaviour
void Start () void Start ()
{ {
VAUAdapter.VA.SetRenderingModuleMuted( RendererID, OutputMuted ); VAUAdapter.VA.SetRenderingModuleMuted( ID, OutputMuted );
VAUAdapter.VA.SetRenderingModuleGain( RendererID, OutputGain ); VAUAdapter.VA.SetRenderingModuleGain( ID, OutputGain );
OutputMutedShadow = OutputMuted; OutputMutedShadow = OutputMuted;
OutputGainShadow = OutputGain; OutputGainShadow = OutputGain;
...@@ -24,12 +29,12 @@ public class VAURendererController : MonoBehaviour ...@@ -24,12 +29,12 @@ public class VAURendererController : MonoBehaviour
{ {
if( OutputMuted != OutputMutedShadow ) if( OutputMuted != OutputMutedShadow )
{ {
VAUAdapter.VA.SetRenderingModuleMuted( RendererID, OutputMuted ); VAUAdapter.VA.SetRenderingModuleMuted( ID, OutputMuted );
OutputMutedShadow = OutputMuted; OutputMutedShadow = OutputMuted;
} }
if( OutputGain != OutputGainShadow ) if( OutputGain != OutputGainShadow )
{ {
VAUAdapter.VA.SetRenderingModuleGain( RendererID, OutputGain ); VAUAdapter.VA.SetRenderingModuleGain( ID, OutputGain );
OutputGainShadow = OutputGain; OutputGainShadow = OutputGain;
} }
} }
......
...@@ -2,19 +2,24 @@ ...@@ -2,19 +2,24 @@
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; 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; public bool OutputMuted = false;
[Tooltip("Control reproduction output gain")]
public double OutputGain = 1.0; public double OutputGain = 1.0;
private bool OutputMutedShadow; private bool OutputMutedShadow;
private double OutputGainShadow; private double OutputGainShadow;
void Start () void Start ()
{ {
VAUAdapter.VA.SetReproductionModuleMuted( ReproductionID, OutputMuted ); VAUAdapter.VA.SetReproductionModuleMuted( ID, OutputMuted );
VAUAdapter.VA.SetReproductionModuleGain( ReproductionID, OutputGain ); VAUAdapter.VA.SetReproductionModuleGain( ID, OutputGain );
OutputMutedShadow = OutputMuted; OutputMutedShadow = OutputMuted;
OutputGainShadow = OutputGain; OutputGainShadow = OutputGain;
...@@ -24,12 +29,12 @@ public class VAUReproductionController : MonoBehaviour ...@@ -24,12 +29,12 @@ public class VAUReproductionController : MonoBehaviour
{ {
if( OutputMuted != OutputMutedShadow ) if( OutputMuted != OutputMutedShadow )
{ {
VAUAdapter.VA.SetReproductionModuleMuted( ReproductionID, OutputMuted ); VAUAdapter.VA.SetReproductionModuleMuted( ID, OutputMuted );
OutputMutedShadow = OutputMuted; OutputMutedShadow = OutputMuted;
} }
if( OutputGain != OutputGainShadow ) if( OutputGain != OutputGainShadow )
{ {
VAUAdapter.VA.SetReproductionModuleGain( ReproductionID, OutputGain ); VAUAdapter.VA.SetReproductionModuleGain( ID, OutputGain );
OutputGainShadow = OutputGain; OutputGainShadow = OutputGain;
} }
} }
......
...@@ -4,19 +4,40 @@ using System.Collections; ...@@ -4,19 +4,40 @@ using System.Collections;
public class VAUAuralizationMode : MonoBehaviour public class VAUAuralizationMode : MonoBehaviour
{ {
[Tooltip("Toggle direct sound")]
public bool DirectSound = true; public bool DirectSound = true;
public bool EarlyReflections = false;
public bool DiffuseDecay = false; [Tooltip("Toggle early reflections")]
public bool SourceDirectivity = true; public bool EarlyReflections = false;
public bool AirAbsorption = false;
public bool AtmosphericTemporalVariations = false; [Tooltip("Toggle diffuse decay")]
public bool Scattering = false; public bool DiffuseDecay = false;
public bool Diffraction = false;
public bool NearFieldEffects = false; [Tooltip("Toggle source directivity")]
public bool DopplerShifts = true; 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; public bool SphericalSpreadingLoss = true;
private class AuralizationMode : System.Object protected class AuralizationMode : System.Object
{ {
public bool DirectSound = true; public bool DirectSound = true;
public bool EarlyReflections = true; public bool EarlyReflections = true;
...@@ -195,7 +216,7 @@ public class VAUAuralizationMode : MonoBehaviour ...@@ -195,7 +216,7 @@ public class VAUAuralizationMode : MonoBehaviour
AuraStringChanged(externAuraString); AuraStringChanged(externAuraString);
} }
AuralizationMode UpdateAuraModeSettings() protected AuralizationMode UpdateAuraModeSettings()
{ {
AuralizationMode am = new AuralizationMode(); AuralizationMode am = new AuralizationMode();
am.DirectSound = DirectSound; am.DirectSound = DirectSound;
......
...@@ -4,9 +4,16 @@ using UnityEngine; ...@@ -4,9 +4,16 @@ using UnityEngine;
public class VAUController : MonoBehaviour public class VAUController : MonoBehaviour
{ {
[Tooltip("Mute global input")]
public bool InputMuted = false; public bool InputMuted = false;
[Tooltip("Control global input gain")]
public double InputGain = 1.0; public double InputGain = 1.0;
[Tooltip("Mute global output")]
public bool OutputMuted = false; public bool OutputMuted = false;
[Tooltip("Control global output gain")]
public double OutputGain = 1.0; public double OutputGain = 1.0;
private bool InputMutedShadow; private bool InputMutedShadow;
......
...@@ -4,17 +4,12 @@ using System.Collections; ...@@ -4,17 +4,12 @@ using System.Collections;
using VA; using VA;
[Tooltip("A human listener that can receive sound and will be rendered by an audio renderer")] public class VAUListener : VAUSoundReceiver {
public class VAUListener : MonoBehaviour {
[Tooltip("Descriptive name")]
public string Name = "HumanListener";
[Tooltip("Number of reverbzones used for determining the current reverb.")] [Tooltip("Number of reverbzones used for determining the current reverb.")]
public int NumMaxReverbZones = 2; public int NumMaxReverbZones = 2;
public string VAAudioRenderer = "MyBinauralArtificialReverb"; public string VAAudioRenderer = "MyBinauralArtificialReverb";
[Tooltip("Add custom VAUHRIR dataset.")]
public VAUDirectivity HRIR = null;
[Tooltip("Anthropometric head width, for HRIR individualization or generic binaural cues")] [Tooltip("Anthropometric head width, for HRIR individualization or generic binaural cues")]
public double HeadWidth = 0.12; public double HeadWidth = 0.12;
...@@ -26,10 +21,7 @@ public class VAUListener : MonoBehaviour { ...@@ -26,10 +21,7 @@ public class VAUListener : MonoBehaviour {
private double ShadowHeadWidth; private double ShadowHeadWidth;
private double ShadowHeadHeight; private double ShadowHeadHeight;
private double ShadowHeadDepth; private double ShadowHeadDepth;
private int _ID;
private VANet _VA = null;
private Quaternion q; private Quaternion q;
private Transform t; private Transform t;
private AudioReverbZone[] reverbZones; private AudioReverbZone[] reverbZones;
...@@ -37,33 +29,24 @@ public class VAUListener : MonoBehaviour { ...@@ -37,33 +29,24 @@ public class VAUListener : MonoBehaviour {
public delegate void ReverbTimeChangedDelegate(double reverbTime); public delegate void ReverbTimeChangedDelegate(double reverbTime);
public event ReverbTimeChangedDelegate ReverbTimeChanged; public event ReverbTimeChangedDelegate ReverbTimeChanged;
public int ID
{
get
{
return _ID;
}
}
void Start() void Start()
{ {
_VA = VAUAdapter.VA; _ID = VAUAdapter.VA.CreateSoundReceiver(Name);
_ID = _VA.CreateSoundReceiver(Name); VAUAdapter.VA.SetSoundReceiverAuralizationMode(_ID, "all");
_VA.SetSoundReceiverAuralizationMode(_ID, "all"); if (Directivity)
if (HRIR) VAUAdapter.VA.SetSoundReceiverDirectivity(_ID, Directivity.ID);
_VA.SetSoundReceiverDirectivity(_ID, HRIR.ID);
else if( VAUAdapter.DefaultHRIRID != -1 ) 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; ShadowHeadWidth = HeadWidth;
ShadowHeadHeight = HeadHeight; ShadowHeadHeight = HeadHeight;
ShadowHeadDepth = HeadDepth; ShadowHeadDepth = HeadDepth;
SetSoundReceiverPositionOrientation(); SetSoundReceiverPositionOrientation();
_VA.SetArtificialReverberationTime(VAAudioRenderer, 0.3f); VAUAdapter.VA.SetArtificialReverberationTime(VAAudioRenderer, 0.3f);
reverbZones = FindObjectsOfType(typeof(AudioReverbZone)) as AudioReverbZone[]; reverbZones = FindObjectsOfType(typeof(AudioReverbZone)) as AudioReverbZone[];
} }
...@@ -80,27 +63,13 @@ public class VAUListener : MonoBehaviour { ...@@ -80,27 +63,13 @@ public class VAUListener : MonoBehaviour {
if( HeadWidth != ShadowHeadWidth || HeadHeight != ShadowHeadHeight || HeadDepth != ShadowHeadDepth ) if( HeadWidth != ShadowHeadWidth || HeadHeight != ShadowHeadHeight || HeadDepth != ShadowHeadDepth )
{ {
_VA.SetSoundReceiverAnthropometricData(_ID, HeadWidth, HeadHeight, HeadDepth); VAUAdapter.VA.SetSoundReceiverAnthropometricData(_ID, HeadWidth, HeadHeight, HeadDepth);
ShadowHeadWidth = HeadWidth; ShadowHeadWidth = HeadWidth;
ShadowHeadHeight = HeadHeight; ShadowHeadHeight = HeadHeight;
ShadowHeadDepth = HeadDepth; ShadowHeadDepth = HeadDepth;
} }
} }
// Uses the View- and Up-Vector to transmit the position of the listener to VA
void SetSoundReceiverPositionOrientation()
{
_VA = VAUAdapter.VA;
t = GetComponent<Transform>();
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() void SetActiveReverbZones()
{ {
if (reverbZones == null) if (reverbZones == null)
...@@ -131,9 +100,9 @@ public class VAUListener : MonoBehaviour { ...@@ -131,9 +100,9 @@ public class VAUListener : MonoBehaviour {
if (actReverbTime < 0.3f) if (actReverbTime < 0.3f)
_VA.SetRenderingModuleMuted("MyBinauralArtificialReverb", true); VAUAdapter.VA.SetRenderingModuleMuted("MyBinauralArtificialReverb", true);
else else
_VA.SetRenderingModuleMuted("MyBinauralArtificialReverb", false); VAUAdapter.VA.SetRenderingModuleMuted("MyBinauralArtificialReverb", false);
shadowReverbTime = actReverbTime; shadowReverbTime = actReverbTime;
...@@ -143,20 +112,7 @@ public class VAUListener : MonoBehaviour { ...@@ -143,20 +112,7 @@ public class VAUListener : MonoBehaviour {
if (ReverbTimeChanged != null) if (ReverbTimeChanged != null)
ReverbTimeChanged(actReverbTime); ReverbTimeChanged(actReverbTime);
_VA.SetArtificialReverberationTime(VAAudioRenderer, actReverbTime); VAUAdapter.VA.SetArtificialReverberationTime(VAAudioRenderer, actReverbTime);
}
void OnSoundReceiverAuralizationModeChanged(string AuraMode)
{
_VA.SetSoundReceiverAuralizationMode(_ID, AuraMode);
}
private void OnDestroy()
{
if (GetComponent<VAUAuralizationMode>() != null)
GetComponent<VAUAuralizationMode>().AuraStringChanged -= OnSoundReceiverAuralizationModeChanged;
_VA.DeleteSoundReceiver(_ID);
} }
} }
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
public class VAURendererArtificialReverb : VAURendererController public class VAURendererArtificialReverb : VAUAudioRenderer
{ {
public double RoomReverberationTime = 1.2; // s public double RoomReverberationTime = 1.2; // s
public double RoomSurfaceArea = 220.0; // m^2 public double RoomSurfaceArea = 220.0; // m^2
...@@ -14,9 +14,9 @@ public class VAURendererArtificialReverb : VAURendererController ...@@ -14,9 +14,9 @@ public class VAURendererArtificialReverb : VAURendererController
void Start () void Start ()
{ {
VAUAdapter.VA.SetArtificialReverberationTime( RendererID, RoomReverberationTime ); VAUAdapter.VA.SetArtificialReverberationTime( ID, RoomReverberationTime );
VAUAdapter.VA.SetArtificialSurfaceArea( RendererID, RoomSurfaceArea ); VAUAdapter.VA.SetArtificialSurfaceArea( ID, RoomSurfaceArea );
VAUAdapter.VA.SetArtificialRoomVolume( RendererID, RoomVolume ); VAUAdapter.VA.SetArtificialRoomVolume( ID, RoomVolume );
RoomReverberationTimeShadow = RoomReverberationTime; RoomReverberationTimeShadow = RoomReverberationTime;
RoomSurfaceAreaShadow = RoomSurfaceArea; RoomSurfaceAreaShadow = RoomSurfaceArea;
...@@ -27,17 +27,17 @@ public class VAURendererArtificialReverb : VAURendererController ...@@ -27,17 +27,17 @@ public class VAURendererArtificialReverb : VAURendererController
{ {
if( RoomReverberationTime != RoomReverberationTimeShadow ) if( RoomReverberationTime != RoomReverberationTimeShadow )
{ {
VAUAdapter.VA.SetArtificialReverberationTime( RendererID, RoomReverberationTime ); VAUAdapter.VA.SetArtificialReverberationTime( ID, RoomReverberationTime );
RoomReverberationTimeShadow = RoomReverberationTime; RoomReverberationTimeShadow = RoomReverberationTime;
} }
if( RoomSurfaceArea != RoomSurfaceAreaShadow ) if( RoomSurfaceArea != RoomSurfaceAreaShadow )
{ {
VAUAdapter.VA.SetArtificialSurfaceArea( RendererID, RoomSurfaceArea ); VAUAdapter.VA.SetArtificialSurfaceArea( ID, RoomSurfaceArea );
RoomSurfaceAreaShadow = RoomSurfaceArea; RoomSurfaceAreaShadow = RoomSurfaceArea;
} }
if( RoomVolume != RoomVolumeShadow ) if( RoomVolume != RoomVolumeShadow )
{ {
VAUAdapter.VA.SetArtificialRoomVolume( RendererID, RoomVolume ); VAUAdapter.VA.SetArtificialRoomVolume( ID, RoomVolume );
RoomVolumeShadow = RoomVolume; RoomVolumeShadow = RoomVolume;
} }
} }
......
...@@ -4,7 +4,6 @@ using System.Collections; ...@@ -4,7 +4,6 @@ using System.Collections;
using VA; using VA;
[Tooltip("Entity that can receive sound and will be rendered by an audio renderer")]
public class VAUSoundReceiver : MonoBehaviour { public class VAUSoundReceiver : MonoBehaviour {
[Tooltip("Descriptive name")] [Tooltip("Descriptive name")]
...@@ -16,8 +15,8 @@ public class VAUSoundReceiver : MonoBehaviour { ...@@ -16,8 +15,8 @@ public class VAUSoundReceiver : MonoBehaviour {
[Tooltip("Connect an directivity to this receiver")] [Tooltip("Connect an directivity to this receiver")]
public VAUDirectivity Directivity = null; public VAUDirectivity Directivity = null;
private int _ID; [Tooltip("Internal VA identifier")]
private VANet _VA = null; protected int _ID;
private Quaternion q; private Quaternion q;
private Transform t; private Transform t;
...@@ -32,13 +31,12 @@ public class VAUSoundReceiver : MonoBehaviour { ...@@ -32,13 +31,12 @@ public class VAUSoundReceiver : MonoBehaviour {
void Start() void Start()
{ {
_VA = VAUAdapter.VA; _ID = VAUAdapter.VA.CreateSoundReceiver(Name);
_ID = _VA.CreateSoundReceiver(Name); VAUAdapter.VA.SetSoundReceiverAuralizationMode(_ID, "all");
_VA.SetSoundReceiverAuralizationMode(_ID, "all"); if (Directivity)
if (HRIR) VAUAdapter.VA.SetSoundReceiverDirectivity(_ID, Directivity.ID);
_VA.SetSoundReceiverDirectivity(_ID, HRIR.ID);
else if( VAUAdapter.DefaultHRIRID != -1 ) else if( VAUAdapter.DefaultHRIRID != -1 )
_VA.SetSoundReceiverDirectivity(_ID, VAUAdapter.DefaultHRIRID); VAUAdapter.VA.SetSoundReceiverDirectivity(_ID, VAUAdapter.DefaultHRIRID);
SetSoundReceiverPositionOrientation(); SetSoundReceiverPositionOrientation();
} }
...@@ -55,22 +53,21 @@ public class VAUSoundReceiver : MonoBehaviour { ...@@ -55,22 +53,21 @@ public class VAUSoundReceiver : MonoBehaviour {
} }
// Uses the View- and Up-Vector to transmit the position of the listener to VA // 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<Transform>(); t = GetComponent<Transform>();
q = t.rotation; q = t.rotation;
Vector3 up = q * Vector3.up; Vector3 up = q * Vector3.up;
Vector3 view = q * Vector3.forward; Vector3 view = q * Vector3.forward;
Vector3 view_ogl = new Vector3(view.x, view.y, -view.z); Vector3 view_ogl = new Vector3(view.x, view.y, -view.z);
Vector3 up_ogl = new Vector3(up.x, up.y, -up.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 )); VAUAdapter.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.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() private void OnDestroy()
...@@ -78,6 +75,6 @@ public class VAUSoundReceiver : MonoBehaviour { ...@@ -78,6 +75,6 @@ public class VAUSoundReceiver : MonoBehaviour {
if (GetComponent<VAUAuralizationMode>() != null) if (GetComponent<VAUAuralizationMode>() != null)
GetComponent<VAUAuralizationMode>().AuraStringChanged -= OnSoundReceiverAuralizationModeChanged; GetComponent<VAUAuralizationMode>().AuraStringChanged -= OnSoundReceiverAuralizationModeChanged;
_VA.DeleteSoundReceiver(_ID); VAUAdapter.VA.DeleteSoundReceiver(_ID);
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment