Commit 9008aab1 authored by Maurice Tayeb Andreas's avatar Maurice Tayeb Andreas

Merge branch 'develop' of https://git.rwth-aachen.de/ita/VAUnity into develop

# Conflicts:
#	VAUListener.cs
parents fef0e60f 79ce0e30
using UnityEngine;
using System;
using System.Collections;
using VA;
public class VAUListener : MonoBehaviour {
public string listenername = "Listener";
public int maxreverbZones = 2;
public string VAAudioRenderer = "MyBinauralArtificialReverb";
private int Listener;
private VANet _VA = null;
private Quaternion q;
private Transform t;
private AudioReverbZone[] reverbZones;
private AudioReverbZone[] shadowReverbZones;
private double currentArtificialReverberationTime = 1;
public int ID
{
get
{
return Listener;
}
}
// Use this for initialization
void Start()
{
_VA = VAUAdapter.VA;
Listener = _VA.CreateListener(listenername, 0, VAUAdapter.DefaultHRIR);
listenername += " " + Listener;
_VA.SetListenerAuralizationMode(Listener, "all");
Debug.Log(listenername + " created");
_VA.SetListenerHRIRDataset(Listener, VAUAdapter.DefaultHRIR);
SetListenerPositionOrientation();
_VA.SetArtificalReverbarationTime(VAAudioRenderer, 2);
}
void OnEnable()
{
if (GetComponent<VAUAuralizationMode>() != null)
GetComponent<VAUAuralizationMode>().AuraStringChanged += OnListenerAuralizationModeChanged;
}
// Update is called once per frame
void Update ()
{
SetListenerPositionOrientation();
SetActiveReverbZones();
}
//uses the View- and Up-Vector to transmit the position of the listener to VA
void SetListenerPositionOrientation()
{
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.SetListenerPosition(Listener, t.transform.position.x, t.transform.position.y, -t.transform.position.z);
_VA.SetListenerOrientationVU(Listener, view_ogl.x, view_ogl.y, view_ogl.z, up_ogl.x, up_ogl.y, up_ogl.z);
}
void SetActiveReverbZones()
{
double actReverbTime = currentArtificialReverberationTime;
reverbZones = FindObjectsOfType(typeof(AudioReverbZone)) as AudioReverbZone[];
if (reverbZones == shadowReverbZones)
return;
if (reverbZones == null)
{
if (actReverbTime != currentArtificialReverberationTime)
_VA.SetArtificalReverbarationTime(VAAudioRenderer, actReverbTime);
return;
}
shadowReverbZones = reverbZones;
int i = 0;
foreach (AudioReverbZone reverbZone in reverbZones)
{
float actdistance = Vector3.Distance(reverbZone.transform.position, gameObject.transform.position);
if (actdistance < reverbZone.maxDistance)
{
if (i <= maxreverbZones)
{
actReverbTime += reverbZone.decayTime;
i++;
}
if (actdistance > reverbZone.minDistance)
{
}
}
}
if ( i > 0)
actReverbTime /= i;
if( actReverbTime != currentArtificialReverberationTime)
_VA.SetArtificalReverbarationTime(VAAudioRenderer, actReverbTime);
}
void OnListenerAuralizationModeChanged(string AuraMode)
{
_VA.SetListenerAuralizationMode(Listener, AuraMode);
}
void OnDisable()
{
if (GetComponent<VAUAuralizationMode>() != null)
GetComponent<VAUAuralizationMode>().AuraStringChanged -= OnListenerAuralizationModeChanged;
}
void OnDestroy()
{
if (_VA.IsConnected())
{
_VA.DeleteListener(Listener);
}
}
}
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