Search code examples
pythongnuradiognuradio-companion

In GNURadio/GRC, how to sequentially use different audio sources as input without having to manually start and stop?


I have 3-4 different audio sources in my flowchart. I want to play each source back to back (not overlayed on top of each other) without having to manually start and stop each source. Essentially, acting like a timer. For example, play source 1 then stop, wait 15 secs, play source 2, wait 30 secs, and so on.... Is there a block in the flow chart that can do this or does anyone have a python block that does this already or something similar?


Solution

  • Figured it out on my own kind of...basically I made my own embedded python block that delays the inputs I want by so many seconds. Here is what I came up with:

    import time 
    import numpy as np
    from gnuradio import gr
    
    
    class blk(gr.sync_block):  
        """Embedded Python Block that time delays the input file"""
    
        # initializes the GRC Block input, output, block title, and parameters
        def __init__(self, delay = 0):  
            gr.sync_block.__init__(
                self,
                name='Time Delayed Input',
                in_sig=[np.float32],
                out_sig=[np.float32]
            )
     
            # sets a callback for time delay in seconds specified in the GRC block
            self.delay = time.sleep(delay)
    
        def work(self,  input_items,  output_items):
            
            # sets output equal to the input to just pass through the block 
            output_items[0][:] = input_items[0]
            
            # calls a time delay in seconds 
            sleep.delay
    
            # returns the input as the output after the specified delay 
            return len(output_items[0])