Skip to content

Commit

Permalink
demo custom mode
Browse files Browse the repository at this point in the history
  • Loading branch information
drowe67 committed Apr 3, 2024
1 parent 735d788 commit cf069d2
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 10 deletions.
15 changes: 10 additions & 5 deletions src/freedv_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,8 @@ void freedv_close(struct freedv *freedv) {
FDV_MODE_ACTIVE(FREEDV_MODE_DATAC3, freedv->mode) ||
FDV_MODE_ACTIVE(FREEDV_MODE_DATAC4, freedv->mode) ||
FDV_MODE_ACTIVE(FREEDV_MODE_DATAC13, freedv->mode) ||
FDV_MODE_ACTIVE(FREEDV_MODE_DATAC14, freedv->mode)) {
FDV_MODE_ACTIVE(FREEDV_MODE_DATAC14, freedv->mode) ||
FDV_MODE_ACTIVE(FREEDV_MODE_DATA_CUSTOM, freedv->mode)) {
FREE(freedv->rx_syms);
FREE(freedv->rx_amps);
FREE(freedv->ldpc);
Expand Down Expand Up @@ -279,7 +280,8 @@ static int is_ofdm_mode(struct freedv *f) {
FDV_MODE_ACTIVE(FREEDV_MODE_DATAC3, f->mode) ||
FDV_MODE_ACTIVE(FREEDV_MODE_DATAC4, f->mode) ||
FDV_MODE_ACTIVE(FREEDV_MODE_DATAC13, f->mode) ||
FDV_MODE_ACTIVE(FREEDV_MODE_DATAC14, f->mode);
FDV_MODE_ACTIVE(FREEDV_MODE_DATAC14, f->mode) ||
FDV_MODE_ACTIVE(FREEDV_MODE_DATA_CUSTOM, f->mode);
}

static int is_ofdm_data_mode(struct freedv *f) {
Expand All @@ -288,7 +290,8 @@ static int is_ofdm_data_mode(struct freedv *f) {
FDV_MODE_ACTIVE(FREEDV_MODE_DATAC3, f->mode) ||
FDV_MODE_ACTIVE(FREEDV_MODE_DATAC4, f->mode) ||
FDV_MODE_ACTIVE(FREEDV_MODE_DATAC13, f->mode) ||
FDV_MODE_ACTIVE(FREEDV_MODE_DATAC14, f->mode);
FDV_MODE_ACTIVE(FREEDV_MODE_DATAC14, f->mode) ||
FDV_MODE_ACTIVE(FREEDV_MODE_DATA_CUSTOM, f->mode);
}

/*---------------------------------------------------------------------------*\
Expand Down Expand Up @@ -479,7 +482,8 @@ void freedv_rawdatacomptx(struct freedv *f, COMP mod_out[],
FDV_MODE_ACTIVE(FREEDV_MODE_DATAC3, f->mode) ||
FDV_MODE_ACTIVE(FREEDV_MODE_DATAC4, f->mode) ||
FDV_MODE_ACTIVE(FREEDV_MODE_DATAC13, f->mode) ||
FDV_MODE_ACTIVE(FREEDV_MODE_DATAC14, f->mode))
FDV_MODE_ACTIVE(FREEDV_MODE_DATAC14, f->mode) ||
FDV_MODE_ACTIVE(FREEDV_MODE_DATA_CUSTOM, f->mode))
freedv_comptx_ofdm(f, mod_out);

if (FDV_MODE_ACTIVE(FREEDV_MODE_FSK_LDPC, f->mode)) {
Expand Down Expand Up @@ -1079,7 +1083,8 @@ int freedv_rawdatacomprx(struct freedv *f, unsigned char *packed_payload_bits,
FDV_MODE_ACTIVE(FREEDV_MODE_DATAC3, f->mode) ||
FDV_MODE_ACTIVE(FREEDV_MODE_DATAC4, f->mode) ||
FDV_MODE_ACTIVE(FREEDV_MODE_DATAC13, f->mode) ||
FDV_MODE_ACTIVE(FREEDV_MODE_DATAC14, f->mode))
FDV_MODE_ACTIVE(FREEDV_MODE_DATAC14, f->mode) ||
FDV_MODE_ACTIVE(FREEDV_MODE_DATA_CUSTOM, f->mode))
rx_status = freedv_comp_short_rx_ofdm(f, (void *)demod_in, 0, 1.0f);
if (FDV_MODE_ACTIVE(FREEDV_MODE_FSK_LDPC, f->mode)) {
rx_status = freedv_rx_fsk_ldpc_data(f, demod_in);
Expand Down
24 changes: 22 additions & 2 deletions src/freedv_data_raw_rx.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "ldpc_codes.h"
#include "modem_stats.h"
#include "octave.h"
#include "ofdm_internal.h"

/* other processes can end this program using signals */

Expand Down Expand Up @@ -216,6 +217,8 @@ int main(int argc, char *argv[]) {
mode = FREEDV_MODE_DATAC13;
if (!strcmp(argv[dx], "DATAC14") || !strcmp(argv[dx], "datac14"))
mode = FREEDV_MODE_DATAC14;
if (!strcmp(argv[dx], "CUSTOM") || !strcmp(argv[dx], "custom"))
mode = FREEDV_MODE_DATA_CUSTOM;
if (mode == -1) {
fprintf(stderr, "Error in mode: %s\n", argv[dx]);
exit(1);
Expand Down Expand Up @@ -248,6 +251,23 @@ int main(int argc, char *argv[]) {
fprintf(stderr, "Setting estimator limits to %d to %d Hz.\n", fsk_lower,
fsk_upper);
fsk_set_freq_est_limits(fsk, fsk_lower, fsk_upper);
} else if (mode == FREEDV_MODE_DATA_CUSTOM) {
// demonstrate custom OFDM raw data modes
struct OFDM_CONFIG ofdm_config;
ofdm_init_mode("datac14", &ofdm_config);
// modify datac14 to have 3 carriers instead of 4, which means
// we have to tweak Np, and the number of unique word bits
ofdm_config.nc = 3;
ofdm_config.np = 6;
ofdm_config.nuwbits = 48;
ofdm_config.bad_uw_errors = 18;
uint8_t uw[] = {1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1,
0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0};
memcpy(ofdm_config.tx_uw, uw, sizeof(uw));
memcpy(&ofdm_config.tx_uw[ofdm_config.nuwbits - sizeof(uw)], uw,
sizeof(uw));
adv.config = (void *)&ofdm_config;
freedv = freedv_open_advanced(mode, &adv);
} else {
freedv = freedv_open(mode);
}
Expand All @@ -264,8 +284,8 @@ int main(int argc, char *argv[]) {
fsk->Ndft);
}

/* for streaming bytes it's much easier use the modes that have a multiple of
* 8 payload bits/frame */
/* for streaming bytes it's much easier use the modes that have a multiple
* of 8 payload bits/frame */
assert((freedv_get_bits_per_modem_frame(freedv) % 8) == 0);
int bytes_per_modem_frame = freedv_get_bits_per_modem_frame(freedv) / 8;
// last two bytes used for CRC
Expand Down
26 changes: 23 additions & 3 deletions src/freedv_data_raw_tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ int main(int argc, char *argv[]) {
mode = FREEDV_MODE_DATAC13;
if (!strcmp(argv[dx], "DATAC14") || !strcmp(argv[dx], "datac14"))
mode = FREEDV_MODE_DATAC14;
if (!strcmp(argv[dx], "CUSTOM") || !strcmp(argv[dx], "custom"))
mode = FREEDV_MODE_DATA_CUSTOM;
if (mode == -1) {
fprintf(stderr, "Error: in mode: %s", argv[dx]);
exit(1);
Expand All @@ -259,10 +261,28 @@ int main(int argc, char *argv[]) {
exit(1);
}

if (mode != FREEDV_MODE_FSK_LDPC)
freedv = freedv_open(mode);
else
if (mode == FREEDV_MODE_FSK_LDPC)
freedv = freedv_open_advanced(mode, &adv);
else if (mode == FREEDV_MODE_DATA_CUSTOM) {
// demonstrate custom OFDM raw data modes
struct OFDM_CONFIG ofdm_config;
ofdm_init_mode("datac14", &ofdm_config);
// modify datac14 to have 3 carriers instead of 4, which means
// we have to tweak Np, and the number of unique word bits
ofdm_config.nc = 3;
ofdm_config.np = 6;
ofdm_config.nuwbits = 48;
ofdm_config.bad_uw_errors = 18;
uint8_t uw[] = {1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1,
0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0};
memcpy(ofdm_config.tx_uw, uw, sizeof(uw));
memcpy(&ofdm_config.tx_uw[ofdm_config.nuwbits - sizeof(uw)], uw,
sizeof(uw));
adv.config = (void *)&ofdm_config;
freedv = freedv_open_advanced(mode, &adv);
} else {
freedv = freedv_open(mode);
}

assert(freedv != NULL);

Expand Down

0 comments on commit cf069d2

Please sign in to comment.