Commit 2305f34c authored by Nathan De Castro's avatar Nathan De Castro

better pitch detection tool, dynamic instructions, working on linear interpolation for pitch color

parent ee759402
......@@ -4,9 +4,8 @@ using UnityEngine;
public class BigEnabler : MonoBehaviour {
public float volume_threshold = 20.0f;
public float pitch_threshold = 0.1f;
public float pitch_threshold = 0.2f;
public float fade_speed = 0.5f;
public bool volume_based = false;
public bool pitch_based = true;
private bool Activated = false;
......@@ -17,10 +16,8 @@ public class BigEnabler : MonoBehaviour {
}
// Update is called once per frame
void Update () {
volume_based = !pitch_based;
pitch_based = !volume_based;
if (volume_based) {
if (!pitch_based) {
if (AM.i.GetRMS () > volume_threshold && Activated == false) {
Activated = true;
enabler.FadeIn (fade_speed);
......
......@@ -4,9 +4,8 @@ using UnityEngine;
public class MediumEnabler : MonoBehaviour {
public float volume_threshold = 10.0f;
public float pitch_threshold = 0.1f;
public float pitch_threshold = 0.2f;
public float fade_speed = 0.5f;
public bool volume_based = false;
public bool pitch_based = true;
private bool Activated = false;
......@@ -17,10 +16,8 @@ public class MediumEnabler : MonoBehaviour {
}
// Update is called once per frame
void Update () {
volume_based = !pitch_based;
pitch_based = !volume_based;
if (volume_based) {
if (!pitch_based) {
if (AM.i.GetRMS () > volume_threshold && Activated == false) {
Activated = true;
enabler.FadeIn (fade_speed);
......
......@@ -4,9 +4,8 @@ using UnityEngine;
public class SmallEnabler : MonoBehaviour {
public float volume_threshold = 3.0f;
public float pitch_threshold = 0.1f;
public float pitch_threshold = 0.2f;
public float fade_speed = 0.5f;
public bool volume_based = false;
public bool pitch_based = true;
private bool Activated = false;
......@@ -17,10 +16,8 @@ public class SmallEnabler : MonoBehaviour {
}
// Update is called once per frame
void Update () {
volume_based = !pitch_based;
pitch_based = !volume_based;
if (volume_based) {
if (!pitch_based) {
if (AM.i.GetRMS () > volume_threshold && Activated == false) {
Activated = true;
enabler.FadeIn (fade_speed);
......
......@@ -27,6 +27,13 @@ public class AM : MonoBehaviour {
private float average_pitch_mid = 0;
private float average_pitch_high = 0;
[Range (0, 64)]
public int low_range = 13;
[Range (0, 512)]
public int mid_range = 44;
[Range (0, 1024)]
public int high_range = 51;
void Start () {
i = this;
spec_data = new float[spec_size];
......@@ -67,18 +74,18 @@ public class AM : MonoBehaviour {
public void PitchAnalysis () {
//Low - Around 84Hz
float Low = spec_data[2] + spec_data[3];
if (Low / 2 > 0.00001) average_pitch_low = Low * 100;
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;
else average_pitch_low = 0;
//Mid - Around 512Hz
float Mid = spec_data[3] + spec_data[4];
if (Mid / 2 > 0.00001) average_pitch_mid = Mid * 100;
float Mid = (spec_data[mid_range] + spec_data[mid_range + 1] + spec_data[mid_range + 2] + spec_data[mid_range + 3] + spec_data[mid_range + 4]) / 5;
if (Mid > 0.00001) average_pitch_mid = Mid * 100;
else average_pitch_mid = 0;
//High - Around 1025Hz
float High = spec_data[5] + spec_data[6];
if (High / 2 > 0.00001) average_pitch_high = High * 100;
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;
}
......@@ -122,7 +129,7 @@ public class AM : MonoBehaviour {
//Be aware! Some mad linear interpolation is happening here:
if (pitch_based) {
return new Color (average_pitch_high, 0, 0.3f + average_pitch_low, 1);
return Color.Lerp(Color.white, Color.black, Mathf.PingPong(Time.time, 1));
} else {
float r = Mathf.Abs ((rms - color_range_min) / color_range_max);
float b = Mathf.Abs (1 - r);
......
......@@ -3,6 +3,7 @@ using UnityEngine.UI;
public class Instructions : MonoBehaviour {
private Text info_text;
public GameObject GO_player;
void Start () {
info_text = GetComponent<Text> ();
......@@ -10,6 +11,7 @@ public class Instructions : MonoBehaviour {
}
void Update () {
if (GO_player.activeSelf) {
if (!SwitchState.switch_status && !SwitchState.player_near_switch)
info_text.text = "Don't worry, you are safe here =)" + "\n" + "Frist, try to find the switch and turn on the light." + "\n";
if (SwitchState.player_near_switch)
......@@ -17,4 +19,5 @@ public class Instructions : MonoBehaviour {
if (SwitchState.switch_status)
info_text.text = "The the dark, you are only safe when silent, but you must make noise to see!" + "\n" + "Head to the green switch to start the game." + "\n" + "Good luck!";
}
}
}
\ No newline at end of file
......@@ -250,7 +250,6 @@ MonoBehaviour:
volume_threshold: 20
pitch_threshold: 0.1
fade_speed: 1
volume_based: 0
pitch_based: 1
--- !u!114 &96832507
MonoBehaviour:
......@@ -264,7 +263,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
fadeDelay: 0
fadeTime: 5
fadeTime: 2
fadeInOnStart: 0
fadeOutOnStart: 1
--- !u!114 &96832508
......@@ -478,7 +477,6 @@ MonoBehaviour:
volume_threshold: 20
pitch_threshold: 0.1
fade_speed: 1
volume_based: 0
pitch_based: 1
--- !u!114 &130922592
MonoBehaviour:
......@@ -492,7 +490,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
fadeDelay: 0
fadeTime: 5
fadeTime: 2
fadeInOnStart: 0
fadeOutOnStart: 1
--- !u!114 &130922593
......@@ -606,7 +604,7 @@ Transform:
- {fileID: 1583608719}
- {fileID: 1294633095}
m_Father: {fileID: 0}
m_RootOrder: 3
m_RootOrder: 5
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &205652143
GameObject:
......@@ -657,7 +655,6 @@ MonoBehaviour:
volume_threshold: 10
pitch_threshold: 0.1
fade_speed: 1
volume_based: 0
pitch_based: 1
--- !u!114 &205652146
MonoBehaviour:
......@@ -671,7 +668,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
fadeDelay: 0
fadeTime: 5
fadeTime: 2
fadeInOnStart: 0
fadeOutOnStart: 1
--- !u!114 &205652147
......@@ -1064,7 +1061,7 @@ Prefab:
objectReference: {fileID: 0}
- target: {fileID: 4188753986315464, guid: ef8622c6f07c11e47aae43d93e8e076a, type: 2}
propertyPath: m_RootOrder
value: 5
value: 7
objectReference: {fileID: 0}
- target: {fileID: 114249406734343344, guid: ef8622c6f07c11e47aae43d93e8e076a,
type: 2}
......@@ -1497,6 +1494,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: fae0d039dd56e9649868086c4dc8ce7b, type: 3}
m_Name:
m_EditorClassIdentifier:
GO_player: {fileID: 1643563760}
--- !u!1 &730031521
GameObject:
m_ObjectHideFlags: 0
......@@ -1546,7 +1544,6 @@ MonoBehaviour:
volume_threshold: 10
pitch_threshold: 0.1
fade_speed: 1
volume_based: 0
pitch_based: 1
--- !u!114 &730031524
MonoBehaviour:
......@@ -1560,7 +1557,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
fadeDelay: 0
fadeTime: 5
fadeTime: 2
fadeInOnStart: 0
fadeOutOnStart: 1
--- !u!114 &730031525
......@@ -1644,7 +1641,7 @@ Prefab:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 2003347223}
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 4481930841849142, guid: 6621ab22a2756ff4c930cb8dd067287d, type: 2}
propertyPath: m_LocalPosition.x
......@@ -1769,6 +1766,31 @@ Prefab:
propertyPath: death_cam
value:
objectReference: {fileID: 135072764}
- target: {fileID: 114807479069452012, guid: 6621ab22a2756ff4c930cb8dd067287d,
type: 2}
propertyPath: low_val
value: 13
objectReference: {fileID: 0}
- target: {fileID: 114807479069452012, guid: 6621ab22a2756ff4c930cb8dd067287d,
type: 2}
propertyPath: mid_val
value: 44
objectReference: {fileID: 0}
- target: {fileID: 114807479069452012, guid: 6621ab22a2756ff4c930cb8dd067287d,
type: 2}
propertyPath: high_val
value: 51
objectReference: {fileID: 0}
- target: {fileID: 114807479069452012, guid: 6621ab22a2756ff4c930cb8dd067287d,
type: 2}
propertyPath: mid_range
value: 21
objectReference: {fileID: 0}
- target: {fileID: 114807479069452012, guid: 6621ab22a2756ff4c930cb8dd067287d,
type: 2}
propertyPath: high_range
value: 55
objectReference: {fileID: 0}
m_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: 6621ab22a2756ff4c930cb8dd067287d, type: 2}
m_IsPrefabParent: 0
......@@ -2012,7 +2034,6 @@ MonoBehaviour:
volume_threshold: 10
pitch_threshold: 0.1
fade_speed: 1
volume_based: 0
pitch_based: 1
--- !u!114 &904893879
MonoBehaviour:
......@@ -2026,7 +2047,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
fadeDelay: 0
fadeTime: 5
fadeTime: 2
fadeInOnStart: 0
fadeOutOnStart: 1
--- !u!114 &904893880
......@@ -2154,7 +2175,6 @@ MonoBehaviour:
volume_threshold: 3
pitch_threshold: 0.1
fade_speed: 1
volume_based: 0
pitch_based: 1
--- !u!114 &996836940
MonoBehaviour:
......@@ -2168,7 +2188,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
fadeDelay: 0
fadeTime: 5
fadeTime: 2
fadeInOnStart: 0
fadeOutOnStart: 1
--- !u!114 &996836941
......@@ -2453,7 +2473,6 @@ MonoBehaviour:
volume_threshold: 3
pitch_threshold: 0.1
fade_speed: 1
volume_based: 0
pitch_based: 1
--- !u!114 &1092435724
MonoBehaviour:
......@@ -2467,7 +2486,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
fadeDelay: 0
fadeTime: 5
fadeTime: 2
fadeInOnStart: 0
fadeOutOnStart: 1
--- !u!1 &1133491159
......@@ -2519,7 +2538,6 @@ MonoBehaviour:
volume_threshold: 3
pitch_threshold: 0.1
fade_speed: 1
volume_based: 0
pitch_based: 1
--- !u!114 &1133491162
MonoBehaviour:
......@@ -2533,7 +2551,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
fadeDelay: 0
fadeTime: 5
fadeTime: 2
fadeInOnStart: 0
fadeOutOnStart: 1
--- !u!114 &1133491163
......@@ -2805,7 +2823,7 @@ Prefab:
objectReference: {fileID: 0}
- target: {fileID: 420908, guid: 4d293c8e162f3874b982baadd71153d2, type: 2}
propertyPath: m_RootOrder
value: 2
value: 4
objectReference: {fileID: 0}
- target: {fileID: 123270, guid: 4d293c8e162f3874b982baadd71153d2, type: 2}
propertyPath: m_TagString
......@@ -2934,7 +2952,6 @@ MonoBehaviour:
volume_threshold: 20
pitch_threshold: 0.1
fade_speed: 1
volume_based: 0
pitch_based: 1
--- !u!114 &1288633540
MonoBehaviour:
......@@ -2948,7 +2965,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
fadeDelay: 0
fadeTime: 5
fadeTime: 2
fadeInOnStart: 0
fadeOutOnStart: 1
--- !u!114 &1288633541
......@@ -3186,7 +3203,6 @@ MonoBehaviour:
volume_threshold: 10
pitch_threshold: 0.1
fade_speed: 1
volume_based: 0
pitch_based: 1
--- !u!114 &1368380280
MonoBehaviour:
......@@ -3200,7 +3216,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
fadeDelay: 0
fadeTime: 5
fadeTime: 2
fadeInOnStart: 0
fadeOutOnStart: 1
--- !u!114 &1368380281
......@@ -3279,11 +3295,6 @@ MeshFilter:
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1368380277}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!4 &1438072862 stripped
Transform:
m_PrefabParentObject: {fileID: 4481930841849142, guid: 6621ab22a2756ff4c930cb8dd067287d,
type: 2}
m_PrefabInternal: {fileID: 770415378}
--- !u!1001 &1470999846
Prefab:
m_ObjectHideFlags: 0
......@@ -3321,7 +3332,7 @@ Prefab:
objectReference: {fileID: 0}
- target: {fileID: 4794239916332596, guid: bb97952d1445b40449dfcb823c3d4eec, type: 2}
propertyPath: m_RootOrder
value: 4
value: 6
objectReference: {fileID: 0}
- target: {fileID: 108478194113650256, guid: bb97952d1445b40449dfcb823c3d4eec,
type: 2}
......@@ -3471,7 +3482,7 @@ Transform:
m_LocalPosition: {x: -29.95, y: 50.700005, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 2003347223}
m_Father: {fileID: 0}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 73.999, y: -39.596, z: -5.479}
--- !u!1 &1553836852
......@@ -3754,7 +3765,6 @@ MonoBehaviour:
volume_threshold: 3
pitch_threshold: 0.1
fade_speed: 1
volume_based: 0
pitch_based: 1
--- !u!114 &1677040217
MonoBehaviour:
......@@ -3768,7 +3778,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
fadeDelay: 0
fadeTime: 5
fadeTime: 2
fadeInOnStart: 0
fadeOutOnStart: 1
--- !u!114 &1677040218
......@@ -3896,7 +3906,6 @@ MonoBehaviour:
volume_threshold: 20
pitch_threshold: 0.1
fade_speed: 1
volume_based: 0
pitch_based: 1
--- !u!114 &1685710003
MonoBehaviour:
......@@ -3910,7 +3919,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
fadeDelay: 0
fadeTime: 5
fadeTime: 2
fadeInOnStart: 0
fadeOutOnStart: 1
--- !u!114 &1685710004
......@@ -4029,7 +4038,7 @@ Transform:
- {fileID: 474589051}
- {fileID: 1134638300}
m_Father: {fileID: 0}
m_RootOrder: 6
m_RootOrder: 8
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1773949532
GameObject:
......@@ -4199,11 +4208,9 @@ Transform:
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 1438072862}
- {fileID: 1549895650}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1001 &2135099781
Prefab:
......@@ -4242,7 +4249,7 @@ Prefab:
objectReference: {fileID: 0}
- target: {fileID: 4000013404917088, guid: b174138e07741d34bafbacccfb696690, type: 2}
propertyPath: m_RootOrder
value: 1
value: 3
objectReference: {fileID: 0}
- target: {fileID: 1000011359339500, guid: b174138e07741d34bafbacccfb696690, type: 2}
propertyPath: m_IsActive
......
No preview for this file type
No preview for this file type
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