summaryrefslogtreecommitdiff
path: root/WaterfallFile_UI/FileSpectrum.swift
diff options
context:
space:
mode:
authorArturs Artamonovs <arturs.artamonovs@protonmail.com>2025-01-06 12:30:49 +0000
committerArturs Artamonovs <arturs.artamonovs@protonmail.com>2025-01-06 12:30:49 +0000
commita0d12ecbac8fe327d1dcd4580fee594e24d4191b (patch)
tree9a7cef9ed0de080bb8c19912f678497a4fca6a86 /WaterfallFile_UI/FileSpectrum.swift
parentf923a3824561c6cf200c638e3d44d1cbf4adf7d8 (diff)
downloadPrySDR-main.tar.gz
PrySDR-main.zip
Waterfall: UI drawing from filemain
Diffstat (limited to 'WaterfallFile_UI/FileSpectrum.swift')
-rw-r--r--WaterfallFile_UI/FileSpectrum.swift55
1 files changed, 50 insertions, 5 deletions
diff --git a/WaterfallFile_UI/FileSpectrum.swift b/WaterfallFile_UI/FileSpectrum.swift
index 6415dfa..ce64836 100644
--- a/WaterfallFile_UI/FileSpectrum.swift
+++ b/WaterfallFile_UI/FileSpectrum.swift
@@ -13,8 +13,15 @@ import CoreImage
class FileSpectrum: NSObject, ObservableObject {
- let default_width = 512
- let default_height = 512
+ static let default_width = 512
+ static let default_height = 512
+ static let defaultSleepTime:UInt32 = 1
+ var offset:Int=0
+ let fileReader = FileReader()
+ var dataBuffer:[Int8] = .init(repeating: 0, count: FileSpectrum.default_width)
+ var allData:[Int8]? = nil
+ let fft512 = NaiveFFT512()
+ var line_counter:Int = 0
let sessionQueue = DispatchQueue(label: "sessionQueue",
attributes: [],
@@ -22,7 +29,7 @@ class FileSpectrum: NSObject, ObservableObject {
@Published var outputImage = emptyCGImage
- let simpleImage = SimpleImage(width: 256, height: 256)
+ let simpleImage = SimpleImage(width: 512, height: 512)
/// A 1x1 Core Graphics image.
static var emptyCGImage: CGImage = {
@@ -40,24 +47,62 @@ class FileSpectrum: NSObject, ObservableObject {
return buffer.makeCGImage(cgImageFormat: fmt!)!
}()
+
+ init(_ input_filename: String) {
+ //get data from u8 file
+
+ do {
+ try fileReader.open(filename: input_filename)
+ } catch {
+ print("Cant open file \(input_filename)")
+ exit(0)
+ }
+ var i8_arr:[Int8]? = nil
+ do {
+ try i8_arr = fileReader.readAll()
+ allData = i8_arr
+ } catch {
+ print("Got error \(error)")
+ }
+
+ fileReader.close()
+ }
func makeSpectrogramImage() -> NSImage {
return NSImage(cgImage: FileSpectrum.emptyCGImage, size: .zero)
}
+
+ //just get data time to time from databuffer and pretend to be realtime data
+ func dataFileProcessor() {
+ //all now is about 512pixels
+ let processingSlice = allData![offset...offset+FileSpectrum.default_width-1]
+ let dataBuffer = Array(processingSlice)
+ var transform_result:[Float] = .init(repeating: 0.0, count: FileSpectrum.default_width)
+ //DispatchQueue.main.async {
+ transform_result = self.fft512.computeLine(dataBuffer)
+ self.simpleImage.drawPalletLine(line: self.line_counter, pixelLine: transform_result)
+ if self.offset+FileSpectrum.default_width < allData!.count {
+ self.offset += FileSpectrum.default_width
+ self.line_counter += 1
+ }
+ //}
+
+ }
func startRunning() {
sessionQueue.async {
print("lets start the task for spectrum analysis")
- for i in 0..<100 {
+ for i in 0..<512 {
print("Process the task \(i)")
self.simpleImage.drawPixel(i, i, PixelData(a: 255, r: 255, g: 0, b: 0))
DispatchQueue.main.async {
+ self.dataFileProcessor()
self.outputImage = self.simpleImage.toCGImage()!
}
- sleep(1)
+ sleep(FileSpectrum.defaultSleepTime)
}
}
}