how to modulate Pulse Width across shape input 1.0 "boundary"?

tigger

Active member
I'm trying to modulate the pulse width across the "boundary" of the Shape input.
That is, the Shape input to the waveformMod can be between -1.0 to +1.0.
from my testing I've found that when Shape = 0.0, the duty cycle is 50%,
when Shape = -0.9, the duty cycle is 90% (hi 90% of the time), and for 0.9, the duty cycle is 10%.

I'd like to be able to have a modulation source connected to the Shape input be able to wrap around to negative when it would
otherwise go above +1.0.

Anyone got any ideas on how to do this?

here's a screen shot of the block diagram.
The test code i have is attached.
right now when the shape input goes above one, the output goes away. Then it comes back when the shape input goes back below 1.0.
(I need some sort of "wrap" module that wraps the value of the signal to negative when above 1.0 and back to positive when below -1.0).
firefox_w0tX7gvocY.png
 

Attachments

  • tad4.ino
    5.2 KB · Views: 9
Sorry, I did not actually look at your sketch, but If I'm correctly understanding what you are asking for, how about checking for when your value goes above 1.0, then subtract 2.0, & checking for when your value goes below -1.0, then add 2.0. Will that do what you want ??

Hope that helps . . .

Mark J Culross
KD5RXT
 
Sorry, I did not actually look at your sketch, but If I'm correctly understanding what you are asking for, how about checking for when your value goes above 1.0, then subtract 2.0, & checking for when your value goes below -1.0, then add 2.0. Will that do what you want ??

Hope that helps . . .

Mark J Culross
KD5RXT
Thanks for the response.
I'm looking for a solution that can be in the signal chain between the sine wave and the "Shape" input to the pulse wave.
This way, it can do this at audio rates or at least at high LFO rates.
 
I think I can probably modify synth_waveform.cpp AudioSynthWaveformModulated::update(void)

the section here...
case WAVEFORM_PULSE:
if (shapedata) {
magnitude15 = signed_saturate_rshift(magnitude, 16, 1);
for (i=0; i < AUDIO_BLOCK_SAMPLES; i++) {
//uint32_t width = ((shapedata->data + 0x8000) & 0xFFFF) << 16; // original line
uint32_t width = ((shapedata->data + ADDED_PW_OFFSET_HERE+ 0x8000) & 0xFFFF) << 16;
if (phasedata < width) {
*bp++ = magnitude15;
} else {
*bp++ = -magnitude15;
}
}
break;
} // else fall through to orginary square without shape modulation

I could add a function to the class to add an offset there.
Then I could add my offset and the modulation signal should cause the wrapping of the width variable.
I'm not sure of the way the signals in this line are promoted to uint32_t values, though.
 
I have a feeling AudioEffectWaveFolder won't quite do what you want, but it might do something interesting ?!
 
Back
Top