                     let processedSamples = process(blockSamples,
                                                    ofLength: sampleLength,
                                                    from: assetReader,
-                                                   downsampledTo: targetSampleCount)
+                                                   downsampledTo: targetSampleCount,
+                                                   samplesPerPixel: samplesPerPixel)
                     outputSamples += processedSamples
                 }
             }

    // swiftlint:disable force_cast
    private func channelCount(from assetReader: AVAssetReader) -> Int {
        let audioTrack = (assetReader.outputs.first as? AVAssetReaderTrackOutput)?.track

        var channelCount = 0
        audioTrack?.formatDescriptions.forEach { formatDescription in
            let audioDescription = CFBridgingRetain(formatDescription) as! CMAudioFormatDescription
            if let basicDescription = CMAudioFormatDescriptionGetStreamBasicDescription(audioDescription) {
                channelCount = Int(basicDescription.pointee.mChannelsPerFrame)
            }
        }

    fileprivate func extract(samplesFrom assetReader: AVAssetReader, downsampledTo targetSampleCount: Int) -> [Float] {
        var outputSamples = [Float]()

        // read upfront to avoid frequent re-calculation (and memory bloat)
        let samplesPerPixel = max(1, sampleCount(from: assetReader) / targetSampleCount)

        assetReader.startReading()
        while assetReader.status == .reading {
            let trackOutput = assetReader.outputs.first!
