Commit b67c4205 authored by Titouan Soulard's avatar Titouan Soulard

trx-bridge: write back to input before reading

parent cda3078f
......@@ -310,6 +310,22 @@ int main(int argc, char *argv[]) {
// Read from output first to know how many samples should be read
output_read_count = output_trx_state.trx_read_func2(&output_trx_state, &output_rx_ts, (void **) output_channels, TRX_BUFFER_SIZE, 0, &read_md);
// Expected behavior: TX (i.e. write) timestamp is set once based on RX (i.e. read)
// 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 an offset between the two timestamps.
if(output_tx_ts == 0) output_tx_ts = output_rx_ts + 4 * SAMPLE_RATE_KHZ;
output_tx_ts += output_read_count;
// Real behavior: sometimes, the TX timestamp deviates, so it should be matched again.
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;
}
// Write back samples read from output
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);
// As much samples should be read from input than from output.
// However, sometimes, the input driver won't return enough samples,
// so we need to loop for samples.
......@@ -326,25 +342,10 @@ int main(int argc, char *argv[]) {
input_read_count += input_read_count_extra;
}
// Expected behavior: TX (i.e. write) timestamp is set once based on RX (i.e. read)
// 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 * 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 * 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 * SAMPLE_RATE_KHZ) {
printf("trx-bridge: input timestamp deviated %lu != %lu\n", input_tx_ts, input_rx_ts + 4 * SAMPLE_RATE_KHZ);
......
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