App is constantly at 100% and over CPU usage
App is constantly at 100% and over CPU usage. Any way to reduce this?
@Pranoy1c are you sure that you use lib in right way?
@Pranoy1c the problem is with this line: DispatchQueue.main.async { d.tunerDidUpdate(self, output: output) }
Probably dispatching on main queue is causing strong reference cycles. When I removed "DispatchQueue.main.async", it was working fine.
@RamyRizkalla actually problem in another line of code.
public func start() {
microphone.start()
tracker.start()
AudioKit.output = silence
AudioKit.start()
if timer == nil {
timer = DispatchTimer(interval: 0.03, closure: { (t, i) -> Void in
if let d = self.delegate {
if self.tracker.amplitude > self.threshold {
let amplitude = self.tracker.amplitude
let frequency = self.smooth(self.tracker.frequency)
let output = Tuner.newOutput(frequency, amplitude)
DispatchQueue.main.async {
d.tunerDidUpdate(self, output: output)
}
}
}
})
}
timer?.start(true)
}
In method start() replace line
timer = DispatchTimer(interval: 0.03, closure: { (t, i) -> Void in
with line
timer = DispatchTimer(interval: 0.03, closure: { [weak self] (t, i) -> Void in
You should care about weak references in closures.