Beethoven 项目使用教程
Beethoven :guitar: A maestro of pitch detection. 项目地址: https://gitcode.com/gh_mirrors/be/Beethoven
1. 项目的目录结构及介绍
Beethoven 是一个音频处理 Swift 库,提供了对音乐信号进行音高检测的简单接口。以下是项目的目录结构及其介绍:
Beethoven/
├── Example/ # 示例项目目录
│ └── GuitarTuner # 吉他调音器示例
├── Project/ # 项目文件
├── Resources/ # 资源文件
├── Source/ # 源代码目录
│ ├── Tests/ # 测试文件
│ │ └── Spec # 测试规格
│ └── ... # 其他源代码文件
├── .gitignore # Git 忽略文件
├── .swift-version # Swift 版本文件
├── .swiftlint.yml # SwiftLint 配置文件
├── .travis.yml # Travis CI 配置文件
├── Beethoven.podspec # CocoaPods 描述文件
├── CONTRIBUTING.md # 贡献指南
├── Cartfile # Carthage 配置文件
├── Cartfile.private # Carthage 私有配置文件
├── Cartfile.resolved # Carthage 解析文件
├── LICENSE.md # 许可证文件
├── Package.swift # Swift 包管理器描述文件
└── README.md # 项目说明文件
2. 项目的启动文件介绍
项目的启动文件主要是 Example/GuitarTuner
目录下的主 Swift 文件,这个文件负责初始化 PitchEngine
类并开始音高检测。
import UIKit
import Beethoven
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// 初始化配置
let config = Config(bufferSize: 4096, estimationStrategy: .yin)
let pitchEngine = PitchEngine(config: config)
// 设置代理并开始检测
pitchEngine.delegate = self
pitchEngine.start()
return true
}
}
3. 项目的配置文件介绍
项目的配置文件是 Config
结构体,它用于设置音频缓冲区大小和音高估计策略。以下是 Config
的基本用法:
struct Config {
var bufferSize: Int
var estimationStrategy: EstimationStrategy
var audioUrl: URL? // 可选,用于指定音频文件路径
}
// 默认配置,用于输入信号跟踪
let config = Config(bufferSize: 4096, estimationStrategy: .yin)
// 输出信号跟踪配置
let config = Config(bufferSize: 4096, estimationStrategy: .yin, audioUrl: audioFileUrl)
EstimationStrategy
枚举用于选择不同的音高估计算法,例如 .yin
、.maxValue
、.quadradic
等。根据不同的需求,开发者可以选择合适的算法来优化音高检测的准确性和性能。
Beethoven :guitar: A maestro of pitch detection. 项目地址: https://gitcode.com/gh_mirrors/be/Beethoven