AKOperation

open class AKOperation: AKComputedParameter

An AKOperation is a computed parameter that can be passed to other operations in the same operation node

  • Redefining description to return the operation string

    Declaration

    Swift

    open var description: String
  • Left input to any stereo operation

    Declaration

    Swift

    open static var leftInput = AKOperation("(14 p) ")
  • Right input to any stereo operation

    Declaration

    Swift

    open static var rightInput = AKOperation("(15 p) ")
  • Dummy trigger

    Declaration

    Swift

    open static var trigger = AKOperation("(0 p) ")
  • An= array of 14 parameters which may be sent to operations

    Declaration

    Swift

    open static var parameters: [AKOperation] =
  • Convert the operation to a mono operation

    Declaration

    Swift

    open func toMono() -> AKOperation
  • Performs absolute value on the operation

    Declaration

    Swift

    open func abs() -> AKOperation
  • Performs floor calculation on the operation

    Declaration

    Swift

    open func floor() -> AKOperation
  • Returns the fractional part of the operation (as opposed to the integer part)

    Declaration

    Swift

    open func fract() -> AKOperation
  • Performs natural logarithm on the operation

    Declaration

    Swift

    open func log() -> AKOperation
  • Performs Base 10 logarithm on the operation

    Declaration

    Swift

    open func log10() -> AKOperation
  • Rounds the operation to the nearest integer

    Declaration

    Swift

    open func round() -> AKOperation
  • Returns a frequency for a given midi note number

    Declaration

    Swift

    open func midiNoteToFrequency() -> AKOperation
  • Initialize the operation as a constant value

    Declaration

    Swift

    public init(_ value: Double)

    Parameters

    value

    Constant value as an operation

  • Initialize the operation with a Sporth string

    Declaration

    Swift

    public init(_ operationString: String)

    Parameters

    operationString

    Valid Sporth string (proceed with caution

  • Initialize the operation

    Declaration

    Swift

    public init(module: String, setup: String = "", inputs: AKParameter...)

    Parameters

    module

    Sporth unit generator

    setup

    Any setup Sporth code that this operation may require

    inputs

    All the parameters of the operation

  • Standard Sine Wave

    • Parameters:
      • frequency: Frequency in cycles per second (Default: 440)
      • amplitude: Amplitude of the output (Default: 1)

    Declaration

    Swift

    public static func sineWave(
            frequency: AKParameter = 440,
            amplitude: AKParameter = 1
            ) -> AKOperation

    Parameters

    frequency

    Frequency in cycles per second (Default: 440)

    amplitude

    Amplitude of the output (Default: 1)

  • Subtraction of parameters

    Declaration

    Swift

    public func minus(_ subtrahend: AKParameter) -> AKOperation

    Parameters

    subtrahend

    The amount to subtract

  • Portamento-style control signal smoothing Useful for smoothing out low-resolution signals and applying glissando to filters.

    • Parameters:
      • input: Input audio signal
      • halfDuration: Duration which the curve will traverse half the distance towards the new value, then half as much again, etc., theoretically never reaching its asymptote. (Default: 0.02)

    Declaration

    Swift

    public func portamento(halfDuration: AKParameter = 0.02) -> AKOperation

    Parameters

    input

    Input audio signal

    halfDuration

    Duration which the curve will traverse half the distance towards the new value, then half as much again, etc., theoretically never reaching its asymptote. (Default: 0.02)

  • Metro produces a series of 1-sample ticks at a regular rate. Typically, this is used alongside trigger-driven modules.

    Declaration

    Swift

    public static func metronome(frequency: AKParameter = 2.0) -> AKOperation

    Parameters

    frequency

    The frequency to repeat. (Default: 2.0)

  • Trigger based linear AHD envelope generator

    • Parameters:
      • trigger: A triggering operation such as a metronome
      • attack: Attack time, in seconds. (Default: 0.1)
      • hold: Hold time, in seconds. (Default: 0.3)
      • release: Release time, in seconds. (Default: 0.2)

    Declaration

    Swift

    public func triggeredWithEnvelope(
            trigger: AKParameter,
            attack: AKParameter = 0.1,
            hold: AKParameter = 0.3,
            release: AKParameter = 0.2
            ) -> AKOperation

    Parameters

    trigger

    A triggering operation such as a metronome

    attack

    Attack time, in seconds. (Default: 0.1)

    hold

    Hold time, in seconds. (Default: 0.3)

    release

    Release time, in seconds. (Default: 0.2)

  • Gate based linear AHD envelope generator

    • Parameters:
      • gate: 1 for on and 0 for off
      • attack: Attack time, in seconds. (Default: 0.1)
      • hold: Hold time, in seconds. (Default: 0.3)
      • release: Release time, in seconds. (Default: 0.2)

    Declaration

    Swift

    public func gatedADSREnvelope(
            gate: AKParameter,
            attack: AKParameter = 0.1,
            decay: AKParameter = 0.0,
            sustain: AKParameter = 1,
            release: AKParameter = 0.2
            ) -> AKOperation

    Parameters

    gate

    1 for on and 0 for off

    attack

    Attack time, in seconds. (Default: 0.1)

    hold

    Hold time, in seconds. (Default: 0.3)

    release

    Release time, in seconds. (Default: 0.2)

  • Loosely based off of the Csound opcode randomh. The design is equivalent to scaled noise sent through a classic sample and hold module.

    • Parameters:
      • minimum: Minimum value to use. (Default: 0)
      • maximum: Maximum value to use. (Default: 1)
      • updateFrequency: Frequency of randomization (in Hz) (Default: 10)

    Declaration

    Swift

    public static func randomNumberPulse(
            minimum: AKParameter = 0,
            maximum: AKParameter = 1,
            updateFrequency: AKParameter = 10
            ) -> AKOperation

    Parameters

    minimum

    Minimum value to use. (Default: 0)

    maximum

    Maximum value to use. (Default: 1)

    updateFrequency

    Frequency of randomization (in Hz) (Default: 10)

  • Multiplication of parameters

    Declaration

    Swift

    public func times(_ parameter: AKParameter) -> AKOperation

    Parameters

    parameter

    The amount to multiply

  • Offsetting by way of multiplication

    Declaration

    Swift

    public func scaledBy(_ parameter: AKParameter) -> AKOperation

    Parameters

    parameter

    The amount to scale by

  • White noise generator

    Declaration

    Swift

    public static func whiteNoise(amplitude: AKParameter = 1.0) -> AKOperation

    Parameters

    amplitude

    Overall level. (Default: 1.0, Minimum: 0.0, Maximum: 10.0)

  • Classic FM Synthesis audio generation.

    • Parameters:
      • baseFrequency: In cycles per second, or Hz, this is the common denominator for the carrier and modulating frequencies. (Default: 440, Minimum: 0.0, Maximum: 20000.0)
      • carrierMultiplier: This multiplied by the baseFrequency gives the carrier frequency. (Default: 1.0, Minimum: 0.0, Maximum: 1000.0)
      • modulatingMultiplier: This multiplied by the baseFrequency gives the modulating frequency. (Default: 1.0, Minimum: 0.0, Maximum: 1000.0)
      • modulationIndex: This multiplied by the modulating frequency gives the modulation amplitude. (Default: 1.0, Minimum: 0.0, Maximum: 1000.0)
      • amplitude: Output Amplitude. (Default: 0.5, Minimum: 0.0, Maximum: 10.0)

    Declaration

    Swift

    public static func fmOscillator(
            baseFrequency: AKParameter = 440,
            carrierMultiplier: AKParameter = 1.0,
            modulatingMultiplier: AKParameter = 1.0,
            modulationIndex: AKParameter = 1.0,
            amplitude: AKParameter = 0.5
            ) -> AKOperation

    Parameters

    baseFrequency

    In cycles per second, or Hz, this is the common denominator for the carrier and modulating frequencies. (Default: 440, Minimum: 0.0, Maximum: 20000.0)

    carrierMultiplier

    This multiplied by the baseFrequency gives the carrier frequency. (Default: 1.0, Minimum: 0.0, Maximum: 1000.0)

    modulatingMultiplier

    This multiplied by the baseFrequency gives the modulating frequency. (Default: 1.0, Minimum: 0.0, Maximum: 1000.0)

    modulationIndex

    This multiplied by the modulating frequency gives the modulation amplitude. (Default: 1.0, Minimum: 0.0, Maximum: 1000.0)

    amplitude

    Output Amplitude. (Default: 0.5, Minimum: 0.0, Maximum: 10.0)

  • Keep track of the number of times a trigger has fired

    • Parameters:
      • maximum: Largest value to hold before looping or being pinned to this value
      • looping: If set to true, when the maximum is reaching, the count goes back to zero, otherwise it stays at the maximum

    Declaration

    Swift

    public func count(maximum: AKParameter = 1_000_000, looping: Bool = true) -> AKOperation

    Parameters

    maximum

    Largest value to hold before looping or being pinned to this value

    looping

    If set to true, when the maximum is reaching, the count goes back to zero, otherwise it stays at the maximum

  • This is a bandlimited square oscillator ported from the square function from the Faust programming language.

    • Parameters:
      • frequency: In cycles per second, or Hz. (Default: 440, Minimum: 0, Maximum: 20000)
      • amplitude: Output amplitude (Default: 1.0, Minimum: 0, Maximum: 10)
      • pulseWidth: Duty cycle width. (Default: 0.5, Minimum: 0, Maximum: 1)

    Declaration

    Swift

    public static func squareWave(
            frequency: AKParameter = 440,
            amplitude: AKParameter = 1.0,
            pulseWidth: AKParameter = 0.5
            ) -> AKOperation

    Parameters

    frequency

    In cycles per second, or Hz. (Default: 440, Minimum: 0, Maximum: 20000)

    amplitude

    Output amplitude (Default: 1.0, Minimum: 0, Maximum: 10)

    pulseWidth

    Duty cycle width. (Default: 0.5, Minimum: 0, Maximum: 1)

  • Brownian noise generator

    Declaration

    Swift

    public static func brownianNoise(amplitude: AKParameter = 1.0) -> AKOperation

    Parameters

    amplitude

    Overall level. (Default: 1.0, Minimum: 0, Maximum: 1.0)

  • Increment a signal by a default value of 1

    • Parameters:
      • on: When to increment
      • by: Increment amount (Default: 1)
      • minimum: Increment amount (Default: 1)
      • maximum: Increment amount (Default: 1)

    Declaration

    Swift

    public func increment(on trigger: AKParameter,
                              by step: AKParameter = 1.0,
                              minimum: AKParameter = 0.0,
                              maximum: AKParameter = 1_000_000) -> AKOperation

    Parameters

    on

    When to increment

    by

    Increment amount (Default: 1)

    minimum

    Increment amount (Default: 1)

    maximum

    Increment amount (Default: 1)

  • Save a value into the parameters array for using outside of the operation

    Declaration

    Swift

    public func save(parameterIndex: Int) -> AKOperation

    Parameters

    parameterIndex

    Location in the parameters array to save this value

  • A signal with random fluctuations This is useful for emulating jitter found in analogue equipment.

    • Parameters:
      • amplitude: The amplitude of the line. Will produce values in the range of (+/-)amp. (Default: 0.5)
      • minimumFrequency: The minimum frequency of change in Hz. (Default: 0.5)
      • maximumFrequency: The maximum frequency of change in Hz. (Default: 4)

    Declaration

    Swift

    public static func jitter(
            amplitude: AKParameter = 0.5,
            minimumFrequency: AKParameter = 0.5,
            maximumFrequency: AKParameter = 4
            ) -> AKOperation

    Parameters

    amplitude

    The amplitude of the line. Will produce values in the range of (+/-)amp. (Default: 0.5)

    minimumFrequency

    The minimum frequency of change in Hz. (Default: 0.5)

    maximumFrequency

    The maximum frequency of change in Hz. (Default: 4)

  • Produces a normalized sawtooth wave between the values of 0 and 1. Phasors are often used when building table-lookup oscillators.

    • Parameters:
      • frequency: Frequency in cycles per second, or Hz. (Default: 1.0, Minimum: 0.0, Maximum: 1000.0)
      • phase: Initial phase (Default: 0)

    Declaration

    Swift

    public static func phasor(
            frequency: AKParameter = 1,
            phase: Double = 0
            ) -> AKOperation

    Parameters

    frequency

    Frequency in cycles per second, or Hz. (Default: 1.0, Minimum: 0.0, Maximum: 1000.0)

    phase

    Initial phase (Default: 0)

  • Karplus-Strong plucked string instrument.

    • Parameters:
      • trigger: Triggering operation
      • frequency: Variable frequency. Values less than the lowest frequency will be doubled until it is greater than that. (Default: 110, Minimum: 0, Maximum: 22000)
      • amplitude: Amplitude (Default: 0.5, Minimum: 0, Maximum: 1)
      • lowestFrequency: Sets the initial frequency. This frequency is used to allocate all the buffers needed for the delay. This should be the lowest frequency you plan on using. (Default: 110)

    Declaration

    Swift

    public static func pluckedString(
            trigger: AKOperation,
            frequency: AKParameter = 110,
            amplitude: AKParameter = 0.5,
            lowestFrequency: Double = 110
            ) -> AKOperation

    Parameters

    trigger

    Triggering operation

    frequency

    Variable frequency. Values less than the lowest frequency will be doubled until it is greater than that. (Default: 110, Minimum: 0, Maximum: 22000)

    amplitude

    Amplitude (Default: 0.5, Minimum: 0, Maximum: 1)

    lowestFrequency

    Sets the initial frequency. This frequency is used to allocate all the buffers needed for the delay. This should be the lowest frequency you plan on using. (Default: 110)

  • Addition/Summation of operations

    Declaration

    Swift

    public func plus(_ parameter: AKParameter) -> AKOperation

    Parameters

    parameter

    The amount to add

  • Offsetting by way of addition

    Declaration

    Swift

    public func offsetBy(_ parameter: AKParameter) -> AKOperation

    Parameters

    parameter

    The amount to offset by

  • Morphing Oscillator

    • Parameters:
      • frequency: Frequency in cycles per second (Default: 440)
      • amplitude: Amplitude of the output (Default: 1)
      • index: Index of waveform 0.0 - 3.0 where 0 = sine, 1 = square, 2 = sawtooth, 3 = reversed sawtooth

    Declaration

    Swift

    public static func morphingOscillator(
            frequency: AKParameter = 440,
            amplitude: AKParameter = 1,
            index: AKParameter = 0
            ) -> AKOperation

    Parameters

    frequency

    Frequency in cycles per second (Default: 440)

    amplitude

    Amplitude of the output (Default: 1)

    index

    Index of waveform 0.0 - 3.0 where 0 = sine, 1 = square, 2 = sawtooth, 3 = reversed sawtooth

  • This scales from -1 to 1 to a range defined by a minimum and maximum point in the input and output domain.

    • Parameters:
      • minimum: Minimum value to scale to. (Default: 0)
      • maximum: Maximum value to scale to. (Default: 1)

    Declaration

    Swift

    public func scale(
            minimum: AKParameter = 0,
            maximum: AKParameter = 1
            ) -> AKOperation

    Parameters

    minimum

    Minimum value to scale to. (Default: 0)

    maximum

    Maximum value to scale to. (Default: 1)

  • Faust-based pink noise generator

    Declaration

    Swift

    public static func pinkNoise(amplitude: AKParameter = 1.0) -> AKOperation

    Parameters

    amplitude

    Overall level. (Default: 1.0, Minimum: 0, Maximum: 1.0)

  • Division of parameters

    Declaration

    Swift

    public func dividedBy(_ denominator: AKParameter) -> AKOperation

    Parameters

    denominator

    The amount to divide

  • Simple square oscillator, not-band limited, can be used for LFO or wave, but squareWave is probably better for audio.

    • Parameters:
      • frequency: In cycles per second, or Hz. (Default: 440, Minimum: 0.0, Maximum: 20000.0)
      • amplitude: Output Amplitude. (Default: 0.5, Minimum: 0.0, Maximum: 1.0)

    Declaration

    Swift

    public static func square(
            frequency: AKParameter = 440,
            amplitude: AKParameter = 0.5,
            phase: AKParameter = 0
            ) -> AKOperation

    Parameters

    frequency

    In cycles per second, or Hz. (Default: 440, Minimum: 0.0, Maximum: 20000.0)

    amplitude

    Output Amplitude. (Default: 0.5, Minimum: 0.0, Maximum: 1.0)

  • Produce a set of triggers spaced apart by time.

    Declaration

    Swift

    public static func periodicTrigger(period: AKParameter = 1.0) -> AKOperation

    Parameters

    period

    Time between triggers (in seconds). Updates at the start of each trigger. (Default: 1.0)

  • Bandlimited sawtooth oscillator This is a bandlimited sawtooth oscillator ported from the sawtooth function from the Faust programming language.

    • Parameters:
      • frequency: In cycles per second, or Hz. (Default: 440, Minimum: 0.0, Maximum: 20000.0)
      • amplitude: Output Amplitude. (Default: 0.5, Minimum: 0.0, Maximum: 1.0)

    Declaration

    Swift

    public static func sawtoothWave(
            frequency: AKParameter = 440,
            amplitude: AKParameter = 0.5
            ) -> AKOperation

    Parameters

    frequency

    In cycles per second, or Hz. (Default: 440, Minimum: 0.0, Maximum: 20000.0)

    amplitude

    Output Amplitude. (Default: 0.5, Minimum: 0.0, Maximum: 1.0)

  • Line Segment to change values over time

    • Parameters:
      • start: Starting value
      • end: Ending value
      • duration: Length of time

    Declaration

    Swift

    public static func lineSegment(
            trigger: AKOperation,
            start: AKParameter,
            end: AKParameter,
            duration: AKParameter
            ) -> AKOperation

    Parameters

    start

    Starting value

    end

    Ending value

    duration

    Length of time

  • Exponential Segment to change values over time

    • Parameters:
      • start: Starting value
      • end: Ending value
      • duration: Length of time

    Declaration

    Swift

    public static func exponentialSegment(
            trigger: AKOperation,
            start: AKParameter,
            end: AKParameter,
            duration: AKParameter
            ) -> AKOperation

    Parameters

    start

    Starting value

    end

    Ending value

    duration

    Length of time

  • Line segments with vertices at random points

    • Parameters:
      • minimum: Minimum value (Default: 0)
      • maximum: Maximum value (Default: 1)
      • updateFrequency: Frequency to change values. (Default: 3)

    Declaration

    Swift

    public static func randomVertexPulse(
            minimum: AKParameter = 0,
            maximum: AKParameter = 1,
            updateFrequency: AKParameter = 3
            ) -> AKOperation

    Parameters

    minimum

    Minimum value (Default: 0)

    maximum

    Maximum value (Default: 1)

    updateFrequency

    Frequency to change values. (Default: 3)

  • This is a bandlimited triangle oscillator ported from the triangle function from the Faust programming language.

    • Parameters:
      • frequency: In cycles per second, or Hz. (Default: 440, Minimum: 0.0, Maximum: 20000.0)
      • amplitude: Output Amplitude. (Default: 0.5, Minimum: 0.0, Maximum: 1.0)

    Declaration

    Swift

    public static func triangleWave(
            frequency: AKParameter = 440,
            amplitude: AKParameter = 0.5
            ) -> AKOperation

    Parameters

    frequency

    In cycles per second, or Hz. (Default: 440, Minimum: 0.0, Maximum: 20000.0)

    amplitude

    Output Amplitude. (Default: 0.5, Minimum: 0.0, Maximum: 1.0)

  • Simple sawtooth oscillator, not-band limited, can be used for LFO or wave, but sawtoothWave is probably better for audio.

    • Parameters:
      • frequency: In cycles per second, or Hz. (Default: 440, Minimum: 0.0, Maximum: 20000.0)
      • amplitude: Output Amplitude. (Default: 0.5, Minimum: 0.0, Maximum: 1.0)

    Declaration

    Swift

    public static func sawtooth(
            frequency: AKParameter = 440,
            amplitude: AKParameter = 0.5,
            phase: AKParameter = 0
            ) -> AKOperation

    Parameters

    frequency

    In cycles per second, or Hz. (Default: 440, Minimum: 0.0, Maximum: 20000.0)

    amplitude

    Output Amplitude. (Default: 0.5, Minimum: 0.0, Maximum: 1.0)

  • Simple reverse sawtooth oscillator, not-band limited, can be used for LFO or wave.

    • Parameters:
      • frequency: In cycles per second, or Hz. (Default: 440, Minimum: 0.0, Maximum: 20000.0)
      • amplitude: Output Amplitude. (Default: 0.5, Minimum: 0.0, Maximum: 1.0)

    Declaration

    Swift

    public static func reverseSawtooth(
            frequency: AKParameter = 440,
            amplitude: AKParameter = 0.5,
            phase: AKParameter = 0
            ) -> AKOperation

    Parameters

    frequency

    In cycles per second, or Hz. (Default: 440, Minimum: 0.0, Maximum: 20000.0)

    amplitude

    Output Amplitude. (Default: 0.5, Minimum: 0.0, Maximum: 1.0)

  • Simple triangle oscillator, not-band limited, can be used for LFO or wave, but triangleWave is probably better for audio.

    • Parameters:
      • frequency: In cycles per second, or Hz. (Default: 440, Minimum: 0.0, Maximum: 20000.0)
      • amplitude: Output Amplitude. (Default: 0.5, Minimum: 0.0, Maximum: 1.0)

    Declaration

    Swift

    public static func triangle(
            frequency: AKParameter = 440,
            amplitude: AKParameter = 0.5,
            phase: AKParameter = 0
            ) -> AKOperation

    Parameters

    frequency

    In cycles per second, or Hz. (Default: 440, Minimum: 0.0, Maximum: 20000.0)

    amplitude

    Output Amplitude. (Default: 0.5, Minimum: 0.0, Maximum: 1.0)