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 --- Radio/Utils/iqconvert/main.swift | 117 ++++++++++++++++++++++++++++++++------- 1 file changed, 97 insertions(+), 20 deletions(-) (limited to 'Radio/Utils/iqconvert/main.swift') diff --git a/Radio/Utils/iqconvert/main.swift b/Radio/Utils/iqconvert/main.swift index 49db280..b8b5f3b 100644 --- a/Radio/Utils/iqconvert/main.swift +++ b/Radio/Utils/iqconvert/main.swift @@ -11,7 +11,11 @@ import ArgumentParser enum SDRInputFormat { case FMT_NONE case FMT_U8 + case FMT_I16 + case FMT_U16 + case FMT_SC16Q11 case FMT_F32 + case FMT_WAV } //set the command line arguments @@ -27,16 +31,17 @@ let args = CommandLineArgs.parseOrExit() if args.listFormats { print("Supported input:") - print(" u8: RTLSDR [not supported]") - print(" u16: AirSpyHF [not supported]") + print(" u8: RTLSDR ") + print(" u16: AirSpyHF ") print(" u16r: AirSpy [not supported]") - print(" i16: AirSpy [not supported]") + print(" i16: AirSpy ") print(" i16r: AirSpy [not supported]") //int16 real 1 * 16bit per sample - print(" sc16q11: BladeRF [not supported]") - print(" fc32r: AirSpy [not supported]") //float32 real 1 * 32bit per sampl + print(" sc16q11: BladeRF ") + print(" fc32r: AirSpy [not supported]") //float32 real 1 * 32bit per sample + print(" fc32: AirSpy [not supported]") print("Supported output:") - print(" fc32: inspectrum, sdr++ ") - print(" wav: SDR# [not suppoprted]") + print(" fc32: inspectrum ") + print(" wav: SDR#,sdr++ [not suppoprted]") } //var inputFilePath:String @@ -60,10 +65,16 @@ if let dotIndex = args.inputFile.lastIndex(of: ".") { let index = args.inputFile.index(dotIndex, offsetBy: 1) let fileExtension = String(args.inputFile[index.. 0 { - outdata_f32 = cnvU8toFloat32(data_u8) -} else { - print("No data in buffer") +switch (inputFormat) { +case .FMT_U8: + if data_u8.count > 0 { + outdata_f32 = cnvU8toFloat32(data_u8) + } else { + print("No data in buffer") + } + break +case .FMT_U16: + if data_u16.count > 0 { + outdata_f32 = cnvU16toFloat32(data_u16) + } else { + print("No data in buffer") + } + break +case .FMT_I16: + if data_i16.count > 0 { + outdata_f32 = cnvI16toFloat32(data_i16) + } else { + print("No data in buffer") + } + break +case .FMT_SC16Q11: + if data_i16.count > 0 { + print("convert to FMT_SC16Q11") + outdata_f32 = cnvSC16Q11toFloat32(data_i16) + } else { + print("No data in buffer") + } + break +default: + print("Cant convert to unknown format") } // write to file -- cgit v1.2.3