AKSampler

open class AKSampler: AKNode

Sampler audio generation.

1) init the audio unit like this: var sampler = AKSampler() 2) load a sound a file: sampler.loadWav(path/to/your/sound/file/in/app/bundle) (without wav extension) 3) connect to the engine: AudioKit.output = sampler 4) start the engine AudioKit.start()

  • Internal audio unit

    Declaration

    Swift

    open var internalAU: AUAudioUnit?
  • Sampler AV Audio Unit

    Declaration

    Swift

    open var samplerUnit = AVAudioUnitSampler()
  • Transposition amount in semitones, from -24 to 24, Default: 0

    Declaration

    Swift

    open var tuning: Double
  • Initialize the sampler node

    Declaration

    Swift

    override public init()
  • Load a wav file

    Declaration

    Swift

    open func loadWav(_ file: String)

    Parameters

    file

    Name of the file without an extension (assumed to be accessible from the bundle)

  • Load an EXS24 sample data file

    Declaration

    Swift

    open func loadEXS24(_ file: String)

    Parameters

    file

    Name of the EXS24 file without the .exs extension

  • Load an AKAudioFile

    Declaration

    Swift

    open func loadAudioFile(_ file: AKAudioFile) throws

    Parameters

    file

    an AKAudioFile

  • Load an array of AKAudioFiles

    If a file name ends with a note name (ex: violinC3.wav) The file will be set to this note Handy to set multi-sampled instruments or a drum kit…

    Declaration

    Swift

    open func loadAudioFiles(_ files: [AKAudioFile] ) throws

    Parameters

    file

    an array of AKAudioFile

  • Load a Melodic SoundFont SF2 sample data file

    • Parameters:
      • file: Name of the SoundFont SF2 file without the .sf2 extension
      • preset: Number of the program to use

    Declaration

    Swift

    open func loadMelodicSoundFont(_ file: String, preset: Int)

    Parameters

    file

    Name of the SoundFont SF2 file without the .sf2 extension

    preset

    Number of the program to use

  • Load a Percussive SoundFont SF2 sample data file

    • Parameters:
      • file: Name of the SoundFont SF2 file without the .sf2 extension
      • preset: Number of the program to use

    Declaration

    Swift

    open func loadPercussiveSoundFont(_ file: String, preset: Int)

    Parameters

    file

    Name of the SoundFont SF2 file without the .sf2 extension

    preset

    Number of the program to use

  • Load a file path

    Declaration

    Swift

    open func loadPath(_ filePath: String)

    Parameters

    filePath

    Name of the file with the extension

  • Output Amplitude. Range: -90.0 -> +12 db, Default: 0 db

    Declaration

    Swift

    open var amplitude: Double = 0
  • Normalized Output Volume. Range: 0 -> 1, Default: 1

    Declaration

    Swift

    open var volume: Double = 1
  • pan

    Pan. Range: -1 -> 1, Default: 0

    Declaration

    Swift

    open var pan: Double = 0
  • Play a MIDI Note

    • Parameters:
      • noteNumber: MIDI Note Number to play
      • velocity: MIDI Velocity
      • channel: MIDI Channnel

    Declaration

    Swift

    open func play(noteNumber: MIDINoteNumber = 60,
                                    velocity: MIDIVelocity = 127,
                                    channel: MIDIChannel = 0)

    Parameters

    noteNumber

    MIDI Note Number to play

    velocity

    MIDI Velocity

    channel

    MIDI Channnel

  • Stop a MIDI Note

    • Parameters:
      • noteNumber: MIDI Note Number to stop
      • channel: MIDI Channnel

    Declaration

    Swift

    open func stop(noteNumber: MIDINoteNumber = 60, channel: MIDIChannel = 0)

    Parameters

    noteNumber

    MIDI Note Number to stop

    channel

    MIDI Channnel