Cabbage Logo
Back to Cabbage Site

Simple question about the gentable

So is there a simple way to use a combobox the switch between the instrument displayed by the gentable aka:
square
saw
sine
or is there an easyer way to switch between waveforms in general?

this is the project i am trying to do it in btw.


(wavelength square)

If you are just using the gentable to display simple waveforms, you can do something like this. The idea is to create a simple table, in this case table number 99, and copy other tables to it just before you update it.

<Cabbage>
form caption("Untitled") size(400, 300), colour(58, 110, 182), pluginid("def1")
gentable bounds(10, 10, 300, 150), tablenumber(99), identchannel("table1"), fill(0), outlinethickness(3)
combobox bounds(316, 10, 80, 20), items("Sine", "Square", "Saw"), channel("waveform")
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d -+rtmidi=NULL -M0 -m0d 
</CsOptions>
<CsInstruments>
; Initialize the global variables. 
ksmps = 32
nchnls = 2
0dbfs = 1


instr 1
    kWaveform chnget "waveform"
    if changed:k(kWaveform) == 1 then
        tablecopy 99, kWaveform
        chnset "tablenumber(99)", "table1" 
    endif
endin

</CsInstruments>
<CsScore>
f99 0 1024 10 1
f1 0 1024 10 1                      ;sine
f2 0 1024 7 1 512 1 0 -1 512 -1     ;square
f3 0 1024 7 -1 512 1 1 -1 511 1     ;saw

;starts instrument 1 and runs it for a week
i1 0 [60*60*24*7] 
</CsScore>
</CsoundSynthesizer>

so it should look like this?

iAtt chnget "att"
iDec chnget "dec"
iSus chnget "sus"
iRel chnget "rel"
kRes chnget "res"
kCutOff chnget "cutoff"
kLFOFreq chnget "LFOFreq"
kAmp chnget "amp"
iPan chnget "pan"

kWaveform chnget "waveform"
    if changed:k(kWaveform) == 1 then
        tablecopy 99, kWaveform
        chnset "tablenumber(99)", "table1" 
    endif
kEnv madsr iAtt, iDec, iSus, iRel 
aOut vco2 iAmp, iFreq, iPan
kLFO lfo 2, kLFOFreq, 5
aLP moogladder aOut, kLFO*kCutOff, kRes
outs kAmp*(aLP*kEnv), kAmp*(aLP*kEnv)
endin

btw this does not chage the wave thats being played by the synth right is there a quik easy way to do that aswell?

in a way like kLFO1 chnget "table1"
EDIT actually why dont i just try that lmao
EDIT2 didnt work

So you want these waveform to be read by the lfo? You can just use an oscillator:

kLFO oscili 1, kLFOFreq, 99

But change the tables first as they move from -1 to +1. Or else use abs() in your filter:

aLP moogladder aOut, abs(kLFO)*kCutOff, kRes

abs() will convert any negative values to positive.

SO my opcode section should look like this now?

instr 1
;instrument 1 is a square wave.
iFreq = p4
iAmp = p5

iAtt chnget "att"
iDec chnget "dec"
iSus chnget "sus"
iRel chnget "rel"
kRes chnget "res"
kCutOff chnget "cutoff"
kLFOFreq chnget "LFOFreq"
kAmp chnget "amp"
iPan chnget "pan"
iFdBack chnget "size"
  
kWaveform chnget "waveform"
    if changed:k(kWaveform) == 1 then
        tablecopy 99, kWaveform
        chnset "tablenumber(99)", "table1" 
    endif
kLFO oscili 1, kLFOFreq, 99
kEnv madsr iAtt, iDec, iSus, iRel 
aOut vco2 iAmp, iFreq, iFdBack
kLFO lfo 2, kLFOFreq, 5
aLP moogladder aOut, abs(kLFO)*kCutOff, kRes
outs kAmp*(aLP*kEnv), kAmp*(aLP*kEnv)
endin

i do need to remove that comment tho

You have two kLFO variables now, the second one will overwrite the first one. Remove the second one, then it should work… I think :crossed_fingers:

it does the sine sounds really cool but the square and saw sound to simulair the square doesnt really sound square

You’re now reading custom LFO waveforms now. You can make them sound whatever you like. Just modify the function tables so they match what the LFO opcode produces. They use GEN07. Alternatively, you can do something like this:

;UNTESTED CODE!
iLFOWaves[] fillarray 0, 3, 5 ; sine, square and downward saw
iWaveform chnget "waveform"
if changed:k(iWaveform) == 1 then
        tablecopy 99, iWaveform
        chnset "tablenumber(99)", "table1" 
endif
kLFO lfo 1, kLFOFreq, iLFOWaves[iWaveform-1]

This will continue to display the simple waveforms, but will use the waveform genearted by the LFO opcode to modulate your signal.

i could just try to make the saw an upward or a sawtooth cuz what ever that code means makes my brain go oof

ok now my synth randomly stopped working it says vco2 is not initialised but i didnt even change the opcodes i just gave some color to the text on the groupboxes

It’s probably because when you choose a square wave you need to pass a PW to it. Ty:

kLFO lfo 1, kLFOFreq, iLFOWaves[iWaveform-1], .5

nah i had a hicup in my non functional reverb unit the size control wasnt finished and it just kinda killed the synth.

btw is there an eay way to do optional reverb i looked at a lot of examples but i cant seem to wrap my head around those in a way i can implement it in my synth.

i know this is getting really offtopic but i dont think making a new thread for everything my miniscule brain doesnt understand is a good idea

You can just use a switch to enable/disable the reverb in an instrument that is always running…

think i can try to copy the one from wavetable example that one seems easy

Go for it. That’s why Iain wrote all those examples, so that people can learn from them :slight_smile:

yeah but i cant seem to find where and how the singal get processed its something to do with reverbsc and thats all i can understand lmao

Try it out, and if it doesn’t work post some code. There are literally 1000s of ways you could be doing this wrong. Save us some time, and show us specifically why it doesn’t work. Don’t worry about posted horrible code that doesn’t work. Just do it :+1: In the long run you’re learn more.

Well my code is right here:

the file is called wavelength square btw

There’s 4 files in there dude. Do you want to me to run through each one and hypothesise what problems you might have? You need to up game here and be specific! :man_shrugging:

i edited my post to late rip :disappointed_relieved:

1 Like