making triangle/ramp switch

For general discussion related FlowStone
Post Reply
tester
Posts: 1786
Joined: Wed Jan 18, 2012 10:52 pm
Location: Poland, internet

making triangle/ramp switch

Post by tester »

I can't find an easy way to do that.

I have flat-ramp generator (with phase offset) to drive something, and I'd like to add some quick switch to the code to flip from ramp to triangle.

One of my guesses is, that some sort of triangle formula could be added to the code, but this would produce double calculations or would involve additional selectors on stream routing. I'd like to avoid that.

Other of my guesses is, that there is some sort of threshold based formula, that would generate flat ramp or flat triangle (in 0-1 range), depending on flip, value that can be provided via separate input.

How to make it?
Attachments
convert.fsm
(27.46 KiB) Downloaded 996 times
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
tester
Posts: 1786
Joined: Wed Jan 18, 2012 10:52 pm
Location: Poland, internet

Re: making triangle/ramp switch

Post by tester »

Hmm... Found and adapted something like this?
Attachments
triramp1.fsm
(27.43 KiB) Downloaded 1031 times
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
User avatar
trogluddite
Posts: 1730
Joined: Fri Oct 22, 2010 12:46 am
Location: Yorkshire, UK

Re: making triangle/ramp switch

Post by trogluddite »

Pretty cool - PWM for triangle waves!

If you're only ever switching in green, you could calculate 1/sw and 1/(1-sw) in a hop - should save a fair few CPU cycles replacing the divides for multiplys in the main equation.

Might also be worth restricting the range of sw by a tiny amount - there's a corner case at each end of the wave where 'zero divides zero' is possible - which would give an indeterminate answer (-1.#IND). If sw = 0, you will always get that on the first sample when ph has just initialised.
Depends what you're going to do with it, but that gives potential for a 'lock-up' situation if feeding into e.g. biquad filters etc. where the #INF can feed back on itself indefinitely. Probably rare that 'ph' would exactly be zero to 32bit precision, but it only needs to happen once in that kind of setup - needing an audio reset to recover!
All schematics/modules I post are free for all to use - but a credit is always polite!
Don't stagnate, mutate to create!
tester
Posts: 1786
Joined: Wed Jan 18, 2012 10:52 pm
Location: Poland, internet

Re: making triangle/ramp switch

Post by tester »

I borrowed this one from SM and cleaned up and slightly modified. The original idea there was to smoothly change/morph from ramp through traigne to saw.

As for hoping - generally this one will be modulated (ramp is needed to get full rotation, triangle is needed to get angle swing back and forth), so not sure which part / how could be hoped.

Yes, I noticed a glitch on initlalizing. By limiting you mean like 1e-36 instead of 0 for phase offset or something in code?
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
tester
Posts: 1786
Joined: Wed Jan 18, 2012 10:52 pm
Location: Poland, internet

Re: making triangle/ramp switch

Post by tester »

Trog - you mean something like this?

Question: Ramp/triangle is feeding/modulating the rotation of local soundspace. Will not the sw limit produce audio glitch, at least from time to time?
Attachments
triramp2.fsm
(27.62 KiB) Downloaded 1029 times
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
DjMmix
Posts: 16
Joined: Wed Nov 09, 2011 8:02 am
Location: france

Re: making triangle/ramp switch

Post by DjMmix »

hi tester,

I took your algo in asm as impossible to understand the conditions of your code (it's not fault of trying to have)

if you could explain your algorithm simply I include in the DLL in C + + code directly thank you :)

and very interesting passage: p
User avatar
Nubeat7
Posts: 1347
Joined: Sat Apr 14, 2012 9:59 am
Location: Vienna
Contact:

Re: making triangle/ramp switch

Post by Nubeat7 »

i remember some further discussion about this code here:
viewtopic.php?f=2&t=1688&start=10

variables are renamed here, maybe its better to understand
here is the fixed schematic with different variablenames, hope this helps
triramp_fix.fsm
(29.49 KiB) Downloaded 1048 times


if you re not familiar with FS DSP code, the & acts like "if - then"

so:

Code: Select all

ramp>=1&1

would mean "if ramp >= 1 then 1"
DjMmix
Posts: 16
Joined: Wed Nov 09, 2011 8:02 am
Location: france

Re: making triangle/ramp switch

Post by DjMmix »

thank's nubeat :)

good explain
tester
Posts: 1786
Joined: Wed Jan 18, 2012 10:52 pm
Location: Poland, internet

Re: making triangle/ramp switch

Post by tester »

Gosh... I don't remember the context! :mrgreen: :-) I only remember, that it is already implemented somewhere (modified or as it is - I don't remember) and probably works fine. Otherwise I would remember it among things to do.

But as I am going to revisit some projects soon (within few months), switching from 'clone' philosophy into 'multifunction/array' based - if there is something to find out - it will come out. Thanks for pointing.
Need to take a break? I have something right for you.
Feel free to donate. Thank you for your contribution.
Post Reply