diff --git a/ElementX/Sources/Services/Timeline/TimelineItems/Items/Messages/VoiceMessages/EstimatedWaveformView.swift b/ElementX/Sources/Services/Timeline/TimelineItems/Items/Messages/VoiceMessages/EstimatedWaveformView.swift index dd4da8c53..4ae87feab 100644 --- a/ElementX/Sources/Services/Timeline/TimelineItems/Items/Messages/VoiceMessages/EstimatedWaveformView.swift +++ b/ElementX/Sources/Services/Timeline/TimelineItems/Items/Messages/VoiceMessages/EstimatedWaveformView.swift @@ -17,29 +17,32 @@ import SwiftUI struct EstimatedWaveform: Equatable, Hashable { + static let dataRange: ClosedRange = 0...1024 let data: [UInt16] } extension EstimatedWaveform { - func normalisedData(keepSamplesCount: Int) -> [Float] { - guard keepSamplesCount > 0 else { + /// Maps the `data` array to Float values in the range 0...1 respecting the `Self.dataRange` limits. + /// Up to `maxSamplesCount` will be returned in the output array + func normalisedData(maxSamplesCount: Int) -> [Float] { + guard maxSamplesCount > 0 else { return [] } + // Filter the data to keep only the expected number of samples - let originalCount = Double(data.count) - let expectedCount = Double(keepSamplesCount) - var filteredData: [UInt16] = [] - if expectedCount < originalCount { - for index in 0.. maxSamplesCount { + result = (0..