|
| 1 | +/*---------------------------------------------------------------------------*\ |
| 2 | +
|
| 3 | + FILE........: freedv_datac0c1_tx.c |
| 4 | + AUTHOR......: David Rowe |
| 5 | + DATE CREATED: Dec 2021 |
| 6 | +
|
| 7 | + Transmitting alternate frames of two different raw data modes. See |
| 8 | + freedv_datac0c1_rx.c |
| 9 | + |
| 10 | +\*---------------------------------------------------------------------------*/ |
| 11 | + |
| 12 | +/* |
| 13 | + Copyright (C) 2021 David Rowe |
| 14 | +
|
| 15 | + All rights reserved. |
| 16 | +
|
| 17 | + This program is free software; you can redistribute it and/or modify |
| 18 | + it under the terms of the GNU Lesser General Public License version 2.1, as |
| 19 | + published by the Free Software Foundation. This program is |
| 20 | + distributed in the hope that it will be useful, but WITHOUT ANY |
| 21 | + WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 22 | + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public |
| 23 | + License for more details. |
| 24 | +
|
| 25 | + You should have received a copy of the GNU Lesser General Public License |
| 26 | + along with this program; if not, see <http://www.gnu.org/licenses/>. |
| 27 | +*/ |
| 28 | + |
| 29 | +#include <assert.h> |
| 30 | +#include <stdlib.h> |
| 31 | +#include <stdio.h> |
| 32 | +#include <stdint.h> |
| 33 | + |
| 34 | +#include "freedv_api.h" |
| 35 | +#include "ofdm_internal.h" |
| 36 | + |
| 37 | +void send_burst(struct freedv *freedv); |
| 38 | + |
| 39 | +int main(void) { |
| 40 | + struct freedv *freedv_c0, *freedv_c1; |
| 41 | + |
| 42 | + freedv_c0 = freedv_open(FREEDV_MODE_DATAC0); assert(freedv_c0 != NULL); |
| 43 | + freedv_c1 = freedv_open(FREEDV_MODE_DATAC1); assert(freedv_c1 != NULL); |
| 44 | + |
| 45 | + for(int b=0; b<10; b++) { |
| 46 | + send_burst(freedv_c0); |
| 47 | + send_burst(freedv_c1); |
| 48 | + } |
| 49 | + |
| 50 | + freedv_close(freedv_c0); |
| 51 | + freedv_close(freedv_c1); |
| 52 | + |
| 53 | + return 0; |
| 54 | +} |
| 55 | + |
| 56 | + |
| 57 | +void send_burst(struct freedv *freedv) { |
| 58 | + size_t bits_per_frame = freedv_get_bits_per_modem_frame(freedv); |
| 59 | + size_t bytes_per_modem_frame = bits_per_frame/8; |
| 60 | + size_t payload_bytes_per_modem_frame = bytes_per_modem_frame - 2; /* 16 bits used for the CRC */ |
| 61 | + size_t n_mod_out = freedv_get_n_tx_modem_samples(freedv); |
| 62 | + uint8_t bytes_in[bytes_per_modem_frame]; |
| 63 | + short mod_out_short[n_mod_out]; |
| 64 | + |
| 65 | + /* generate a test frame */ |
| 66 | + uint8_t testframe_bits[bits_per_frame]; |
| 67 | + ofdm_generate_payload_data_bits(testframe_bits, bits_per_frame); |
| 68 | + freedv_pack(bytes_in, testframe_bits, bits_per_frame); |
| 69 | + |
| 70 | + /* send preamble */ |
| 71 | + int n_preamble = freedv_rawdatapreambletx(freedv, mod_out_short); |
| 72 | + fwrite(mod_out_short, sizeof(short), n_preamble, stdout); |
| 73 | + |
| 74 | + /* The raw data modes require a CRC in the last two bytes */ |
| 75 | + uint16_t crc16 = freedv_gen_crc16(bytes_in, payload_bytes_per_modem_frame); |
| 76 | + bytes_in[bytes_per_modem_frame-2] = crc16 >> 8; |
| 77 | + bytes_in[bytes_per_modem_frame-1] = crc16 & 0xff; |
| 78 | + |
| 79 | + /* modulate and send a data frame */ |
| 80 | + freedv_rawdatatx(freedv, mod_out_short, bytes_in); |
| 81 | + fwrite(mod_out_short, sizeof(short), n_mod_out, stdout); |
| 82 | + |
| 83 | + /* send postamble */ |
| 84 | + int n_postamble = freedv_rawdatapostambletx(freedv, mod_out_short); |
| 85 | + fwrite(mod_out_short, sizeof(short), n_postamble, stdout); |
| 86 | + |
| 87 | + /* create some silence between bursts */ |
| 88 | + int inter_burst_delay_ms = 200; |
| 89 | + int samples_delay = FREEDV_FS_8000*inter_burst_delay_ms/1000; |
| 90 | + short sil_short[samples_delay]; |
| 91 | + for(int i=0; i<samples_delay; i++) sil_short[i] = 0; |
| 92 | + fwrite(sil_short, sizeof(short), samples_delay, stdout); |
| 93 | +} |
0 commit comments