AKTable

@objc
public class AKTable : NSObject, MutableCollection, Codable

A table of values accessible as a waveform or lookup mechanism

  • Declaration

    Swift

    public typealias Index = Int
  • Declaration

    Swift

    public typealias IndexDistance = Int
  • Declaration

    Swift

    public typealias Element = Float
  • Declaration

    Swift

    public typealias SubSequence = ArraySlice<Element>
  • Initialize and set up the default table

    Declaration

    Swift

    @objc
    public init(_ type: AKTableType = .sine,
          phase: Float = 0,
          count: IndexDistance = 4_096)

    Parameters

    type

    AKTableType of the new table

    phase

    Phase offset

    count

    Size of the table (multiple of 2)

  • Create table from audio file

    Declaration

    Swift

    public convenience init(file: AKAudioFile)
  • Offset of the phase

    Declaration

    Swift

    public var phaseOffset: Int { get }
  • Create an AKTable with the contents of a pcmFormatFloat32 file. This method is intended for wavetables (i.e., 2048 or 4096 samples), not large audio files. Parameters:

    • url: URL to the file

    Declaration

    Swift

    public static func fromAudioFile(_ url: URL) -> AKTable?
  • Will write to CAF in temporary directory Parameters:

    • fileName: String name of file

    Declaration

    Swift

    public func writeToAudioFile(_ fileName: String) throws
  • This method will start at rootFrequency * octave, walk up by octaveStepSize, and halt before reaching nyquist. This method outputs an array where each entry is a tuple of frequency and the maximum number of harmonics. This method is pitch-based, which is not the only way to distribute harmonics.

    Parameters:

    • rootFrequency: the lowest frequency wavetable. 8.17579891564375 corresponds to C0, or nn = 0
    • octaveStepSize: fractions of an octave (i.e., 1).

    Example Output: [(8.1787833827893177, 2696), (16.357566765578635, 1348), (32.715133531157271, 674), (65.430267062314542, 337), (131.25, 168), (262.5, 84), (525.0, 42), (1050.0, 21), (2205.0, 10), (4410.0, 5), (11025.0, 2), (22050.0, 1)]

    Declaration

    Swift

    public class func harmonicPitchRange(rootFrequency: Double = 8.175_798_915_643_75, octaveStepSize: Double = 1) -> [(Double, Int)]
  • This method will start at rootFrequency * octave, walk up by octaveStepSize, and halt before reaching nyquist. This method outputs an array where each entry is a tuple of frequency and the maximum number of harmonics. This method is pitch-based, which may not be the best way to distribute harmonics.

    The design is to create wavetables with the most harmonics for frequencies LESS THAN the frequency of the table. ASSUME a nyquist 1 harmonic table. Allows the harmonic distribution to not consider the outlier. Parameters:

    • f0: the lowest frequency wavetable. 130.8127826503 corresponds to C-1, or nn = 48
    • f1: the highest frequency wavetable. 2093.0045224048 corresponds to C6, or nn = 96

    • wavetableCount: The number of wavetables from which to interpolate from f0 to f1

    Declaration

    Swift

    public class func harmonicFrequencyRange(f0: Double = 130.812_782_650_3, f1: Double = 2_093.004_522_404_8, wavetableCount: Int = 12) -> [(Double, Int)]
  • Set table values to sum of sines approximating a sawtooth with harmonicCount harmonics. Parameters:

    • harmonicCount: the number of harmonics to synthesize
    • clear: will clear the table first

    Declaration

    Swift

    public func sawtooth(harmonicCount: Int = 1_024, clear: Bool = true)
  • Set table values to sum of sines approximating a square with harmonicCount harmonics. Parameters:

    • harmonicCount: the number of harmonics to synthesize
    • clear: will clear the table first

    Declaration

    Swift

    public func square(harmonicCount: Int = 1_024, clear: Bool = true)
  • Set table values to sum of sines approximating a triangle with harmonicCount harmonics. Parameters:

    • harmonicCount: the number of harmonics to synthesize
    • clear: will clear the table first

    Declaration

    Swift

    public func triangle(harmonicCount: Int = 1_024, clear: Bool = true)
  • Set table values to sum of sines approximating a pulse width of period with harmonicCount harmonics. Due to DC component, and scaling/normalizing, a clear parameter is not provided. Parameters:

    • harmonicCount: the number of harmonics to synthesize
    • period: float on (0,1) for the range above 0

    Declaration

    Swift

    public func pwm(harmonicCount: Int = 1_024, period: Float = 1 / 8)
  • returns a tuple with min, max, absMax

    Declaration

    Swift

    public func minMax() -> (min: Float, max: Float, absMax: Float)
  • In-place normalize

    Declaration

    Swift

    public func normalize()
  • In-place reverse samples

    Declaration

    Swift

    public func reverse()
  • In-place invert samples

    Declaration

    Swift

    public func invert()
  • compare self with t, return mean-squared distance.

    Declaration

    Swift

    public func msd(t: AKTable) -> Element