I am trying to detect pitch from iOS microphone with AudioKit, and here is the code
init() {
guard let input = engine.input else {
fatalError()
}
mic = input
filter = HighPassFilter(mic, cutoffFrequency: 200, resonance: 40)
silence = Fader(filter, gain: 0)
tracker = PitchTap(silence) { pitch , amp in
DispatchQueue.main.async {
print(pitch[0], amp[0])
self.update(pitch[0], amp[0])
}
}
engine.output = filter
}
func start() {
recordFrequency = []
do {
try engine.start()
tracker.start()
} catch let err {
Log(err)
}
}
Because there's always some detect (frequency 20 to 200) when I don't make sounds, I add a high pass filter to filt the sound lower than 40 dB and 200 frequencies, But it seems not work, what should I do?
Thanks.
It looks like you just have some connection point issues. Try putting the tracker before you make the signal silent:
filter = HighPassFilter(mic, cutoffFrequency: 200, resonance: 40)
tracker = PitchTap(filter) { pitch , amp in
DispatchQueue.main.async {
print(pitch[0], amp[0])
self.update(pitch[0], amp[0])
}
}
silence = Fader(tracker, gain: 0)
engine.output = filter