Mercurial > hg > Game > Games
comparison Orchestland/Assets/Scripts/TempoCheck.cs @ 1:f7675884f2a1
Add Orchestland project
author | Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 17 Jul 2015 23:09:20 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
0:347d21cdfc22 | 1:f7675884f2a1 |
---|---|
1 using UnityEngine; | |
2 using System.Collections; | |
3 | |
4 public class TempoCheck : MonoBehaviour { | |
5 public int maxAverageValue = 8; | |
6 public float defaultBPM = 120f; | |
7 | |
8 float time_old = 0; | |
9 float[] tempo_ary; | |
10 int ary_num = 0; | |
11 float tempo_average = 120f; | |
12 // Use this for initialization | |
13 void Start () { | |
14 tempo_average = defaultBPM; | |
15 tempo_ary = tempo_ary = new float[maxAverageValue]; | |
16 for (int i = 0; i < tempo_ary.Length; i++) { | |
17 tempo_ary [i] = defaultBPM; | |
18 } | |
19 } | |
20 | |
21 // Update is called once per frame | |
22 void Update () { | |
23 } | |
24 | |
25 public void Beat(){ | |
26 float time_now = Time.time; | |
27 float time_delta = time_now - time_old; | |
28 float tempo_now = 60f / time_delta; | |
29 if (tempo_now > 80 && tempo_now < 200) { | |
30 tempo_ary [ary_num] = tempo_now; | |
31 ary_num++; | |
32 if (ary_num >= tempo_ary.Length) { | |
33 ary_num = 0; | |
34 } | |
35 } | |
36 if (tempo_now < 250) { | |
37 time_old = Time.time; | |
38 } | |
39 | |
40 // calc average | |
41 float tempo_total = 0; | |
42 for (int i = 0; i < tempo_ary.Length; i++) { | |
43 tempo_total += tempo_ary [i]; | |
44 } | |
45 tempo_average = tempo_total / tempo_ary.Length; | |
46 } | |
47 | |
48 public float GetTempoAverage(){ | |
49 return tempo_average; | |
50 } | |
51 } |