How to program a VCA for an Arduino DUE DDS project?

Hello,

I'm working on an Arduino Due based synth based on this wonderful post: http://rcarduino.blogspot.jp/2012/12/arduino-due-dds-part-1-sinewaves-and.html

I'm attempting to implement a very simple volume control and running into some issues. My thought was to simply multiply the audio output by a fraction, which sort-of works. However, if I have a sawtooth wave (just for example), and I sweep through multiplying the output, I get these results:

Multiplying by 0 - .15: The output sometimes get distorted. I'm imagining that's because the bits get squished together and my perfectly nice sawtooth wave becomes a bit mutated.

Multiplying by .15 - .60: This seems to work fairly well. The volume changes, and the sound's character remains the same.

Multiplying by .60 - 1: Strangely, this seems to stop changing the sounds volume, and the sound's character starts changing again (and sometimes the volume actually sounds like it's decreasing!)

My code is quite simple:

// cv is my control voltage, which ranges from 0 to 255 // audio ranges from 0 to 4095 // my class returns a uint32_t

return((float)((float)cv/(float)255) * audio);

Thanks for any suggestions, - Bret

Hi, my projects were based on that blog too. To make the volume control, I just multiply as you say, and there is no problems.

I don't understand why you use float values : if your class returns a 32 bit integer value and all your data is in 32 bits, you don't need this. And most of all, you multiply a float with an audio data which is maybe an integer. It won't work, and it will use resources for nothing.

Just do : return((audio*cv) >> 8 ) ;

(with every data uint32_t).

Thanks, that did the trick! Also thanks for the hints on using bit shifting instead of floats. I'm using fixed point maths in different areas of my sketch, but I'm still a bit rusty at my microcontroller programming.

Did you create the groovino? If so, I've been meaning to get into contact with you. I'm working on a project that might interest you. :-) If you have a moment to hear about it, please email me at clone45 at gmail. Maybe we can collaborate.

Thanks, - Bret