我是iOS版AudioKit的新手,我已经跟踪了声音的63Hz均衡器的最大幅度,并使用AKEqualizerFilter
类将其增益值更改为0。它已成功更改,我可以收听,但是我想知道如何使用AKFrequencyTracker类以幅度/ dB /增益的形式显示该更改?
这是我的代码,用于更改63Hz声音的增益值。
var filterBand3 = AKEqualizerFilter(
filterBand2, centerFrequency: 64, bandwidth: 70.8, gain: 0.0).
先谢谢了。
更新
第一步,我使用iPhone麦克风录制歌曲,与此同时,我正在跟踪EQ 63 Hz频段的最高振幅。这是我第一个控制器的代码。
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")
}
}
}
在那之后,我将AKEqualizerFilter类的EQ 63 Hz的增益值设置为“ 0”,然后再次跟踪63 Hz频带的幅度。
第二个控制器类在这里。
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
}
}
我的问题是,在应用增益值为“ 0”的AKEqualizerFilter之后,振幅的最大值与应用滤波器之前的振幅最大值保持相同(或有些时间变化),我认为应该减小EQ 63频带的振幅。
我想向客户展示幅度的变化,以证明均衡器工作正常。