Library of API functions that implement FreeDV "modes", useful for
embedding FreeDV in other programs.
-
- TODO:
- [X] speex tx/rx works
- [X] txt messages
- [X] optional test tx framemode
-
+
\*---------------------------------------------------------------------------*/
/*
struct freedv *f;
int Nc, codec2_mode, nbit, nbyte;
- if ((mode != FREEDV_MODE_1600) && (mode != FREEDV_MODE_700))
+ if ((mode != FREEDV_MODE_1600) && (mode != FREEDV_MODE_700) && (mode != FREEDV_MODE_700B))
return NULL;
f = (struct freedv*)malloc(sizeof(struct freedv));
f->sz_error_pattern = fdmdv_error_pattern_size(f->fdmdv);
}
- if (mode == FREEDV_MODE_700) {
+ if ((mode == FREEDV_MODE_700) || (mode == FREEDV_MODE_700B)) {
f->snr_squelch_thresh = 0.0;
f->squelch_en = 0;
- codec2_mode = CODEC2_MODE_700;
+ if (mode == FREEDV_MODE_700)
+ codec2_mode = CODEC2_MODE_700;
+ else
+ codec2_mode = CODEC2_MODE_700B;
f->cohpsk = cohpsk_create();
f->nin = COHPSK_NOM_SAMPLES_PER_FRAME;
f->n_nom_modem_samples = COHPSK_NOM_SAMPLES_PER_FRAME;
return NULL;
if (mode == FREEDV_MODE_1600)
f->n_speech_samples = codec2_samples_per_frame(f->codec2);
- if (mode == FREEDV_MODE_700)
+ if ((mode == FREEDV_MODE_700) || (mode == FREEDV_MODE_700B))
f->n_speech_samples = 2*codec2_samples_per_frame(f->codec2);
f->prev_rx_bits = (float*)malloc(sizeof(float)*2*codec2_bits_per_frame(f->codec2));
if (f->prev_rx_bits == NULL)
f->packed_codec_bits = (unsigned char*)malloc(nbyte*sizeof(char));
if (mode == FREEDV_MODE_1600)
f->codec_bits = (int*)malloc(nbit*sizeof(int));
- if (mode == FREEDV_MODE_700)
+ if ((mode == FREEDV_MODE_700) || (mode == FREEDV_MODE_700B))
f->codec_bits = (int*)malloc(COHPSK_BITS_PER_FRAME*sizeof(int));
if ((f->packed_codec_bits == NULL) || (f->codec_bits == NULL))
assert(f != NULL);
int bit, byte, i, j, k;
int bits_per_codec_frame, bits_per_modem_frame;
- int data, codeword1, data_flag_index;
+ int data, codeword1, data_flag_index, nspare;
COMP tx_fdm[f->n_nom_modem_samples];
- assert((f->mode == FREEDV_MODE_1600) || (f->mode == FREEDV_MODE_700));
+ assert((f->mode == FREEDV_MODE_1600) || (f->mode == FREEDV_MODE_700) || (f->mode == FREEDV_MODE_700B));
if (f->mode == FREEDV_MODE_1600) {
bits_per_codec_frame = codec2_bits_per_frame(f->codec2);
}
- if (f->mode == FREEDV_MODE_700) {
+ if ((f->mode == FREEDV_MODE_700) || (f->mode == FREEDV_MODE_700B)) {
bits_per_codec_frame = codec2_bits_per_frame(f->codec2);
bits_per_modem_frame = COHPSK_BITS_PER_FRAME;
}
}
- // spare bits in frame that codec defines. Use these 2
+ // spare bits in frame that codec defines. Use these spare
// bits/frame to send txt messages
+ if (f->mode == FREEDV_MODE_700)
+ nspare = 2;
+ else
+ nspare = 1; // Just one spare bit for FREEDV_MODE_700B
+
data_flag_index = codec2_get_spare_bit_index(f->codec2);
- for(k=0; k<2; k++) {
+ for(k=0; k<nspare; k++) {
if (f->nvaricode_bits) {
f->codec_bits[j+data_flag_index+k] = f->tx_varicode_bits[f->varicode_bit_index++];
//fprintf(stderr, "%d %d\n", j+data_flag_index+k, f->codec_bits[j+data_flag_index+k]);
assert(f != NULL);
int bits_per_codec_frame, bytes_per_codec_frame, bits_per_fdmdv_frame;
int i, j, bit, byte, nin_prev, nout, k;
- int recd_codeword, codeword1, data_flag_index, n_ascii;
+ int recd_codeword, codeword1, data_flag_index, n_ascii, nspare;
short abit[1];
char ascii_out;
int reliable_sync_bit;
}
- if (f->mode == FREEDV_MODE_700) {
+ if ((f->mode == FREEDV_MODE_700) || (f->mode == FREEDV_MODE_700B)) {
float rx_bits[COHPSK_BITS_PER_FRAME];
int sync;
for (j=0; j<COHPSK_BITS_PER_FRAME; j+=bits_per_codec_frame) {
- /* extract txt msg data bits */
+ /* extract txt msg data bit(s) */
- for(k=0; k<2; k++) {
+ if (f->mode == FREEDV_MODE_700)
+ nspare = 2;
+ else
+ nspare = 1;
+
+ for(k=0; k<nspare; k++) {
abit[0] = rx_bits[data_flag_index+j+k] < 0.0;
n_ascii = varicode_decode(&f->varicode_dec_states, &ascii_out, abit, 1, 1);
void my_put_next_rx_char(void *callback_state, char c) {
struct my_callback_state* pstate = (struct my_callback_state*)callback_state;
if (pstate->ftxt != NULL) {
- fprintf(pstate->ftxt, "%c", c);
+ fprintf(pstate->ftxt, "%c\n", c);
}
}
int n_max_modem_samples;
if (argc < 4) {
- printf("usage: %s 1600|700 InputModemSpeechFile OutputSpeechRawFile [--test_frames]\n", argv[0]);
+ printf("usage: %s 1600|700|700B InputModemSpeechFile OutputSpeechRawFile [--test_frames]\n", argv[0]);
printf("e.g %s 1600 hts1a_fdmdv.raw hts1a_out.raw txtLogFile\n", argv[0]);
exit(1);
}
mode = FREEDV_MODE_1600;
if (!strcmp(argv[1],"700"))
mode = FREEDV_MODE_700;
+ if (!strcmp(argv[1],"700B"))
+ mode = FREEDV_MODE_700B;
assert(mode != -1);
if (strcmp(argv[2], "-") == 0) fin = stdin;