Skip to content

Instantly share code, notes, and snippets.

@marcusficner
Created June 19, 2020 10:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcusficner/63feeedea5d02b971570784b8907fc9b to your computer and use it in GitHub Desktop.
Save marcusficner/63feeedea5d02b971570784b8907fc9b to your computer and use it in GitHub Desktop.
Draw a waveform with SwiftUI using a Path
struct ContentView: View {
@ObservedObject var audioEngine = AudioEngine()
var body: some View {
GeometryReader { geometry in
Path { path in
path.move(to: CGPoint(x: 0, y: geometry.size.height/2))
for i in 0..<Int(geometry.size.width) {
path.addLine(to: CGPoint(x: CGFloat(i), y: (geometry.size.height/2) + (self.scaleFactor * CGFloat(self.audioEngine.buffer[i]))))
}
}
.stroke(Color.blue)
}
}
let scaleFactor: CGFloat = 400
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment