【发布时间】:2015-04-09 17:41:07
【问题描述】:
在 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")
【问题讨论】:
标签: swift core-audio midi audiounit