From 972a6d3e4d3b684fbadeb5cd046a8634ec24eb8c Mon Sep 17 00:00:00 2001 From: Arturs Artamonovs Date: Mon, 3 Feb 2025 22:31:45 +0000 Subject: iqconvert: converts from u8 to f32 without issues --- Radio/Utils/iqconvert/main.swift | 50 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) (limited to 'Radio/Utils/iqconvert/main.swift') diff --git a/Radio/Utils/iqconvert/main.swift b/Radio/Utils/iqconvert/main.swift index f619529..49db280 100644 --- a/Radio/Utils/iqconvert/main.swift +++ b/Radio/Utils/iqconvert/main.swift @@ -35,7 +35,7 @@ if args.listFormats { print(" sc16q11: BladeRF [not supported]") print(" fc32r: AirSpy [not supported]") //float32 real 1 * 32bit per sampl print("Supported output:") - print(" fc32: inspectrum, sdr++ [not supported]") + print(" fc32: inspectrum, sdr++ ") print(" wav: SDR# [not suppoprted]") } @@ -84,8 +84,54 @@ if let dotIndex = args.outputFile.lastIndex(of: ".") { print("Input file format:\(inputFormat) output file format:\(outputFormat)") +//read from file +//if let data_u8:[UInt8] = fileReader.readAll() { +var data_u8:[UInt8] = [] +do { + data_u8 = try fileReader.readAll() +} catch { + print("Reading file: \(error)") + exit(1) +} -fileReader.close() +//convert to output format +var outdata_f32:[Float32] = [] +if data_u8.count > 0 { + outdata_f32 = cnvU8toFloat32(data_u8) +} else { + print("No data in buffer") +} +// write to file +let fileWrite = FileWriter() +var file_ok = false +if (checkIfFileExists(args.outputFile)) { + do { + print("try to delet file for write") + try fileWrite.deleteForWrite(filename: args.outputFile) + } catch { + print("cant delete file \(error)") + exit(1) + } +} else { + do { + print("try to creating file") + try fileWrite.createForWrite(filename: args.outputFile) + } catch { + print("cant create file \(error)") + exit(1) + } +} + +do { + try fileWrite.writeAll(outdata_f32) +} catch { + print("Cant write to file \(error)") + exit(1) +} + + +fileReader.close() +fileWrite.close() -- cgit v1.2.3