             j += 1
         }
         reversedBuffer?.frameLength = length
-
         return reversedBuffer
     }
 

        }

        value.amplitude = peakValue

        AKLog(value)

        return value
    }

    // Returns the highest level in the given array
    private func getPeak(from buffer: [Float]) -> Float {
        // create variable with very small value to hold the peak value
        var peak: Float = -10_000.0

        for i in 0 ..< buffer.count {
            // store the absolute value of the sample

        let sampleRate = self.format.sampleRate
        let channelCount = Int(self.format.channelCount)

        // AKLog("fadeBuffer() inTime: \(inTime) outTime: \(outTime)")

        // initial starting point for the gain, if there is a fade in, start it at .01 otherwise at 1
        var gain: Double = inTime > 0 ? 0.01 : 1
