Tuesday, May 25, 2021

Gnuradio: SineWave generator python block choppy audio out

for testing something I am trying to develop my own SineWave generator using python block in gnuradio

the block is here

"""  Embedded Python Blocks:    Each time this file is saved, GRC will instantiate the first class it finds  to get ports and parameters of your block. The arguments to __init__  will  be the parameters. All of them are required to have default values!  """    import numpy as np  from gnuradio import gr      class blk(gr.sync_block):  # other base classes are basic_block, decim_block, interp_block      """Embedded Python Block example - a simple multiply const"""        def __init__(self, sample_rate=192e3, frequency=1e3, amplitude=1):  # only default arguments here          """arguments to this function show up as parameters in GRC"""          gr.sync_block.__init__(              self,              name='SineWave Generator',   # will show up in GRC              in_sig=[np.float32],              #in_sig=None,              out_sig=[np.float32]          )          # if an attribute with the same name as a parameter is found,          # a callback is registered (properties work, too).          self.sample_rate = sample_rate          self.frequency = frequency          self.amplitude = amplitude                  def work(self, input_items, output_items):          """example: multiply with constant"""          print "length of input =",  len(input_items[0])          print "length of output =",  len(output_items[0])                    for i in range(0, len(output_items[0])): #8192              output_items[0][i] = np.sin(2 * np.pi * self.frequency * (i / self.sample_rate)) * self.amplitude                                         return len(output_items[0])

and is used in my flowgraph like so https://imgur.com/28kE1Sj

this block produces sine wave corecly but the audio is realy choopy like I woulldn't be able to generate sinewave fast enough or something (sample_rate shouldn't be a problem as the same flowgraph works corecly if I substitute my block with Signal Source)

also I am using Null source (because I didn't yet figure out how to create a python block without any source (as soon as I set in_sig=None no audio ever comes out of my block, so I am not sure how Signal source gets away with generating audio without any source connected to its input)

Thanks for Anwsering and Best Regards

 

No comments:

Post a Comment