Created
May 30, 2016 21:05
-
-
Save traviskirton/ad06eaa2b1dbcb81df6ae1efa6cc5477 to your computer and use it in GitHub Desktop.
Grab the max and avg values of an audio sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class WorkSpace: CanvasController { | |
var max0 = 0.0 | |
var max1 = 0.0 | |
var avg0 = 0.0 | |
var avg1 = 0.0 | |
var player = AudioPlayer("BlackVelvet.m4a")! | |
var timer: Timer? | |
override func setup() { | |
player.meteringEnabled = true | |
timer = Timer(interval: 1/60.0) { | |
self.player.updateMeters() | |
self.updateValues() | |
} | |
player.play() | |
timer?.start() | |
} | |
func updateValues() { | |
if max0 < abs(player.peakPower(0)) { | |
max0 = abs(player.peakPower(0)) | |
} | |
if max1 < abs(player.peakPower(1)) { | |
max1 = abs(player.peakPower(1)) | |
} | |
if avg0 < abs(player.averagePower(0)) { | |
avg0 = abs(player.averagePower(0)) | |
} | |
if avg1 < abs(player.averagePower(1)) { | |
avg1 = abs(player.averagePower(1)) | |
} | |
print("\(max0)\t\(max1)\t\(avg0)\t\(avg1)") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment