Skip to content

Commit

Permalink
improve performance by using a pre-calculated window
Browse files Browse the repository at this point in the history
  • Loading branch information
YuAo committed Dec 20, 2021
1 parent a45fa56 commit 5b326d2
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions Sources/AudioPrism/AudioPrism.swift
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ public final class AudioPrism: @unchecked Sendable {
private var sampleBuffer: [Float] = []
private var previousFFTValues: [Float]

private let window: [Float]

private var _timeDomainData: TimeDomainData?
private var _frequencyData: FrequencyData?

Expand All @@ -177,6 +179,10 @@ public final class AudioPrism: @unchecked Sendable {
self.options = options
self.frequencyBinCount = options.fftSize/2
self.previousFFTValues = [Float](repeating: 0, count: frequencyBinCount)

var window = [Float](repeating: 0, count: options.fftSize)
vDSP_blkman_window(&window, vDSP_Length(options.fftSize), 0)
self.window = window
}

deinit {
Expand Down Expand Up @@ -229,9 +235,6 @@ public final class AudioPrism: @unchecked Sendable {

var samples = Array(sampleBuffer.suffix(options.fftSize))

var window = [Float](repeating: 0, count: options.fftSize)
vDSP_blkman_window(&window, vDSP_Length(options.fftSize), 0)

var frequencyData = [Float](repeating: 0, count: frequencyBinCount)
var uint8Values = [UInt8](repeating: 0, count: frequencyBinCount)

Expand Down

0 comments on commit 5b326d2

Please sign in to comment.