Arduino DDS synth - add a LFO ?

Hi everybody

I'm using a nice bit of code that you can find here to make a nice midi-controlled oscillator. It's nicely working, however i'd like to add an LFO (low-freq osc) to get some sweet modulation. I added another osc (o2), and tweaked the output computation :

outputvalue = (((uint8_t)(o1.amplitude>>8)*(((uint8_t)(o2.amplitude>>8)) * pgm_read_byte(sintable+((o2.phase>>16)%LUTsize)))>>8)>>8 * pgm_read_byte(sintable+((o1.phase>>16)%LUTsize)))>>8;

The main idea behind this is to make o1.amplitude vary in function of the o2 oscillator. More readable translation : output = ([vol osc 1]{[vol osc 2][phase osc 2]})*[phase osc 1]

BUT It's not working, i get no sound, and can't understand why.

Any idea, my good fellows ?

I'd start with saving, and printing, a bunch of intermediate results, in a simple sketch, to see what value ends up in output value.

Thanks !

I don't know why i was afraid to do some serial debugging... I just had to take the output calculation out of the interrupt routine :D

I just had to take the output calculation out of the interrupt routine

The bit manipulation stuff is fast, so you could probably get by with that in the ISR, but the multiplication and modulo stuff isn't. They definitely do not belong in the ISR.

I might have pointed that out, if I was aware that the one line of code you posted was in an ISR.

Glad you got it working, though.

Haha, no, i did not solved the problem, i just figured that i could debug the calculation outside of the ISR AND get a right computation, because that would have been mad to put some serial.print in a 16khz ISR :P So i've put the phase calculation in the main loop, and i'm grabbing data via serial. Looks like i have a rollover issue, my multiplication exceeds 255 very often.

So, intermediate variables, of the right type, are going to be key to getting the correct results. Either that or more casting.