为什么这不起作用?如果我不能让AUGraph产生窦音并且它有效。但是当我将AUGraph添加到声音库时,它并没有发出声音。
func play() {
var status = OSStatus(noErr)
status = NewMusicPlayer(&musicPlayer)
if status != OSStatus(noErr) {
println("bad status \(status) creating player")
displayStatus(status)
return
}
status = MusicPlayerSetSequence(musicPlayer, self.musicSequence)
if status != OSStatus(noErr) {
displayStatus(status)
println("setting sequence")
return
}
status = MusicPlayerPreroll(musicPlayer)
if status != OSStatus(noErr) {
displayStatus(status)
return
}
status = MusicPlayerStart(musicPlayer)
if status != OSStatus(noErr) {
displayStatus(status)
return
}
直到这里它工作正常。之后不是。
status = NewAUGraph(&self.processingGraph)
if status != OSStatus(noErr) {
displayStatus(status)
return
}
status = MusicSequenceSetAUGraph(self.musicSequence, self.processingGraph)
if status != OSStatus(noErr) {
displayStatus(status)
return
}
var samplerNode = AUNode()
var ioNode = AUNode()
var cd:AudioComponentDescription = AudioComponentDescription(
componentType: OSType(kAudioUnitType_MusicDevice),
componentSubType: OSType(kAudioUnitSubType_Sampler),
componentManufacturer: OSType(kAudioUnitManufacturer_Apple),
componentFlags: 0,
componentFlagsMask: 0)
status = AUGraphAddNode(self.processingGraph, &cd, &samplerNode)
if status != OSStatus(noErr) {
displayStatus(status)
return
}
var ioUnitDescription:AudioComponentDescription = AudioComponentDescription(
componentType: OSType(kAudioUnitType_Output),
componentSubType: OSType(kAudioUnitSubType_RemoteIO),
componentManufacturer: OSType(kAudioUnitManufacturer_Apple),
componentFlags: 0,
componentFlagsMask: 0)
status = AUGraphAddNode(self.processingGraph, &ioUnitDescription, &ioNode)
if status != OSStatus(noErr) {
displayStatus(status)
return
}
loadSF2Preset(0)
}
func loadSF2Preset(preset:UInt8) {
if let bankURL = NSBundle.mainBundle().URLForResource("gs_instruments", withExtension: "dls") {
var instdata = AUSamplerInstrumentData(fileURL: Unmanaged.passUnretained(bankURL),
instrumentType: UInt8(kInstrumentType_DLSPreset),
bankMSB: UInt8(kAUSampler_DefaultMelodicBankMSB),
bankLSB: UInt8(kAUSampler_DefaultBankLSB),
presetID: preset)
var status = AudioUnitSetProperty(
self.samplerUnit,
UInt32(kAUSamplerProperty_LoadInstrument),
UInt32(kAudioUnitScope_Global),
0,
&instdata,
UInt32(sizeof(AUSamplerInstrumentData)))
//CheckError(status)
}
}