Mozzi sound synthesis library

Can someone help me port this library?
Post Reply
tfried
Posts: 19
Joined: Mon Dec 04, 2017 8:45 pm

Mozzi sound synthesis library

Post by tfried » Tue Dec 05, 2017 9:50 am

Hi all!

I have an initial (incomplete but basically functional) port of the Mozzi sound synthesis library at https://github.com/tfry-git/Mozzi . Do check it out, and you're welcome to help me finish the details ;) .

I've started discussing a few aspects over at the "New Users" board (viewtopic.php?f=2&t=2931#p37992). To continue from there (in reply to Steve):

PWM modulation frequency is bounded only by CPU speed and audio resolution. Right now I'm using 10 audio bits on my 72MHz board, resulting in around 70kHz carrier frequency. That frequency is a physical limit that cannot trivially be improved on other than by reducing the resolution per audio sample. (One technique available for use in Mozzi on AVR, - and yet to be ported - is to split the audio bits over two pins, such that each pin only needs to write 6 or 7 bits, allowing to ramp up the carrier frequency, accordingly).

The interrupts we are talking about are happening at the rate of the generated audio output, which is 16kHz by default. Thus the duty cycle of the PWM pin is updated roughly every 4 PWM periods. That seems kind of close in spirit to the repetition counter feature (if I understood that, correctly), except the repetion is happening all "on its own" via the PWM timer.

Of course an audio rate higher than 16kHz may also be desirable, but it does not need to be any near as high as the PWM carrier frequency.

User avatar
RogerClark
Posts: 7680
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Mozzi sound synthesis library

Post by RogerClark » Tue Dec 05, 2017 9:58 am

Thanks for sharing

arpruss
Posts: 153
Joined: Sat Sep 30, 2017 3:34 am

Re: Mozzi sound synthesis library

Post by arpruss » Tue Dec 05, 2017 6:06 pm

tfried wrote:
Tue Dec 05, 2017 9:50 am
PWM modulation frequency is bounded only by CPU speed and audio resolution. Right now I'm using 10 audio bits on my 72MHz board, resulting in around 70kHz carrier frequency.
I am curious how you got such a high rate of the carrier. At 10bits, doesn't that require pulsing at 70MHz? The fastest I've been able to pulse the digital pin has been 7.2MHz, using memory-to-memory DMA.

tfried
Posts: 19
Joined: Mon Dec 04, 2017 8:45 pm

Re: Mozzi sound synthesis library

Post by tfried » Tue Dec 05, 2017 10:04 pm

I am curious how you got such a high rate of the carrier.
Not that hard actually (but PWM setup can be confusing, indeed): I set the timer prescaleFactor to 1, i.e. counting at full CPU speed. Then set the overflow to 1024, so that the timer period is 72Mhz / 1024 =~ 70kHz. You can now "write analog values" by varying the duty cycle between 0 and 1023 (i.e. 10 bits). For as long as that number of cycles, the PWM pin will be high, then low until the timer has counted to the overflow value.

So, in theory, you could get a 36MHz oscillation by setting prescaleFactor to 1, overflow to 2, duty to 1. In reality, I reckon the slew rate will not be high enough for a full swing from low to high at that rate, so I wouldn't be surprised if 7 MHz is around the maximum you can achieve (I'm sure somebody has tried and can tell the details).

The same problem is likely to distort the output in my PWM setup. However, it only affects very low and very high duty cycles. So perhaps in reality the useful range may be closer to 50...974. Still almost 10 bits.

Post Reply