From a62644166590dddd565b21a66afd47644875a358 Mon Sep 17 00:00:00 2001 From: Ahmet Inan Date: Sat, 19 Jul 2025 12:40:47 +0200 Subject: [PATCH] made specifying the mode nicer --- Makefile | 2 +- README.md | 4 ++-- encode.cc | 55 +++++++++++++++++++++++++++++++++++++++++++++++-------- 3 files changed, 50 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index 1902930..100344a 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,7 @@ CXX = clang++ -stdlib=libc++ -march=native all: encode decode test: encode decode - $(QEMU) ./encode audio.wav 48000 16 1 1500 ANONYMOUS 48 /dev/urandom + $(QEMU) ./encode audio.wav 48000 16 1 1500 ANONYMOUS QAM16 1/2 short /dev/urandom $(QEMU) ./decode audio.wav /dev/null encode: encode.cc common.hh diff --git a/README.md b/README.md index 55be736..55b0f66 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ dd if=/dev/urandom of=uncoded.dat bs=1 count=256 Encode file ```uncoded.dat``` to ```encoded.wav``` [WAV](https://en.wikipedia.org/wiki/WAV) audio file with 48000 Hz sample rate, 16 bits and only 1 (real) channel: ``` -./encode encoded.wav 48000 16 1 1500 ANONYMOUS 176 uncoded.dat +./encode encoded.wav 48000 16 1 1500 ANONYMOUS QAM16 1/2 short uncoded.dat ``` Start recording to ```recorded.wav``` audio file and stop after 5 seconds: @@ -96,7 +96,7 @@ Prerequisite: [disorders](https://github.com/aicodix/disorders) Encode ```uncoded.dat``` to [analytic](https://en.wikipedia.org/wiki/Analytic_signal) audio signal, add [multipath](https://en.wikipedia.org/wiki/Multipath_propagation), [CFO, SFO](https://en.wikipedia.org/wiki/Carrier_frequency_offset), [AWGN](https://en.wikipedia.org/wiki/Additive_white_Gaussian_noise), decode and compare: ``` -./encode - 48000 16 2 1500 ANONYMOUS 176 uncoded.dat | ../disorders/multipath - - ../disorders/multipath.txt 10 | ../disorders/cfo - - 234.567 | ../disorders/sfo - - 147 | ../disorders/awgn - - -20 | ./decode - - | diff -q -s uncoded.dat - +./encode - 48000 16 2 1500 ANONYMOUS QAM16 1/2 short uncoded.dat | ../disorders/multipath - - ../disorders/multipath.txt 10 | ../disorders/cfo - - 234.567 | ../disorders/sfo - - 147 | ../disorders/awgn - - -20 | ./decode - - | diff -q -s uncoded.dat - ``` ### Reading diff --git a/encode.cc b/encode.cc index 268e08c..bcd630d 100644 --- a/encode.cc +++ b/encode.cc @@ -361,8 +361,8 @@ int64_t base37_encoder(const char *str) int main(int argc, char **argv) { - if (argc < 9) { - std::cerr << "usage: " << argv[0] << " OUTPUT RATE BITS CHANNELS OFFSET CALLSIGN MODE INPUT.." << std::endl; + if (argc < 11) { + std::cerr << "usage: " << argv[0] << " OUTPUT RATE BITS CHANNELS OFFSET CALLSIGN MODULATION CODERATE FRAMESIZE INPUT.." << std::endl; return 1; } @@ -383,10 +383,48 @@ int main(int argc, char **argv) std::cerr << "Unsupported call sign." << std::endl; return 1; } - int input_count = argc - 8; - int oper_mode = std::atoi(argv[7]); - if (oper_mode < 0 || oper_mode > 255) { - std::cerr << "Unsupported operation mode." << std::endl; + int oper_mode = 0; + char *modulation = argv[7]; + if (!strcmp(modulation, "DBPSK")) { + oper_mode |= 0 << 4; + } else if (!strcmp(modulation, "DQPSK")) { + oper_mode |= 1 << 4; + } else if (!strcmp(modulation, "D8PSK")) { + oper_mode |= 2 << 4; + } else if (!strcmp(modulation, "QAM16")) { + oper_mode |= 3 << 4; + } else if (!strcmp(modulation, "QAM64")) { + oper_mode |= 4 << 4; + } else if (!strcmp(modulation, "QAM256")) { + oper_mode |= 5 << 4; + } else if (!strcmp(modulation, "QAM1024")) { + oper_mode |= 6 << 4; + } else if (!strcmp(modulation, "QAM4096")) { + oper_mode |= 7 << 4; + } else { + std::cerr << "Unsupported modulation." << std::endl; + return 1; + } + char *code_rate = argv[8]; + if (!strcmp(code_rate, "1/2")) { + oper_mode |= 0 << 1; + } else if (!strcmp(code_rate, "2/3")) { + oper_mode |= 1 << 1; + } else if (!strcmp(code_rate, "3/4")) { + oper_mode |= 2 << 1; + } else if (!strcmp(code_rate, "5/6")) { + oper_mode |= 3 << 1; + } else { + std::cerr << "Unsupported code rate." << std::endl; + return 1; + } + char *frame_size = argv[9]; + if (!strcmp(frame_size, "short")) { + oper_mode |= 0; + } else if (!strcmp(frame_size, "normal")) { + oper_mode |= 1; + } else { + std::cerr << "Unsupported frame size." << std::endl; return 1; } int band_width = 2400; @@ -399,12 +437,13 @@ int main(int argc, char **argv) typedef DSP::Complex cmplx; DSP::WriteWAV output_file(output_name, output_rate, output_bits, output_chan); output_file.silence(output_rate); + int input_count = argc - 10; switch (output_rate) { case 44100: - delete new Encoder(&output_file, argv + 8, input_count, freq_off, call_sign, oper_mode); + delete new Encoder(&output_file, argv + 10, input_count, freq_off, call_sign, oper_mode); break; case 48000: - delete new Encoder(&output_file, argv + 8, input_count, freq_off, call_sign, oper_mode); + delete new Encoder(&output_file, argv + 10, input_count, freq_off, call_sign, oper_mode); break; default: std::cerr << "Unsupported sample rate." << std::endl;