gpt4 book ai didi

xcode - 从iOS转换为Mac OS时出现AVFoundation AVAudioPlayerNode错误

转载 作者:行者123 更新时间:2023-12-03 02:33:14 26 4
gpt4 key购买 nike

我正在将Audio Foundation示例代码iOS转换为Swift 3 Mac OS
因为似乎很容易理解

一切似乎都可以,但是我得到了一个错误

2016-09-09 09:52:17.371 Imaginator_001[5456:217674] 09:52:17.370 ERROR: AVAudioNode.mm:747: AUSetFormat: error -10868 2016-09-09 09:52:17.371 Imaginator_001[5456:217674] error -10868



而且我也不是很安静地确定为什么有什么建议会很棒
import Cocoa
import AVFoundation

class MainWindowController: NSWindowController {

var engine: AVAudioEngine!
var playerA: AVAudioPlayerNode!
var playerB: AVAudioPlayerNode!

override func windowDidLoad() {
super.windowDidLoad()

// Do any additional setup after loading
engine = AVAudioEngine()
playerA = AVAudioPlayerNode()
playerB = AVAudioPlayerNode()
playerA.volume = 0.5
playerB.volume = 0.5

//Use stereo audio file
let url = Bundle.main().urlForResource("vox", withExtension: "wav")
// Here you are creating an AVAudioFile from the sound file,
// preparing a buffer of the correct format and length and loading


// the file into the buffer.
let file = try? AVAudioFile(forReading: url!)


let buffer = AVAudioPCMBuffer(pcmFormat: file!.processingFormat, frameCapacity: AVAudioFrameCount(file!.length))

try! file!.read(into: buffer)

// This is a reverb with a cathedral preset. It's nice and ethereal
// You're also setting the wetDryMix which controls the mix between the effect and the
// original sound.
let reverb = AVAudioUnitReverb()
reverb.loadFactoryPreset(AVAudioUnitReverbPreset.cathedral)
reverb.wetDryMix = 50

// This is a distortion with a radio tower preset which works well for speech
// As distortion tends to be quite loud you're setting the wetDryMix to only 25
let distortion = AVAudioUnitDistortion()
distortion.loadFactoryPreset(AVAudioUnitDistortionPreset.speechRadioTower)
distortion.wetDryMix = 25

// Attach the four nodes to the audio engine
engine.attach(playerA)
engine.attach(playerB)
engine.attach(reverb)
engine.attach(distortion)

// Connect playerA to the reverb
engine.connect(playerA, to: reverb, format: buffer.format)

// Connect the reverb to the mixer
engine.connect(reverb, to: engine.mainMixerNode, format: buffer.format)

// Connect playerB to the distortion
engine.connect(playerB, to: distortion, format: buffer.format)

// Connect the distortion to the mixer
engine.connect(distortion, to: engine.mainMixerNode, format: buffer.format)

// Schedule playerA and playerB to play the buffer on a loop
playerA.scheduleBuffer(buffer, at: nil, options: AVAudioPlayerNodeBufferOptions.loops, completionHandler: nil)
playerB.scheduleBuffer(buffer, at: nil, options: AVAudioPlayerNodeBufferOptions.loops, completionHandler: nil)

// Start the audio engine
engine.prepare()
try! engine.start()


}//eo overide


@IBAction func play(_ sender: AnyObject) {
playerA.volume = 0.5
playerB.volume = 0.5

playerA.play()
playerB.play()

}

}

最佳答案

解决了我使用单声道音频文件而不是立体声的问题,即使它在iso中作为单声道工作也是如此。

关于xcode - 从iOS转换为Mac OS时出现AVFoundation AVAudioPlayerNode错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39407756/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com