Cabbage Logo
Back to Cabbage Site

Terrible performance

I am playing testing my synth and I am witnessing extremely bad performance, 2 oscilator with 3 second release time , sweep through 7 octaves overloads my CPU at half through of the sweep. At the same time doing the same with Europa in Reason but this time with 3 oscilator , same release time, it barely registers on the cpu meter for the same full sweep.

Is this a CSOUND issue or am I doing something wrong ?

<Cabbage>
#define LAYER1_COLOR colour(61, 106, 73, 255)
#define LAYER2_COLOR colour(100, 50, 50, 255)
form caption("LazerHawk") size(800, 700), colour(100, 100, 182), pluginid("LHSYSUB")
keyboard bounds(0, 600, 800, 100)
image bounds(2, 0, 800, 60), colour(153, 153, 255, 255) outlinecolour(192, 18, 18, 255),plant("Header"){
label      bounds(0, 5, 200, 20), text("LazerHawk v0.01"), colour(60, 60, 120, 122), fontcolour(0, 0, 0, 255)

}
image bounds(2, 60, 800, 40), colour(100, 100, 255, 255) outlinecolour(192, 18, 18, 255),plant("Timbres"){
button bounds(0, 10, 60, 30), value(1), colour:1(0, 155, 0, 255), colour:0(155,0,0,255), channel("Timbre1"),identchannel("ID_Timbre1"), text("timbre 1")
}


image bounds(0, 100, 800, 200), $LAYER1_COLOR ,channel("Layer1"), identchannel("ID_Layer1"), plant("layer1plant"){

  groupbox bounds(0,0,200,200), $LAYER1_COLOR, text("Sound Generator 1"), fontcolour("black"), identchannel("ID_Sound_Generator_1"){
    ;label      bounds(0, 5, 200, 20),   text("Sound Generator 1"), colour(60, 60, 120, 122), fontcolour(0, 0, 0, 255)

    combobox   bounds(2, 25, 100, 25),  items("sine" , "saw", "square", "triangle"), channel("SG1_Wav"),colour(60, 60, 120, 122), fontcolour(0, 0, 0, 255)
    rslider    bounds(100, 25, 50, 50), text("PWM"),channel("SG1_PWM"), range(0.01, 0.99, .01, 1, 0.001),identchannel("ID_SG1_PWM"), textcolour(0,0,0)
    rslider    bounds(150, 25, 50, 50), text("Phase"), channel("SG1_Phase"), range(0.01, 0.99, .01, 1, 0.001), identchannel("ID_SG1_Phase")textcolour(0,0,0)
    rslider    bounds(150, 70, 50, 50), text("Noise"), channel("SG1_Noise_Volume"), range(0.001, 0.99, .001, 1, 0.001), textcolour(0,0,0)

    groupbox bounds(2,120,196,80), $LAYER1_COLOR, text("Amp Envelope"), fontcolour("black"){
    ;label      bounds(0, 120, 190, 20), text("Amp Envelope"), colour(60, 60, 120, 122), fontcolour(0, 0, 0, 255)
      rslider    bounds(0, 25, 50, 50),  text("A"), channel("SG1_Env_Amp_A"), range(0.001, 3, .01, 1, 0.001), textcolour(0,0,0)
      rslider    bounds(50, 25, 50, 50), text("D"), channel("SG1_Env_Amp_D"), range(0.02, 3, 2, 1, 0.001), textcolour(0,0,0)
      rslider    bounds(100, 25, 50, 50),text("S"), channel("SG1_Env_Amp_S"), range(0.02, .99, .99, 1, 0.001), textcolour(0,0,0)
      rslider    bounds(150, 25, 50, 50),text("R"), channel("SG1_Env_Amp_R"), range(0.1, 3, .01, 1, 0.001), textcolour(0,0,0)
    }
  }

  groupbox bounds(200,0,200,200), $LAYER1_COLOR, text("RM"), fontcolour("black"){
    ;label      bounds(210, 5, 190, 20), text("AM"), colour(60, 60, 120, 122), fontcolour(0, 0, 0, 255)
    rslider    bounds(0, 25, 50, 50), text("Freq"), channel("SG1_RM_Frequency"), range(1, 8000, 1, .5, 1), textcolour(0,0,0)
    rslider    bounds(50, 25, 50, 50), text("Vol"), channel("SG1_RM_Volume"), range(0.001, 1, 0.01, 1, 0.001), textcolour(0,0,0)

    combobox   bounds(4, 75, 96, 25),items("ring" , "am", "chaos", "frozen"), channel("SG1_AM_Type"),colour(60, 60, 120, 122), fontcolour(0, 0, 0, 255)
    label      bounds(4, 105, 50, 11),text("AM Type"), $LAYER1_COLOR, fontcolour(0, 0, 0, 255)
    combobox   bounds(100, 75, 98, 25),items("sine" , "saw", "square", "triangle"), channel("SG1_AM_Wav"),colour(60, 60, 120, 122), fontcolour(0, 0, 0, 255)
    label      bounds(100, 105, 50, 11),text("AM Wav"), $LAYER1_COLOR, fontcolour(0, 0, 0, 255)

    ;label      bounds(0, 120, 190, 20), text("Ring Amp Envelope"), colour(60, 60, 120, 122), fontcolour(0, 0, 0, 255)
    groupbox bounds(2,120,196,78), $LAYER1_COLOR, text("RM Envelope"), fontcolour("black"){
      rslider    bounds(0, 30, 50, 50),  text("A"), channel("SG1_Env_RM_A"), range(0.001, 3, .01, 1, 0.001), textcolour(0,0,0)
      rslider    bounds(50, 30, 50, 50),  text("D"), channel("SG1_Env_RM_D"), range(0.02, 3, 2, 1, 0.001), textcolour(0,0,0)
      rslider    bounds(100, 30, 50, 50),  text("S"), channel("SG1_Env_RM_S"), range(0.02, .99, .99, 1, 0.001), textcolour(0,0,0)
      rslider    bounds(150, 30, 50, 50),  text("R"), channel("SG1_Env_RM_R"), range(0.02, 3, 12, 1, 0.001), textcolour(0,0,0)
    }
  }

  groupbox bounds(400,0,100,100), $LAYER1_COLOR, text("Filter HP"), fontcolour("black"){
    ;label      bounds(410, 5, 90, 20),  text("Filter HP"), colour(60, 60, 120, 122), fontcolour(0, 0, 0, 255)
    rslider    bounds(0, 25, 50, 50), text("Freq"), channel("SG1_High_Pass_Frequency"), range(100, 16000, 100, 1, 0.001), textcolour(0,0,0)
    rslider    bounds(50, 25, 50, 50), text("Reas"), channel("SG1_High_Pass_Reasonance"), range(1, 200, 1, 1, 0.001), textcolour(0,0,0)
  }
  groupbox bounds(500,0,100,100), $LAYER1_COLOR, text("Filter LP"), fontcolour("black"){
    ;label      bounds(0, 5, 90, 20),  text("Filter LP"), colour(60, 60, 120, 122), fontcolour(0, 0, 0, 255)
    rslider    bounds(0, 25, 50, 50), text("Freq"), channel("SG1_Low_Pass_Frequency"), range(100, 16000, 16000, 1, 0.001), textcolour(0,0,0)
    rslider    bounds(50, 25, 50, 50), text("Reas"), channel("SG1_Low_Pass_Reasonance"), range(0.01, 1, 0, 1, 0.001), textcolour(0,0,0)
  }
  groupbox bounds(400,100,200,100), $LAYER1_COLOR, text("Filter Envelope"), fontcolour("black"){
    ;label      bounds(400, 120, 190, 20), text("Filter Envelope"), colour(60, 60, 120, 122), fontcolour(0, 0, 0, 255)
    rslider    bounds(0, 30, 50, 50),  text("A"), channel("SG1_Env_Filters_A"), range(0.001, 3, .01, 1, 0.001), textcolour(0,0,0)
    rslider    bounds(50, 30, 50, 50),  text("D"), channel("SG1_Env_Filters_D"), range(0.02, 3, 2, 1, 0.001), textcolour(0,0,0)
    rslider    bounds(100, 30, 50, 50),  text("S"), channel("SG1_Env_Filters_S"), range(0.02, .99, .99, 1, 0.001), textcolour(0,0,0)
    rslider    bounds(150, 30, 50, 50),  text("R"), channel("SG1_Env_Filters_R"), range(0.02, 3, 12, 1, 0.001), textcolour(0,0,0)
  }
  
} 
image bounds(0, 300, 800, 200), $LAYER2_COLOR ,channel("Layer2"), identchannel("ID_Layer2"), plant("layer2plant"){

  groupbox bounds(0,0,200,200), $LAYER2_COLOR, text("Sound Generator 2"), fontcolour("black"){
    ;label      bounds(0, 5, 200, 20),   text("Sound Generator 1"), colour(60, 60, 120, 122), fontcolour(0, 0, 0, 255)

    combobox   bounds(2, 25, 100, 25),  items("sine" , "saw", "square", "triangle"), channel("SG2_Wav"),colour(60, 60, 120, 122), fontcolour(0, 0, 0, 255)
    rslider    bounds(100, 25, 50, 50), text("PWM"),channel("SG2_PWM"), range(0.01, 0.99, .01, 1, 0.001),identchannel("ID_SG2_PWM"), textcolour(0,0,0)
    rslider    bounds(150, 25, 50, 50), text("Phase"), channel("SG2_Phase"), range(0.01, 0.99, .01, 1, 0.001), identchannel("ID_SG2_Phase")textcolour(0,0,0)
    rslider    bounds(150, 70, 50, 50), text("Noise"), channel("SG2_Noise_Volume"), range(0.01, 0.99, .01, 1, 0.001), textcolour(0,0,0)

    groupbox bounds(2,120,196,80), $LAYER2_COLOR, text("Amp Envelope"), fontcolour("black"){
    ;label      bounds(0, 120, 190, 20), text("Amp Envelope"), colour(60, 60, 120, 122), fontcolour(0, 0, 0, 255)
      rslider    bounds(0, 25, 50, 50),  text("A"), channel("SG2_Env_Amp_A"), range(0.001, 3, .01, 1, 0.001), textcolour(0,0,0)
      rslider    bounds(50, 25, 50, 50), text("D"), channel("SG2_Env_Amp_D"), range(0.02, 3, 2, 1, 0.001), textcolour(0,0,0)
      rslider    bounds(100, 25, 50, 50),text("S"), channel("SG2_Env_Amp_S"), range(0.02, .99, .99, 1, 0.001), textcolour(0,0,0)
      rslider    bounds(150, 25, 50, 50),text("R"), channel("SG2_Env_Amp_R"), range(0.1, 3, .01, 1, 0.001), textcolour(0,0,0)
    }
  }

  groupbox bounds(200,0,200,200), $LAYER2_COLOR, text("RM"), fontcolour("black"){
    ;label      bounds(210, 5, 190, 20), text("AM"), colour(60, 60, 120, 122), fontcolour(0, 0, 0, 255)
    rslider    bounds(0, 25, 50, 50), text("Freq"), channel("SG2_RM_Frequency"), range(1, 8000, 1, .5, 1), textcolour(0,0,0)
    rslider    bounds(50, 25, 50, 50), text("Vol"), channel("SG2_RM_Volume"), range(0.001, 1, 0.01, 1, 0.001), textcolour(0,0,0)

    combobox   bounds(4, 75, 96, 25),items("ring" , "am", "chaos", "frozen"), channel("SG2_AM_Type"),$LAYER2_COLOR, fontcolour(0, 0, 0, 255)
    label      bounds(4, 105, 50, 11),text("AM Type"), $LAYER2_COLOR, fontcolour(0, 0, 0, 255)
    combobox   bounds(100, 75, 98, 25),items("sine" , "saw", "square", "triangle"), channel("SG2_AM_Wav"),$LAYER2_COLOR, fontcolour(0, 0, 0, 255)
    label      bounds(100, 105, 50, 11),text("AM Wav"), $LAYER2_COLOR, fontcolour(0, 0, 0, 255)

    ;label      bounds(0, 120, 190, 20), text("Ring Amp Envelope"), colour(60, 60, 120, 122), fontcolour(0, 0, 0, 255)
    groupbox bounds(2,120,196,78), $LAYER2_COLOR, text("RM_Envelope"), fontcolour("black"){
      rslider    bounds(0, 30, 50, 50),  text("A"), channel("SG2_Env_RM_A"), range(0.001, 3, .01, 1, 0.001), textcolour(0,0,0)
      rslider    bounds(50, 30, 50, 50),  text("D"), channel("SG2_Env_RM_D"), range(0.02, 3, 2, 1, 0.001), textcolour(0,0,0)
      rslider    bounds(100, 30, 50, 50),  text("S"), channel("SG2_Env_RM_S"), range(0.02, .99, .99, 1, 0.001), textcolour(0,0,0)
      rslider    bounds(150, 30, 50, 50),  text("R"), channel("SG2_Env_RM_R"), range(0.02, 3, 12, 1, 0.001), textcolour(0,0,0)
    }
  }

  groupbox bounds(400,0,100,100), $LAYER2_COLOR, text("Filter HP"), fontcolour("black"){
    ;label      bounds(410, 5, 90, 20),  text("Filter HP"), colour(60, 60, 120, 122), fontcolour(0, 0, 0, 255)
    rslider    bounds(0, 25, 50, 50), text("Freq"), channel("SG2_High_Pass_Frequency"), range(100, 16000, 100, 1, 0.001), textcolour(0,0,0)
    rslider    bounds(50, 25, 50, 50), text("Reas"), channel("SG2_High_Pass_Reasonance"), range(1, 200, 1, 1, 0.001), textcolour(0,0,0)
  }
  groupbox bounds(500,0,100,100), $LAYER2_COLOR, text("Filter LP"), fontcolour("black"){
    ;label      bounds(0, 5, 90, 20),  text("Filter LP"), colour(60, 60, 120, 122), fontcolour(0, 0, 0, 255)
    rslider    bounds(0, 25, 50, 50), text("Freq"), channel("SG2_Low_Pass_Frequency"), range(100, 16000, 16000, 1, 0.001), textcolour(0,0,0)
    rslider    bounds(50, 25, 50, 50), text("Reas"), channel("SG2_Low_Pass_Reasonance"), range(0.01, 1, 0, 1, 0.001), textcolour(0,0,0)
  }
  groupbox bounds(400,100,200,100), $LAYER2_COLOR, text("Filter Envelope"), fontcolour("black"){
    ;label      bounds(400, 120, 190, 20), text("Filter Envelope"), colour(60, 60, 120, 122), fontcolour(0, 0, 0, 255)
    rslider    bounds(0, 30, 50, 50),  text("A"), channel("SG2_Env_Filters_A"), range(0.001, 3, .01, 1, 0.001), textcolour(0,0,0)
    rslider    bounds(50, 30, 50, 50),  text("D"), channel("SG2_Env_Filters_D"), range(0.02, 3, 2, 1, 0.001), textcolour(0,0,0)
    rslider    bounds(100, 30, 50, 50),  text("S"), channel("SG2_Env_Filters_S"), range(0.02, .99, .99, 1, 0.001), textcolour(0,0,0)
    rslider    bounds(150, 30, 50, 50),  text("R"), channel("SG2_Env_Filters_R"), range(0.02, 3, 12, 1, 0.001), textcolour(0,0,0)
  }

}

image bounds(0, 500, 800, 100) colour(120, 69, 69, 255),plant("Master"){
label      bounds(0, 0, 190, 20), text("General"), colour(60, 60, 120, 122), fontcolour(0, 0, 0, 255)
rslider    bounds(0, 25, 50, 50),  text("Mix"), channel("SGMix"), range(0.0, 1, .5, 1, .01), textcolour(0,0,0)
;rslider    bounds(50, 25, 50, 50), trackerinsideradius(0.6), text("SG2"), channel("SG2 Amp"), range(0.0, .5, 0, 1, 0.001), textcolour(0,0,0)

label      bounds(200, 0, 190, 20), text("Chorus"), colour(60, 60, 120, 122), fontcolour(0, 0, 0, 255)
;rslider    bounds(0, 25, 50, 50), trackerinsideradius(0.6), text("Mix"), channel("SGMix"), range(0.0, 1, .5, 1, .01), textcolour(0,0,0)
;rslider    bounds(50, 25, 50, 50), trackerinsideradius(0.6), text("SG2"), channel("SG2 Amp"), range(0.0, .5, 0, 1, 0.001), textcolour(0,0,0)


label      bounds(400, 0, 190, 20), text("Reverb"), colour(60, 60, 120, 122), fontcolour(0, 0, 0, 255)
rslider    bounds(400, 25, 50, 50),  text("Size"), channel("Master_Reverb_Size"), range(0.0, 1, 0, .5, .01), textcolour(0,0,0)
rslider    bounds(450, 25, 50, 50),  text("Damp"), channel("Master_Reverb_Damp"), range(0.0, 1, 0, .5, .01), textcolour(0,0,0)
rslider    bounds(500, 25, 50, 50),  text("Mix"), channel("Master_Reverb_Mix"), range(0.0, 1, 0, .5, .01), textcolour(0,0,0)
rslider    bounds(550, 25, 50, 50),  text("Level"), channel("Master_Reverb_Level"), range(0.0, 1, 0, .5, .01), textcolour(0,0,0)


}

;gentable bounds(600, 100, 200, 200), tablenumber(1), identchannel("table"), active(1), samplerange(0,4096);, amprange(-0.5,1,-1,0.1) 

combobox bounds(0, 30, 100, 25), populate("*.snaps")
filebutton bounds(116, 30, 60, 25), text("Save"), populate("*.snaps"), mode("snapshot")
button bounds(20, 104, 150, 14), value(1), colour:1(0, 155, 0, 255), colour:0(155,0,0,255), channel("SG1_on_off"),identchannel("ID_SG1_on_off"), text("Sound Generator 1"), fontcolour:0("black"), fontcolour:1("black")

</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d -+rtmidi=NULL -M0 -m0d --midi-key-cps=4 --midi-velocity-amp=5 
</CsOptions>
<CsInstruments>
; Initialize the global variables.
ksmps = 32
nchnls = 2
0dbfs = 1

seed 0

;giWave ftgen 1, 0, 4096, -2,2, 0, 2, 0
;giSampleTime = 4096
;giFt   ftgen 1, 0, giSampleTime, 2, 0
giWave ftgen 1, 0, 4096, 10, 1, 1, 1, 1 

; =======================
; ||     OPCODES       ||
; =======================



; =======================
; || SOUND GENERATOR 1 ||
; =======================

;cpuprc 1,90
maxalloc 1,32
instr 1
  
; -----------------------
; | variable definition |
; -----------------------

  ; Waveform
  iSG1wavStr chnget "SG1_Wav"
  if iSG1wavStr == 1 then      ;sine
    chnset "active(0)", "ID_PWM"
    iSG1wav = 0
  elseif iSG1wavStr == 2 then  ;saw
    chnset "active(0)", "ID_PWM"
    iSG1wav = 0
  elseif iSG1wavStr == 3 then  ;square
    chnset "active(1)", "ID_PWM"
    iSG1wav = 2
  elseif iSG1wavStr == 4 then  ;triangle
    chnset "active(0)", "ID_PWM"
    iSG1wav = 4
  endif
  
  ; PWM
  kSG1PWM chnget "SG1_PWM"
  
  ; Phase
  kSG1Phase chnget "SG1_Phase"
  
  ; noise generator
  kSG1NoiseVolume chnget "SG1_Noise_Volume"
  
  ; Amp Envelope
  iSG1EnvAmpAttack chnget "SG1_Env_Amp_A"
  iSG1EnvAmpDecay chnget "SG1_Env_Amp_D"
  iSG1EnvAmpSustain chnget "SG1_Env_Amp_S"
  iSG1EnvAmpRelease chnget "SG1_Env_Amp_R"
  
  ; Ring Modulator
  kSG1RMFrequency chnget "SG1_RM_Frequency"
  kSG1RMVolume chnget "SG1_RM_Volume"
  
  ; Ring Modulator Envelope
  iSG1EnvRMAttack chnget "SG1_Env_RM_A"
  iSG1EnvRMDecay chnget "SG1_Env_RM_D"
  iSG1EnvRMSustain chnget "SG1_Env_RM_S"
  iSG1EnvRMRelease chnget "SG1_Env_RM_R"
  
  ; Low Pass
  kSG1FilterLpF chnget "SG1_Low_Pass_Frequency"
  kSG1FilterLpR chnget "SG1_Low_Pass_Reasonance"
  
  ; High Pass
  kSG1FilterHpF chnget "SG1_High_Pass_Frequency"
  kSG1FilterHpR chnget "SG1_High_Pass_Reasonance"
  
  ; Filter Envelope
  iSG1EnvFilterAttack chnget "SG1_Env_Filters_A"
  iSG1EnvFilterDecay chnget "SG1_Env_Filters_D"
  iSG1EnvFilterSustain chnget "SG1_Env_Filters_S"
  iSG1EnvFilterRelease chnget "SG1_Env_Filters_R"

; ---------------------------
; | end variable definition |
; ---------------------------
      
  ; generate ring modulator sine
  aSG1RMsine poscil kSG1RMVolume, kSG1RMFrequency, -1
  iSG1EnvRMRelease limit iSG1EnvRMRelease , 0.001, iSG1EnvAmpRelease ; release cannot be longer than amp env release
  kSG1EnvRM madsr iSG1EnvRMAttack, iSG1EnvRMDecay, iSG1EnvRMSustain, iSG1EnvRMRelease
  aSG1RM = aSG1RMsine * kSG1EnvRM
 
  ; generate SG1 sound with envelope
  kSG1EnvAmp madsr iSG1EnvAmpAttack, iSG1EnvAmpDecay, iSG1EnvAmpSustain, iSG1EnvAmpRelease
  aSG1 vco2 p5*kSG1EnvAmp, p4, iSG1wav, kSG1PWM, kSG1Phase
  
  ; generate SG1 noise
  aSG1Noise noise kSG1NoiseVolume, 0
  aSG1Noise = aSG1Noise * kSG1EnvAmp
  aSG1 = aSG1 + aSG1Noise
  
  ; apply ring modulation to SG1 sound
  aSG1RMsound = (aSG1RM * aSG1)
  aSG1 = (aSG1*(1-kSG1RMVolume))+aSG1RMsound
  
  ; apply LP  and HP filter 
  iSG1EnvFilterRelease limit iSG1EnvFilterRelease , 0.001, iSG1EnvAmpRelease ; release cannot be longer than amp env release
  kSG1EnvFilter madsr iSG1EnvFilterAttack, iSG1EnvFilterDecay, iSG1EnvFilterSustain, iSG1EnvFilterRelease
  aSG1FLp moogladder aSG1,kSG1FilterLpF * kSG1EnvFilter,kSG1FilterLpR
  aSG1FHp bqrez aSG1FLp, kSG1FilterHpF * kSG1EnvFilter, kSG1FilterHpR, 1
  aSG1Output balance aSG1FHp, aSG1
  
  
; =======================
; || SOUND GENERATOR 2 ||
; =======================



; -----------------------
; | variable definition |
; -----------------------
  ;print p5
  ; Waveform
  iSG2Wav chnget "SG2_Wav"
 
  ; PWM 
  kSG2PWM chnget "SG2_PWM"
  
  ; Phase
  kSG2Phase chnget "SG2_Phase"
  
  ; Amp Envelope
  iSG2EnvAmpAttack chnget "SG2_Env_Amp_A"
  iSG2EnvAmpDecay chnget "SG2_Env_Amp_D"
  iSG2EnvAmpSustain chnget "SG2_Env_Amp_S"
  iSG2EnvAmpRelease chnget "SG2_Env_Amp_R"
  
  ; Ring Modulator
  kSG2RMFrequency chnget "SG2_RM_Frequency"
  kSG2RMVolume chnget "SG2_RM_Volume"
  
  ; Ring Modulator Envelope
  iSG2EnvRMAttack chnget "SG2_Env_RM_A"
  iSG2EnvRMDecay chnget "SG2_Env_RM_D"
  iSG2EnvRMSustain chnget "SG2_Env_RM_S"
  iSG2EnvRMRelease chnget "SG2_Env_RM_R"
  
  ; Low Pass
  kSG2FilterLpF chnget "SG2_Low_Pass_Frequency"
  kSG2FilterLpR chnget "SG2_Low_Pass_Reasonance"
  
  ; High Pass
  kSG2FilterHpF chnget "SG2_High_Pass_Frequency"
  kSG2FilterHpR chnget "SG2_High_Pass_Reasonance"
  
  ; Filter Envelope
  iSG2EnvFilterAttack chnget "SG2_Env_Filters_A"
  iSG2EnvFilterDecay chnget "SG2_Env_Filters_D"
  iSG2EnvFilterSustain chnget "SG2_Env_Filters_S"
  iSG2EnvFilterRelease chnget "SG2_Env_Filters_R"
  
; ---------------------------
; | end variable definition |
; ---------------------------

  ; generate ring modulator sine
  aSG2RMsine poscil kSG2RMVolume, kSG2RMFrequency, -1
  iSG2EnvRMRelease limit iSG2EnvRMRelease , 0.001, iSG2EnvAmpRelease ; release cannot be longer than amp env release
  kSG2EnvRM madsr iSG2EnvRMAttack, iSG2EnvRMDecay, iSG2EnvRMSustain, iSG2EnvRMRelease
  aSG2RM = aSG2RMsine * kSG2EnvRM
  
  ; generate main oscilator
  aSG2Sine init 0
  kSG2EnvAmp madsr iSG2EnvAmpAttack, iSG2EnvAmpDecay, iSG2EnvAmpSustain, iSG2EnvAmpRelease
  if iSG2Wav == 1 then ; sine
    aSG2Sine poscil p5*kSG2EnvAmp, p4, -1
  elseif iSG2Wav == 2 then ; saw
    aSG2sine vco2 p5*kSG2EnvAmp, p4, 0 , kSG2PWM, kSG2Phase
  elseif iSG2Wav == 3 then ; square
    aSG2Sine vco2 p5*kSG2EnvAmp, p4, 2, kSG2PWM, kSG2Phase
  elseif iSG2Wav == 4 then ; triangle
    aSG2Sine vco2 p5*kSG2EnvAmp, p4, 4, kSG2PWM, kSG2Phase
  endif
  
  ; apply ring modulation
  if kSG2RMVolume > 0.001 then
    aSG2RMsound = (aSG2RM * aSG2sine)
    aSG2 = (aSG2Sine*(1-kSG2RMVolume))+aSG2RMsound
  else
    aSG2 = aSG2Sine 
  endif
  
  ;HP Filter
  iSG2EnvFilterRelease limit iSG2EnvFilterRelease , 0.001, iSG2EnvAmpRelease ; release cannot be longer than amp env release
  kSG2EnvFilter madsr iSG2EnvFilterAttack, iSG2EnvFilterDecay, iSG2EnvFilterSustain, iSG2EnvFilterRelease
  denorm aSG2
  aSG2FHp bqrez aSG2, kSG2FilterHpF * kSG2EnvFilter, kSG2FilterHpR, 1
 
  ;LP Filter
  denorm aSG2FHp
  aSG2FLp bqrez aSG2FHp,kSG2FilterLpF * kSG2EnvFilter,kSG2FilterLpR, 0
  aSG2Output = aSG2FHp
    


; =====================
; ||  Master Section ||  
; =====================


; -----------------------
; | variable definition |
; -----------------------
  
  ; general
  kSG1Amp chnget "SG1_Amp"
  kMix chnget "SGMix"
  
  ; reverb
  kMasterReverbSize chnget "Master_Reverb_Size"
  kMasterReverbDamp chnget "Master_Reverb_Damp" 
  kMasterReverbMix chnget "Master_Reverb_Mix"
  kMasterReverbLevel chnget "Master_Reverb_Level"
 
  
  ; mix knob left : only generator 1 sounds at 100% volume
  ; mix knob right : only generator 2 sounds at 100% volume
  ; mix knob middle: both generators sound at 50% volume each
 
  aoutL = (aSG1Output * (1.0 - kMix)) + (aSG2Output * kMix)
  aoutR = (aSG1Output * (1.0 - kMix)) + (aSG2Output * kMix)
  
  ; master output
  aMoutL = aoutL
  aMOutR = aoutL
  
; ---------------------------
; | end variable definition |
; ---------------------------
  
  ; enable Reverb only if room size is bellow 0
  kShoudlReverd = 0 
  if (kMasterReverbSize == 0) then
    aMOutL = aoutL
    aMOutR = aoutL
    outs aMOutL, aMOutR
  else
    ;denorm aMOutL
    ;denorm aMOutR
    aMOutL, aMOutR freeverb aoutL, aoutR, kMasterReverbSize, kMasterReverbDamp, 48000
    aMOutL = aMOutL + aoutL
    aMOutR = aMOutR + aoutR
    ; master output
    outs aMOutL, aMOutR
  endif
  
 
  ;chnset	"tablenumber(2)", "table"	; update table display
  
endin

instr 2
  if metro(4) == 1 then
    event "i", "updateGUI", 0, 1
  endif
endin

instr updateGUI
  
  iSG1wavStr chnget "SG1_Wav"
  iSG1onoff chnget "SG1_on_off"
  ;chnset "displaytype('waveform')","wavdisplay"
  if iSG1onoff == 0 then
    chnset "active(0)", "ID_Layer1"
    chnset "active(1)", "ID_SG1_on_off"
    ;chnset "active(0)", "ID_Sound_Generator_1"
  else
    chnset "active(1)", "ID_Layer1"
    ;chnset "active(1)", "ID_Sound_Generator_1"
  endif
  if iSG1wavStr == 1 then      ;sine
    chnset "active(0)", "ID_SG1_PWM"
    chnset "active(0)", "ID_SG1_Phase"
  elseif iSG1wavStr == 2 then  ;saw
    chnset "active(0)", "ID_SG1_PWM"
    chnset "active(0)", "ID_SG1_Phase"
  elseif iSG1wavStr == 3 then  ;square
    chnset "active(1)", "ID_SG1_PWM"
    chnset "active(1)", "ID_SG1_Phase"
  elseif iSG1wavStr == 4 then  ;triangle
    chnset "active(0)", "ID_SG1_PWM"
    chnset "active(0)", "ID_SG1_Phase"    
  endif
endin
</CsInstruments>
<CsScore>
;causes Csound to run for about 7000 years...
;f0 z
i1 0 z
i2 0 z
</CsScore>
</CsoundSynthesizer>

Sorry, I don’t have time right now to look into this in any great depth, but can you try commenting out the GUI update stuff to see if that helps?

I dont think its the gui , because i am triggering it from reason using the piano widget of reason without displaying my synth’s GUI and still I hear crackling noises because the CPU goes above 50%. I have a 3.4 Ghz quad core.

Does CSOUND suppose to be much slower than a VST ? I assumed because CSOUND csd file is not truly a script but rather an initialization file that the performance would be very good because everything is precomputed.

Take your time , I am in no rush. I will investigate this slowly myself. I will start testing CSOUND with triggering 128 notes at the same time.

I just tried this now, and I’m not seeing the same problems? I’m only using my laptop, which is i7 1.8Gz, 4 cores. Strange. Do you see the same issues when running in Cabbage? I move from .4 and 1% with release time set to 3%. Reaper craps outs because of distortions because I’m sweeping through so many notes at once.

The general rule of thumb is that Csound will run its code about a third slower than natively compiled code, which is still darn good to be fair.

I don’t think this will be an issue of you are using one of the oscil family of opcodes. In fact, as an experiment, try swapping out the vco2 opcodes with calls to a plain old oscili.

If you are using a band-limited vco2 then that might cause some issues (for lots and lots of notes). IIRC, each time you hit a note, vco2 will generate an anti-aliasing table for the vco opcode to read. I’m certain that it does this using highly optimised FFT operations, but it will inevitably cause some kind overhead?

Try swapping out the vco2’s and let us know…

I have the exact same issue running in Cabbage, I also tried several Cabbage examples and have the exact same problem.

Release time, if you mean my settings is counting in seconds not %.

If Reaper craps out that means you have the same problem, try a highly optimised VST and see CPU usage.

The numbers I am getting here is definetly not 30% slower is more like 3 times slower.

I will give a try on your vco2 advice, but I doubt that is the problem.

Sorry, I meant 3 seconds. Note sure how the % got there.

When I say “craps out” I just mean it mutes the channel, which Reaper does whenever a sound get too hot. The CPU meter never goes above 4.

Lets see. It has to make some difference considering oscili doesn’t have to pre-calculate any tables. FWIW, here is a screenshot of how things go for me with your instrument (although I realise it doesn’t help much!)

oops the code I gave I have limited the polyphony to 32 voices, I was testing some things and forgotten to comment this out please comment out line 184

maxalloc 1,32

it is not Reaper that mutes the channel its actually CSOUND because of that line it does not allow new notes unless the 32th voice is released. Once you comment this out you will hear all the cracking noises of a dropout and the cpu usage will double.

That line helped me avoid those crackling sounds.

And swapping out the vco2 opcodes? Does this help things?

nope oscili has the exact same problem , just tested it, not even the slightest diffirence

Ok. then it looks like it could be a Cabbage issue rather that Csound. Can you give me step by step instructions to recreate the problem. As you have seen from my screen-cast, I can’t get the same CPU Apocalypse here when I run your instrument…

1 Like

Well the good news is that I dont have to provide you with step by step, just go to example “Pad Synth” you provide with Cabbage, I just sweep fast through the octaves with the mouse mouse a couple of times and boom , audio dropouts, CPU goes to 40%.

Its not CPU Apocalypse because it does not consume the entire CPU, my OS is not slowing down or anything like that, 40% afterall is peanuts compared to when I play AAA games :smiley: but the audio dropouts are annoying obviously.

However there is another strange thing, If I select ASIO driver for my audio card , I get noise coming out of my monitors which I never experienced with any DAW. If I select MME MOTU , no noise. ASIO4ALL fails to find the card.

I also tried with my pro MOTU and standard iMac audio card, same issue

What processor do you have? My laptop is not that old, but I assume most desktops would kick its ass in terms of performance. As you can see, the PadSynth examples doesn’t present any issues for me.

you move your mouse too slow try much faster, like 10 times faster, at the speed you moving I get same peformance as well.

My computer is later 2013 27’’ iMac. So yeah its very old.Actually thanks for reminding me I will try when I get the chance to test this on my brother’s computer which is a modern one with powerful specs.

As much I would like to blame Cabbage, I don’t see why it would be a Cabbage issue in this case. I assume it does not interfere when the VST plays. Maybe a JUCE GUI problem but still I cannot see how that may be the case when I have the gui hidden and still experience the same issue.

I’ll try when I get a chance. Right now my battery is about to die and I’m travelling for the next few days so I’ll only be online with a phone. But keep me updated with anything you discover :+1:

1 Like

sure mate, If you are still on vacation have fun. If you are not, still have fun :smiley:

I will definitely investigate this.

I am also very curious to start testing with porting this directly to CSOUND API as well, I think it will be a big boost to speed. I read this morning a CSOUND journal on using wxWidgets with CSOUND via the CSOUND C API and ignited my interest again about combining QT with CSOUND.
http://www.csounds.com/journal/2006summer/wxCsound.html

lol just realised you wrote the article, wow you are a CSOUND veteran

hmm it seems as suspected this is a CSOUND problem , judging from this

if this dude has an issue with just a typical supersaw its no wonder I have such problems myself with even more voices (32 is basically the minimum for me after that I get audio dropouts) and he is dead wrong , 32 voices is nothing even for my 10 year old Yamaha Motif ES6 which can easily output 128 , it seems he experiences the exact same issue as I have.

Nonetheless I will keep investigating but from the looks of it CSOUND C API is my only ideal option right now.

Try writing a native Csound version outside of Cabbage to see if it also spikes with so many voices. If it does, then using the API directly won’t make any difference…

Did you get any further with this? I still can’t create the issue you are seeing, even if I play as fast as I can with the virtual MIDI keyboard.

I also went ahead and exported a simple vco2 based instrument into Reaper and stacked as many notes on top of each other as I could fit into the piano roll. I see no real issues in CPU in this way either.

I’m pretty sure my iMac at work is similarly spec-ed to yours. I will try this again there and let you know how I get on with it.

On my iMac (2013, 3.4GHz) this test drives me CPU up to 17 and if I leave it long enough I start to get dropouts…

not yet, I redesigned the synth with a more performance friendly concept but the fact you dont get any performance issues that is a big plus. Currently my synth does not work because of the redesign , as soon as I get to make sounds again I will test performance again and see what is going.