I am new to AudioKit for iOS, I have tracked the maximum amplitude of 63Hz equalizer of a sound and I changed the gain value of it to 0 using AKEqualizerFilter
class. It's successfully changed and I can listen it but I want to know how can we display that change in the form of amplitude/dB/Gain using AKFrequencyTracker class?
here is my code which changes the gain value of 63Hz sound.
var filterBand3 = AKEqualizerFilter(
filterBand2, centerFrequency: 64, bandwidth: 70.8, gain: 0.0).
Thanks in advance.
UPDATE
First step, I record a song using iPhone microphone, in parallel I am tracking highest amplitude of EQ 63 Hz band. here is the code of my first controller.
override func viewDidLoad() {
super.viewDidLoad()
do {
let tape = try AKAudioFile()
player = try AKAudioPlayer(file: tape)
let mic = AKMicrophone()
micCopy1 = AKBooster(mic)
micCopy2 = AKBooster(mic)
micCopy3 = AKBooster(mic)
let mixer = AKMixer(player, mic)
tracker = AKFrequencyTracker(mixer)
recorder = try AKNodeRecorder(node: mixer, file: tape)
AudioKit.output = tracker
try AudioKit.start()
gameTimer = Timer.scheduledTimer(timeInterval: 0.005, target: self, selector: #selector(runTimedCode), userInfo: nil, repeats: true)
} catch {
AKLog("AudioKit did not start!")
}
}
@objc func runTimedCode()
{
print(“Amplitude :: ", tracker.amplitude)
print(“Frequency :: ", tracker.frequency)
trackeddB1Slider.value = 0
if tracker.frequency > 62 && tracker.frequency < 110 {
if tracker.amplitude > maxAmpValues {
self.lable1.text = String(format: "Max: %0.3f ", tracker.amplitude)
maxAmpValues = tracker.amplitude
}
trackeddB1Slider?.value = tracker.amplitude
}
}
@IBAction func startRecordungActoin(_ sender: Any) {
if recorder!.isRecording {
recorder!.stop()
gameTimer.invalidate()
} else {
do {
try recorder!.record()
} catch {
AKLog("Couldn't record")
}
}
}
After that, I set the gain value "0" of EQ 63 Hz for AKEqualizerFilter class and then i track the amplitude again for 63 Hz band.
My second controller class is here.
var tracker = AKFrequencyTracker()
@IBAction func startEQ(_ sender: Any) {
do {
let player = try AKAudioPlayer(file: recordedAudioFile!)
player.looping = true
filterBand2 = AKEqualizerFilter(player, centerFrequency: 32, bandwidth: 44.7, gain: 1.0)
filterBand3 = AKEqualizerFilter(filterBand2, centerFrequency: 63, bandwidth: 70.8, gain: 0.0)
filterBand4 = AKEqualizerFilter(filterBand3, centerFrequency: 125, bandwidth: 141, gain: 1.0)
filterBand5 = AKEqualizerFilter(filterBand4, centerFrequency: 250, bandwidth: 282, gain: 1.0)
filterBand6 = AKEqualizerFilter(filterBand5, centerFrequency: 500, bandwidth: 562, gain: 1.0)
let filterBand7 = AKEqualizerFilter(filterBand6, centerFrequency: 1_000, bandwidth: 1_112, gain: 1.0)
tracker = AKFrequencyTracker(filterBand7)
AudioKit.output = tracker
do {
try AudioKit.start()
} catch {
AKLog("AudioKit did not start!")
}
player.play()
gameTimer = Timer.scheduledTimer(timeInterval: 0.005, target: self, selector: #selector(runTimedCode), userInfo: nil, repeats: true)
}
catch {
}
}
@objc func runTimedCode()
{
print(“Amplitude :: ", tracker.amplitude)
print(“Frequency :: ", tracker.frequency)
trackeddB1Slider.value = 0
if tracker.frequency > 62 && tracker.frequency < 110 {
if tracker.amplitude > NewMaxAmpValues[0] {
self.lable1.text = String(format: "Max: %0.3f ", tracker.amplitude)
NewMaxAmpValues[0] = tracker.amplitude
}
trackedDB1Slider?.value = tracker.amplitude
}
}
My Problem is, maximum value of amplitude remain same (Or some time grater) after applying AKEqualizerFilter with "0" gain value as before applying filter, I supposed that amplitude should be cut down for EQ 63 band.
I want to show the change in amplitude to client to prove that the equalizer is working fine.