diff options
author | Arturs Artamonovs <arturs.artamonovs@protonmail.com> | 2025-05-23 09:48:25 +0100 |
---|---|---|
committer | Arturs Artamonovs <arturs.artamonovs@protonmail.com> | 2025-05-23 09:48:25 +0100 |
commit | 76869b1d3eac88cc6bdef2ef6f3a009b5c28c84d (patch) | |
tree | 61c1a3bdf7b691fd42336c8d66fd27c633392d56 /Radio | |
parent | 5aa1435739fa1cd150dd8cd8fb2fee5473d5ed3f (diff) | |
download | PrySDR-76869b1d3eac88cc6bdef2ef6f3a009b5c28c84d.tar.gz PrySDR-76869b1d3eac88cc6bdef2ef6f3a009b5c28c84d.zip |
genearation of s8/u8/s16/u16/s16q11 works as expectedmain
Diffstat (limited to 'Radio')
-rw-r--r-- | Radio/Utils/GenSin/main.swift | 98 |
1 files changed, 75 insertions, 23 deletions
diff --git a/Radio/Utils/GenSin/main.swift b/Radio/Utils/GenSin/main.swift index b247dc2..9f624e2 100644 --- a/Radio/Utils/GenSin/main.swift +++ b/Radio/Utils/GenSin/main.swift @@ -7,6 +7,7 @@ import Foundation import ArgumentParser +import ComplexModule /* Takes as input @@ -24,6 +25,7 @@ enum OutputFormat { case FMT_WAV_INT16 case FMT_WAV_F32 } +var complex_type:Bool = false print("gen sin") @@ -42,12 +44,21 @@ struct CommandLineArgs: ParsableCommand { let args = CommandLineArgs.parseOrExit() +if args.version { + print("Software version \(software_version)") + exit(0) +} + if args.listFormats { print("Supported output:") - print(" s8,u8: [DONE]") - print(" s16,u16: not") - print(" s16q11: not") - print(" f32: not ") + print(" s8,u8 : [DONE]") + print(" cs8,cu8 : [TEST]") + print(" s16,u16 : [DONE]") + print(" cs16,cu16: [TEST]") + print(" s16q11 : [TEST]") + print(" cs16q11 : [TEST]") + print(" f32 : not ") + print(" cf32 : not ") print(" wav i16, fc32: not") } @@ -57,19 +68,36 @@ if let dotIndex = args.outputFile.lastIndex(of: ".") { let index = args.outputFile.index(dotIndex, offsetBy: 1) let fileExtension = String(args.outputFile[index..<args.outputFile.endIndex]) print("\(args.outputFile) extension \(fileExtension)") - let supportedExtensionList = ["s8","u8","s16","u16"] + let supportedExtensionList = ["s8","cs8","u8","cu8","s16","cs16","u16","cu16","s16q11","cs16q11"] if supportedExtensionList.contains(fileExtension) { if ["s8"].contains(fileExtension) { outputFormat = OutputFormat.FMT_S8 + } else if ["cs8"].contains(fileExtension){ + outputFormat = OutputFormat.FMT_S8 + complex_type = true } else if ["u8"].contains(fileExtension) { outputFormat = OutputFormat.FMT_U8 + } else if ["cu8"].contains(fileExtension) { + outputFormat = OutputFormat.FMT_U8 + complex_type = true } else if ["s16"].contains(fileExtension) { outputFormat = OutputFormat.FMT_S16 + } else if ["cs16"].contains(fileExtension) { + outputFormat = OutputFormat.FMT_S16 + complex_type = true } else if ["u16"].contains(fileExtension) { outputFormat = OutputFormat.FMT_U16 - }// else if ["wav"].contains(fileExtension) { - // outputFormat = OutputFormat.FMT_WAV_F32 - //} + } else if ["cu16"].contains(fileExtension) { + outputFormat = OutputFormat.FMT_U16 + complex_type = true + } else if ["s16q11"].contains(fileExtension) { + outputFormat = OutputFormat.FMT_SC16Q11 + } else if ["cs16q11"].contains(fileExtension) { + outputFormat = OutputFormat.FMT_SC16Q11 + complex_type = true + } else if ["wav"].contains(fileExtension) { + outputFormat = OutputFormat.FMT_WAV_F32 + } else { print("Unknown output format") } @@ -81,23 +109,49 @@ var outdata_u8:[UInt8] = [] var outdata_s16:[Int16] = [] var outdata_u16:[UInt16] = [] var outdata_f32:[Float32] = [] +var outdata_cf32:[Complex<Float32>] = [] + +//var outdata_cs8:[Complex<Int8>] = [] +//var outdata_cu8:[UInt8] = [] +//var outdata_cs16:[Int16] = [] +//var outdata_cu16:[UInt16] = [] +//var outdata_cs16q11:[Complex<Int16>] = [] +//var outdata_cf32:[Float32] = [] //generate signal outdata_f32 = genSin(args.samplerate, args.freq, args.amplitude, 0.0, args.num) -if outputFormat == OutputFormat.FMT_S8 { - outdata_s8 = cnvFloat32ToInt8(outdata_f32) -} else if outputFormat == OutputFormat.FMT_U8 { - outdata_u8 = cnvFloat32ToUInt8(outdata_f32) -} else if outputFormat == OutputFormat.FMT_S16 { - outdata_s16 = cnvFloat32ToInt16(outdata_f32) -} else if outputFormat == OutputFormat.FMT_U16 { - outdata_u16 = cnvFloat32ToUInt16(outdata_f32) +outdata_cf32 = genSin(args.samplerate, args.freq, args.amplitude, 0.0, args.num) +if complex_type == false { + if outputFormat == OutputFormat.FMT_S8 { + outdata_s8 = cnvFloat32ToInt8(outdata_f32) + } else if outputFormat == OutputFormat.FMT_U8 { + outdata_u8 = cnvFloat32ToUInt8(outdata_f32) + } else if outputFormat == OutputFormat.FMT_S16 { + outdata_s16 = cnvFloat32ToInt16(outdata_f32) + } else if outputFormat == OutputFormat.FMT_U16 { + outdata_u16 = cnvFloat32ToUInt16(outdata_f32) + } else if outputFormat == OutputFormat.FMT_SC16Q11 { + outdata_s16 = cnvFloat32ToS16Q11(outdata_f32) + } else { + print("Unimplemented output format converter") + } +//complex numbers } else { - print("Unimplemented output format converter") + if outputFormat == OutputFormat.FMT_S8 { + outdata_s8 = cnvFloat32ToCInt8(outdata_cf32) + } else if outputFormat == OutputFormat.FMT_U8 { + outdata_u8 = cnvFloat32ToCUInt8(outdata_cf32) + } else if outputFormat == OutputFormat.FMT_S16 { + outdata_s16 = cnvFloat32ToCInt16(outdata_cf32) + } else if outputFormat == OutputFormat.FMT_U16 { + outdata_u16 = cnvFloat32ToCUInt16(outdata_cf32) + } else if outputFormat == OutputFormat.FMT_SC16Q11 { + outdata_s16 = cnvFloat32ToS16Q11(outdata_cf32) + } else { + print("Unimplemented complex output format converter") + } } - - // write to file let fileWrite = FileWriter() var file_ok = false @@ -124,7 +178,8 @@ do { try fileWrite.writeAll(outdata_s8) } else if outputFormat == OutputFormat.FMT_U8 { try fileWrite.writeAll(outdata_u8) - } else if outputFormat == OutputFormat.FMT_S16 { + } else if (outputFormat == OutputFormat.FMT_S16) + || (outputFormat == OutputFormat.FMT_SC16Q11) { try fileWrite.writeAll(outdata_s16) } else if outputFormat == OutputFormat.FMT_U16 { try fileWrite.writeAll(outdata_u16) @@ -137,6 +192,3 @@ do { } fileWrite.close() - - - |