-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFP.cs
More file actions
107 lines (92 loc) · 4.4 KB
/
Copy pathFP.cs
File metadata and controls
107 lines (92 loc) · 4.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
using System;
using System.Collections.Generic;
namespace BeatTimer {
public struct FP
{
public FP(double time, int f, int p)
{
T = time;
F = f;
P = p;
}
/*
public FP(double time, double f, double p) {
double paverage = 51275.34475664618;
double pdeviation = 23120.601566104728;
double faverage = 1466585.6747473634;
double fdeviation = 816264.2562507965;
T = time;
F = f > faverage + fdeviation / 2 ? 2 : f > faverage - fdeviation / 2 ? 1 : 0;
P = p > paverage + pdeviation / 2 ? 2 : p > paverage - pdeviation / 2 ? 1 : 0;
}*/
public double T { get; }
public int F { get; }
public int P { get; }
public override string ToString()
{
return $"Time: {T,10:0.00}, Freneticism: {F,10}, Physicality: {P,10}";
}
}
class BeatParser {
// Average physicality and freneticism calculated by a sampling and averaging a collection of many different songs
private static double paverageaverage = 23755.8733045355;
private static double pdeviationaverage = 11806.04783001002;
private static double faverageaverage = 662660.6961113685;
private static double fdeviationaverage = 324379.5395565418;
/// <summary>
/// Get list of FP-tuples for each 8 beat count (every 64 eighth-notes)
/// </summary>
/// <param name="beats">Beat data list generated by BeatTimer</param>
/// <param name="pdevnum">Threshold in number of standard deviations for physicality levels</param>
/// <param name="fdevnum">Threshold in number of standard deviations for freneticism levels</param>
/// <param name="avgratio">
/// How much to weight song's particular standard deviation vs the average standard deviation
/// (0.0-1.0 where 0 gives the individiual song all the weight and 1 gives the average the full weight)
/// </param>
/// <returns>FP data list</returns>
public static List<FP> FPdata(List<Beat> beats, double pdevnum = 0.5, double fdevnum = 0.5, double avgratio = 0.5) {
var fp = new List<FP>();
var times = new List<double>();
var physicalities = new List<double>();
var freneticisms = new List<double>();
for (int i = 0; i < beats.Count; i += 64) {
double p = 0;
double f = 0;
int max = Math.Min(i + 64, beats.Count);
int min = max - 64;
for (int j = max - 1; j >= min; j--) {
p += beats[j].A;
f += beats[j].I;
}
physicalities.Add(p);
freneticisms.Add(f);
times.Add(beats[i].T);
}
stddev(physicalities, out double pdev, out double paverage);
stddev(freneticisms, out double fdev, out double faverage);
pdev = pdev * (1 - avgratio) + pdeviationaverage * avgratio;
paverage = paverage * (1 - avgratio) + paverageaverage * avgratio;
fdev = fdev * (1 - avgratio) + fdeviationaverage * avgratio;
faverage = faverage * (1 - avgratio) + faverageaverage * avgratio;
for (int i = 0; i < times.Count; i++) {
int pvalue = physicalities[i] > paverage + pdev * pdevnum ? 2 : physicalities[i] > paverage - pdev * pdevnum ? 1 : 0;
int fvalue = freneticisms[i] > faverage + fdev * fdevnum ? 2 : freneticisms[i] > faverage - fdev * fdevnum ? 1 : 0;
fp.Add(new FP(times[i], fvalue, pvalue));
}
return fp;
}
// https://stackoverflow.com/questions/3141692/standard-deviation-of-generic-list
public static void stddev(List<double> values, out double deviation, out double average) {
double sum = 0;
for (int i = 0; i < values.Count; i++) {
sum += values[i];
}
average = sum / values.Count;
sum = 0;
for (int i = 0; i < values.Count; i++) {
sum += Math.Pow(values[i] - average, 2);
}
deviation = Math.Sqrt(sum / (values.Count - 1));
}
}
}