Commit b18cc59f authored by Nathan De Castro's avatar Nathan De Castro
Browse files

fixed audio source output, random switch, light angle and color

parent a3416545
......@@ -98,6 +98,7 @@
<None Include="Assets\Standard Assets\Effects\ImageEffects\Shaders\frag_ao.cginc" />
<None Include="Assets\Materials\Monster\shaders\bumpSpecmap.shader" />
<None Include="Assets\UCLAGameLab\Wireframe\Shaders\UCLA GameLab Wireframe.shader" />
<None Include="Assets\Data\SessionData.txt" />
<None Include="Assets\Materials\Monster\shaders\metalA.shader" />
<None Include="Assets\Standard Assets\Effects\ToonShading\Shaders\ToonBasicOutline.shader" />
<None Include="Assets\Standard Assets\Effects\ImageEffects\Shaders\_DepthOfField\DepthOfField34.shader" />
......
......@@ -93,6 +93,7 @@
<None Include="Assets\Standard Assets\Effects\ImageEffects\Shaders\frag_ao.cginc" />
<None Include="Assets\Materials\Monster\shaders\bumpSpecmap.shader" />
<None Include="Assets\UCLAGameLab\Wireframe\Shaders\UCLA GameLab Wireframe.shader" />
<None Include="Assets\Data\SessionData.txt" />
<None Include="Assets\Materials\Monster\shaders\metalA.shader" />
<None Include="Assets\Standard Assets\Effects\ToonShading\Shaders\ToonBasicOutline.shader" />
<None Include="Assets\Standard Assets\Effects\ImageEffects\Shaders\_DepthOfField\DepthOfField34.shader" />
......
......@@ -161,6 +161,7 @@
<None Include="Assets\Standard Assets\Effects\ImageEffects\Shaders\frag_ao.cginc" />
<None Include="Assets\Materials\Monster\shaders\bumpSpecmap.shader" />
<None Include="Assets\UCLAGameLab\Wireframe\Shaders\UCLA GameLab Wireframe.shader" />
<None Include="Assets\Data\SessionData.txt" />
<None Include="Assets\Materials\Monster\shaders\metalA.shader" />
<None Include="Assets\Standard Assets\Effects\ToonShading\Shaders\ToonBasicOutline.shader" />
<None Include="Assets\Standard Assets\Effects\ImageEffects\Shaders\_DepthOfField\DepthOfField34.shader" />
......
......@@ -55,6 +55,7 @@
<Compile Include="Assets\Scripts\Effects\MediumEnabler.cs" />
<Compile Include="Assets\Scripts\Effects\Rotator.cs" />
<Compile Include="Assets\Scripts\Effects\SmallEnabler.cs" />
<Compile Include="Assets\Scripts\Effects\SoundScaler.cs" />
<Compile Include="Assets\Scripts\Effects\SwitchStart.cs" />
<Compile Include="Assets\Scripts\Effects\SwitchState.cs" />
<Compile Include="Assets\Scripts\Tools\AM.cs" />
......@@ -64,18 +65,21 @@
<Compile Include="Assets\Scripts\Tools\GhostSound.cs" />
<Compile Include="Assets\Scripts\Tools\LightScript.cs" />
<Compile Include="Assets\Scripts\Tools\PlayerSound.cs" />
<Compile Include="Assets\Scripts\Tools\RandSwitch.cs" />
<Compile Include="Assets\Scripts\Tools\RippleEffect.cs" />
<Compile Include="Assets\Scripts\Tools\Timer.cs" />
<Compile Include="Assets\Scripts\UI\GameSettings.cs" />
<Compile Include="Assets\Scripts\UI\GS.cs" />
<Compile Include="Assets\Scripts\UI\Info.cs" />
<Compile Include="Assets\Scripts\UI\Instructions.cs" />
<Compile Include="Assets\Scripts\UI\LoadStart.cs" />
<Compile Include="Assets\Scripts\UI\LoadTuto.cs" />
<Compile Include="Assets\Scripts\UI\SessionRecorder.cs" />
<Compile Include="Assets\Scripts\UI\Visibility.cs" />
<Compile Include="Assets\Scripts\VR\InteractableItem.cs" />
<Compile Include="Assets\Scripts\VR\Tutorial.cs" />
<Compile Include="Assets\Scripts\VR\WandButtons.cs" />
<Compile Include="Assets\Scripts\VR\WandController.cs" />
<Compile Include="Assets\Scripts\VR\lightfollow.cs" />
<Compile Include="Assets\SteamVR\Extras\SteamVR_GazeTracker.cs" />
<Compile Include="Assets\SteamVR\Extras\SteamVR_LaserPointer.cs" />
<Compile Include="Assets\SteamVR\Extras\SteamVR_Teleporter.cs" />
......@@ -199,6 +203,7 @@
<None Include="Assets\Standard Assets\Effects\ImageEffects\Shaders\frag_ao.cginc" />
<None Include="Assets\Materials\Monster\shaders\bumpSpecmap.shader" />
<None Include="Assets\UCLAGameLab\Wireframe\Shaders\UCLA GameLab Wireframe.shader" />
<None Include="Assets\Data\SessionData.txt" />
<None Include="Assets\Materials\Monster\shaders\metalA.shader" />
<None Include="Assets\Standard Assets\Effects\ToonShading\Shaders\ToonBasicOutline.shader" />
<None Include="Assets\Standard Assets\Effects\ImageEffects\Shaders\_DepthOfField\DepthOfField34.shader" />
......
fileFormatVersion: 2
guid: 048cc16df3124f14ca433f616f3f7c60
folderAsset: yes
timeCreated: 1492092619
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
4/17/2017 2:08:58 PM | Player stopped after: 5 seconds
4/17/2017 2:09:39 PM | Player stopped after: 3 seconds
4/17/2017 2:09:54 PM | Player stopped after: 1 seconds
4/17/2017 2:11:32 PM | Player lost after: 7 seconds
4/17/2017 2:11:32 PM | Player lost after: 7 seconds
4/17/2017 2:11:32 PM | Player lost after: 7 seconds
4/17/2017 2:11:32 PM | Player lost after: 7 seconds
4/17/2017 2:11:32 PM | Player lost after: 7 seconds
4/17/2017 2:11:32 PM | Player lost after: 7 seconds
4/17/2017 2:11:32 PM | Player lost after: 8 seconds
4/17/2017 2:11:32 PM | Player lost after: 8 seconds
4/17/2017 2:11:32 PM | Player lost after: 8 seconds
4/17/2017 2:11:32 PM | Player lost after: 8 seconds
4/17/2017 2:11:32 PM | Player lost after: 8 seconds
4/17/2017 2:11:32 PM | Player lost after: 8 seconds
4/17/2017 2:11:32 PM | Player lost after: 8 seconds
4/17/2017 2:11:32 PM | Player lost after: 8 seconds
4/17/2017 2:11:32 PM | Player lost after: 8 seconds
4/17/2017 2:11:32 PM | Player lost after: 8 seconds
4/17/2017 2:11:32 PM | Player lost after: 8 seconds
4/17/2017 2:11:32 PM | Player lost after: 8 seconds
4/17/2017 2:11:32 PM | Player lost after: 8 seconds
4/17/2017 2:11:32 PM | Player lost after: 8 seconds
4/17/2017 2:11:32 PM | Player lost after: 8 seconds
4/17/2017 2:11:32 PM | Player lost after: 8 seconds
4/17/2017 2:11:32 PM | Player lost after: 8 seconds
4/17/2017 2:11:32 PM | Player lost after: 8 seconds
4/17/2017 2:11:32 PM | Player lost after: 8 seconds
4/17/2017 2:11:32 PM | Player lost after: 8 seconds
4/17/2017 2:11:32 PM | Player lost after: 8 seconds
4/17/2017 2:11:32 PM | Player lost after: 8 seconds
4/17/2017 2:11:32 PM | Player lost after: 8 seconds
4/17/2017 2:11:32 PM | Player lost after: 8 seconds
4/17/2017 2:11:32 PM | Player lost after: 8 seconds
4/17/2017 2:11:32 PM | Player lost after: 8 seconds
4/17/2017 2:11:32 PM | Player lost after: 8 seconds
4/17/2017 2:11:32 PM | Player lost after: 8 seconds
4/17/2017 2:11:32 PM | Player lost after: 8 seconds
4/17/2017 2:11:32 PM | Player lost after: 8 seconds
4/17/2017 2:11:32 PM | Player lost after: 8 seconds
4/17/2017 2:11:32 PM | Player lost after: 8 seconds
4/17/2017 2:11:32 PM | Player lost after: 8 seconds
4/17/2017 2:11:32 PM | Player lost after: 8 seconds
4/17/2017 2:11:32 PM | Player lost after: 8 seconds
4/17/2017 2:11:32 PM | Player lost after: 8 seconds
4/17/2017 2:11:32 PM | Player lost after: 8 seconds
4/17/2017 2:11:32 PM | Player lost after: 8 seconds
4/17/2017 2:11:32 PM | Player lost after: 8 seconds
4/17/2017 2:11:32 PM | Player lost after: 8 seconds
4/17/2017 2:11:33 PM | Player lost after: 8 seconds
4/17/2017 2:11:33 PM | Player lost after: 8 seconds
4/17/2017 2:11:33 PM | Player lost after: 8 seconds
4/17/2017 2:11:33 PM | Player lost after: 8 seconds
4/17/2017 2:11:33 PM | Player lost after: 8 seconds
4/17/2017 2:11:33 PM | Player lost after: 8 seconds
4/17/2017 2:11:33 PM | Player lost after: 8 seconds
4/17/2017 2:11:33 PM | Player lost after: 8 seconds
4/17/2017 2:11:33 PM | Player lost after: 8 seconds
4/17/2017 2:11:33 PM | Player lost after: 8 seconds
4/17/2017 2:11:33 PM | Player lost after: 9 seconds
4/17/2017 2:11:33 PM | Player lost after: 9 seconds
4/17/2017 2:11:33 PM | Player lost after: 9 seconds
4/17/2017 2:11:33 PM | Player lost after: 9 seconds
4/17/2017 2:11:33 PM | Player lost after: 9 seconds
4/17/2017 2:11:33 PM | Player lost after: 9 seconds
4/17/2017 2:11:33 PM | Player lost after: 9 seconds
4/17/2017 2:11:33 PM | Player lost after: 9 seconds
4/17/2017 2:11:33 PM | Player lost after: 9 seconds
4/17/2017 2:11:33 PM | Player lost after: 9 seconds
4/17/2017 2:11:33 PM | Player lost after: 9 seconds
4/17/2017 2:11:33 PM | Player lost after: 9 seconds
4/17/2017 2:11:33 PM | Player lost after: 9 seconds
4/17/2017 2:11:33 PM | Player lost after: 9 seconds
4/17/2017 2:11:33 PM | Player lost after: 9 seconds
4/17/2017 2:11:33 PM | Player lost after: 9 seconds
4/17/2017 2:11:33 PM | Player lost after: 9 seconds
4/17/2017 2:11:33 PM | Player lost after: 9 seconds
4/17/2017 2:11:33 PM | Player lost after: 9 seconds
4/17/2017 2:11:33 PM | Player lost after: 9 seconds
4/17/2017 2:11:33 PM | Player lost after: 9 seconds
4/17/2017 2:11:33 PM | Player lost after: 9 seconds
4/17/2017 2:11:33 PM | Player lost after: 9 seconds
4/17/2017 2:11:33 PM | Player lost after: 9 seconds
4/17/2017 2:11:33 PM | Player lost after: 9 seconds
4/17/2017 2:11:33 PM | Player lost after: 9 seconds
4/17/2017 2:12:32 PM | Player stopped after: 55 seconds
4/17/2017 2:16:33 PM | Player lost after: 16 seconds
4/17/2017 2:16:33 PM | Player lost after: 16 seconds
4/17/2017 2:16:33 PM | Player lost after: 16 seconds
4/17/2017 2:16:33 PM | Player lost after: 16 seconds
4/17/2017 2:16:33 PM | Player lost after: 16 seconds
4/17/2017 2:16:33 PM | Player lost after: 16 seconds
4/17/2017 2:16:33 PM | Player lost after: 16 seconds
4/17/2017 2:16:33 PM | Player lost after: 16 seconds
4/17/2017 2:16:33 PM | Player lost after: 16 seconds
4/17/2017 2:16:33 PM | Player lost after: 16 seconds
4/17/2017 2:16:33 PM | Player lost after: 16 seconds
4/17/2017 2:16:33 PM | Player lost after: 16 seconds
4/17/2017 2:16:33 PM | Player lost after: 16 seconds
4/17/2017 2:16:33 PM | Player lost after: 16 seconds
4/17/2017 2:16:34 PM | Player lost after: 16 seconds
4/17/2017 2:16:34 PM | Player lost after: 16 seconds
4/17/2017 2:16:34 PM | Player lost after: 16 seconds
4/17/2017 2:16:34 PM | Player lost after: 16 seconds
4/17/2017 2:16:34 PM | Player lost after: 16 seconds
4/17/2017 2:16:34 PM | Player lost after: 16 seconds
4/17/2017 2:16:34 PM | Player lost after: 16 seconds
4/17/2017 2:16:34 PM | Player lost after: 16 seconds
4/17/2017 2:16:34 PM | Player lost after: 16 seconds
4/17/2017 2:16:34 PM | Player lost after: 16 seconds
4/17/2017 2:16:34 PM | Player lost after: 16 seconds
4/17/2017 2:16:34 PM | Player lost after: 16 seconds
4/17/2017 2:16:34 PM | Player lost after: 16 seconds
4/17/2017 2:16:34 PM | Player lost after: 16 seconds
4/17/2017 2:16:34 PM | Player lost after: 16 seconds
4/17/2017 2:16:34 PM | Player lost after: 16 seconds
4/17/2017 2:16:34 PM | Player lost after: 16 seconds
4/17/2017 2:16:34 PM | Player lost after: 16 seconds
4/17/2017 2:16:34 PM | Player lost after: 16 seconds
4/17/2017 2:16:34 PM | Player lost after: 17 seconds
4/17/2017 2:16:34 PM | Player lost after: 17 seconds
4/17/2017 2:16:34 PM | Player lost after: 17 seconds
4/17/2017 2:16:34 PM | Player lost after: 17 seconds
4/17/2017 2:16:34 PM | Player lost after: 17 seconds
4/17/2017 2:16:34 PM | Player lost after: 17 seconds
4/17/2017 2:16:34 PM | Player lost after: 17 seconds
4/17/2017 2:16:34 PM | Player lost after: 17 seconds
4/17/2017 2:16:34 PM | Player lost after: 17 seconds
4/17/2017 2:16:34 PM | Player lost after: 17 seconds
4/17/2017 2:16:34 PM | Player lost after: 17 seconds
4/17/2017 2:16:34 PM | Player lost after: 17 seconds
4/17/2017 2:16:34 PM | Player lost after: 17 seconds
4/17/2017 2:16:34 PM | Player lost after: 17 seconds
4/17/2017 2:16:34 PM | Player lost after: 17 seconds
4/17/2017 2:16:34 PM | Player lost after: 17 seconds
4/17/2017 2:16:34 PM | Player lost after: 17 seconds
4/17/2017 2:16:34 PM | Player lost after: 17 seconds
4/17/2017 2:16:34 PM | Player lost after: 17 seconds
fileFormatVersion: 2
guid: baa441b68c1b71843b2fefb338e91d6a
timeCreated: 1492431006
licenseType: Free
TextScriptImporter:
userData:
assetBundleName:
assetBundleVariant:
......@@ -18,6 +18,7 @@ public class AI : MonoBehaviour {
public GameObject waypoints; //All waypoints
protected Transform[] wayPos; //Array to store each waypoint's transform
private int dest_point = 0; //Init the destination
private bool reset_seen = false;
//RAYCAST RELATED VARIABLE
private float ray_magnitude = 0; //Essentially the detection distance (length of the ray)
......@@ -32,11 +33,12 @@ public class AI : MonoBehaviour {
// Use this for initialization
void Start () {
if (target == null) target = GameObject.FindGameObjectWithTag("Player");
agent = GetComponent<UnityEngine.AI.NavMeshAgent> ();
wayPos = new Transform[waypoints.GetComponentsInChildren<Transform> ().Length];
for (int i = 1; i<waypoints.GetComponentsInChildren<Transform> ().Length; i++) //i is set to 1 because GetComponentsInChildren also takes the parent once. We don't want that
for (int i = 1; i < waypoints.GetComponentsInChildren<Transform> ().Length; i++) //i is set to 1 because GetComponentsInChildren also takes the parent once. We don't want that
{
wayPos[i] = waypoints.GetComponentsInChildren<Transform> () [i];
wayPos[i] = waypoints.GetComponentsInChildren<Transform> ()[i];
}
AudioSource[] samples = GetComponents<AudioSource> (); //Neat way to have multiple samples with a single audio source!
......@@ -46,8 +48,8 @@ public class AI : MonoBehaviour {
}
void FixedUpdate () {
ray_magnitude = AM.i.GetSpotAngle() / ghost_awarness;
if (GameSettings.instance.lose_state == false && GameSettings.instance.win_state == false) //IF you die, these won't be called anymore.
ray_magnitude = AM.i.GetSpotAngle () / ghost_awarness;
if (GS.i.lose_state == false && GS.i.win_state == false) //IF you die, these won't be called anymore.
{
state_manager (); //Manages the AI's different states
ray_casting (); //Draws the ray
......@@ -74,7 +76,7 @@ public class AI : MonoBehaviour {
}
void state_manager () {
if ((sees_the_player || enemies_converge) && CurrentPlayer.instance != null) //if any agent sees a live player, all will converge towards it's location
if ((sees_the_player || enemies_converge) && CurrentPlayer.instance != null) //if any agent sees a live player, all will converge towards it's location
{
chase_player_state ();
} else {
......@@ -91,23 +93,31 @@ public class AI : MonoBehaviour {
transform.LookAt (target.transform.position);
delta = Vector3.Distance (transform.position, target.transform.position);
if (delta > proximity) {
reset_seen = false;
transform.Translate (Vector3.forward * chase_speed * Time.deltaTime);
} else {
if (!reset_seen) {
wayPos[0] = target.transform; //Sets the first waypoint to be the last player's location (Adding does not seem to work...)
reset_seen = true;
}
}
if (Vector3.Distance (transform.position, target.transform.position) < proximity) //If agent is to close: play death sound, destroy the player, sets the state to "lost"
{
bool harm_only = false;
if (harm_only) { death.Play (); transform.position.Set (8, 5.6f, 9); return; }
last_player_T = target.transform.position;
death.Play ();
// target.GetComponent<playerActions>().ReleaseCamera(); // I chose to have 2 cameras instead of moving the fps one.
Camera.main.GetComponent<AudioListener> ().enabled = false;
GameSettings.instance.death_cam.SetActive (true);
GameSettings.instance.death_cam.GetComponent<AudioListener> ().enabled = true;
GameSettings.instance.death_cam.transform.LookAt (AI.last_player_T);
GameSettings.instance.death_cam.transform.Translate (Vector3.right * Time.deltaTime);
GS.i.death_cam.SetActive (true);
GS.i.death_cam.GetComponent<AudioListener> ().enabled = true;
GS.i.death_cam.transform.LookAt (AI.last_player_T);
GS.i.death_cam.transform.Translate (Vector3.right * Time.deltaTime);
target.SetActive (false);
print ("You died.");
GameSettings.instance.lose_state = true;
GS.i.lose_state = true;
agent.speed = patrol_speed - 2;
}
}
......
......@@ -4,19 +4,7 @@
public class CurrentPlayer : MonoBehaviour {
public static CurrentPlayer instance;
public GameObject player;
void Awake () {
instance = this;
// print("PlayerSettings initialized");
player = this.gameObject;
}
void Start () {
}
void Update () {
instance = this;
}
}
\ No newline at end of file
using UnityEngine;
public class SoundScaler : MonoBehaviour {
// Update is called once per frame
void Update () {
this.gameObject.transform.lossyScale.Set (1 + AM.i.GetComplexPitch ().x, 1 + AM.i.GetComplexPitch ().y, 1 + AM.i.GetComplexPitch ().z);
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 47d5fa4f8e84c584e99815999289a9c5
timeCreated: 1492085592
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
......@@ -5,21 +5,15 @@ public class SwitchStart : MonoBehaviour {
public GameObject switch_on;
public GameObject switch_off;
static public bool player_near_switch;
// Use this for initialization
void Start () {
}
private bool player_near_switch;
// Update is called once per frame
void Update () {
player_near_switch = Vector3.Distance (CurrentPlayer.instance.transform.position, this.transform.position) < 7;
player_near_switch = Vector3.Distance (CurrentPlayer.instance.transform.position, transform.position) < 7;
//Turns on the light when the button is pressed
if (Input.GetKeyDown (KeyCode.Return) && player_near_switch) {
SceneManager.LoadScene ("Start");
SceneManager.LoadScene ("Game");
switch_off.SetActive (!switch_off.activeSelf);
switch_on.SetActive (!switch_off.activeSelf);
}
......
......@@ -5,8 +5,8 @@ public class SwitchState : MonoBehaviour {
public Light main_light;
public GameObject switch_on;
public GameObject switch_off;
static public bool switch_status;
static public bool player_near_switch;
static public bool switch_status = false;
static public bool player_near_switch = false;
public bool start_with_light = true;
// Use this for initialization
......@@ -19,7 +19,7 @@ public class SwitchState : MonoBehaviour {
// Update is called once per frame
void Update () {
player_near_switch = Vector3.Distance (CurrentPlayer.instance.transform.position, this.transform.position) < 7;
player_near_switch = Vector3.Distance (CurrentPlayer.instance.transform.position, transform.position) < 7;
//Turns on the light when the button is pressed
if ((Input.GetKeyDown (KeyCode.Return) && player_near_switch) || Input.GetKeyDown (KeyCode.L)) {
......
......@@ -7,23 +7,23 @@ public class AM : MonoBehaviour {
private AudioSource mic_source;
//Globals
public bool pitch_based = true;
public float color_range_min = 3;
public bool pitch_based = true; //Wether or not to use pitch rather then amplitude for calculations
public float color_range_min = 3; //Sets how low can the light color go
public float color_range_max = 40;
public float spot_fading_speed = 2;
public float splash_force_scaler = 100;
public float audio_update_rate = 40.0f;
private float[] spec_data;
private float[] samp_data;
private int spec_size = 1024;
private int samp_size = 1024;
private int buffer_size = 44100;
private int fmax = 24000;
private float rms;
private float vol;
private float spot_angle = 1;
public float spot_fading_speed = 0.5f; //How fast should the light angle fade back to the center
public float splash_force_scaler = 100; //How powerful can a splash be
public float audio_update_rate = 40.0f; //How fast do you want to calculate the audio (Drastically affects FPS on low end computers)
public float pitch_precision = 0.1f; //How precise do you want the check to be
private float[] spec_data; //Will contain the spectrum information from the microphone
private float[] samp_data; //Will contain sample amplitude from the microphone
private int spec_size = 1024; //Size of the spectrum buffer
private int samp_size = 64; //Size of the sample buffer (this can be low since we are just averaging the volume)
private int buffer_size = 24000; // Half of the actual buffer size (from 0 until the Nyquist rate)
private float rms = 0; //Will store the RMS values
private float vol = 0; //Will store the volume in dB
private float spot_angle = 1; //The spot angle at start
private float average_pitch_low = 0;
private float average_pitch_mid = 0;
private float average_pitch_high = 0;
......@@ -45,8 +45,7 @@ public class AM : MonoBehaviour {
void Start () {
i = this;
buffer_size = AudioSettings.outputSampleRate;
fmax = AudioSettings.outputSampleRate / 2;
buffer_size = AudioSettings.outputSampleRate / 2;
spec_data = new float[spec_size];
samp_data = new float[samp_size];
......@@ -56,28 +55,37 @@ public class AM : MonoBehaviour {
mic_source.pitch = 0.95f; //slightly slower to avoid stuttering
mic_source.loop = true; //loops the second of audio
mic_source.Play (); //starts the playback
mic_source.volume = 0.5f; //Mutes the audiosource
mic_source.volume = 0.0000001f; //Mutes the audiosource
set_low = false;
set_mid = false;
set_high = false;
InvokeRepeating ("BufferPopulator", 0, 1.0f / audio_update_rate); //Begins another thread
InvokeRepeating ("AmplitudeAnalysis", 0, 1.0f / audio_update_rate); //Begins another thread
InvokeRepeating ("ComplexPitchAnalysis", 0, 1.0f / audio_update_rate); //Begins another thread
InvokeRepeating ("AmplitudeAnalysis", 1, 1.0f / audio_update_rate); //Begins another thread
InvokeRepeating ("ComplexPitchAnalysis", 2, 1.0f / audio_update_rate); //Begins another thread
}
public void BufferPopulator () {
void BufferPopulator () {
mic_source.GetSpectrumData (spec_data, 0, FFTWindow.BlackmanHarris);
mic_source.clip.GetData (samp_data, 0);
}
//Anaylsis function:
public void AmplitudeAnalysis () {
int eter = 0;
float rms_sum = 0;
void AmplitudeAnalysis () {
float vol_sum = 0;
for (int i = 0; i < samp_size; i++) {
vol_sum += Mathf.Abs (samp_data[i] * samp_data[i]); //Calculates the square sum of all the data
}
rms = Mathf.Sqrt (vol_sum / samp_size) * 100; //RMS value
if (eter < 5) {
eter++;
rms_sum += Mathf.Sqrt (vol_sum / samp_size) * 100; //RMS sum value to average
} else {
rms = rms_sum / eter; //Final averaged RMS value
rms_sum = 0;
eter = 0;
}
vol = 0;
if (!(vol < 0))
......@@ -85,7 +93,7 @@ public class AM : MonoBehaviour {
else vol = 0;
}
public void ComplexPitchAnalysis () {
void ComplexPitchAnalysis () {
//Low - Around 84Hz
float Low = (spec_data[low_range] + spec_data[low_range + 1] + spec_data[low_range + 2] + spec_data[low_range + 3]) / 4;
if (Low > 0.00001) average_pitch_low = Low * 100;
......@@ -97,7 +105,8 @@ public class AM : MonoBehaviour {
else average_pitch_mid = 0;
//High - Around 1025Hz
float High = (spec_data[high_range] + spec_data[high_range + 1] + spec_data[high_range + 2] + spec_data[high_range + 3] + spec_data[high_range + 4] + spec_data[high_range + 5] + spec_data[high_range + 6] + spec_data[high_range + 7]) / 8;
float High = (spec_data[high_range] + spec_data[high_range + 1] + spec_data[high_range + 2] +
spec_data[high_range + 3] + spec_data[high_range + 4] + spec_data[high_range + 5] + spec_data[high_range + 6] + spec_data[high_range + 7]) / 8;
if (High > 0.00001) average_pitch_high = High * 100;
else average_pitch_high = 0;
......@@ -109,8 +118,7 @@ public class AM : MonoBehaviour {
//Getter functions:
public float GetRMS () {
float output = map (rms, 0.0f, 5.0f, 0.0f, 1.0f); //remaps the rms to usefull values
return output;
return rms;
}
public float GetVolume () {
return vol;
......@@ -118,15 +126,37 @@ public class AM : MonoBehaviour {
public string GetAveragePitch () {
string output = "N/A";
float confidence = 0.1f;
Vector3 control_vector = new Vector3 (confidence, confidence, confidence);
Vector3 delta_low = calibrated_low - GetComplexPitch ();
Vector3 delta_mid = calibrated_mid - GetComplexPitch ();
Vector3 delta_high = calibrated_high - GetComplexPitch ();
if (delta_low.x <= control_vector.x && delta_low.y <= control_vector.y && delta_low.z <= control_vector.z) output = "LOW";
if (delta_mid.x <= control_vector.x && delta_mid.y <= control_vector.y && delta_mid.z <= control_vector.z) output = "MEDIUM";
if (delta_high.x <= control_vector.x && delta_high.y <= control_vector.y && delta_high.z <= control_vector.z) output = "HIGH";
float safe_zero = 0.0000000001f; //Makes sure I never divide by zero without affecting the output
//Divides each value from the from the calibrated buffers with the current buffers to see whether a certain pitch is being produced.
//This part makes the caluclations
double delta_low_x = GetComplexPitch ().x / (safe_zero + calibrated_low.x);
double delta_low_y = GetComplexPitch ().y / (safe_zero + calibrated_low.y);
double delta_low_z = GetComplexPitch ().z / (safe_zero + calibrated_low.z);
double delta_mid_x = GetComplexPitch ().x / (safe_zero + calibrated_low.x);
double delta_mid_y = GetComplexPitch ().y / (safe_zero + calibrated_low.y);
double delta_mid_z = GetComplexPitch ().z / (safe_zero + calibrated_low.z);
double delta_high_x = GetComplexPitch ().x / (safe_zero + calibrated_low.x);
double delta_high_y = GetComplexPitch ().y / (safe_zero + calibrated_low.y);
double delta_high_z = GetComplexPitch ().z / (safe_zero + calibrated_low.z);
// And compares and concludes
if (delta_low_x <= 1 + pitch_precision && delta_low_x >= 1 - pitch_precision &&
delta_low_y <= 1 + pitch_precision && delta_low_y >= 1 - pitch_precision &&
delta_low_z <= 1 + pitch_precision && delta_low_z >= 1 - pitch_precision)
output = "LOW";
if (delta_mid_x <= 1 + pitch_precision && delta_mid_x >= 1 - pitch_precision &&
delta_mid_y <= 1 + pitch_precision && delta_mid_y >= 1 - pitch_precision &&
delta_mid_z <= 1 + pitch_precision && delta_mid_z >= 1 - pitch_precision)
output = "MEDIUM";
if (delta_high_x <= 1 + pitch_precision && delta_high_x >= 1 - pitch_precision &&
delta_high_y <= 1 + pitch_precision && delta_high_y >= 1 - pitch_precision &&
delta_high_z <= 1 + pitch_precision && delta_high_z >= 1 - pitch_precision)
output = "HIGH";
return output;
}
......@@ -136,9 +166,9 @@ public class AM : MonoBehaviour {
}
public float GetSpotAngle () {
if (GetRMS () > 0.2f && spot_angle < 30) spot_angle++;
if (GetRMS () > 0.4f && spot_angle < 70) spot_angle += 3;
if (GetRMS () > 0.7f && spot_angle < 100) spot_angle += 5;
if (GetVolume () > 20f && spot_angle < 30) spot_angle += 0.3f;
if (GetVolume () > 25f && spot_angle < 80) spot_angle += 1;
if (GetVolume () > 30f && spot_angle < 120) spot_angle += 3;
if (spot_angle >= 1) spot_angle -= spot_fading_speed;
......@@ -150,67 +180,69 @@ public class AM : MonoBehaviour {
}
public Color GetLightColor () {
//Be aware! Some mad linear interpolation is happening here:
if (pitch_based) {
return new Color (average_pitch_high / 2, average_pitch_high / 4, 0.7f, 0.4f);
} else {
float r = Mathf.Abs ((rms - color_range_min) / color_range_max);
float r = 0;
float b = Mathf.Abs (1 - r);
return new Color (r, 0, b, 0.8f);
}
}
//TOOLS:
public float map (float value, float low_in, float high_in, float low_out, float high_out) {
return low_out + (value - low_in) * (high_out - low_out) / (high_in - low_in);
}
public float BandLow () {
float output = 0;
float flow = 80;
float fhigh = 110;
if (average_pitch_mid > 0.4 && r <= 0.4) r += 0.05f;
if (<