0

In a command line Xcode project for Mac, using Swift, I am setting up an AudioGraph in order to play a MIDI file.
At runtime, I repeatedly have an error -10879 (kAudioUnitErr_InvalidProperty) when I try to assign a SoundFont to the sampler unit.
As you can see in the code, I tried to set another property for the same sampler unit, with no success either. It looks like the sampler unit does not want to be bothered...
I am pulling my hair, but I do not have the slightest idea why it is so!
Here is my code, thank you for any hair-saving idea.

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")
popisar
  • 379
  • 2
  • 3
  • 15

1 Answers1

0

The Sampler AU does not use this property (noted in AudioUnitProperties.h). For iOS, this is only used by the MIDISynth AU. To load a DLS preset into the Sampler, use kAUSamplerProperty_LoadInstrument. There is a Tech Note describing this on the developer site.

nethack
  • 36
  • 1
  • 1
  • 7