# TX and RX synchronization to control latency

**URL:** <https://www.ruby-forum.com/t/tx-and-rx-synchronization-to-control-latency/242876>\
**Category:** GNU Radio\
**Created:** [August 4, 2015, 2:44pm UTC](https://www.ruby-forum.com/t/tx-and-rx-synchronization-to-control-latency/242876 "2015-08-04T14:44:40Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sadaf\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@Sadaf\_N](https://www.ruby-forum.com/u/Sadaf_N)\
**Post date:** [August 4, 2015, 2:44pm UTC](https://www.ruby-forum.com/t/tx-and-rx-synchronization-to-control-latency/242876/1 "2015-08-04T14:44:40Z")

</div>

Hello,

the recommended way to control latency due to buffers both in software  
and hardware is to synchronize the TX and RX streams, namely to have a  
mechanism that emits samples only when samples are received, minus a  
maximum latency.

My naive solution to implement that is this:

class synchronize(gr.hier\_block2):  
def **init** (self, fs, delay):  
gr.hier\_block2. **init** (self, self. **class**. **name** ,  
gr.io\_signature(2, 2, gr.sizeof\_gr\_complex),  
gr.io\_signature(1, 1, gr.sizeof\_gr\_complex))

```
    delay = blocks.delay(gr.sizeof_gr_complex, int(fs * delay))
    multiply = blocks.multiply_const_cc(0)
    add = blocks.add_cc()
    self.connect((self, 0), (add, 0))
    self.connect((self, 1), delay, multiply, (add, 1))
    self.connect(add, self)

```

Which is simple enough, but also probably not the most efficient or  
elegant way. There is a better way of doing it, other than writing a new  
block, probably based on the delay block?

Cheers,  
Daniele
