         }
     }
 }
+
+extension AKTable: RandomAccessCollection  {
+    public typealias Indices = Array<Element>.Indices
+
+    @inline(__always)
+    public func index(before i: Index) -> Index {
+        return i - 1
+    }
+
+    @inline(__always)
+    public func index(after i: Index) -> Index {
+        return i + 1
+    }
+
+    @inline(__always)
+    public func index(_ i: Index, offsetBy n: Index) -> Index {
+        return i + n
+    }
+
+    @inline(__always)
+    public func formIndex(after i: inout Index) {
+        i += 1
+    }
+    
+    @inline(__always)
+    public func distance(from start: Index, to end: Index) -> IndexDistance {
+        return end - start
+    }
+}

    ///   - size: Size of the table (multiple of 2)
    ///
    public init(_ type: AKTableType = .sine,
                  phase: Double = 0,
                  count: Int = 4096) {
        self.type = type
        self.phase = phase
        
        self.content = [Float](zeroes: count)
        
        switch type {
        case .sine:
            self.standardSineWave()

    /// Reversed sawtooth waveform from 0-1
    case positiveReverseSawtooth

}

/// A table of values accessible as a waveform or lookup mechanism
public struct AKTable: MutableCollection {
    public typealias Index = Int
    public typealias IndexDistance = Int
    public typealias Element = Float
    public typealias SubSequence = ArraySlice<Element>

    // MARK: - Properties    /// Values stored in the table

    private var content = [Element]()

    public var phase: Float {
        didSet {
            phase = (0...1).clamp(phase)
        }
    }

    public var startIndex: Index {
        return content.startIndex
    }

    public var endIndex: Index {
        return content.endIndex
    }

    public subscript(index: Index) -> Element {
        get {
            return content[index]
        }
        set {
            content[index] = newValue
        }
    }

    public subscript(bounds: Range<Index>) -> SubSequence {
        get {
            return content[bounds]
        }
        set {
            content[bounds] = newValue
        }
    }

    /// Type of table
    var type: AKTableType
