Repository Public MIT
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project : SP GlassKit7// File : Examples/Gallery/Media/GlassWaveformExample.swift8// Module : Examples9// Repository : https://git.spboucher.ai/sp-glasskit10// Project Website : https://glass.spboucher.ai11// Created : 2026-12-0212// Last Modified : 2026-12-0213//14// Author : Simon-Pierre Boucher15// Position : Professor of Finance16// Institution : Université du Québec en Outaouais (UQO)17// Organization : SP Boucher18// Website : https://spboucher.ai19// Git : https://git.spboucher.ai20//21// Preferred Contact: contact@spboucher.ai22// Development : dev@spboucher.ai23// Support : support@spboucher.ai24// Security/Admin : admin@spboucher.ai25//26// Copyright (c) 202627// Simon-Pierre Boucher28// All rights reserved where applicable. This file is governed by the29// applicable project license, copyright notices and relevant law.30// Existing third-party rights and notices remain unaffected.31//32// License : MIT33//34// Do not embed credentials, private keys, access tokens,35// certificates or confidential personal information.36//37// =============================================================================38// END OF SP BOUCHER SOURCE HEADER39// =============================================================================4041import SwiftUI42import SPGlassKit4344public struct GlassWaveformExample: GlassExample {45 public static let componentID = "glass-waveform"46 /// Aggregated once, when the example is created, not on every frame.47 @State private var voice = GlassWaveformData(samples: Self.syntheticSamples(count: 48_000), maxBuckets: 96, aggregation: .rms)48 @State private var peaks = GlassWaveformData(samples: Self.syntheticSamples(count: 48_000), maxBuckets: 160)49 @State private var progress = 0.355051 public init() {}5253 public var body: some View {54 VStack(alignment: .leading, spacing: 16) {55 Text("RMS, 96 buckets, with progress")56 .font(.headline)57 GlassWaveform(voice, progress: progress)58 Slider(value: $progress, in: 0...1) { Text("Progress") }5960 Text("Peak, 160 buckets")61 .font(.headline)62 GlassWaveform(peaks, minimumHeight: 72)6364 Text("No samples")65 .font(.headline)66 GlassWaveform(.empty, minimumHeight: 24)6768 Text("Sample data · a synthetic signal built from sine waves.")69 .font(.caption)70 .foregroundStyle(.secondary)71 }72 .padding()73 }7475 /// A deterministic signal: a carrier shaped by two slow envelopes.76 static func syntheticSamples(count: Int) -> [Float] {77 (0..<count).map { index in78 let t = Double(index) / Double(count)79 let envelope = 0.55 + 0.45 * sin(t * .pi * 6)80 let swell = 0.6 + 0.4 * cos(t * .pi * 17)81 return Float(sin(Double(index) * 0.21) * envelope * swell)82 }83 }84}8586#Preview("GlassWaveform") { GlassWaveformExample().glassTheme(.aurora) }87