         }
     }
     
-    func test(totalCurrentSamples: Int, lowerSamplesPerPixel: Int, remainder: Int, currentRemained: inout Int) -> (samplesToProcess: Int, downsampleCount: Int) {
-
-        let samplesPerPixel: Int = 44
-        let totalSamplesToProcess: Int = totalCurrentSamples
-        
-        // TODO: >= here?
-//        if currentRemained >= remainder {
-//            samplesPerPixel = lowerSamplesPerPixel
-//            totalSamplesToProcess = totalCurrentSamples
-//        }
-//        else {
-//            samplesPerPixel = lowerSamplesPerPixel + 1
-//            
-//            let potentialDownsampleCount = totalCurrentSamples / lowerSamplesPerPixel
-//            
-//            // TODO: >= here?
-//            if currentRemained + potentialDownsampleCount >= remainder {
-//                totalSamplesToProcess = (remainder - currentRemained) * samplesPerPixel
-//            }
-//            else {
-//                totalSamplesToProcess = totalCurrentSamples
-//            }
-//            
-//            
-//        }
-        
-        let samplesToProcess = (totalSamplesToProcess / samplesPerPixel) * samplesPerPixel
-        let downsample = samplesToProcess / samplesPerPixel
-
-        print("downsample: \(downsample), samplesToProcess: \(samplesToProcess)")
-
-        currentRemained += downsample
-        
-        return (samplesToProcess, downsample)
-        
-//        if currentRemained >= remainder {
-//            let samplesPerPixel = lowerSamplesPerPixel
-//            let samplesToProcess = (totalCurrentSamples / samplesPerPixel) * samplesPerPixel
-//            let downsample = samplesToProcess / samplesPerPixel
-//            return (samplesToProcess, downsample)
-//        }
-//        
-//        let samplesPerPixel = lowerSamplesPerPixel + 1
-//        var samplesToProcess = (totalCurrentSamples / samplesPerPixel) * samplesPerPixel
-//        var downsample = samplesToProcess / samplesPerPixel
-//
-//        var changed: Bool = false
-//        if currentRemained + downsample > remainder {
-//            let diff = remainder - currentRemained
-//           
-//            downsample = diff
-//            samplesToProcess = downsample * samplesPerPixel
-//            
-//            changed = true
-//        }
-//        
-//        currentRemained += downsample
-//        
-//        print("downsample: \(downsample), samplesToProcess: \(samplesToProcess), changed: \(changed)")
-//        
-//        return (samplesToProcess, downsample)
-    }
-    
-    func processSamples(fromData sampleBuffer: inout Data, sampleMax: inout CGFloat, outputSamples: inout [CGFloat], samplesToProcess: Int, downSampledLength: Int, samplesPerPixel: Int, filter2: [Float]) {
-    
-        let filter = [Float](repeating: 1.0 / Float(samplesPerPixel), count: samplesPerPixel)
+    func processSamples(fromData sampleBuffer: inout Data, sampleMax: inout CGFloat, outputSamples: inout [CGFloat], samplesToProcess: Int, downSampledLength: Int, samplesPerPixel: Int, filter: [Float]) {
         sampleBuffer.withUnsafeBytes { (samples: UnsafePointer<Int16>) in
             var processingBuffer = [Float](repeating: 0.0, count: samplesToProcess)
             

                           samplesToProcess: samplesToProcess,
                           downSampledLength: downSampledLength,
                           samplesPerPixel: samplesPerPixel,
                           filter2: filter)
        }
        
        // Process the remaining samples at the end which didn't fit into samplesPerPixel

        }

        var sampleMax = format.noiseFloor
        let samplesPerPixel = max(1, channelCount * slice.count / targetSamples)
        let filter = [Float](repeating: 1.0 / Float(samplesPerPixel), count: samplesPerPixel)

        var outputSamples = [CGFloat]()
        var sampleBuffer = Data()
        
        var totalSampleCount = 0

        // 16-bit samples
        reader.startReading()
