Commit 13856694 authored by Titouan Soulard's avatar Titouan Soulard

trx-bridge: timestamp improvements

parent b5706454
......@@ -2,6 +2,7 @@
// Size of TRX buffer in IQ samples (complex)
#define TRX_BUFFER_SIZE 4096
#define SAMPLE_RATE_KHZ 30720
char *bridge_trx_input_get_param_string(void *app_opaque, const char *prop_name) {
return potoml_toml_get_string((struct PotomlTomlSubset *) app_opaque, prop_name);
......@@ -300,7 +301,6 @@ int main(int argc, char *argv[]) {
while(1) {
// Read from output first to know how many samples should be read
output_rx_ts = 0;
output_read_count = output_trx_state.trx_read_func2(&output_trx_state, &output_rx_ts, (void **) output_channels, TRX_BUFFER_SIZE, 0, &read_md);
// As much samples should be read from input than from output.
......@@ -314,7 +314,7 @@ int main(int argc, char *argv[]) {
input_read_count_extra = input_trx_state.trx_read_func2(&input_trx_state, &input_rx_ts, (void **) input_channels, output_read_count - input_read_count, 0, &read_md);
// If no samples can be read, escape from infinite loop
// This return to operations, but will discard some frames
// This return to operations, but might discard some frames
if(input_read_count_extra == 0) break;
input_read_count += input_read_count_extra;
}
......@@ -323,25 +323,26 @@ int main(int argc, char *argv[]) {
// timestamp and incremented after every write.
// The buffer size in TRX SDR is four times the samples rate, so this
// value is used here as tn offset between the two timestamps.
if(output_tx_ts == 0) output_tx_ts = output_rx_ts + 4 * 23040;
if(input_tx_ts == 0) input_tx_ts = input_rx_ts + 4 * 23040;
if(output_tx_ts == 0) output_tx_ts = output_rx_ts + 4 * SAMPLE_RATE_KHZ;
if(input_tx_ts == 0) input_tx_ts = input_rx_ts + 4 * SAMPLE_RATE_KHZ;
output_tx_ts += output_read_count;
input_tx_ts += input_read_count;
// Write back samples read from input and output
if(input_read_count > 0) output_trx_state.trx_write_func2(&output_trx_state, output_tx_ts, (const void **) input_channels, input_read_count, 0, &write_md);
if(output_read_count > 0) input_trx_state.trx_write_func2(&input_trx_state, input_tx_ts, (const void **) output_channels, output_read_count, 0, &write_md);
// Real behavior: sometimes, the TX timestamp deviates, so it should be matched again.
if(output_tx_ts != output_rx_ts + 4 * 23040) {
printf("Output timestamp don't match %lu != %lu\n", output_tx_ts, output_rx_ts + 4 * 23040);
output_tx_ts = output_rx_ts + 4 * 23040;
if(output_tx_ts != output_rx_ts + 4 * SAMPLE_RATE_KHZ) {
printf("trx-bridge: output timestamp deviated %lu != %lu\n", output_tx_ts, output_rx_ts + 4 * SAMPLE_RATE_KHZ);
output_tx_ts = output_rx_ts + 4 * SAMPLE_RATE_KHZ;
}
if(input_tx_ts != input_rx_ts + 4 * 23040) {
printf("Input timestamp don't match %lu != %lu\n", input_tx_ts, input_rx_ts + 4 * 23040);
input_tx_ts = input_rx_ts + 4 * 23040;
if(input_tx_ts != input_rx_ts + 4 * SAMPLE_RATE_KHZ) {
printf("trx-bridge: input timestamp deviated %lu != %lu\n", input_tx_ts, input_rx_ts + 4 * SAMPLE_RATE_KHZ);
input_tx_ts = input_rx_ts + 4 * SAMPLE_RATE_KHZ;
}
output_trx_state.trx_write_func2(&output_trx_state, output_tx_ts, (const void **) input_channels_base, input_read_count, 0, &write_md);
output_tx_ts += input_read_count;
input_trx_state.trx_write_func2(&input_trx_state, input_tx_ts, (const void **) output_channels, output_read_count, 0, &write_md);
input_tx_ts += output_read_count;
}
dlclose(input_lib_handle);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment