|
From: | Mitja kocjančič |
Subject: | Re: Gnuradio: SineWave generator python block choppy audio out |
Date: | Wed, 26 May 2021 10:37:40 +0200 |
Hi Mitja!
Great to have you here :)
Couple of things up front:
1. This is GNU Radio 3.7. Especially if you want to implement things in Python blocks, 3.8
or later is a *must*. GNU Radio 3.7 is really just in legacy keepalive mode, not actively
developed. Please update to GNU Radio 3.8 or 3.9. You really should not start developing
for GNU Radio 3.7 in 2021!
2. WX GUI is dead. We stopped being able to support it a long time ago. Please use Qt GUI
instead.
All in all, please update your version of GNU Radio. In case any bugs occur, we won't be
able to help you with GNU Radio 3.7. GNU Radio 3.8 can be natively installed on almost all
modern Linux distros directly from their package managers, and on Windows, and OS X using
conda and other tools, without any complications.
With that out of the way, let's look at your code:
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
No surprise the sound is choppy! You reset your i to 0 for every new call to work();
however, GNU Radio doesn't guarantee that work is called with number of items equal to a
multiple of your sine period.
So, this is a bug in your design. What you'd want is really something like
def work(self, input_items, output_items):
# get rid of the for loop!
startnr = self.ninputs_written(0)
f_rel = 2 * np.pi * self.frequency / self.sample_rate
number = len(output_items[0])
output_items[0][:] = self.amplitude*np.sin(f_rel * np.arange(startnr, startnr+number))
return number
Best regards
Marcus
[Prev in Thread] | Current Thread | [Next in Thread] |