简体   繁体   English

在AudioKit中过滤音频

[英]Filtering audio in AudioKit

What i need to do: 我需要做什么:

  • record audio file; 录制音频文件;
  • as it's record from iPhone/iPad microphone it can be quiet, so i need to filter it to make it louder; 因为它是iPhone / iPad麦克风的记录,它可以很安静,所以我需要过滤它以使它更大声;
  • save filtered record; 保存过滤记录;

I'm new in audio programming, but as I understand so far I need " All Pass " filter (if not please correct me). 我是音频编程的新手,但据我所知,到目前为止我需要“ 全通 ”滤镜(如果不是请纠正我)。

For this task I've found two libs: Novocaine and AudioKit , but Novocaine written in C, so it's harder to implement it in swift, and I decided to use AudioKit, but I didn't found "All Pass" filter there. 为了完成这项任务,我发现了两个库: NovocaineAudioKit ,但用C语言写的Novocaine,所以在swift中实现它更难,我决定使用AudioKit,但我没有在那里找到“All Pass”过滤器。

Does anybody know how to implement it in AudioKit and save filtered file? 有人知道如何在AudioKit中实现它并保存过滤后的文件吗? Thank you! 谢谢!

You have a few choices, for musical recordings I recommend AKBooster as it purely boosts the audio, you have to be careful how much you boost, otherwise you might cause clipping. 你有一些选择,对于音乐录音,我推荐AKBooster,因为它纯粹提升音频,你必须小心你提升多少,否则你可能会导致削波。

For spoken word audio I recommend AKPeakLimiter. 对于口语单词音频,我推荐使用AKPeakLimiter。 It will give you the maximum volume without clipping. 它会给你最大的音量而不会削减。 Set the attackTime and decayTime to lower values to hear a more pronounced effect. 将attackTime和decayTime设置为较低的值以听到更明显的效果。

The values of the sliders won't represent the values of the parameters until you move them. 在移动滑块之前,滑块的值不会表示参数的值。

import UIKit
import AudioKit

class ViewController: UIViewController {

    let mic = AKMicrophone()
    let boost = AKBooster()
    let limiter = AKPeakLimiter()

    override func viewDidLoad() {
        super.viewDidLoad()

        mic >>> boost >>> limiter
        AudioKit.output = limiter
        AudioKit.start()

        let inset: CGFloat = 10.0
        let width = view.bounds.width - inset * 2


        for i in 0..<4 {
            let y = CGFloat(100 + i * 50)
            let slider = UISlider(frame: CGRect(x: inset, y: y, width: width, height: 30))
            slider.tag = i
            slider.addTarget(self, action: #selector(sliderAction(slider:)), for: .valueChanged)
            view.addSubview(slider)
        }

        boost.gain = 1

    }

    @objc func sliderAction(slider: UISlider) {
        switch slider.tag {
        case 0:
            boost.gain = slider.value * 40
        case 1:
            limiter.preGain = slider.value * 40
        case 2:
            limiter.attackTime = max(0.001, slider.value * 0.03)
        case 4:
            limiter.decayTime = max(0.001, slider.value * 0.06)
        default: break

        }
    }

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM