Skip to content

Commit 26ac09b

Browse files
committed
Update Visualizer algo
1 parent a075a1e commit 26ac09b

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

MVTouchbar/MVTouchbar/volume.swift

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public class volume {
8484
trailingPeak = peak
8585
}
8686
// if(peak.isNaN) {peak = 0.0}
87-
let method = 0 // TODO: Make configurable by user
87+
let method = 2 // TODO: Make configurable by user
8888
var finalPeaks : [Int] = []
8989

9090
switch method { //switchs volume scale calculations
@@ -117,18 +117,24 @@ public class volume {
117117
let s = powf(peaks.max()!, 0.1)
118118
for i in 0...99 { // Number of frequencies in each loudness level varies logarithmically
119119
if peaks[i] == 0.0 {
120-
finalPeaks.append(0)
120+
finalPeaks.append(1)
121121
continue
122122
}
123123
var peak = logA(x: peaks[i], ofBase: s)
124+
if(peak.isNaN){
125+
peak = 1.0
126+
}
124127
if peak < 0.0 {
125-
peak = 0.0
128+
peak = 1.0
126129
}
127-
if(peak.isNaN){
128-
peak = 0.0
130+
131+
if peak > 10.0 {
132+
peak = peak/10
129133
}
134+
130135
finalPeaks.append(Int(peak))
131136
}
137+
print(finalPeaks)
132138
default:
133139
fatalError() //should never default
134140
break

0 commit comments

Comments
 (0)