Mozzi Modulation and Waveform summing

602 views
Skip to first unread message

Alberto Carlassare

unread,
Jun 2, 2016, 2:21:05 PM6/2/16
to Mozzi-users
Hi,

thank you for accepting me in Mozzi User Group. Thank you also for developing this library that is very handful for getting sound generation with arduino.

I found the examples and the API page really useful to understand how Mozzi works and I 've got my arduino splitting nice waveform. I need some suggestions about how to modulate waveform correctly. I tried to make modulation calculation (for example modulate de lowpassfilter frequency with an lfo or an ADSR) inside de updateAudio() function but arduino is glitching, probably isn't capable to make those calculations so fast. So I get it working as following. 
Let's say I have an Oscil called Lfo1 at a rate from 0 to 20(any waveform). I call Lfo1.next() inside de updateAudio() function and write the value in a variable (let's call it Lfo1ModValue). Afterthat, inside the updateControl(), I do calculations. For example I modulated lowpassfilter cutoff frequency value in relation to Lfo1ModValue. It's working quite good but I want to be sure this workflow is the best suitable or if it exists a better suitable method. All modulation calculations are supposed to be done inside updateControl() routine? I also applied and ADSR to Filter Cutoff and it works great!

I need also some support about the range of values updateAudio() can return. The function return an integer by default (16bit). But the PWM Out value must be 8bit. Can I return a value greater than 127 or lower than -128 from updateAudio(), and what happens if I do? I'm right if I suppose that oscil.next() function give back a value between -128 and 127? Is it necessary to stay into this range? So which is the most suitable way to get it working when summing oscillators? I do this: (osc1.next()*osc2.next())>>8. Is this the right way? Let's say osc2 is switched off and give back 0 all the time, we get into trouble!!! Or maybe it's me I'm messing up thing

Why in same examples is there (float) before next()? What does it stand for?

I was wondering on how to use scaler values. For example if I want to set a Oscillator Volume value I should do this: (Osc1.next()*Volume) and set Volume as a float between 0 and 1. but that it doesn't work really good, I suppose because the return will be integer and truncate the value. So What is the best formula for getting this kind of parameter workings best.


Sorry for the big amount of issue. If required I'll open a dedicated thread for each issue.


Alberto

Tim Barrass

unread,
Jun 6, 2016, 6:50:33 AM6/6/16
to mozzi...@googlegroups.com
Hi Alberto,

it sounds like you're doing a good job of figuring out how it works.

updateAudio() returns -244 to 243 in STANDARD or STANDARD_PLUS modes.  There's some more about it here (sorry it's not as easy to find as I thought): https://sensorium.github.io/Mozzi/doc/html/group__core.html#ga0b8ca8ad62b88c01b639bad62eafcbf1
On a Teensy 3.x you get 12 bits.
HIFI mode provides 14 bits of range for output (not for Teensy 3.x).


>summing oscillators? I do this: (osc1.next()*osc2.next())>>8
To sum oscillators, I would do this: (osc1.next()+osc2.next())>>1;



> (float) before next()? What does it stand for?
It's called "cast to float" and it turns the returned value into a float, if it's an int or whatever.  It makes a difference to the results of calculations, like
float x = (float) 1/2; // 0.5
float x = 1/2; // you might get 0, if 1 is treated as an int (I'd have to test it to see what happens - sometimes arduino chooses what you want, but not always)


>(Osc1.next()*Volume) and set Volume as a float between 0 and 1.
This is how I would do it
byte Volume = 255; // a byte between 0-255
int out = (Osc1.next()*Volume)>>8;

OK good luck,
Tim


--
You received this message because you are subscribed to the Google Groups "Mozzi-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mozzi-users...@googlegroups.com.
To post to this group, send email to mozzi...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/mozzi-users/279c31da-89a7-4536-aed1-3a4ef3799322%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Alberto Carlassare

unread,
Jun 7, 2016, 9:01:44 PM6/7/16
to Mozzi-users
Hi Tim, very helpful your support, I'm getting good results with Mozzi. I will keep you updated.

Alberto

Alberto Carlassare

unread,
Jun 14, 2016, 8:06:01 PM6/14/16
to Mozzi-users
Hi tim,

Thanks to your Mozzi library and the throubleshooting in this group I've got it! A basic synth based on arduino UNO, Mozzi as audio engine and a few components:

The synth has:
3 oscillators
1 low pass filter
2 envelopes
2 lfos
12 modulation patches with 10 sources and 14 destinations

The synth is controlled through 5 analog pots, a switch, a led and an 16x2 lcd. I still have to implement MIDI, but I believe that it is easy stuff :-).

I want to fine tune all the parameters, but the synth is already sounding very good (being an arduino). Im thinking to add to the build an analog filter that could be driven by 3 pwm arduino pins (cutoff, resonance, amp) so I can get a more harsh sound and I can get free memory from the atmega to improve functionalities. Right now 90% of arduino resources are spent.

I'm looking forward to add the shruthi's smr4 mkII low pass filter, from Mutable Instruments

Thanks for everything

Reply all
Reply to author
Forward
0 new messages