From 5aa1435739fa1cd150dd8cd8fb2fee5473d5ed3f Mon Sep 17 00:00:00 2001 From: Arturs Artamonovs Date: Thu, 20 Mar 2025 11:55:33 +0000 Subject: gensin: generate sinusoid in u8,s8,u16,s16 formats --- Utils/FileReader.swift | 46 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 38 insertions(+), 8 deletions(-) (limited to 'Utils/FileReader.swift') 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] { -- cgit v1.2.3