Skip to content

Instantly share code, notes, and snippets.

@grav
Last active June 19, 2016 19:45
Show Gist options
  • Save grav/fb1c729e691ac3b08a32c142b9cace7c to your computer and use it in GitHub Desktop.
Save grav/fb1c729e691ac3b08a32c142b9cace7c to your computer and use it in GitHub Desktop.
Simple oscillator in python, using pyext (http://grrrr.org/research/software/py/)
class osc(pyext._class):
t = 0.0
f = 0.0
def bang_3(self):
print "SR:",self._samplerate(),"BS:",self._blocksize(),"F:",self.f
def _dsp(self):
# if _dsp is present it must return True to enable DSP
return pyext._arraysupport()
def _signal(self):
# not great, since
# only allow f to change once per block
self.f = self._invec(0)[0]
d = self.f*2*pi*(self._blocksize()/self._samplerate())
self._outvec(0)[:] = np.sin(np.linspace(self.t,self.t+d,self._blocksize()))
self.t += d
if self.t > 2.0*pi:
self.t -= 2.0*pi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment