在采样器中设置 kMusicDeviceProperty_SoundBankURL 时出现错误 -10879 (kAudioUnitErr_InvalidProperty)
Error -10879 (kAudioUnitErr_InvalidProperty) when setting kMusicDeviceProperty_SoundBankURL in a sampler
在 Mac 的命令行 Xcode 项目中,使用 Swift,我正在设置 AudioGraph 以播放 MIDI 文件。
在运行时,当我尝试将 SoundFont 分配给采样器单元时,我反复出现错误 -10879 (kAudioUnitErr_InvalidProperty)。
正如您在代码中看到的,我尝试为同一个采样器单元设置另一个 属性,但也没有成功。看来采样器单元不想被打扰...
我在扯头发,但我一点也不知道为什么会这样!
这是我的代码,谢谢你的任何拯救头发的想法。
import Foundation
import AVFoundation
var processingGraph = AUGraph()
var samplerNode = AUNode()
var samplerUnit = AudioUnit()
var ioNode = AUNode()
var ioUnit = AudioUnit()
//*********************** Create the graph ************************
// create the graph
CheckError(NewAUGraph(&processingGraph), "Error creating new AUGraph")
// create the sampler node
var samplerDescription:AudioComponentDescription = AudioComponentDescription(
componentType: UInt32(kAudioUnitType_MusicDevice),
componentSubType: UInt32(kAudioUnitSubType_Sampler),
componentManufacturer: UInt32(kAudioUnitManufacturer_Apple),
componentFlags: 0,
componentFlagsMask: 0)
CheckError(AUGraphAddNode(processingGraph, &samplerDescription, &samplerNode), "Error creating Sampler node")
println("samplerNode: \(samplerNode)")
// create the ionode
var ioUnitDescription:AudioComponentDescription = AudioComponentDescription(
componentType: UInt32(kAudioUnitType_Output),
componentSubType: UInt32(kAudioUnitSubType_GenericOutput),
componentManufacturer: UInt32(kAudioUnitManufacturer_Apple),
componentFlags: 0,
componentFlagsMask: 0)
CheckError(AUGraphAddNode(processingGraph, &ioUnitDescription, &ioNode), "Error creating RemoteIO node")
// open the graph
CheckError(AUGraphOpen(processingGraph), "Error opening the graph")
// get audioUnits
CheckError(AUGraphNodeInfo(processingGraph, samplerNode, nil, &samplerUnit), "Error retrieving Sampler AU")
println("samplerUnit: \(samplerUnit)")
CheckError(AUGraphNodeInfo(processingGraph, ioNode, nil, &ioUnit), "Error retrieving IO AU")
var bankURL = NSURL(string: "/Path/To/A/.sf2/Sound/Font")!
println("\(bankURL)")
CheckError(AudioUnitSetProperty (samplerUnit,
UInt32(kMusicDeviceProperty_SoundBankURL),
UInt32(kAudioUnitScope_Global),
UInt32(0),
&bankURL, UInt32(sizeof(bankURL.dynamicType))), "AudioUnitSetProperty: kMusicDeviceProperty_SoundBankURL")
//var maxCPULoad:Float32 = 0.8;
//CheckError(AudioUnitSetProperty (samplerUnit,
// UInt32(kAudioUnitProperty_CPULoad),
// UInt32(kAudioUnitScope_Global),
// 0,
// &maxCPULoad, UInt32(sizeof(Float32))), "AudioUnitSetProperty: kAudioUnitProperty_CPULoad")
采样器 AU 不使用此 属性(在 AudioUnitProperties.h 中注明)。对于 iOS,这仅供 MIDISynth AU 使用。要将 DLS 预设加载到采样器中,请使用 kAUSamplerProperty_LoadInstrument。开发人员网站上有一篇技术说明对此进行了描述。
在 Mac 的命令行 Xcode 项目中,使用 Swift,我正在设置 AudioGraph 以播放 MIDI 文件。
在运行时,当我尝试将 SoundFont 分配给采样器单元时,我反复出现错误 -10879 (kAudioUnitErr_InvalidProperty)。
正如您在代码中看到的,我尝试为同一个采样器单元设置另一个 属性,但也没有成功。看来采样器单元不想被打扰...
我在扯头发,但我一点也不知道为什么会这样!
这是我的代码,谢谢你的任何拯救头发的想法。
import Foundation
import AVFoundation
var processingGraph = AUGraph()
var samplerNode = AUNode()
var samplerUnit = AudioUnit()
var ioNode = AUNode()
var ioUnit = AudioUnit()
//*********************** Create the graph ************************
// create the graph
CheckError(NewAUGraph(&processingGraph), "Error creating new AUGraph")
// create the sampler node
var samplerDescription:AudioComponentDescription = AudioComponentDescription(
componentType: UInt32(kAudioUnitType_MusicDevice),
componentSubType: UInt32(kAudioUnitSubType_Sampler),
componentManufacturer: UInt32(kAudioUnitManufacturer_Apple),
componentFlags: 0,
componentFlagsMask: 0)
CheckError(AUGraphAddNode(processingGraph, &samplerDescription, &samplerNode), "Error creating Sampler node")
println("samplerNode: \(samplerNode)")
// create the ionode
var ioUnitDescription:AudioComponentDescription = AudioComponentDescription(
componentType: UInt32(kAudioUnitType_Output),
componentSubType: UInt32(kAudioUnitSubType_GenericOutput),
componentManufacturer: UInt32(kAudioUnitManufacturer_Apple),
componentFlags: 0,
componentFlagsMask: 0)
CheckError(AUGraphAddNode(processingGraph, &ioUnitDescription, &ioNode), "Error creating RemoteIO node")
// open the graph
CheckError(AUGraphOpen(processingGraph), "Error opening the graph")
// get audioUnits
CheckError(AUGraphNodeInfo(processingGraph, samplerNode, nil, &samplerUnit), "Error retrieving Sampler AU")
println("samplerUnit: \(samplerUnit)")
CheckError(AUGraphNodeInfo(processingGraph, ioNode, nil, &ioUnit), "Error retrieving IO AU")
var bankURL = NSURL(string: "/Path/To/A/.sf2/Sound/Font")!
println("\(bankURL)")
CheckError(AudioUnitSetProperty (samplerUnit,
UInt32(kMusicDeviceProperty_SoundBankURL),
UInt32(kAudioUnitScope_Global),
UInt32(0),
&bankURL, UInt32(sizeof(bankURL.dynamicType))), "AudioUnitSetProperty: kMusicDeviceProperty_SoundBankURL")
//var maxCPULoad:Float32 = 0.8;
//CheckError(AudioUnitSetProperty (samplerUnit,
// UInt32(kAudioUnitProperty_CPULoad),
// UInt32(kAudioUnitScope_Global),
// 0,
// &maxCPULoad, UInt32(sizeof(Float32))), "AudioUnitSetProperty: kAudioUnitProperty_CPULoad")
采样器 AU 不使用此 属性(在 AudioUnitProperties.h 中注明)。对于 iOS,这仅供 MIDISynth AU 使用。要将 DLS 预设加载到采样器中,请使用 kAUSamplerProperty_LoadInstrument。开发人员网站上有一篇技术说明对此进行了描述。