Cabbage Logo
Back to Cabbage Site

FM Synth

Hi all,

This is my 1st Cabbage Instrument, would love input or advice from anyone.

There are a couple of things I’d still like to add to it, however, at the moment, the CPU is blowing out after about 30 seconds whenever I play a lot of notes in succession. I’d love any feedback or advice on how to make the code more efficient. I’m neither a coder nor a mathematician, and only a few months new to CSound - so I’m sure I’ve done more than a few silly things here.

FM_TEST_8:12:18.csd (45.7 KB)

Presets please :slight_smile:

FM_TEST_8:12:18.csd (45.9 KB)
FM_TEST_8:12:18.snaps (21.0 KB)

The interface is too big to show on my laptop screen. I’ll try once I have access to a bigger screen.

From what I can see, to make a big improvement in the performance of your code you can do at least two things:

  1. set the ksmps value to 256. That means 5.8ms of lag when you click on a note, that is still perceived as an immediate response by the human brain, but it will decrease the stress very much on your CPU.

  2. get rid of all those if/then/chnset at the end of your instrument:

    if (kalgorithmselect == 5) then
    chnset “outlinecolour(0,128,0)”, “Op2LFOGUI”
    chnset “outlinecolour(0,128,0)”, “Op2GUI”
    chnset “outlinecolour(0,128,0)”, “Op2 EGGUI”
    chnset “outlinecolour(0,128,0)”, “Op2TimeGUI”
    chnset “outlinecolour(0,128,0)”, “Op2CurveGUI”
    chnset “outlinecolour(0,128,0)”, “Op2LevelGUI”
    chnset “trackercolour(128,0,128)”, “LFOMode2RateGUI”

I don’t know for what they are, but if I remove them the max polyphony increases.

Then I think you could try to make many k-time variables in i-time variables, so that they are computed only once.

1 Like
  1. set the ksmps value to 256. That means 5.8ms of lag when you click on a note, that is still perceived as an immediate response by the human brain, but it will decrease the stress very much on your CPU.

Thanks for that, I haven’t had time to work on it the last day - but tried this quickly this afternoon and it made it much more usable! Appreciated.

你好我想问一下csound里面的例子里面的simpleFm synth怎么在白菜里面实现呢谢谢

What simpleFM synth are you referring to?

I’m sorry, Google translate is failing me here. I didn’t write that code, so I can’t really comment…

工程文件是這樣的
Simple_FM_Synth000.csd (23.1 KB)

I didn’t write this code, but I can tell you that it uses standard FM techniques. More details on FM in Csound can be found here:
https://csound-floss.firebaseapp.com/sound-synthesis/frequency-modulation

A very simple FM example, based on this file is attached below.

FMSimple.csd (2.4 KB)

Note that CsoundQT examples use invalue and outvalue opcodes whereas Cabbage use chnget and chnset.

您好,我搜索了此網址,但是顯示其不存在。

Is it not accessible in your country?

應該是

你好,我想知道為什麼把ftgen放進fm裡面没有效果,可以幫忙看看嗎,謝謝。
fm ftgen.csd (6.3 KB)

I think this line is the problem:

massign 0,4 ; send all midi notes to instr 3

I think it should be:

massign 0,2 ; send all midi notes to instr 2

There is no instrument 4 defined. Note also that this line changes the contents of function table 1:

giwave ftgen 1,0, 4096,10, i(gkstr1)*i(kstatus1), i(gkstr2)*i(kstatus2), i(gkstr3)*i(kstatus3)

You define it as a sine wave, but it get overwritten here. So it might be best to use a different table number for the display.

Hope this helps.

你好,我改變後,工程沒有聲音了。fm ftgen.csd (6.3 KB)

Try this one. it works fine for me here.
fmftgen.csd (6.3 KB)

非常感謝你的幫助!

You’re welcome, I guess we should also thank Google translate :slight_smile: