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č <veso...@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 < > anas...@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 >> >