discuss-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Gnuradio: SineWave generator python block choppy audio out


From: Mitja kocjančič
Subject: Re: Gnuradio: SineWave generator python block choppy audio out
Date: Wed, 26 May 2021 19:11:55 +0200

although later testing shows that yours doesn't flicker like Markuc does when changing frequency or sample rate on the fly

V V sre., 26. maj 2021 ob 19:08 je oseba Mitja kocjančič <veso266@gmail.com> napisala:
both yours and Maruc solutions work very well, didn't spot any visual difference between them, so thank you both

V V sre., 26. maj 2021 ob 18:50 je oseba Achilleas Anastasopoulos <anastas@umich.edu> napisala:
Hi all,

I do not think that the proposed algorithm by Marcus is the correct way to implement this block, 
because it assumes that the frequency has remained the same throughout the life of the block!
The correct way is to keep a state variable (say, "self.phase") that is initialized to 0 and  records the accumulated state (modulo 2 pi) up to the last call of work.
Then in one call of work you should just generate the sin wave as suggested:

f_rel = 2 * np.pi * self.frequency / self.sample_rate
number = len(output_items[0])
phases = (f_rel * np.arange(0,number)+self.phase ) % (2*np.pi)
output_items[0][:] = self.amplitude*np.sin(phases)
self.phase=phases[-1]+ f_rel

best
Achilleas

reply via email to

[Prev in Thread] Current Thread [Next in Thread]