<commit_before>//
//  AKTuningTable.swift
//  AudioKit
//
//  Created by <NAME> on 3/17/17.
//  Copyright © 2017 AudioKit. All rights reserved.
//

/// Tuning table stores frequencies at which to play MIDI notes
@objc open class AKTuningTable: NSObject {

    /// For clarity, typealias Frequency as a Double
    public typealias Frequency = Double

    /// Standard Nyquist frequency
    private static let NYQUIST: Frequency = AKSettings.sampleRate / 2

    /// Total number of MIDI Notes available to play
    public static let midiNoteCount = 128

    /// Note number for standard reference note
    public var middleCNoteNumber: MIDINoteNumber = 60 {
        didSet {
            updateTuningTable()
        }
    }

    /// Frequency of standard reference note
    public var middleCFrequency: Frequency = 261.0 {
        didSet {
            updateTuningTable()
        }
    }

    /// Octave number for standard reference note.  Can be negative
    /// ..., -2, -1, 0, 1, 2, ...
    public var middleCOctave: Int = 0 {
        didSet {
            updateTuningTable()
        }
    }

    private var content = [Frequency](repeating: 1.0, count: midiNoteCount)
    private var frequencies = [Frequency]()

    /// Initialization for standard default 12 tone equal temperament
    public override init() {
        super.init()
        twelveToneEqualTemperament()
    }

    /// Pull out frequency information for a given note number
    public func frequency(forNoteNumber noteNumber: MIDINoteNumber) -> Frequency {
        return content[Int(noteNumber)]
    }
    
    /// Set frequency of a given note number
    public func setFrequency(_ frequency: Frequency, at noteNumber: MIDINoteNumber) {
        content[Int(noteNumber)] = frequency
    }

    /// Default tuning table is 12ET.
    /// Note this is [nearly] equivalent to 440.0*exp2((noteNumber - 69.0)/12.0))
    public func twelveToneEqualTemperament() {
        var equalTempermentFrequencies = [Frequency](repeatElement(1.0, count: 12))
        for i in 0 ... 11 {
            equalTempermentFrequencies[i] = Frequency(pow(2.0, Frequency(Frequency(i) / 12.0)))
        }
        tuningTable(fromFrequencies: equalTempermentFrequencies)
    }

    /// Create the tuning using the input frequencies
    public func tuningTable(fromFrequencies inputFrequencies: [Frequency]) {
        if inputFrequencies.isEmpty {
            AKLog("No input frequencies")
            return
        }

        // octave reduce
        let frequenciesOctaveReduce = inputFrequencies.map({(frequency: Frequency) -> Frequency in
            var l2 = log2(frequency)
            while l2 < 0 {<commit_msg>Arguments should be documented as well<commit_after>//
//  AKTuningTable.swift
//  AudioKit
//
//  Created by <NAME> on 3/17/17.
//  Copyright © 2017 AudioKit. All rights reserved.
//

/// Tuning table stores frequencies at which to play MIDI notes
@objc open class AKTuningTable: NSObject {

    /// For clarity, typealias Frequency as a Double
    public typealias Frequency = Double

    /// Standard Nyquist frequency
    private static let NYQUIST: Frequency = AKSettings.sampleRate / 2

    /// Total number of MIDI Notes available to play
    public static let midiNoteCount = 128

    /// Note number for standard reference note
    public var middleCNoteNumber: MIDINoteNumber = 60 {
        didSet {
            updateTuningTable()
        }
    }

    /// Frequency of standard reference note
    public var middleCFrequency: Frequency = 261.0 {
        didSet {
            updateTuningTable()
        }
    }

    /// Octave number for standard reference note.  Can be negative
    /// ..., -2, -1, 0, 1, 2, ...
    public var middleCOctave: Int = 0 {
        didSet {
            updateTuningTable()
        }
    }

    private var content = [Frequency](repeating: 1.0, count: midiNoteCount)
    private var frequencies = [Frequency]()

    /// Initialization for standard default 12 tone equal temperament
    public override init() {
        super.init()
        twelveToneEqualTemperament()
    }

    /// Pull out frequency information for a given note number
    public func frequency(forNoteNumber noteNumber: MIDINoteNumber) -> Frequency {
        return content[Int(noteNumber)]
    }
    
    /// Set frequency of a given note number
    public func setFrequency(_ frequency: Frequency, at noteNumber: MIDINoteNumber) {
        content[Int(noteNumber)] = frequency
    }

    /// Default tuning table is 12ET.
    /// Note this is [nearly] equivalent to 440.0*exp2((noteNumber - 69.0)/12.0))
    public func twelveToneEqualTemperament() {
        var equalTempermentFrequencies = [Frequency](repeatElement(1.0, count: 12))
        for i in 0 ... 11 {
            equalTempermentFrequencies[i] = Frequency(pow(2.0, Frequency(Frequency(i) / 12.0)))
        }
        tuningTable(fromFrequencies: equalTempermentFrequencies)
    }

    /// Create the tuning using the input frequencies
    ///
    /// - parameter fromFrequencies: An array of frequencies
    ///
    public func tuningTable(fromFrequencies inputFrequencies: [Frequency]) {
        if inputFrequencies.isEmpty {
            AKLog("No input frequencies")
            return
        }

        // octave reduce
        let frequenciesOctaveReduce = inputFrequencies.map({(frequency: Frequency) -> Frequency in
            var l2 = log2(frequency)
            while l2 < 0 {
{'fraction_non_alphanumeric': 0.09216845216106391, 'fraction_numerical': 0.021425932766900628, 'mean_word_length': 2.3425925925925926, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4033132', 'n_tokens_mistral': 1616, 'n_tokens_neox': 1445, 'n_words': 475}