AKSamplePlayer

open class AKSamplePlayer: AKNode, AKComponent

Audio player that loads a sample into memory

  • Four letter unique description of the node

    Declaration

    Swift

    public static let ComponentDescription = AudioComponentDescription(generator: "smpl")
  • Ramp Time represents the speed at which parameters are allowed to change

    Declaration

    Swift

    @objc open dynamic var rampTime: Double = AKSettings.rampTime
  • startPoint in samples - where to start playing the sample from

    Declaration

    Swift

    @objc open dynamic var startPoint: Sample = 0
  • endPoint - this is where the sample will play to before stopping. A value less than the start point will play the sample backwards.

    Declaration

    Swift

    @objc open dynamic var endPoint: Sample = 0
  • playback rate - A value of 1 is normal, 2 is double speed, 0.5 is halfspeed, etc.

    Declaration

    Swift

    @objc open dynamic var rate: Double = 1
  • Volume - amplitude adjustment

    Declaration

    Swift

    @objc open dynamic var volume: Double = 1
  • Loop Enabled - if enabled, the sample will loop back to the startpoint when the endpoint is reached. When disabled, the sample will play through once from startPoint to endPoint

    Declaration

    Swift

    @objc open dynamic var loopEnabled: Bool = false
  • Number of samples in the audio stored in memory

    Declaration

    Swift

    open var size: Sample
  • Position in the audio file from 0 - 1

    Declaration

    Swift

    open var normalizedPosition: Double
  • Position in the audio in samples, but represented as a double since you could conceivably be at a non-integer sample

    Declaration

    Swift

    open var position: Double
  • Tells whether the node is processing (ie. started, playing, or active)

    Declaration

    Swift

    @objc open dynamic var isStarted: Bool
  • Initialize this SamplePlayer node

    Declaration

    Swift

    public init(file: AVAudioFile,
                    startPoint: Sample = 0,
                    endPoint: Sample = 0,
                    rate: Double = 1,
                    volume: Double = 1,
                    maximumSamples: Int = 0,
                    completionHandler: @escaping AKCCallback = { })

    Parameters

    file

    Initial file to load (defining maximum size unless maximum samples are also set

    startPoint

    Point in samples from which to start playback

    endPoint

    Point in samples at which to stop playback

    rate

    Multiplication factor from original speed (Default: 1)

    volume

    Multiplication factor of the overall amplitude (Default: 1)

    maximumSamples

    Largest number of samples that will be loaded into the sample player

    completionHandler

    Callback to run when the sample playback is completed

  • Function to start, play, or activate the node, all do the same thing

    Declaration

    Swift

    @objc open func start()
  • Function to stop or bypass the node, both are equivalent

    Declaration

    Swift

    @objc open func stop()
  • Play from a certain sample

    Declaration

    Swift

    open func play(from: Sample = 0)
  • Play from a certain sample for a certain number of samples

    Declaration

    Swift

    open func play(from: Sample = 0, length: Sample = 0)
  • Play from a certain sample to an end sample

    Declaration

    Swift

    open func play(from: Sample = 0, to: Sample = 0)
  • Load a new audio file into memory

    Declaration

    Swift

    open func loadSound(file: AVAudioFile)