From 991def1debf162a96913bb1dd6ab0f0f8af0a438 Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Thu, 18 Sep 2025 19:03:19 +0200 Subject: [PATCH] realtime waveform --- bitchat/Views/RealtimeScrollingWaveform.swift | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 bitchat/Views/RealtimeScrollingWaveform.swift diff --git a/bitchat/Views/RealtimeScrollingWaveform.swift b/bitchat/Views/RealtimeScrollingWaveform.swift new file mode 100644 index 00000000..7a0caf4d --- /dev/null +++ b/bitchat/Views/RealtimeScrollingWaveform.swift @@ -0,0 +1,60 @@ +import SwiftUI +import Combine + +/// Real-time scrolling waveform for live recording. +/// Provide a normalized amplitude [0,1]. The view maintains a sliding window of bars. +struct RealtimeScrollingWaveform: View { + var amplitudeNorm: CGFloat + var bars: Int = 240 + var barColor: Color = Color(red: 0, green: 1, blue: 0.5) // neon-ish green + + @State private var samples: [CGFloat] = [] + @State private var ticker = Timer.publish(every: 0.02, on: .main, in: .common).autoconnect() + + var body: some View { + GeometryReader { geo in + Canvas { ctx, size in + let w = size.width + let h = size.height + guard w > 0 && h > 0 else { return } + let n = samples.count + guard n > 0 else { return } + let stepX = w / CGFloat(n) + let midY = h / 2 + let stroke: CGFloat = 1.2 + + for i in 0.. 0 { samples.removeFirst(overflow) } + } + } + } +}