blob: b4dca7e16d60b921fad8e8fd1198b41909ec46cc (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
//
// NaiveFFT.swift
// PrySDR
//
// Created by Jacky Jack on 05/01/2025.
//
import Foundation
import Accelerate
//SUpports now only fixed sizes and not flexible implementation just a PoC
class NaiveFFT512 {
static let sampleCount = 512
let forwardDCT = vDSP.DCT(count: sampleCount, transformType: .II)!
init() {
}
func getSampleCount() -> Int {
return NaiveFFT512.sampleCount
}
func computeLine(_ processingArray: [Int8]) -> [Float] {
var dataFloat = [Float](repeating: 0.0, count: NaiveFFT512.sampleCount)
if processingArray.count != NaiveFFT512.sampleCount {
print("Not supporting arrays not equail to \(NaiveFFT512.sampleCount)")
return []
}
vDSP.convertElements(of: processingArray, to: &dataFloat)
//dataFloat = vDSP.add(127.0, dataFloat)
//print(dataFloat)
//move from -127.0 to 128.0 range -1.0...1.0
//var adjusted = vDSP.divide(dataFloat, Float(sampleCount))
var adjusted = dataFloat
//print(adjusted)
var transform_result = forwardDCT.transform(adjusted)
transform_result = vDSP.absolute(transform_result)
return transform_result
}
}
|