Forum Rule: Always post complete source code & details to reproduce any issue!

# Thread: very simple sine generator algorithm

1. ## very simple sine generator algorithm

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.

http://www.claysturner.com/dsp/digital_resonators.pdf

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 :

Code:
equ	oscSin	reg0
equ	oscCos	reg1
equ	oscFreq	pot0

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

2. Here is also a thread about it on the FV-1 forum that explains a bit more

http://www.spinsemi.com/forum/viewtopic.php?t=523

3. 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.

4. @Jp3141:
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.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•