Repository navigation
Expand file tree
/
Copy pathSoundControllerGroup.java
More file actions
202 lines (176 loc) · 5.31 KB
/
Copy pathSoundControllerGroup.java
File metadata and controls
202 lines (176 loc) · 5.31 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
import signal.library.SignalFilter;
public class SoundControllerGroup {
public SoundControllerGroup(String name,int bands,int[] ranges, int repeatDelay,Application app){
this.name = name;
this.historySize=ranges[ranges.length-1];
this.activeBands = new boolean[bands];
this.perBandScores = new float[bands];
this.energyHistory = new float[historySize];
this.scoreHistory = new float[historySize];
this.modulationHistory = new float[historySize];
this.beatSense=8;
this.ranges=ranges;
this.repeatDelay=repeatDelay;
this.signalFilter = new SignalFilter(app);
this.signalFilter.setMinCutoff(10);
}
//settings
private float energyThreshold= 0.3f;
private float modulationReleaseSmooth=0.9f;
private float modulationAttackSmooth=0.8f;
private boolean autoBeatSense = true;
public float beatSenseSense=1.2f;
private int skipFrames=0;
private int repeatDelay;
//group data
private String name;
private boolean[] activeBands;
private float[] energyHistory;
private float[] scoreHistory;
private float[] perBandScores;
private float[] modulationHistory;
private float smoothEnergy;
private float beatSense;
private int roundRobinIndex=0;
private int historySize;
private int[] ranges;
private boolean onBeat;
private SignalFilter signalFilter;
private boolean filter=true;
public void process(float[][] energyBandHistory,float[][] bandAvgs, int index){
energyThreshold=0.5f;
//sum energy
energyHistory[index]=0;
float score=0;
int cpt=0;
for(int i=0;i<energyBandHistory.length;i++){
float bandScore=0;
for(int j=0;j<ranges.length;j++){
if(energyBandHistory[i][index]>energyThreshold * 10 && bandAvgs[j][i]<energyBandHistory[i][index]){
bandScore += Math.sqrt((energyBandHistory[i][index]-bandAvgs[j][i])/bandAvgs[j][i]*(j+1));
}
}
perBandScores[i]=bandScore;
if(activeBands[i]){
cpt++;
score+=bandScore;
energyHistory[index]+=energyBandHistory[i][index];
}
}
if(cpt>0){
energyHistory[index]/=(float)cpt;
score /= cpt;
//score++;
}
//smooth energy
float smooth = 0.8f;
if(smoothEnergy<smooth*energyHistory[index]){
smoothEnergy*=smooth;
}else{
smoothEnergy=energyHistory[index];
}
energyThreshold=0.1f;
if(filter==false){
this.signalFilter.setMinCutoff(0.05f);
this.signalFilter.setBeta(4.0f);
// minCutoff = 0.05; // decrease this to get rid of slow speed jitter
//float beta = 4.0; // increase this to get rid of high speed lag
score = 1000f*signalFilter.filterUnitFloat(score/1000f,System.currentTimeMillis()/100d);
}
//compute score
if (energyHistory[index] > energyThreshold){
scoreHistory[index] = score;
//energyHistory[index]/energyPeakAvg;
//energyHistory[index]/(avgs[0])
//*avgs[0]/avgs[1]
;
}else{
scoreHistory[index]=0;
}
//compute modulation
//modulationReleaseSmooth=0.9f;
//modulationAttackSmooth=0.8f;
float newMod = scoreHistory[index] * scoreHistory[index] / beatSense / beatSense ;
float oldMod = modulationHistory[roundRobinIndex];
if (newMod*(1f-modulationAttackSmooth)+oldMod*modulationReleaseSmooth>oldMod){
// modulation.put(group, newMod*(1f-modulationAttackSmooth)+oldMod*modulationReleaseSmooth);
newMod = newMod*(1f-modulationAttackSmooth)+oldMod*modulationReleaseSmooth;
}else{
// modulation.put(group,modulationReleaseSmooth * oldMod);
newMod =modulationReleaseSmooth * oldMod;
}
if (newMod > 2f){
newMod= 2f;
}
modulationHistory[index]=newMod;
//onBeat
if (skipFrames <= 0 && scoreHistory[index] > beatSense) {
onBeat = true;
skipFrames = repeatDelay;
}
if (skipFrames > 0){
skipFrames--;
}
float avgsScore[] = new float[ranges.length];
//float maxsScore[] = new float[ranges.length];
//float minsScore[] = new float[ranges.length];
for(int i=0;i<ranges.length;i++){
avgsScore[i]=Utils.average(scoreHistory, index, ranges[i]);
//maxsScore[i]=MathUtils.max(scoreHistory, index, ranges[i]);
//minsScore[i]=MathUtils.min(scoreHistory, index, ranges[i]);
}
//compute beatSense
if (autoBeatSense && energyHistory[index]>energyThreshold) {
// beatSense = beatSense*0.99 +0.01*max*0.6;
beatSense = beatSense * 0.99f
+0.01f*( avgsScore[ranges.length-1])*2 * beatSenseSense;
// if(variance(score)>1)
// beatSense=0.99*beatSense + beatSenseSense*(0.01*variance(score));
if (beatSense > 19)
beatSense = 19f;
if (beatSense < 1.1)
beatSense = 1.1f;
}
//make new index public
roundRobinIndex = index;
}
public float getModulation(){
return(modulationHistory[roundRobinIndex]);
}
public boolean[] getActiveBands(){
return(activeBands);
}
public float getEnergy(){
return(energyHistory[roundRobinIndex]);
}
public float getScore(){
return(scoreHistory[roundRobinIndex]);
}
public float[] getPerBandScores(){
return(perBandScores);
}
public float getBeatSense(){
return(beatSense);
}
public void setOnBeat(){
onBeat=true;
}
public void setOnBeat(boolean onBeat){
this.onBeat=onBeat;
}
public void setAutoBeatSense(boolean autoBeatSense){
this.autoBeatSense=autoBeatSense;
}
public void setBeatSense(float beatSense){
this.beatSense=beatSense;
}
public void setBeatSenseSense(float beatSenseSense){
this.beatSenseSense=beatSenseSense;
}
public String getName(){
return(this.name);
}
public boolean isOnBeat(){
return(onBeat);
}
}