aboutsummaryrefslogtreecommitdiff
path: root/src/cohpsk_mod.c
diff options
context:
space:
mode:
authordrowe67 <[email protected]>2023-07-14 12:36:50 +0930
committerDavid Rowe <[email protected]>2023-07-14 12:36:50 +0930
commitb86e88413d4c6ec428aaedb147f7675f28882fe4 (patch)
treece360925856e25d4343d59a37e2e6bac142d3752 /src/cohpsk_mod.c
parent0c2e969cfbe85548801eeb20ad8113969604892a (diff)
clang-format -i applied to src unittest misc
Diffstat (limited to 'src/cohpsk_mod.c')
-rw-r--r--src/cohpsk_mod.c158
1 files changed, 81 insertions, 77 deletions
diff --git a/src/cohpsk_mod.c b/src/cohpsk_mod.c
index 5d5443a..b3819a3 100644
--- a/src/cohpsk_mod.c
+++ b/src/cohpsk_mod.c
@@ -28,92 +28,96 @@
*/
#include <assert.h>
+#include <errno.h>
+#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <math.h>
-#include <errno.h>
#include "codec2_cohpsk.h"
#include "codec2_fdmdv.h"
int opt_exists(char *argv[], int argc, char opt[]) {
- int i;
- for (i=0; i<argc; i++) {
- if (strcmp(argv[i], opt) == 0) {
- return i;
- }
+ int i;
+ for (i = 0; i < argc; i++) {
+ if (strcmp(argv[i], opt) == 0) {
+ return i;
}
- return 0;
+ }
+ return 0;
}
-int main(int argc, char *argv[])
-{
- FILE *fin, *fout;
- struct COHPSK *cohpsk;
- char tx_bits_char[2*COHPSK_BITS_PER_FRAME];
- int tx_bits[2*COHPSK_BITS_PER_FRAME];
- COMP tx_fdm[COHPSK_NOM_SAMPLES_PER_FRAME];
- short tx_fdm_scaled[COHPSK_NOM_SAMPLES_PER_FRAME];
- int diversity;
- int i;
-
- if (argc < 3) {
- fprintf(stderr, "\n");
- fprintf(stderr, "usage: %s InputOneCharPerBitFile OutputModemRawFile [-nd]\n", argv[0]);
- fprintf(stderr, "\n");
- fprintf(stderr, " --nd non-diversity mode, input frames of %d bits\n", 2*COHPSK_BITS_PER_FRAME);
- fprintf(stderr, "\n");
- exit(1);
- }
-
- if (strcmp(argv[1], "-") == 0) fin = stdin;
- else if ( (fin = fopen(argv[1],"rb")) == NULL ) {
- fprintf(stderr, "Error opening input file: %s: %s.\n",
- argv[1], strerror(errno));
- exit(1);
- }
-
- if (strcmp(argv[2], "-") == 0) fout = stdout;
- else if ( (fout = fopen(argv[2],"wb")) == NULL ) {
- fprintf(stderr, "Error opening output modem sample file: %s: %s.\n",
- argv[2], strerror(errno));
- exit(1);
- }
-
- cohpsk = cohpsk_create();
-
- if (opt_exists(argv, argc, "--nd")) {
- diversity = 2;
- }
- else {
- diversity = 1;
- }
- fprintf(stderr, "diversity: %d\n", diversity);
-
- while(fread(tx_bits_char, sizeof(char), COHPSK_BITS_PER_FRAME*diversity, fin) == COHPSK_BITS_PER_FRAME*diversity) {
-
- for(i=0; i<COHPSK_BITS_PER_FRAME*diversity; i++)
- tx_bits[i] = tx_bits_char[i];
- cohpsk_mod(cohpsk, tx_fdm, tx_bits, COHPSK_BITS_PER_FRAME*diversity);
- cohpsk_clip(tx_fdm, COHPSK_CLIP, COHPSK_NOM_SAMPLES_PER_FRAME);
-
- /* scale and save to disk as shorts */
-
- for(i=0; i<COHPSK_NOM_SAMPLES_PER_FRAME; i++)
- tx_fdm_scaled[i] = COHPSK_SCALE * tx_fdm[i].real;
-
- fwrite(tx_fdm_scaled, sizeof(short), COHPSK_NOM_SAMPLES_PER_FRAME, fout);
-
- /* if this is in a pipeline, we probably don't want the usual
- buffering to occur */
-
- if (fout == stdout) fflush(stdout);
- }
-
- fclose(fin);
- fclose(fout);
- cohpsk_destroy(cohpsk);
-
- return 0;
+int main(int argc, char *argv[]) {
+ FILE *fin, *fout;
+ struct COHPSK *cohpsk;
+ char tx_bits_char[2 * COHPSK_BITS_PER_FRAME];
+ int tx_bits[2 * COHPSK_BITS_PER_FRAME];
+ COMP tx_fdm[COHPSK_NOM_SAMPLES_PER_FRAME];
+ short tx_fdm_scaled[COHPSK_NOM_SAMPLES_PER_FRAME];
+ int diversity;
+ int i;
+
+ if (argc < 3) {
+ fprintf(stderr, "\n");
+ fprintf(stderr,
+ "usage: %s InputOneCharPerBitFile OutputModemRawFile [-nd]\n",
+ argv[0]);
+ fprintf(stderr, "\n");
+ fprintf(stderr,
+ " --nd non-diversity mode, input frames of %d bits\n",
+ 2 * COHPSK_BITS_PER_FRAME);
+ fprintf(stderr, "\n");
+ exit(1);
+ }
+
+ if (strcmp(argv[1], "-") == 0)
+ fin = stdin;
+ else if ((fin = fopen(argv[1], "rb")) == NULL) {
+ fprintf(stderr, "Error opening input file: %s: %s.\n", argv[1],
+ strerror(errno));
+ exit(1);
+ }
+
+ if (strcmp(argv[2], "-") == 0)
+ fout = stdout;
+ else if ((fout = fopen(argv[2], "wb")) == NULL) {
+ fprintf(stderr, "Error opening output modem sample file: %s: %s.\n",
+ argv[2], strerror(errno));
+ exit(1);
+ }
+
+ cohpsk = cohpsk_create();
+
+ if (opt_exists(argv, argc, "--nd")) {
+ diversity = 2;
+ } else {
+ diversity = 1;
+ }
+ fprintf(stderr, "diversity: %d\n", diversity);
+
+ while (fread(tx_bits_char, sizeof(char), COHPSK_BITS_PER_FRAME * diversity,
+ fin) == COHPSK_BITS_PER_FRAME * diversity) {
+ for (i = 0; i < COHPSK_BITS_PER_FRAME * diversity; i++)
+ tx_bits[i] = tx_bits_char[i];
+ cohpsk_mod(cohpsk, tx_fdm, tx_bits, COHPSK_BITS_PER_FRAME * diversity);
+ cohpsk_clip(tx_fdm, COHPSK_CLIP, COHPSK_NOM_SAMPLES_PER_FRAME);
+
+ /* scale and save to disk as shorts */
+
+ for (i = 0; i < COHPSK_NOM_SAMPLES_PER_FRAME; i++)
+ tx_fdm_scaled[i] = COHPSK_SCALE * tx_fdm[i].real;
+
+ fwrite(tx_fdm_scaled, sizeof(short), COHPSK_NOM_SAMPLES_PER_FRAME, fout);
+
+ /* if this is in a pipeline, we probably don't want the usual
+ buffering to occur */
+
+ if (fout == stdout) fflush(stdout);
+ }
+
+ fclose(fin);
+ fclose(fout);
+ cohpsk_destroy(cohpsk);
+
+ return 0;
}