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/GenSin/main.swift | 142 +++++++++++++++++++++++++++++++++++ Radio/Utils/WaterfallFile/main.swift | 2 +- Radio/Utils/iqconvert/main.swift | 117 ++++++++++++++++++++++++----- 3 files changed, 240 insertions(+), 21 deletions(-) create mode 100644 Radio/Utils/GenSin/main.swift (limited to 'Radio') diff --git a/Radio/Utils/GenSin/main.swift b/Radio/Utils/GenSin/main.swift new file mode 100644 index 0000000..b247dc2 --- /dev/null +++ b/Radio/Utils/GenSin/main.swift @@ -0,0 +1,142 @@ +// +// main.swift +// GenSin +// +// Created by Jacky Jack on 21/02/2025. +// + +import Foundation +import ArgumentParser + +/* +Takes as input +*/ + + +enum OutputFormat { + case FMT_NONE + case FMT_U8 + case FMT_S8 + case FMT_U16 + case FMT_S16 + case FMT_SC16Q11 + case FMT_F32 + case FMT_WAV_INT16 + case FMT_WAV_F32 +} + +print("gen sin") + +//set the command line arguments +struct CommandLineArgs: ParsableCommand { + @Argument var outputFile:String = "" + @Flag(help:"Version \(software_version)") var version: Bool = false + @Flag(name: .shortAndLong) var verbose: Bool = false + @Option(name:.shortAndLong) var samplerate: Int = 1000 + @Option(name:.shortAndLong) var amplitude: Float = 1.0 + @Option(name:.shortAndLong) var freq: Int = 10 + @Option(name:.shortAndLong) var num: Int = 100000 + //@Option(name:.shortAndLong) var type: String = "sine" + @Flag(name: .shortAndLong) var listFormats: Bool = false +} + +let args = CommandLineArgs.parseOrExit() + +if args.listFormats { + print("Supported output:") + print(" s8,u8: [DONE]") + print(" s16,u16: not") + print(" s16q11: not") + print(" f32: not ") + print(" wav i16, fc32: not") +} + +//outputfile Format +var outputFormat = OutputFormat.FMT_NONE +if let dotIndex = args.outputFile.lastIndex(of: ".") { + let index = args.outputFile.index(dotIndex, offsetBy: 1) + let fileExtension = String(args.outputFile[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