Skip to content
Snippets Groups Projects

add simple way to insert delays

Merged Hugo Winbladh requested to merge 184-add-simple-way-to-add-delays into master
2 files
+ 52
0
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 22
0
@@ -340,6 +340,28 @@ class InputPort(AbstractPort):
@@ -340,6 +340,28 @@ class InputPort(AbstractPort):
self.connect(src)
self.connect(src)
return self
return self
 
def delay(self, number: int) -> "InputPort":
 
"""
 
Inserts `number` amount of delay elements before the input port.
 
 
Returns the input port of the first delay element in the chain.
 
"""
 
from b_asic.special_operations import Delay
 
if not isinstance(number, int) or number < 0:
 
raise TypeError("Number of delays must be a positive integer")
 
tmp_signal = None
 
if any(self.signals):
 
tmp_signal = self.signals[0]
 
tmp_signal.remove_destination()
 
current = self
 
for i in range(number):
 
d = Delay()
 
current.connect(d)
 
current = d.input(0)
 
if tmp_signal is not None:
 
tmp_signal.set_destination(current)
 
return current
 
class OutputPort(AbstractPort, SignalSourceProvider):
class OutputPort(AbstractPort, SignalSourceProvider):
"""
"""
Loading