我确实尝试在音频文件中添加效果,它确实可以在iOS 9上运行,但在iOS10中它只能在iphone 6s中运行,在旧设备上运行,在模拟器中运行良好,我的信息中有私有用法说明。用于照片,相机和微缩胶片的plist文件 我确实在线上发现了输卵管错误audioEngine.mainMixerNode.installTapOnBus
2016-09-21 13:08:20.109701 $$$$[557:86076] [central] 54: ERROR: [0x16e34f000] >avae> AVAudioNode.mm:751: AUSetFormat: error -10865
2016-09-21 13:08:20.110111 Tell Your Story[557:86076] *** Terminating app due to uncaught exception 'com.apple.coreaudio.avfaudio', reason: 'error -10865'
我的功能是为音频添加效果
private fund addEffetToAudioFile(pitch: Float, rate: Float, reverb: Float, echo: Float) { // Initialize variables
audioEngine = AVAudioEngine()
audioPlayerNode = AVAudioPlayerNode()
audioEngine.attachNode(audioPlayerNode)
// Setting the pitch
let pitchEffect = AVAudioUnitTimePitch()
pitchEffect.pitch = pitch
audioEngine.attachNode(pitchEffect)
// Setting the platback-rate
let playbackRateEffect = AVAudioUnitVarispeed()
playbackRateEffect.rate = rate
audioEngine.attachNode(playbackRateEffect)
// Setting the reverb effect
let reverbEffect = AVAudioUnitReverb()
reverbEffect.loadFactoryPreset(AVAudioUnitReverbPreset.Cathedral)
reverbEffect.wetDryMix = reverb
audioEngine.attachNode(reverbEffect)
// Setting the echo effect on a specific interval
let echoEffect = AVAudioUnitDelay()
echoEffect.delayTime = NSTimeInterval(echo)
audioEngine.attachNode(echoEffect)
// Chain all these up, ending with the output
audioEngine.connect(audioPlayerNode, to: playbackRateEffect, format: nil)
audioEngine.connect(playbackRateEffect, to: pitchEffect, format: nil)
audioEngine.connect(pitchEffect, to: reverbEffect, format: nil)
audioEngine.connect(reverbEffect, to: echoEffect, format: nil)
audioEngine.connect(echoEffect, to: audioEngine.mainMixerNode, format: nil)
// Good practice to stop before starting
audioPlayerNode.stop()
// Play the audio file
if (audioEngine != nil) {
audioEngine?.stop()
}
do {
audioFile = try AVAudioFile(forReading: self.recordedAudioURL)
} catch {
print("Error: Can't create audio file")
self.showAlert(TYSAudioEditorHelper.Alerts.AudioFileError, message: String(error))
return
}
audioPlayerNode.scheduleFile(audioFile, atTime: nil, completionHandler: {
print("Complete")
})
try! audioEngine.start()
let dirPaths: AnyObject = NSSearchPathForDirectoriesInDomains( NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true)[0]
let tmpFileUrl: NSURL = NSURL.fileURLWithPath(dirPaths.stringByAppendingPathComponent(kOutputSoundWithEffectFileName))
do {
self.newAudio = try AVAudioFile(forWriting: tmpFileUrl, settings:[
AVFormatIDKey: NSNumber(unsignedInt:kAudioFormatMPEG4AAC_HE),
AVEncoderAudioQualityKey : AVAudioQuality.Medium.rawValue,
AVEncoderBitRateKey : 12800,
AVNumberOfChannelsKey: 2,
AVSampleRateKey : 44100.0
])
/*Error in this line*/ audioEngine.mainMixerNode.installTapOnBus(0, bufferSize: 2048, format: audioEngine.mainMixerNode.inputFormatForBus(1)) { (buffer: AVAudioPCMBuffer!, time: AVAudioTime!) -> Void in
print(self.newAudio.length)
if (self.newAudio.length) < (self.audioFile.length) {
//Let us know when to stop saving the file, otherwise saving infinitely
do {
try self.newAudio.writeFromBuffer(buffer)
} catch {
print("Problem Writing Buffer")
}
} else {
self.audioEngine.mainMixerNode.removeTapOnBus(0)
//if we dont remove it, will keep on tapping infinitely
self.newAudio = nil
if (self.audioEngine != nil) {
self.audioEngine?.stop()
}
self.removeOldFileIfExist(self.kOriginalVideoSoundFileName)
self.saveAudioFileInVideo(tmpFileUrl)
}
}
} catch {
print("Problem")
}
do {
try audioEngine.start()
} catch {
showAlert(TYSAudioEditorHelper.Alerts.AudioEngineError, message: String(error))
return
}
// play the recording!
audioPlayerNode.play()
}
答案 0 :(得分:0)
kAudioUnitErr_PropertyNotWritable = -10865
根据https://developer.apple.com/reference/avfoundation/avaudionode/1387122-installtap
格式: 如果为非nil,则尝试将其应用为指定输出总线的格式。 这只应在连接到未连接到另一个节点的输出总线时完成;否则将导致错误。指定总线上的抽头和连接格式(如果非零)应该相同。否则,后一操作将覆盖任何先前设置的格式。 对于AVAudioOutputNode,必须将tap格式指定为nil。
可能是以下之一:
mainMixerNode已连接到另一个节点,因此您需要在安装水龙头之前断开它们
mainMixerNode是一个AVAudioOutputNode,所以你需要为这个参数传入nil