Updating internal class names and using more object-oriented approach

parent c0690de0
......@@ -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;
}
}
......
......@@ -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;
}
}
......
......@@ -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;
......
......@@ -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;
......
......@@ -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<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()
{
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<VAUAuralizationMode>() != null)
GetComponent<VAUAuralizationMode>().AuraStringChanged -= OnSoundReceiverAuralizationModeChanged;
VAUAdapter.VA.SetArtificialReverberationTime(VAAudioRenderer, actReverbTime);
_VA.DeleteSoundReceiver(_ID);
}
}
......@@ -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;
}
}
......
......@@ -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<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 ));
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<VAUAuralizationMode>() != null)
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