<commit_before>//
//  AVAudioTimeShim.swift
//  AudioKit
//
//  Created by <NAME>, revision history on GitHub.
//  Copyright © 2017 Audive Inc. All rights reserved.
//

/// Utility to convert between host time and seconds
private let ticksToSeconds: Double = {
    var tinfo = mach_timebase_info()
    let err = mach_timebase_info(&tinfo)
    let timecon = Double(tinfo.numer) / Double(tinfo.denom)
    return timecon * 0.000000001
}()

/// Utility to convert between seconds to host time.
private let secondsToTicks: Double = {
    var tinfo = mach_timebase_info()
    let err = mach_timebase_info(&tinfo)
    let timecon = Double(tinfo.denom) / Double(tinfo.numer)
    return timecon * 1_000_000_000
}()

extension AVAudioTime {
    /// AVAudioTime.extrapolateTime fails for host time valid times, use
    /// extrapolateTimeShimmed instead. https://bugreport.apple.com/web/?problemID=34249528
    open func extrapolateTimeShimmed(fromAnchor anchorTime: AVAudioTime) -> AVAudioTime {
        guard ((isSampleTimeValid && sampleRate == anchorTime.sampleRate) || isHostTimeValid) &&
            !(isSampleTimeValid && isHostTimeValid) &&
            anchorTime.isSampleTimeValid && anchorTime.isHostTimeValid else {
            return self
        }
        if isHostTimeValid && anchorTime.isHostTimeValid {
            let secondsDiff = Double(hostTime.safeSubtract(anchorTime.hostTime)) * ticksToSeconds
            let sampleTime = anchorTime.sampleTime + AVAudioFramePosition(round(secondsDiff * anchorTime.sampleRate))
            let audioTime = AVAudioTime(hostTime: hostTime, sampleTime: sampleTime, atRate: anchorTime.sampleRate)
            return audioTime
        } else {
            let secondsDiff = Double(sampleTime - anchorTime.sampleTime) / anchorTime.sampleRate
            let hostTime = anchorTime.hostTime + secondsDiff / ticksToSeconds
            return AVAudioTime(hostTime: hostTime, sampleTime: sampleTime, atRate: anchorTime.sampleRate)
        }
    }

    /// An AVAudioTime with a valid hostTime representing now.
    public static func now() -> AVAudioTime {
        return AVAudioTime(hostTime: mach_absolute_time())
    }

    /// Returns an AVAudioTime offset by seconds.
    open func offset(seconds: Double) -> AVAudioTime {
        AKLog("isSampleTimeValid", isSampleTimeValid, "isHostTimeValid", isHostTimeValid)

        if isSampleTimeValid && isHostTimeValid {
            return AVAudioTime(hostTime: hostTime + seconds / ticksToSeconds,
                               sampleTime: sampleTime + AVAudioFramePosition(seconds * sampleRate),
                               atRate: sampleRate)
        } else if isHostTimeValid {
            return AVAudioTime(hostTime: hostTime + seconds / ticksToSeconds)
        } else if isSampleTimeValid {
            return AVAudioTime(sampleTime: sampleTime + AVAudioFramePosition(seconds * sampleRate),
                               atRate: sampleRate)
        }
        return self
    }

    /// The time in seconds between receiver and otherTime.
    open func timeIntervalSince(otherTime: AVAudioTime) -> Double? {
        if isHostTimeValid && otherTime.isHostTimeValid {
            return Double(hostTime.safeSubtract(otherTime.hostTime)) * ticksToSeconds
        }
        if isSampleTimeValid && otherTime.isSampleTimeValid {
            return Double(sampleTime - otherTime.sampleTime) / sampleRate
        }
        if isSampleTimeValid && isHostTimeValid {
            let completeTime = otherTime.extrapolateTimeShimmed(fromAnchor: self)
            return Double(sampleTime - completeTime.sampleTime) / sampleRate
        }<commit_msg>removed debug statement<commit_after>//
//  AVAudioTimeShim.swift
//  AudioKit
//
//  Created by <NAME>, revision history on GitHub.
//  Copyright © 2017 Audive Inc. All rights reserved.
//

/// Utility to convert between host time and seconds
private let ticksToSeconds: Double = {
    var tinfo = mach_timebase_info()
    let err = mach_timebase_info(&tinfo)
    let timecon = Double(tinfo.numer) / Double(tinfo.denom)
    return timecon * 0.000000001
}()

/// Utility to convert between seconds to host time.
private let secondsToTicks: Double = {
    var tinfo = mach_timebase_info()
    let err = mach_timebase_info(&tinfo)
    let timecon = Double(tinfo.denom) / Double(tinfo.numer)
    return timecon * 1_000_000_000
}()

extension AVAudioTime {
    /// AVAudioTime.extrapolateTime fails for host time valid times, use
    /// extrapolateTimeShimmed instead. https://bugreport.apple.com/web/?problemID=34249528
    open func extrapolateTimeShimmed(fromAnchor anchorTime: AVAudioTime) -> AVAudioTime {
        guard ((isSampleTimeValid && sampleRate == anchorTime.sampleRate) || isHostTimeValid) &&
            !(isSampleTimeValid && isHostTimeValid) &&
            anchorTime.isSampleTimeValid && anchorTime.isHostTimeValid else {
            return self
        }
        if isHostTimeValid && anchorTime.isHostTimeValid {
            let secondsDiff = Double(hostTime.safeSubtract(anchorTime.hostTime)) * ticksToSeconds
            let sampleTime = anchorTime.sampleTime + AVAudioFramePosition(round(secondsDiff * anchorTime.sampleRate))
            let audioTime = AVAudioTime(hostTime: hostTime, sampleTime: sampleTime, atRate: anchorTime.sampleRate)
            return audioTime
        } else {
            let secondsDiff = Double(sampleTime - anchorTime.sampleTime) / anchorTime.sampleRate
            let hostTime = anchorTime.hostTime + secondsDiff / ticksToSeconds
            return AVAudioTime(hostTime: hostTime, sampleTime: sampleTime, atRate: anchorTime.sampleRate)
        }
    }

    /// An AVAudioTime with a valid hostTime representing now.
    public static func now() -> AVAudioTime {
        return AVAudioTime(hostTime: mach_absolute_time())
    }

    /// Returns an AVAudioTime offset by seconds.
    open func offset(seconds: Double) -> AVAudioTime {
        if isSampleTimeValid && isHostTimeValid {
            return AVAudioTime(hostTime: hostTime + seconds / ticksToSeconds,
                               sampleTime: sampleTime + AVAudioFramePosition(seconds * sampleRate),
                               atRate: sampleRate)
        } else if isHostTimeValid {
            return AVAudioTime(hostTime: hostTime + seconds / ticksToSeconds)
        } else if isSampleTimeValid {
            return AVAudioTime(sampleTime: sampleTime + AVAudioFramePosition(seconds * sampleRate),
                               atRate: sampleRate)
        }
        return self
    }

    /// The time in seconds between receiver and otherTime.
    open func timeIntervalSince(otherTime: AVAudioTime) -> Double? {
        if isHostTimeValid && otherTime.isHostTimeValid {
            return Double(hostTime.safeSubtract(otherTime.hostTime)) * ticksToSeconds
        }
        if isSampleTimeValid && otherTime.isSampleTimeValid {
            return Double(sampleTime - otherTime.sampleTime) / sampleRate
        }
        if isSampleTimeValid && isHostTimeValid {
            let completeTime = otherTime.extrapolateTimeShimmed(fromAnchor: self)
            return Double(sampleTime - completeTime.sampleTime) / sampleRate
        }
{'fraction_non_alphanumeric': 0.08169798190675018, 'fraction_numerical': 0.008907446068197634, 'mean_word_length': 2.762303664921466, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '674482', 'n_tokens_mistral': 1983, 'n_tokens_neox': 1900, 'n_words': 480}