Oscillators - train and triangle? - or something else?

    Mar 28 2012 | 7:16 pm
    I'm working on writing a multi-mode oscillator configuration in gen/codebox, and would love some advice on the triangle and train sections, since these aren't oscillators per se.
    I'm using Train and Triangle , but I'm pretty sure that's not the right way to do it.. I've included what I have so far.

    • Mar 28 2012 | 8:22 pm
      Hmm, when I load your patch the Gen subpatcher appears to revert to default (ie. in1 + in2).
    • Mar 28 2012 | 11:54 pm
      It's because we don't have the gen file.
    • Mar 29 2012 | 1:39 am
      Oops.. (it's copy compressed in the gen file, right?)
    • Mar 29 2012 | 3:56 pm
      nope. how bout this..
    • Mar 29 2012 | 10:49 pm
      Train is a pulse generator, so it is 'sort of' an oscillator. It's not driven by frequency, but rather pulse period, which is specified in samples. So [train 44100] pulses once per second (1Hz) for example, and [train 22050] pulses at 2Hz etc. It's basically inspired by the MSP [train~] object, but measures time in samples rather than milliseconds.
      Triangle is also inspired by the MSP [triangle~] object. It is more like a wave shaper. The name comes from the fact that if you send a phasor ramp in, you get a triangle wave out. The result is not band-limited, so it's more useful for LFOs.
      Hope that helps!
    • Mar 30 2012 | 4:43 pm
      There's been a lot written about band-limited (or alias-reducing, more accurately...) oscillators. Unfortunately, for most of them the math is not easy to follow.
      This article in CMJ was pretty good: "New Perspectives on Distortion Synthesis for Virtual Analog Oscillators". Here's something based on it that I've extended to include PWM, and can handle FM!
      If you don't mind the darker sound, you can just skip the postfilter. This is not production-ready (probably need to move filters inside of gen...), but it sounds pretty nasty.
    • Mar 30 2012 | 7:07 pm
      man that is sick!!!
    • Apr 02 2012 | 1:11 am
      Thanks Peter for the great reference! That's really awesome. And thank you for the code.
      I actually recently acquired the Audio Programming Book, and Lazzarini looms large there as you probably know. It was the first place I looked for information on band-limiting.
      I rolled the FM (with the exception of the line~ objects, I don't think there's an equivalent in gen~) and PWM into gen and introduced some AM as well (after the tanh). As a sort of personal challenge I also I translated the object style to GenExpr code boxes.
      I noticed that for cycle in GenExpr, you can't set the index to phase. In the docs it says "In GenExpr, only the built-in sinusoid wavetable can be used", I have to think that means you can't set the index attribute, but the language is not entirely clear, or I'm doing it wrong.
      Still haven't gotten my head around history in gen for the filter section.. maybe that'll be my next undertaking.
    • Apr 02 2012 | 7:39 am
      i think cycle not being able to be set to phase index in GenExpr is a bug. i do not see why it should not work.
    • Apr 02 2012 | 8:06 am
      and here is peter's "post filter" in gen~ for fun:
    • Apr 02 2012 | 3:38 pm
      Re: cycle not being able to set via phase: I wonder if this has to do with table lookups not working inside genexpr. That's my best guess.
      Thanks for posting. I'm working on an optimized version now.
    • Apr 02 2012 | 5:38 pm
      Confirmed the indexed cycle in GenExpr is a bug; and the fix is going to be in the next Gen update. Also the buffer/data limitation is going to be lifted too :-)
    • Apr 02 2012 | 7:38 pm
      Great news Graham. Gen just keeps on giving.
      Here is a resonant twopole Highpass that might be interesting in this situation:
    • Apr 02 2012 | 8:39 pm
      Here's my tweaked version. Most of the calculations are replaced with lookup tables. The pulsewidth can go as narrow as 1% now (was previously 10%)
      After a little evaluation, I found that a fixed highshelf filter gave a better result, so that's in there in place of the moving shelf. (highpass + original)
      Also, the FM is much cleaner in this version since I've got it connected to the PWM, so there's less stepping as you sweep the modulation index. One thing to note, because the FM is interacting with the scaling factor, the sound is not as bright, because the spectral tilt becomes that of a modulated sine rather than a modulated square. I think this is a more useful sound.
      It's more expensive as an oscillator than rect~ and slightly brighter, but you do get FM. The tradeoff, for the time being at least, is the lack of hard sync. Need to brush up on maths before that one gets dealt with...
    • Apr 03 2012 | 5:36 pm
      Good to know about the indexed cycle.
      So I thought I'd try to tackle equation 22 (Moog-like Sawtooth) on Page 34 of that CMJ article PM cited above, and maybe this isn't the place for this, but here's what I have after blindly swinging at the thing.
    • Apr 06 2017 | 9:28 pm
      hello, where is [PM.PMW~] please ?
    • May 10 2017 | 2:38 pm
      Train and triangle derived from phasor wave below. Self-explaining, i guess.