mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-24 07:05:35 +00:00
Various improvements
This commit is contained in:
@@ -80,6 +80,26 @@ public final class AudioWaveform: Equatable {
|
||||
return result
|
||||
}
|
||||
|
||||
public func subwaveform(from start: Double, to end: Double) -> AudioWaveform {
|
||||
let normalizedStart = max(0.0, min(1.0, start))
|
||||
let normalizedEnd = max(normalizedStart, min(1.0, end))
|
||||
|
||||
let numSamples = self.samples.count / 2
|
||||
let startIndex = Int(Double(numSamples) * normalizedStart) * 2
|
||||
let endIndex = Int(Double(numSamples) * normalizedEnd) * 2
|
||||
|
||||
let rangeLength = endIndex - startIndex
|
||||
let subData: Data
|
||||
|
||||
if rangeLength > 0 {
|
||||
subData = self.samples.subdata(in: startIndex..<endIndex)
|
||||
} else {
|
||||
subData = Data()
|
||||
}
|
||||
|
||||
return AudioWaveform(samples: subData, peak: self.peak)
|
||||
}
|
||||
|
||||
public static func ==(lhs: AudioWaveform, rhs: AudioWaveform) -> Bool {
|
||||
return lhs.peak == rhs.peak && lhs.samples == rhs.samples
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user