         readFile.points = downSampledData.map{CGFloat($0)}
     }
     
-    func readArray( array:[Float]){
+    private func readArray( array:[Float]){
         readFile.arrayFloatValues = array
     }
-    
-    func addDurationOfFileWith(url: URL?) {
-        do {
-            let file = try AVAudioFile(forReading: fileUrl!)
-            let format = AVAudioFormat(commonFormat: .pcmFormatFloat32, sampleRate: file.fileFormat.sampleRate, channels: file.fileFormat.channelCount, interleaved: false)
-            
-            let recAsset = AVAsset(url: fileUrl!)
-            duration = recAsset.duration.seconds
-            
-            let buf = AVAudioPCMBuffer(pcmFormat: format!, frameCapacity: UInt32(file.length))
-            try file.read(into: buf!)
-            readFile.arrayFloatValues = Array(UnsafeBufferPointer(start: buf!.floatChannelData?[0], count:Int(buf!.frameLength)))
-        }catch {
-            print(error)
-        }
-    }
-    
 }

            i += 1
        }
        
        UIColor(red: 212.0/255.0, green: 216.0/255.0, blue: 217.0/255.0, alpha: 1.0).set()
        aPath.lineJoinStyle = .round
        path = aPath
        path?.stroke()
        path?.fill()
        
        let animation2 = CABasicAnimation(keyPath: "strokeColor")
        animation2.duration = 10
        animation2.fromValue = UIColor(red: 212.0/255.0, green: 216.0/255.0, blue: 217.0/255.0, alpha: 1.0)
        animation2.toValue = UIColor.red
        self.shapeLayer.add(animation2, forKey: "coloring")
        shapeLayer.strokeColor = UIColor(red: 232/255, green: 59/255, blue: 86/255, alpha: 1.0).cgColor
        shapeLayer.lineJoin = kCALineJoinRound
        shapeLayer.lineWidth = 2
        shapeLayer.frame.size.width = self.frame.width
        shapeLayer.frame.size.height = 30
        shapeLayer.path = (path!.cgPath)
        self.clipsToBounds = true
        
    }
    
    func convertToPoints() {
        var processingBuffer = [Float](repeating: 0.0,
                                       count: Int(readFile.arrayFloatValues.count))
        let sampleCount = vDSP_Length(readFile.arrayFloatValues.count)

struct readFile {
    static var arrayFloatValues: [Float] = []
    static var points: [CGFloat] = []
}

class SonogramView: UIView {
    
    @IBInspectable var sonogramColor: UIColor = UIColor(red: 212.0/255.0, green: 216.0/255.0, blue: 217.0/255.0, alpha: 1.0)
    @IBInspectable var shapeColor: UIColor = UIColor(red: 232/255, green: 59/255, blue: 86/255, alpha: 1.0)
    @IBInspectable var animationFromColor: UIColor = UIColor(red: 212.0/255.0, green: 216.0/255.0, blue: 217.0/255.0, alpha: 1.0)
    @IBInspectable var animationToColor: UIColor = UIColor.red
    
    var shapeLayer: CAShapeLayer!
    var duration: Double = 0
    
    // override draw
    
    override func draw(_ rect: CGRect) {
        drawMyView(rect: rect)
    }
    
    // MARK: public API
    
    func addDurationOfFileWith(url: URL) {
        do {
            let file = try AVAudioFile(forReading: url)
            let format = AVAudioFormat(commonFormat: .pcmFormatFloat32, sampleRate: file.fileFormat.sampleRate, channels: file.fileFormat.channelCount, interleaved: false)
            
            let recAsset = AVAsset(url: url)
            duration = recAsset.duration.seconds
            
            let buf = AVAudioPCMBuffer(pcmFormat: format!, frameCapacity: UInt32(file.length))!
            try file.read(into: buf)
            readFile.arrayFloatValues = Array(UnsafeBufferPointer(start: buf.floatChannelData?[0], count:Int(buf.frameLength)))
        } catch {
            print(error)
        }
    }
    
    // MARK: private API
    
    private func drawMyView(rect: CGRect) {
        convertToPoints()
        var f = 0
        let aPath = UIBezierPath()
        
        aPath.lineWidth = 2.0
