Skip to content
Snippets Groups Projects
Commit 64db29c6 authored by Carolin Breuer's avatar Carolin Breuer
Browse files

update for package integration

parent cae6db2a
Branches
No related tags found
No related merge requests found
Showing
with 617 additions and 245 deletions
*.meta
#*.meta
HTML
*.bat
*.mat
......
fileFormatVersion: 2
guid: 7ac734e542f63904084c02b6f63b9a6c
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
</state>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ContentModelStore">
<e p="C:\Users\reimers\AppData\Local\JetBrains\Rider2020.2\extResources" t="IncludeRecursive" />
<e p="C:\Users\reimers\AppData\Local\JetBrains\Rider2020.2\resharper-host\Local\Transient\Rider\v202\SolutionCaches\_.19.00" t="ExcludeRecursive" />
<e p="D:\VR\Unity\vaunity_package\Runtime\VAUnity\AudioSource" t="IncludeFlat" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ContentModelUserStore">
<attachedFolders />
<explicitIncludes />
<explicitExcludes />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/.idea.AudioSource.dir/riderModule.iml" filepath="$PROJECT_DIR$/.idea/.idea.AudioSource.dir/riderModule.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RiderProjectSettingsUpdater">
<option name="vcsConfiguration" value="2" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="BranchesTreeState">
<expand>
<path>
<item name="ROOT" type="e8cecc67:BranchNodeDescriptor" />
<item name="LOCAL_ROOT" type="e8cecc67:BranchNodeDescriptor" />
</path>
<path>
<item name="ROOT" type="e8cecc67:BranchNodeDescriptor" />
<item name="REMOTE_ROOT" type="e8cecc67:BranchNodeDescriptor" />
</path>
<path>
<item name="ROOT" type="e8cecc67:BranchNodeDescriptor" />
<item name="REMOTE_ROOT" type="e8cecc67:BranchNodeDescriptor" />
<item name="GROUP_NODE:origin" type="e8cecc67:BranchNodeDescriptor" />
</path>
<path>
<item name="ROOT" type="e8cecc67:BranchNodeDescriptor" />
<item name="REMOTE_ROOT" type="e8cecc67:BranchNodeDescriptor" />
<item name="GROUP_NODE:origin" type="e8cecc67:BranchNodeDescriptor" />
<item name="GROUP_NODE:features" type="e8cecc67:BranchNodeDescriptor" />
</path>
</expand>
<select />
</component>
<component name="ChangeListManager">
<list default="true" id="64cf1d69-50fd-47e5-95ca-1d6d45ea73a8" name="Default Changelist" comment="" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$/.." />
</component>
<component name="HighlightingSettingsPerFile">
<setting file="file://$PROJECT_DIR$/../VAUnity.cs" root0="SKIP_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/VAUSoundSourceGeneric.cs" root0="SKIP_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/../VAStarter.cs" root0="SKIP_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/VAUSoundSource.cs" root0="SKIP_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/../../VACS.cs" root0="SKIP_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/VAUSignalSourceAudioFile.cs" root0="SKIP_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/../Utils/VAUObject.cs" root0="SKIP_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/../VAAdapter.cs" root0="SKIP_HIGHLIGHTING" />
</component>
<component name="ProjectId" id="2EzCucslvLFR4leg0EkGKMaI4jy" />
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent">
<property name="RunOnceActivity.OpenProjectViewOnStart" value="true" />
<property name="WebServerToolWindowFactoryState" value="false" />
<property name="vue.rearranger.settings.migration" value="true" />
</component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="64cf1d69-50fd-47e5-95ca-1d6d45ea73a8" name="Default Changelist" comment="" />
<created>1663589252937</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1663589252937</updated>
<workItem from="1663589255737" duration="1770000" />
</task>
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="3" />
</component>
<component name="UnityProjectConfiguration" hasMinimizedUI="null" />
<component name="UnityUnitTestConfiguration" currentTestLauncher="NUnit" />
<component name="Vcs.Log.Tabs.Properties">
<option name="TAB_STATES">
<map>
<entry key="MAIN">
<value>
<State />
</value>
</entry>
</map>
</option>
</component>
<component name="VcsManagerConfiguration">
<option name="CLEAR_INITIAL_COMMIT_MESSAGE" value="true" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="RIDER_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$/../.." />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
......@@ -2,16 +2,29 @@
namespace VAUnity
{
public abstract class VAUSignalSource : MonoBehaviour {
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 abstract class VAUSignalSource : VAUObject<string>
{
public abstract bool IsLooping { get; }
public string ID
public virtual void Play()
{
get
_va.SetSignalSourceBufferPlaybackAction(_id, "play");
}
public virtual void Pause()
{
return _ID;
_va.SetSignalSourceBufferPlaybackAction(_id, "pause");
}
public virtual void Stop()
{
_va.SetSignalSourceBufferPlaybackAction(_id, "stop");
}
void OnDestroy()
{
if (_id.Length > 0)
_va.DeleteSignalSource(_id);
}
}
}
fileFormatVersion: 2
guid: 58e93aab6f5f1c34f99dc99c16fabaff
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using UnityEditor.VersionControl;
using UnityEngine;
using VA;
using UnityEngine;
using System.IO;
namespace VAUnity
{
public class VAUSignalSourceAudioFile : VAUSignalSource
{
[Tooltip("Absolute or relative file path (relative to Assets folder or any folder added to search path using AddSearchPath)")]
public string FilePath;
[Tooltip("Absolute or relative file path (relative to project Root folder, Package folder or any folder added to search path using AddSearchPath)")]
[SerializeField] private string filePath;
public string Name; // Versatile name
[Tooltip("Will loop the audio signal source.")]
public bool IsLooping = true;
[Tooltip("Will immediately start the signal source payback.")]
public bool PlayOnStart = true;
[Tooltip("Playback state")]
public string PlaybackState = "invalid";
public bool isLooping = true;
private VANet _va = null;
public override bool IsLooping => isLooping;
void OnEnable()
protected override void Awake()
{
if (!_va.IsConnected())
{
Debug.LogError( "Could not enable signal source '" + FilePath + "', not connected to VA" );
return;
}
_ID = _va.CreateSignalSourceBufferFromFile(FilePath, Name);
Debug.Assert(_ID.Length > 0, "Could not create audio file signal source '" + Name + "' from file path " + FilePath);
//Debug.Log("Created audio file signal source with id '" + _ID + "'");
_va.SetSignalSourceBufferLooping (_ID, IsLooping);
}
void Start()
{
_va = VAUnity.VA;
if (PlayOnStart)
{
_va.SetSignalSourceBufferPlaybackAction(_ID, "PLAY");
}
base.Awake();
UpdatePlaybackState();
}
//GetAbsolutePath();
void OnDestroy()
{
if (_ID.Length > 0)
_va.DeleteSignalSource(_ID);
}
_id = _va.CreateSignalSourceBufferFromFile(filePath, name);
Debug.Assert(_id.Length > 0, "Could not create audio file signal source '" + name + "' from file path " + filePath);
void Update()
{
UpdatePlaybackState();
//Debug.Log("Current play state for signal souce " + _ID + ": " + VAUAdapter.VA.GetSignalSourceBufferPlaybackState(_ID));
//Debug.Log("Created audio file signal source with id '" + _ID + "'");
_va.SetSignalSourceBufferLooping (_id, isLooping);
}
private void UpdatePlaybackState()
/// <summary>
/// Get the direct path to the VA Server
/// </summary>
private void GetAbsolutePath()
{
if (_ID.Length > 0)
PlaybackState = _va.GetSignalSourceBufferPlaybackState(_ID);
filePath = Path.GetFullPath(filePath);
Debug.Log("SignalSourceAudioFile absolute path:" + filePath);
}
}
}
fileFormatVersion: 2
guid: 4b4e9418285005b45b89a3d7ea1611fb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System;
using UnityEngine;
using VA;
using UnityEngine.Events;
namespace VAUnity
{
public class VAUSoundSource : VAUSoundObject
/// <summary>
/// Abstract Sound Source Interface with basic functionality for sound sources, e.g. updating position and
/// orientation, handling Directivity, handling volume and mute updates.
/// </summary>
public abstract class VAUSoundSource : VAUSoundObject
{
[Tooltip("Activate this if you want to validate & change volume and mute/unmute state on every update loop.")]
public bool ContinuousGainObserver = false;
[Tooltip("Set an explicit renderer for this source")]
[SerializeField] protected VAUAudioRenderer audioRenderer;
[Tooltip("Activate this if you dont want to pause the playback while the SoundSource is disabled but rather stop it.")]
public bool stopOnDisable = false;
[Tooltip("custom VAUDirectivity Script.")]
[SerializeField] protected VAUDirectivity directivity = null;
[Tooltip("Insert a custom VAUDirectivity-Script.")]
public VAUDirectivity Directivity = null;
[Tooltip("Invoke Event if sound state is changing from not playing to playing. Not effected by mute.")]
[SerializeField] public UnityEvent onSoundStart;
[Tooltip("Insert a custom VAUSignalSource-Script.")]
public VAUSignalSource SignalSource = null;
[Tooltip("Invoke Event if sound state is changing from playing to not playing. Not effected by mute.")]
[SerializeField] public UnityEvent onSoundStops;
[Tooltip("Set an explicit renderer for this source [todo]")]
public VAUAudioRenderer Renderer = null;
// todo Set an explicit renderer for this source
// [Tooltip("Set an explicit renderer for this source")]
// public VAUAudioRenderer Renderer = null;
public void SetDirectivity(VAUDirectivity directivity)
{
this.directivity = directivity;
}
[Tooltip("Sound power in Watts (default is 31mW)")]
public double SoundPower = 0.0031;
public abstract bool IsLooping { get; }
public abstract string SignalSourceId { get; }
private VANet _va = null;
private string _AudiofileSignalSource = null;
protected bool _isPlaying = false;
private float _volumeShadow;
private bool _muteShadow;
/// <summary>
/// Play Sound Source
/// </summary>
public virtual void Play()
{
onSoundStart?.Invoke();
_isPlaying = true;
}
void Start()
/// <summary>
/// Pause Sound Source
/// </summary>
public virtual void Pause()
{
_va = VAUnity.VA;
_isPlaying = false;
onSoundStops?.Invoke();
}
if (!_va.IsConnected())
/// <summary>
/// Stop Sound Source
/// </summary>
public virtual void Stop()
{
Debug.LogError( "Could not create sound source, not connected to VA" );
return;
_isPlaying = false;
onSoundStops?.Invoke();
}
// Add sound source
_ID = _va.CreateSoundSource(this.name);
_va.SetSoundSourceAuralizationMode(_ID, "all");
_va.SetSoundSourceSoundPower (_ID, SoundPower);
// Connect to directivity, if linked or attached
if (Directivity)
_va.SetSoundSourceDirectivity(_ID, Directivity.ID);
else if (GetComponent<VAUDirectivity>())
_va.SetSoundSourceDirectivity(_ID, GetComponent<VAUDirectivity>().ID);
/// <summary>
/// if signal source is playing back or not
/// </summary>
/// <returns>true if sound source in VA is running and false if not</returns>
public abstract bool GetPlaybackState();
// Connect to signal source, if linked or attached
if (SignalSource)
/// <summary>
/// Helper to see if signal source is playing back or not
/// </summary>
/// <param name="signalSourceId">input SignalSource</param>
/// <returns>true if sound source in VA is running and false if not</returns>
protected bool GetPlaybackState(string signalSourceId)
{
_va.SetSoundSourceSignalSource(_ID, SignalSource.ID);
}
else
var state= _va.GetSignalSourceBufferPlaybackState(signalSourceId);
switch (state)
{
Debug.LogError("Signal Source not found", this);
case "PLAYING":
return true;
case "STOPPED":
case "PAUSED":
return false;
default:
Debug.LogError("Invalid Signal source State: "+state,this);
return false;
}
// Initially, set the pose (otherwise rendering module can not spatialize)
SetSoundSourcePositionOrientation();
}
// Update is called once per frame
void Update()
/// <summary>
/// Returns Signal Source ID
/// </summary>
/// <returns>signal source Id</returns>
public string GetSignalSourceFromSoundSource()
{
SetSoundSourcePositionOrientation();
return _va.GetSoundSourceSignalSource(_id);
}
if (ContinuousGainObserver)
/// <summary>
/// Set Mute Status of Sound Source
/// </summary>
/// <param name="mute"></param>
public void SetMuted(bool mute)
{
_va.SetSoundSourceMuted(_ID, GetComponent<AudioSource>().mute);
_va.SetSoundSourceSoundPower(_ID, GetComponent<AudioSource>().volume * 31.69e-3 ); // Volume of 1.0 results in default sound power: 31.67 mW -> 94 dB SPL @ 1m
}
_va.SetSoundSourceMuted(_id, mute);
_muteShadow = mute;
}
void SetSoundSourcePositionOrientation()
/// <summary>
/// create SoundSource
/// </summary>
protected override void Awake()
{
base.Awake();
SetSoundReceiverPositionOrientation(out var vaPosition, out var vaOrientationView,
out var vaOrientationUp);
VAUnity.VA.SetSoundSourcePosition(_ID, vaPosition);
VAUnity.VA.SetSoundSourceOrientationVU(_ID, vaOrientationView, vaOrientationUp);
// _id = _va.CreateSoundSource(this.name);
}
/// <summary>
/// Set Initial Position and Orientation + Add Directivity
/// </summary>
protected virtual void Start()
{
// Do not create SoundSource in Awake(), it might depend on an uninitialized Renderer!
if (audioRenderer == null || !audioRenderer.IsSoundSourceExplicitRenderer)
_id =_va.CreateSoundSource(Name);
else
_id = audioRenderer.CreateSoundSourceExplicitRenderer();
if (directivity)
_va.SetSoundSourceDirectivity(_id, directivity.ID);
else if (GetComponent<VAUDirectivity>())
_va.SetSoundSourceDirectivity(_id, GetComponent<VAUDirectivity>().ID);
public void OnDisable()
// Initially, set the pose (otherwise rendering module can not spatialize)
SetSoundSourcePositionOrientation();
}
/// <summary>
/// Update Position and Orientation if changed
/// </summary>
protected virtual void Update()
{
if (transform.hasChanged)
SetSoundSourcePositionOrientation();
transform.hasChanged = false;
if (_isPlaying && !IsLooping)
{
if (GetPlaybackState()) return;
_isPlaying = false;
onSoundStops?.Invoke();
if (_AudiofileSignalSource != null) {
if (stopOnDisable)
_va.SetSignalSourceBufferPlaybackAction (_AudiofileSignalSource, "stop");
else
_va.SetSignalSourceBufferPlaybackAction (_AudiofileSignalSource, "pause");
}
}
private void OnDestroy()
/// <summary>
/// Stop and delete Signal source and sound source at the end
/// </summary>
protected virtual void OnDestroy()
{
//_VA = VAUnity.VA;
if (_va.IsConnected())
{
_va.SetSoundSourceSignalSource(_ID, "");
Stop();
_va.SetSoundSourceSignalSource(_id, "");
_va.DeleteSoundSource(ID);
// Temptative signal source deletion
if (_AudiofileSignalSource != null)
_va.DeleteSignalSource (_AudiofileSignalSource);
}
}
// Starts Playback
public void Play()
/// <summary>
/// Updates Sound Source Position Orientation
/// </summary>
private void SetSoundSourcePositionOrientation()
{
_va.SetSignalSourceBufferPlaybackAction(SignalSource.ID, "play");
SetSoundReceiverPositionOrientation(out var vaPosition, out var vaOrientationView,
out var vaOrientationUp);
_va.SetSoundSourcePosition(_id, vaPosition);
_va.SetSoundSourceOrientationVU(_id, vaOrientationView, vaOrientationUp);
}
// Stopps Playback
public void Stop()
/// <summary>
/// Updates Sound Volume and mute unmute on change
/// </summary>
/// <param name="volumeWatts">volume in watts</param>
/// <param name="mute">is muted</param>
/// <param name="forceUpdate">update without comparing to last values.</param>
protected void UpdateSoundSource(float volumeWatts, bool mute, bool forceUpdate = false)
{
_va.SetSignalSourceBufferPlaybackAction(SignalSource.ID, "stop");
}
// Mutes Sound Source
public void SetMuted(bool bMute)
if (Math.Abs(_volumeShadow - volumeWatts) > 1e-5 || forceUpdate)
{
_va.SetSoundSourceMuted(_ID, bMute);
_va.SetSoundSourceSoundPower(_id, volumeWatts);
_volumeShadow = volumeWatts;
}
// Returns Playback state as string (PLAYING or STOPPED)
public string GetPlaybackState()
if (_muteShadow != mute || forceUpdate)
{
return _va.GetSignalSourceBufferPlaybackState(SignalSource.ID);
_va.SetSoundSourceMuted(_id, mute);
_muteShadow = mute;
}
public string GetSignalSource()
{
return _va.GetSoundSourceSignalSource(Int32.Parse(SignalSource.ID));
}
public void SetSignalSource(VAUSignalSource newSignalSource)
{
if (!newSignalSource || newSignalSource == SignalSource) return;
SignalSource = newSignalSource;
_va.SetSoundSourceSignalSource(_ID, SignalSource.ID);
}
}
}
fileFormatVersion: 2
guid: fe3a41401d1ffe34aa7a4aede47d3579
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System;
using UnityEditor;

using UnityEngine;
using UnityEngine.Serialization;
namespace VAUnity
{
/// <summary>
/// Create a Sound Source and Signal Source in VA based on the Audio Source in Unity.
/// injected properties are volume (gain converted to watts), mute status, audio clip, loop, playOnAwake
/// </summary>
[RequireComponent(typeof(AudioSource))]
public class VAUSoundSourceAudioSource : VAUSoundObject
public class VAUSoundSourceAudioSource : VAUSoundSource
{
// [Tooltip("Activate this if you want to validate & change volume and mute/unmute state on every update loop.")]
[Tooltip("Insert a custom VAUDirectivity-Script.")]
public VAUDirectivity Directivity = null;
private string _AudiofileSignalSource = null;
private string _signalSourceId = null;
private AudioSource _audioSource;
public override bool IsLooping => _audioSource.loop;
public override string SignalSourceId => _signalSourceId;
public string audioFileForTesting = "";
private float _volumeShadow;
private bool _muteShadow;
private void Awake()
protected override void Awake()
{
base.Awake();
_audioSource = GetComponent<AudioSource>();
}
void Start()
{
_VA = VAUnity.VA;
if (!_VA.IsConnected())
/// <summary>
/// Init Sound Source and Signal Source in VA
/// </summary>
protected override void Start()
{
Debug.LogError("Could not create sound source, not connected to VA");
return;
}
// Add sound source
_ID = _VA.CreateSoundSource(this.name);
// Connect to directivity, if linked or attached
if (Directivity)
_VA.SetSoundSourceDirectivity(_ID, Directivity.ID);
else if (GetComponent<VAUDirectivity>())
_VA.SetSoundSourceDirectivity(_ID, GetComponent<VAUDirectivity>().ID);
// Volume of 1.0 results in default sound power: 31.67 mW -> 94 dB SPL @ 1m
//UpdateSoundSource(_audioSource.volume * 31.69e-3f, _audioSource.mute, true);
// Set gain control once
UpdateSoundSource(true);
base.Start();
// Create and connect audio signal source
if (_audioSource.clip)
{
var filePath = _audioSource.clip.name + ".wav";
var sName = this.name + "_signal";
var isLooping = _audioSource.loop;
var playOnAwake = _audioSource.playOnAwake;
_AudiofileSignalSource = _VA.CreateSignalSourceBufferFromFile(filePath, sName);
Debug.Assert(_AudiofileSignalSource.Length > 0,
"Could not create integrated audio file signal source '" + sName + "' file from path " + filePath);
_VA.SetSignalSourceBufferLooping(_AudiofileSignalSource, isLooping);
if (playOnAwake)
_VA.SetSignalSourceBufferPlaybackAction(_AudiofileSignalSource, "play");
_VA.SetSoundSourceSignalSource(_ID, _AudiofileSignalSource);
//var filePath = AssetDatabase.GetAssetPath(_audioSource.clip);
var sName = _audioSource.clip.name + "_signal";
//CreateSignalSource(filePath, sName);
}
else
{
if(audioFileForTesting!="")
CreateSignalSource(audioFileForTesting, name);
else
Debug.LogError("No Audioclip in AudioSource.", this);
}
// Initially, set the pose (otherwise rendering module can not spatialize)
SetSoundSourcePositionOrientation();
transform.hasChanged = true;
}
// Update is called once per frame
void Update()
private void CreateSignalSource(string filePath, string sName)
{
if (transform.hasChanged)
SetSoundSourcePositionOrientation();
transform.hasChanged = false;
//var playOnAwake = _audioSource.playOnAwake;
_signalSourceId = _va.CreateSignalSourceBufferFromFile(filePath, sName);
Debug.Assert(_signalSourceId.Length > 0,
"Could not create integrated audio file signal source '" + sName + "' file from path " + filePath);
_va.SetSignalSourceBufferLooping(_signalSourceId, IsLooping);
UpdateSoundSource();
_va.SetSoundSourceSignalSource(_id, _signalSourceId);
//if (playOnAwake)
// Play();
}
private void UpdateSoundSource(bool forceUpdate = false)
{
if (_volumeShadow != _audioSource.volume || forceUpdate)
/// <summary>
/// Get Called every frames and update changes in Sound Power and mute status
/// </summary>
protected override void Update()
{
_VA.SetSoundSourceSoundPower(_ID,
_audioSource.volume *
31.69e-3); // Volume of 1.0 results in default sound power: 31.67 mW -> 94 dB SPL @ 1m
_volumeShadow = _audioSource.volume;
base.Update();
// Volume of 1.0 results in default sound power: 31.67 mW -> 94 dB SPL @ 1m
//UpdateSoundSource(_audioSource.volume * 31.69e-3f, _audioSource.mute);
}
if (_muteShadow != _audioSource.mute || forceUpdate)
protected override void OnDestroy()
{
_VA.SetSoundSourceMuted(_ID, _audioSource.mute);
_muteShadow = _audioSource.mute;
base.OnDestroy();
if (_va.IsConnected())
{
_va.SetSoundSourceSignalSource(_id, "");
_va.DeleteSoundSource(ID);
// Temptative signal source deletion
if (_signalSourceId != null)
_va.DeleteSignalSource(_signalSourceId);
}
}
void SetSoundSourcePositionOrientation()
/// <summary>
/// Play Sound Source
/// </summary>
public override void Play()
{
SetSoundReceiverPositionOrientation(out var vaPosition, out var vaOrientationView,
out var vaOrientationUp);
_VA.SetSoundSourcePosition(_ID, vaPosition);
_VA.SetSoundSourceOrientationVU(_ID, vaOrientationView, vaOrientationUp);
base.Play();
_va.SetSignalSourceBufferPlaybackAction(_signalSourceId, "play");
}
public void OnDisable()
/// <summary>
/// Pause Sound Source
/// </summary>
public override void Pause()
{
_VA.SetSignalSourceBufferPlaybackAction(_AudiofileSignalSource, "stop");
base.Pause();
_va.SetSignalSourceBufferPlaybackAction(_signalSourceId, "pause");
}
private void OnDestroy()
{
if (_VA.IsConnected())
/// <summary>
/// Stop Sound Source
/// </summary>
public override void Stop()
{
_VA.SetSoundSourceSignalSource(_ID, "");
_VA.DeleteSoundSource(ID);
// Temptative signal source deletion
if (_AudiofileSignalSource != null)
_VA.DeleteSignalSource(_AudiofileSignalSource);
base.Stop();
_va.SetSignalSourceBufferPlaybackAction(_signalSourceId, "stop");
}
/// <summary>
/// if signal source is playing back or not
/// </summary>
/// <returns>true if sound source in VA is running and false if not</returns>
public override bool GetPlaybackState()
{
return GetPlaybackState(_signalSourceId);
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 4c6e08d2153871b47940ab81f7e74fe9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System;
using UnityEngine;
namespace VAUnity
{
/// <summary>
/// Create a Sound Source in VA based on the inspector settings
/// </summary>
public class VAUSoundSourceGeneric : VAUSoundSource
{
[Tooltip("Insert a custom VAUSignalSource-Script.")]
[SerializeField] private VAUSignalSource signalSource;
[Tooltip("Sound power in Watts (default is 31mW)")]
[Min(0)][SerializeField] private float soundPower = 0.0031f;
[Tooltip("Mutes the sound source")]
[SerializeField] private bool isMuted = false;
[Tooltip("Will immediately start the signal source payback.")]
[SerializeField] protected bool playOnStart = false;
public override bool IsLooping => signalSource.IsLooping;
public override string SignalSourceId => signalSource.ID;
/// <summary>
/// Init Sound Source and Signal Source in VA
/// </summary>
protected override void Start()
{
base.Start();
_va.SetSoundSourceAuralizationMode(_id, "all");
UpdateSoundSource(soundPower, isMuted, true);
// Connect to directivity, if linked or attached
// Connect to signal source, if linked or attached
if (signalSource)
{
_va.SetSoundSourceSignalSource(_id, signalSource.ID);
}
else
{
Debug.LogError("Signal Source not found", this);
}
if(playOnStart)
Play();
}
/// <summary>
/// Get Called every frames and update changes in Sound Power and mute status
/// </summary>
protected override void Update()
{
base.Update();
UpdateSoundSource(soundPower, isMuted);
}
protected override void OnDestroy()
{
base.OnDestroy();
//_VA = VAUnity.VA;
if (_va.IsConnected())
{
// Temptative signal source deletion
if (signalSource.ID != null)
_va.DeleteSignalSource (signalSource.ID);
}
}
/// <summary>
/// Play Sound Source
/// </summary>
public override void Play()
{
base.Play();
signalSource.Play();
}
/// <summary>
/// Pause Sound Source
/// </summary>
public override void Pause()
{
base.Pause();
signalSource.Pause();
}
/// <summary>
/// Stop Sound Source
/// </summary>
public override void Stop()
{
base.Stop();
signalSource.Stop();
}
/// <summary>
/// if signal source is playing back or not
/// </summary>
/// <returns>true if sound source in VA is running and false if not</returns>
public override bool GetPlaybackState()
{
return GetPlaybackState(signalSource.ID);
}
/// <summary>
/// Updates the Signal Source of the SoundSource.
/// Note: Playback properties of the SignalSource will *NOT* be changed!
/// </summary>
/// <param name="newSignalSource">SignalSource that shall be connected to the SoundSource</param>
public void SetSignalSource(VAUSignalSource newSignalSource)
{
if (!newSignalSource)
{
Debug.LogError("Setting signal source for SoundSource " + ID +" failed: SignalSource is not initialized!");
return;
}
signalSource = newSignalSource;
_va.SetSoundSourceSignalSource(ID, signalSource.ID);
}
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment