相关疑难解决方法(0)

将pcm加载到AVAudioPCMBuffer

我有以下代码:

func loadSoundfont(_ pitch : String) {
    let path: String = Bundle.main.path(forResource: "\(self.id)/\(pitch)", ofType: "f32")!
    let url = URL(fileURLWithPath: path)

    do {
        let file = try AVAudioFile(forReading: url, commonFormat: AVAudioCommonFormat.pcmFormatFloat32, interleaved: true)
        let format = file.processingFormat
        let capacity = AVAudioFrameCount(file.length)
        self.buffer = AVAudioPCMBuffer(pcmFormat: format, frameCapacity: capacity)
        try file.read(into: self.buffer!)
    } catch let error as NSError {
        print("ERROR HERE", error.localizedDescription)
    }
}
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:1954115647这是:kAudioFileUnsupportedFileTypeError

我的A4.f32文件包含PCM浮点32。在这里我缺少什么吗?我的文件中没有标题,是否可能导致此问题?

avfoundation swift swift3

5
推荐指数
1
解决办法
1187
查看次数

标签 统计

avfoundation ×1

swift ×1

swift3 ×1