Progress

parent 84400381
......@@ -8,14 +8,16 @@ using VA;
// Adapter to VA (singleton)
public class VAUAdapter : MonoBehaviour
{
public static string Server = "localhost";
public static int Port = 12340;
public static string AdditionalSearchPath = ""; // Provide further paths where VA should look for audio files, directivities and HRIRs.
public static bool ResetOnAwake = true;
public static bool DeactivateUnitySoundOnAwake = true;
public static string HostIP = "localhost";
public static string GlobalAuralizationMode = "all";
public static string DefaultHRIRPath = "$(DefaultHRIR)";
private static int Port = 12340;
private static string DefaultHRIRPath = "$(DefaultHRIR)";
private static int _DefaultHRIRID;
private static int _DefaultHRIRID = -1;
private static VANet _VA = null;
// No public construction allowed
......@@ -30,7 +32,6 @@ public class VAUAdapter : MonoBehaviour
_VA = new VANet();
Init();
}
return _VA;
}
}
......@@ -39,10 +40,28 @@ public class VAUAdapter : MonoBehaviour
{
if (!_VA.IsConnected())
{
_VA.Connect(HostIP, Port);
_VA.Reset();
_VA.SetGlobalAuralizationMode(GlobalAuralizationMode);
_DefaultHRIRID = _VA.LoadHRIRDataset(DefaultHRIRPath, "UnityDefaultHRIR");
if (!_VA.Connect(Server, Port))
{
Debug.LogError("Could not connect to VA server on " + Server + " using port " + Port);
return;
}
// Add Asset folder as search path for VA (only works if VA is running on same host PC)
if (!_VA.AddSearchPath(Application.dataPath))
Debug.LogError("Could not add application assets folder to VA search path, VA server running on remote host?");
if (AdditionalSearchPath.Length > 0)
{
_VA.AddSearchPath(AdditionalSearchPath);
// ... append more if required.
}
if (ResetOnAwake)
_VA.Reset();
if (DefaultHRIRPath.Length > 0)
_DefaultHRIRID = _VA.LoadHRIRDataset(DefaultHRIRPath, "UnityDefaultHRIR");
}
}
......@@ -53,19 +72,17 @@ public class VAUAdapter : MonoBehaviour
return _DefaultHRIRID;
}
}
// Use this for initialization
void Awake()
{
if (_VA==null)
if (_VA == null)
_VA = new VANet();
Init();
DeactivateUnitySound();
// Add Asset folder
_VA.AddSearchPath(Application.dataPath);
if (DeactivateUnitySoundOnAwake)
DeactivateUnitySound();
}
void OnEnable()
......@@ -81,9 +98,12 @@ public class VAUAdapter : MonoBehaviour
void OnDisable()
{
// @todo: probably better to remove these objects directly in C# scripts.
VAUSoundSource[] SoundSources = FindObjectsOfType<VAUSoundSource>();
foreach (VAUSoundSource SoundSource in SoundSources)
{
_VA.SetSoundSourceSignalSource(SoundSource.ID, "");
_VA.DeleteSoundSource(SoundSource.ID);
}
......@@ -96,7 +116,6 @@ public class VAUAdapter : MonoBehaviour
GetComponent<VAUAuralizationMode>().AuraStringChanged -= OnGlobalAuralizationModeChanged;
_VA.Disconnect();
}
void DeactivateUnitySound()
......
......@@ -2,25 +2,29 @@
using System.Collections.Generic;
using UnityEngine;
public class VAUAudiofileSignalSource : VAUSignalSource {
public string FilePath;
public string Name;
public bool IsLooping = true;
public bool PlayOnStart = true;
// Use this for initialization
public class VAUAudiofileSignalSource : VAUSignalSource
{
public string FilePath; // Absolute or relative path to audio file (relative to Assets folder or any folder added to search path using AddSearchPath)
public string Name; // Versatile name
public bool IsLooping = true; // Will loop the audio signal source
public bool PlayOnStart = true; // Will immediately start the signal source payback
void Awake()
{
_ID = VAUAdapter.VA.CreateAudiofileSignalSource(FilePath, Name);
Debug.Assert(_ID.Length > 0);
Debug.Assert(_ID.Length > 0, "Could not create audio file signal source '" + Name + "' file from path " + FilePath);
}
// Use this for initialization
void Start()
{
VAUAdapter.VA.SetAudiofileSignalSourceIsLooping(_ID, IsLooping);
if( PlayOnStart )
if (PlayOnStart)
VAUAdapter.VA.SetAudiofileSignalSourcePlaybackAction(_ID, "PLAY");
}
void OnDestroy()
{
if (_ID.Length > 0)
VAUAdapter.VA.DeleteSignalSource(_ID);
}
}
using UnityEngine;
using System.Collections;
public class VAUAuralizationMode : MonoBehaviour {
public class VAUAuralizationMode : MonoBehaviour
{
public bool DirectSound = true;
public bool EarlyReflections = false;
......@@ -15,7 +16,7 @@ public class VAUAuralizationMode : MonoBehaviour {
public bool DopplerShifts = true;
public bool SphericalSpreadingLoss = true;
private class AuralizationMode
private class AuralizationMode : System.Object
{
public bool DirectSound = true;
public bool EarlyReflections = true;
......@@ -29,33 +30,43 @@ public class VAUAuralizationMode : MonoBehaviour {
public bool DopplerShifts = true;
public bool SphericalSpreadingLoss = true;
public static bool operator ==(AuralizationMode left, AuralizationMode right)
public override bool Equals(System.Object other)
{
return (GetHashCode() == other.GetHashCode());
}
override public int GetHashCode()
{
int iCompare = 0;
iCompare += left.DirectSound != right.DirectSound ? 1 : 0;
iCompare += left.EarlyReflections != right.EarlyReflections ? 1 : 0;
iCompare += left.DiffuseDecay != right.DiffuseDecay ? 1 : 0;
iCompare += left.SourceDirectivity != right.SourceDirectivity ? 1 : 0;
iCompare += left.AirAbsorption != right.AirAbsorption ? 1 : 0;
iCompare += left.AtmosphericTemporalVariations != right.AtmosphericTemporalVariations ? 1 : 0;
iCompare += left.Scattering != right.Scattering ? 1 : 0;
iCompare += left.Diffraction != right.Diffraction ? 1 : 0;
iCompare += left.NearFielEffects != right.NearFielEffects ? 1 : 0;
iCompare += left.DopplerShifts != right.DopplerShifts ? 1 : 0;
iCompare += left.SphericalSpreadingLoss != right.SphericalSpreadingLoss ? 1 : 0;
return ( iCompare == 0 );
iCompare += DirectSound ? 1 << 1 : 0;
iCompare += EarlyReflections ? 1 << 2 : 0;
iCompare += DiffuseDecay ? 1 << 3 : 0;
iCompare += SourceDirectivity ? 1 << 4 : 0;
iCompare += AirAbsorption ? 1 << 5 : 0;
iCompare += AtmosphericTemporalVariations ? 1 << 6 : 0;
iCompare += Scattering ? 1 << 7 : 0;
iCompare += Diffraction ? 1 << 8 : 0;
iCompare += NearFielEffects ? 1 << 9 : 0;
iCompare += DopplerShifts ? 1 << 10 : 0;
iCompare += SphericalSpreadingLoss ? 1 << 11 : 0;
return iCompare;
}
public static bool operator ==(AuralizationMode left, AuralizationMode right)
{
return left.Equals(right);
}
public static bool operator !=(AuralizationMode left, AuralizationMode right)
{
return !(left == right);
return !(left.Equals(right));
}
}
private AuralizationMode AuraModeShadow = new AuralizationMode();
public delegate void OnAuraStringChangedDelegate(string sAuraString);
public event OnAuraStringChangedDelegate AuraStringChanged;
......@@ -70,7 +81,7 @@ public class VAUAuralizationMode : MonoBehaviour {
if (AuraMode.DirectSound != AuraModeShadow.DirectSound)
{
AuraString = AuraMode.DirectSound ? "+DS" : "-DS";
AuraString = AuraMode.DirectSound ? "+DS" : "-DS";
AuraModeShadow.DirectSound = AuraMode.DirectSound;
if (AuraStringChanged != null)
AuraStringChanged(AuraString);
......@@ -183,6 +194,7 @@ public class VAUAuralizationMode : MonoBehaviour {
if (externAuraString == "-SL") SphericalSpreadingLoss = false;
AuraStringChanged(externAuraString);
}
AuralizationMode UpdateAuraModeSettings()
{
AuralizationMode am = new AuralizationMode();
......
......@@ -4,9 +4,9 @@ using UnityEngine;
public class VAUDirectivity : MonoBehaviour {
protected int _ID = -1;
public string Path = "";
public string Name = "";
protected int _ID = -1; // Stores the internal id that is assigned by VA
public string FilePath = ""; // Absolute or relative path (relative to Assets folder), also use AddSearchPath for special folders.
public string Name = ""; // Versatile name for this directivity
public int ID
{
......@@ -15,16 +15,17 @@ public class VAUDirectivity : MonoBehaviour {
return _ID;
}
}
// Use this for initialization
void Start ()
{
if (Path.Length > 0)
_ID = VAUAdapter.VA.LoadDirectivity(Path, Name);
}
// Update is called once per frame
void Update () {
if (FilePath.Length > 0)
_ID = VAUAdapter.VA.LoadDirectivity(FilePath, Name);
}
private void OnDestroy()
{
if (_ID != -1)
VAUAdapter.VA.FreeDirectivity(_ID);
_ID = -1;
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class VAUHRIRDataset : MonoBehaviour {
protected int _ID = -1; // ID assigned by VA
public string FilePath = ""; // Absolute or relative file path (relative to Assets folder or any folder added to search path using AddSearchPath)
public string Name = ""; // Versatile name
public int ID
{
get
{
return _ID;
}
}
// Use this for initialization
void Start ()
{
if (FilePath.Length > 0)
_ID = VAUAdapter.VA.LoadHRIRDataset(FilePath, Name);
}
private void OnDestroy()
{
if (_ID != -1)
VAUAdapter.VA.FreeHRIRDataset(_ID);
_ID = -1;
}
}
......@@ -126,9 +126,6 @@ public class VAUListener : MonoBehaviour {
void OnDestroy()
{
if (_VA.IsConnected())
{
_VA.DeleteListener(Listener);
}
_VA.DeleteListener(Listener);
}
}
......@@ -4,7 +4,7 @@ using UnityEngine;
public class VAUSignalSource : MonoBehaviour {
protected string _ID = "";
protected string _ID = ""; // Identifier string that is either assigned by VA for a managed (dynamic) signal source, or selected string for an unmanaged signal source (like live input)
public string ID
{
......
......@@ -14,7 +14,7 @@ public class VAUSoundSource : MonoBehaviour
private int _ID;
private Quaternion q;
private Transform t;
private string _AudiofileSignalSource;
private string _AudiofileSignalSource = null;
public int ID
{
......@@ -57,7 +57,7 @@ public class VAUSoundSource : MonoBehaviour
bool PlayOnAwake = GetComponent<AudioSource>().playOnAwake;
_AudiofileSignalSource = _VA.CreateAudiofileSignalSource(FilePath, Name);
Debug.Assert(_AudiofileSignalSource.Length > 0);
Debug.Assert(_AudiofileSignalSource.Length > 0, "Could not create integrated audio file signal source '" + Name + "' file from path " + FilePath);
_VA.SetAudiofileSignalSourceIsLooping(_AudiofileSignalSource, IsLooping);
if (PlayOnAwake)
_VA.SetAudiofileSignalSourcePlaybackAction(_AudiofileSignalSource, "play");
......@@ -119,10 +119,11 @@ public class VAUSoundSource : MonoBehaviour
_VA = VAUAdapter.VA;
if (_VA.IsConnected())
{
_VA.SetSoundSourceSignalSource(_ID, "");
_VA.DeleteSoundSource(_ID);
// Temptative signal source deletion
if (_AudiofileSignalSource.Length > 0)
if (_AudiofileSignalSource != null)
_VA.DeleteSignalSource(_AudiofileSignalSource);
}
}
......
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