Created
June 19, 2020 10:18
-
-
Save marcusficner/63feeedea5d02b971570784b8907fc9b to your computer and use it in GitHub Desktop.
Draw a waveform with SwiftUI using a Path
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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