Repository Public MIT
1import SwiftUI2import SPGlassKit34public struct GlassWaveformExample: GlassExample {5 public static let componentID = "glass-waveform"6 /// Aggregated once, when the example is created, not on every frame.7 @State private var voice = GlassWaveformData(samples: Self.syntheticSamples(count: 48_000), maxBuckets: 96, aggregation: .rms)8 @State private var peaks = GlassWaveformData(samples: Self.syntheticSamples(count: 48_000), maxBuckets: 160)9 @State private var progress = 0.351011 public init() {}1213 public var body: some View {14 VStack(alignment: .leading, spacing: 16) {15 Text("RMS, 96 buckets, with progress")16 .font(.headline)17 GlassWaveform(voice, progress: progress)18 Slider(value: $progress, in: 0...1) { Text("Progress") }1920 Text("Peak, 160 buckets")21 .font(.headline)22 GlassWaveform(peaks, minimumHeight: 72)2324 Text("Progress without the playhead")25 .font(.headline)26 GlassWaveform(voice, progress: progress, showsPlayhead: false)2728 Text("No samples")29 .font(.headline)30 GlassWaveform(.empty, minimumHeight: 24)3132 Text("Sample data · a synthetic signal built from sine waves.")33 .font(.caption)34 .foregroundStyle(.secondary)35 }36 .padding()37 }3839 /// A deterministic signal: a carrier shaped by two slow envelopes.40 static func syntheticSamples(count: Int) -> [Float] {41 (0..<count).map { index in42 let t = Double(index) / Double(count)43 let envelope = 0.55 + 0.45 * sin(t * .pi * 6)44 let swell = 0.6 + 0.4 * cos(t * .pi * 17)45 return Float(sin(Double(index) * 0.21) * envelope * swell)46 }47 }48}4950#Preview("GlassWaveform") { GlassWaveformExample().glassTheme(.aurora) }51