Cabbage Logo
Back to Cabbage Site

Interchangeable waveforms using one oscillator?

So for example being able to switch between a sine and a saw and a square using just one oscillator. Or just being able to have 2 and be able to turn one off and one on. How do you do it? Is there a function like aout but for sines? And how would you be able to toggle between the waveforms?

There are a few approaches you could take here. One would be to simply mix between the sound sources. You could use ntrpol to do this.

You could also look at use the tabmorpha opcode, which will let you switch between tables. If you want to avoid aliasing you should use vco2init to create those tables and then vco2 to read from them.

When one source is playing back 100% you might want to mute the other. A simple if block should do here.

Let me know how you get on :wink:

Have you checked out the squinewave opcode? It can make bandlimited sawtooth, square, pulse, and sine waves, and transition smoothly between them.

One thing that took me a while to figure out about squinewave: its a-rate arguments must be a-rate - it will cause an error if you use i- or k-rate inputs or use a constant. to workaround this I just use the a() function to turn anything and everything into an a-rate variable.

I always forget that one! Thanks for reminding us :+1:

So would you just do squinewave and then the wave type at the end? And say if I wanted to add huttons to control different types of wave, say, press one button and it would make it a triangle, or press another and it makes it a sine? And do you have to type anything before squinewave, like vco2?

From the manual:

Classic waveforms have simple values:

  • sine: clip=0, skew=0
  • saw(like): clip=0, skew=+1 or -1 (left- or right-facing)
  • square: clip=1, skew=0
  • pulse: clip=1, skew=+1 or -1

I guess if you used a combobox to choose the waveform you could do something like this:

if chnget:k("waveform") == 1 then
    ;sine
    aClip = a(0)
    aSkew = a(0)
elseif chnget:k("waveform") == 2 then
    ;saw left facing
    aClip = a(0)
    aSkew = a(1)
endif

Of course there are many ways of doing this!

How would I run this through a low pass? What do I put after moogladder ( alp moogladder (the wave) for example)? I’m very curious about this as it will help me massively

Essentially what I mean by this is what would I put for the outs. Creating this does not make any errors but does not output any sound.

I send you a link to a short tutorial that covers this. You can find a similar tutorial here as a series of short videos.

I can’t seem to find the part where it shows the skew/clip parts and where they use it in an out

I’m not sure I understand? Something like this I imagine:

aout squinewave acps, aClip, aSkew

This is just lifted from the manual…