View Full Version : very simple sine generator algorithm

08-14-2016, 10:42 PM
I've been working on a project using the teensy/audio and FV-1 effects chip, and in the process I am learning many efficient techniques to make assembler dsp code for the FV-1. I just found a sine/cosine oscillator technique that uses only a few multiply/accumulate and registers to create a sine/cosine oscillator. I wanted to post the PDF here in case anyone wanted to check them out and possibly implement them before I get to it.


I think its possible with these methods to make an extremely efficient group of library objects that could allow for loads of oscillators.

The Assembler code for the FV-1 implementation is :

equ oscSin reg0
equ oscCos reg1
equ oscFreq pot0

;----------- load ---------------
SKP RUN , 3 ; skips the next 3 instructions after the initial first run
WRAX oscSin, 0 ; writes to the register defined by equ oscSin above (reg0)
; and multiplies the accumulator by 0
SOF 0, -1 ; scale and offset the accumulator, times 0 plus -1
WRAX oscCos, 0 ; write to cosine register and clear accumulator

;------ Oscillator--------------
RDAX oscSin, 0.6 ; read sine register multiplied by 0.6
MULX oscFreq ; multiply by register defined by equ above (pot input 0)

RDAX oscCos, 1 ; add cosine register times 1
WRAX oscCos, -0.6 ; write to cosine register and multiply accumulator by -0.6
MULX oscFreq ; multiply by register currently defined as pot0

RDAX oscSin, 1 ; add sine register times 1
WRAX oscSin, 0 ; write to sine register and clear accumulator

08-16-2016, 08:07 AM
Here is also a thread about it on the FV-1 forum that explains a bit more


08-16-2016, 03:50 PM
Be careful if you run this loop for long durations -- because of roundoff error in the multiplication, the amplitude may not remain precisely constant. For some frequencies, it may grow to overflow or decay to zero eventually. Digital oscillators like this need an amplitude regulation loop to avoid this behaviour.

08-19-2016, 05:18 PM
Very interesting, do you know of any resources I could read more about this issue or what I might google to find more? I haven't had any issues yet in my tests but most of them are using multiple oscillators for FM/amp/ring modulation.

Also wondering if you know if it is possible to inject signal or triggers into these as resonators and for them to decay (like a resonant bandpass filter). I am looking for the best way to implement a low resource sine resonator bank for physical modeling of harmonic/inharmonic modes.