在采样器中设置kMusicDeviceProperty_SoundBankURL时出现错误-10879(kAudioUnitErr_InvalidProperty)

时间:2015-04-09 17:41:07

标签: swift core-audio midi audiounit

在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")

1 个答案:

答案 0 :(得分:0)

采样器AU不使用此属性(在AudioUnitProperties.h中注明)。对于iOS,这仅供MIDISynth AU使用。要将DLS预设加载到采样器中,请使用kAUSamplerProperty_LoadInstrument。在开发者网站上有一个技术说明描述了这一点。