Skip to content

Commit

Permalink
Update Visualizer.swift
Browse files Browse the repository at this point in the history
  • Loading branch information
hiroshihorie committed Nov 14, 2024
1 parent 5ce416e commit 380d2d7
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions Sources/LiveKitComponents/UI/Visualizer/Visualizer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@ import AVFoundation
import LiveKit
import SwiftUI

class AudioProcessor: ObservableObject, AudioRenderer {
private weak var _track: AudioTrack?
private let isCentered: Bool
public class AudioProcessor: ObservableObject, AudioRenderer {
public let isCentered: Bool
public let smoothingFactor: Float

// Normalized to 0.0-1.0 range.
@Published var bands: [Float]
@Published public var bands: [Float]

private let _processor: AudioVisualizeProcessor
private weak var _track: AudioTrack?

init(track: AudioTrack?,
bandCount: Int,
isCentered: Bool = true,
smoothingFactor: Float = 0.3)
public init(track: AudioTrack?,
bandCount: Int,
isCentered: Bool = true,
smoothingFactor: Float = 0.3)
{
self.isCentered = isCentered
self.smoothingFactor = smoothingFactor
Expand All @@ -46,7 +46,7 @@ class AudioProcessor: ObservableObject, AudioRenderer {
_track?.remove(audioRenderer: self)
}

func render(pcmBuffer: AVAudioPCMBuffer) {
public func render(pcmBuffer: AVAudioPCMBuffer) {
let newBands = _processor.process(pcmBuffer: pcmBuffer)
guard var newBands else { return }

Expand Down Expand Up @@ -134,7 +134,7 @@ class AudioProcessor: ObservableObject, AudioRenderer {
/// ```
/// BarAudioVisualizer(audioTrack: audioTrack, barColor: .blue, barCount: 10)
/// ```
struct BarAudioVisualizer: View {
public struct BarAudioVisualizer: View {
public let barCount: Int
public let barColor: Color
public let barCornerRadius: CGFloat
Expand All @@ -146,13 +146,13 @@ struct BarAudioVisualizer: View {

@StateObject private var audioProcessor: AudioProcessor

init(audioTrack: AudioTrack,
barColor: Color = .white,
barCount: Int = 7,
barCornerRadius: CGFloat = 100,
barSpacingFactor: CGFloat = 0.015,
barMinOpacity: CGFloat = 0.35,
isCentered: Bool = true)
public init(audioTrack: AudioTrack,
barColor: Color = .white,
barCount: Int = 7,
barCornerRadius: CGFloat = 100,
barSpacingFactor: CGFloat = 0.015,
barMinOpacity: CGFloat = 0.35,
isCentered: Bool = true)
{
self.audioTrack = audioTrack
self.barColor = barColor
Expand All @@ -167,7 +167,7 @@ struct BarAudioVisualizer: View {
isCentered: isCentered))
}

var body: some View {
public var body: some View {
GeometryReader { geometry in
let barMinHeight = (CGFloat(geometry.size.width) - CGFloat(geometry.size.width * barSpacingFactor) * CGFloat(barCount + 2)) / CGFloat(barCount)
HStack(alignment: .center, spacing: geometry.size.width * barSpacingFactor) {
Expand Down

0 comments on commit 380d2d7

Please sign in to comment.