basically, what happens in the backend is equivalent to the following Pd-pseudocode:
[whatever-goes-into-a-digital-dac~]
|
[expr~ $v1 > 0.5]
|
[actual-digital-output~]
so, you can achieve PWM by adding an offset to a [phasor~]
in your patch:
[phasor~ 50]
| [r~ widthControl]
| |
[+~ ]
|
[dac~ 11]
To understand what this does, let's replace the [dac~ 11]
in the second block with the pseudocode from the first block:
[phasor~ 50]
| [r~ widthControl]
| |
[+~ ]
|
[expr~ $v1 > 0.5]
|
[actual-digital-output~]
and so the effect of [r~ widthControl]
is as follows:
- at 0.5 , the [actual-digital-output~]
is going to have a pulse width of 100% (constant 1)
- at 0 , the [actual-digital-output~]
is going to have a pulse width of 50%
- at -0.5 , the [actual-digital-output~]
is going to have a pulse width of 0% (constant 0)
and intermediate values will produce intermediate results (e.g.: at 0.3 you get a pulse width of 80%)
In your case, using the simple envelope detector suggested by @lokki, you would use something like this: