diff options
author | Arturs Artamonovs <arturs.artamonovs@protonmail.com> | 2025-03-20 11:55:33 +0000 |
---|---|---|
committer | Arturs Artamonovs <arturs.artamonovs@protonmail.com> | 2025-03-20 11:55:33 +0000 |
commit | 5aa1435739fa1cd150dd8cd8fb2fee5473d5ed3f (patch) | |
tree | af2bf7690d3661e863544a5255ec0e6182eeb61f /Utils/FileReader.swift | |
parent | 972a6d3e4d3b684fbadeb5cd046a8634ec24eb8c (diff) | |
download | PrySDR-5aa1435739fa1cd150dd8cd8fb2fee5473d5ed3f.tar.gz PrySDR-5aa1435739fa1cd150dd8cd8fb2fee5473d5ed3f.zip |
gensin: generate sinusoid in u8,s8,u16,s16 formatsmain
Diffstat (limited to 'Utils/FileReader.swift')
-rw-r--r-- | Utils/FileReader.swift | 46 |
1 files changed, 38 insertions, 8 deletions
diff --git a/Utils/FileReader.swift b/Utils/FileReader.swift index 1f9c561..e0447b3 100644 --- a/Utils/FileReader.swift +++ b/Utils/FileReader.swift @@ -64,7 +64,7 @@ class FileReader { return [] } - func readAll() throws -> [UInt8] { + func readAllUInt8() throws -> [UInt8] { var ret_arr:[UInt8]? = nil if let file = fileHandle { do { @@ -90,7 +90,7 @@ class FileReader { } } - func readAll() throws -> [Int8] { + func readAllInt8() throws -> [Int8] { var ret_arr:[Int8]? = nil if let file = fileHandle { do { @@ -122,14 +122,44 @@ class FileReader { } } - func readAll() throws -> [UInt16] { - print("FileReader not implemented") - return [] + //https://forums.swift.org/t/swift-5-read-binary-file-problem-with-unsafe-mutable-pointers/31048/6 + func readAllInt16() throws -> [Int16] { + var ret_arr:[Int16]? = nil + if let file = fileHandle { + do { + if let databuf = try file.readToEnd() { + ret_arr = [Int16](asInt16(databuf)) + } + print(ret_arr![0],ret_arr![1],ret_arr![2],ret_arr![3]) + } catch { + print("ReadAll i8 error:\(error)") + throw FileReaderError.readError + } + } + if ret_arr == nil { + return [] + } else { + return ret_arr! + } } - func readAll() throws -> [Int16] { - print("FileReader not implemented") - return [] + func readAllUInt16() throws -> [UInt16] { + var ret_arr:[UInt16]? = nil + if let file = fileHandle { + do { + if let databuf = try file.readToEnd() { + ret_arr = [UInt16](asUInt16(databuf)) + } + } catch { + print("ReadAll i8 error:\(error)") + throw FileReaderError.readError + } + } + if ret_arr == nil { + return [] + } else { + return ret_arr! + } } func readAll() throws -> [Float] { |