Cabbage Logo
Back to Cabbage Site

Csound and Cabbage beta - incompatibilities?

Hi Rory,
this is a follow up of our previous chat regarding some strange behaviour of the latest Cabbage betas ( after June 14 - #20210614.1 fixing guiMode for cabbageSetValue to June 25th).

  • on mac, reverting back from the later beta seems only possible by first deleting the old app (new installers no longer overwrite old ones)
  • somewhere between the dates above Cabbage installers start to come with Csound 6.16. In my instrument, I have audio dropouts only with Csound 6.16, not Csound 6.15. I have now isolated the source of these dropouts in the posted short code example. I hope you can help figure out what is going on.
  • the FFT display does no longer work with later beta. Could you please check the example?

This code works without dropouts with Csound 6.15 (regardless of Cabbage version). I’m not using ADSR because I want to dynamically change damping (sustain), but as you can here this makes no difference. As soon as you move metro or sustain slides you should be able to hear “pops” - with Csound 6.16. I suspect turnoff might be causing them. But not with Csound 6.15!
There are some buttons: (1) to switch off oscillator; the envelope alone is casuing pops, (2) “not dynamic” sustain uses linseg and also causes pops, (3) I tried to look at the signal, maybe you have suggestions if signal display could be triggered in a useful way to identify these pops.

<Cabbage>
form caption("test POP") size(400, 300), colour(0,0,0,100) guiMode("queue"), pluginId("def1")

rslider bounds(28, 138, 70, 70) range(0, 1, 0.2, 0.7, 1e-06) channel("MetroFrq") colour(255, 255, 0, 255)  trackerColour(255, 255, 100, 255) markerColour(0, 0, 0, 255) popupText("0")
label   bounds(22, 208, 80, 20) text("METRO") fontColour(255, 255, 0, 255) channel("label4")

rslider bounds(116, 138, 50, 50) range(0.0001, 10, 0.01, 0.25, 1e-06) channel("Attack") colour(255, 255, 220, 255) trackerColour(227, 176, 255, 255) markerColour(0, 0, 0, 255) popupText("0")
label   bounds(110, 188, 60, 16) text("ATTACK")  fontColour(227, 176, 255, 255) channel("label7")

rslider bounds(66, 14, 70, 70) range(0, 1, 0.7, 1, 1e-06) channel("Sustain") colour(100, 100, 150, 255) trackerColour(255, 255, 220, 255) markerColour(255, 255, 220, 255) popupText("0")
label   bounds(14, 84, 180, 20) text("DYNAMIC SUSTAIN")  fontColour(220, 220, 220, 255) channel("label10")

button bounds(276, 10, 30, 30) channel("NoOscil") text(" ") colour:1(255, 255, 0, 255)
label   bounds(204, 40, 180, 12) text("NO OSCILLATOR")  fontColour(220, 220, 220, 255) 

button bounds(276, 60, 30, 30) channel("UseEnvelope") text(" ") colour:1(255, 255, 0, 255)
label   bounds(202, 90, 180, 12) text("NOT DYNAMIC - using envelope")  fontColour(220, 220, 220, 255) 

button bounds(136, 234, 30, 30) channel("Display") text(" ") value(0) colour:1(255, 255, 0, 255)
label   bounds(118, 266, 50, 12) text("DISPLAY")  fontColour(220, 220, 220, 255) channel("label19")

signaldisplay bounds(174, 150, 221, 148), updateRate(20)  displayType("waveform"), signalVariable("a1") zoom(-1) colour(0, 255, 0, 255), backgroundColour("black")

hslider  bounds(174, 124, 220, 23), channel("NPeriods"), text("Number-Periods"),range(1, 1000, 800, 1, 1) popupText("0")

</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-d -n -+rtmidi=null -M0 -m0d --displays
</CsOptions>
<CsInstruments>

ksmps = 16
nchnls = 2
0dbfs = 1

giSin ftgen 0,0,2^19,10,1	; sin

instr 1
kMetroFrq = 20*cabbageGet:k("MetroFrq")
kAtt = cabbageGetValue:k("Attack")
gkDamp = 1e-4*ksmps*(1-0.9*cabbageGet:k("Sustain")) * (1 + kMetroFrq)

if timeinstk:k() > 1 && metro:k(kMetroFrq) == 1 then
event "i", "Note", 0, 180, kAtt, cabbageGetValue:k("NoOscil"), cabbageGetValue:k("UseEnvelope")
endif

a1 chnget "mix"
chnclear "mix"


; ---- display
if cabbageGetValue:k("Display") == 1 then

kNPeriods chnget "NPeriods"
iprd init 100/sr
if changed(kNPeriods)==1 then 
    reinit	RESTART_DISP    
endif

RESTART_DISP:
inprds = i(kNPeriods)
display a1, iprd, inprds
rireturn

display a1, .1, 1
endif

outs a1, a1
endin


;--------------------------------------------------------
instr Note
ka = active:k("Note")/32 ; count notes

kH init 1
kenv = linseg:k(0, p4, 1);

if p6 == 0 then ; dynamic damping
kH *= 0.99995*(1-gkDamp) 
else
kH = linseg:k(1, .005/i(gkDamp), 0) ;use non-dynamic envelope
endif


if p5 == 0 then
a1 = oscili(.5, 440 + ka*440, giSin, 0)
a1 = a(kH*kenv)*a1
else
a1 = a(kH*kenv)
endif

chnmix    a1, "mix"


if kH<1e-5 then
    turnoff
endif

endin

</CsInstruments>
<CsScore>
;causes Csound to run for about 7000 years...
f0 z
i 1 0 -1;[60*60*24*7]
</CsScore>
</CsoundSynthesizer>

--------- And here is an example with FFT display that works with older Cabbage but not with the later betas. I hope you can make it work again.

form caption("test display") size(390, 660) pluginId("ted1") colour(0, 0, 0)


<Cabbage>

rslider bounds(8, 6, 60, 60) range(1, 10000, 440, 0.5, 0.001) channel("Frq") text("Frq") 

; --- DISPLAY SIGNAL
signaldisplay bounds(0, 212, 365, 180),  updateRate(20)  displayType("waveform"), signalVariable("aSig") zoom(-1) colour(0, 255, 0, 255), backgroundColour("black")

image    bounds(6, 392, 361, 45), plant("display"), colour(0, 0, 0, 0)
{
hslider  bounds(0, 19, 315, 19), channel("NPeriods"), text("Number-Periods"),range(1, 500, 100, 1, 1) popupText("0")
}

; --- DISPLAY SPECTRUM
; use x/y coordinates for mouse, size of this is re-defined in the init step 
gentable outlineThickness(0), bounds(0, 442, 365, 160), sampleRange(0, 512) ampRange(0.0, 1.0, 0.0, 0.0100) identChannel("ampFFT") tableNumber(1.0), tablebackgroundColour(0, 0, 0, 255), tableGridColour(245, 245, 245, 20), outlineThickness(0), tableColour:0(0, 200, 0, 200)

image    bounds(6, 608, 356, 45), plant("display"), colour(0, 0, 0, 0)
{
hslider  bounds(0, 0, 242, 19), channel("Yzoom"), text("Y Zoom"), textBox(1), valuetextBox(1), range(1e-3,1e3,1,.1,1e-6)
hslider  bounds(0, 19, 242, 19), channel("smooth"), text("Smooth"),  textBox(1), valuetextBox(1), range(0,5,0.5)
label    bounds(250, 0, 60, 12), text("FFT Size")  
combobox bounds(252, 15, 55, 18), channel("FFTSize"), text("64","128","256","512", "1024", "2048", "4096", "8192"), value(5)
}

label bounds(-132, 378, 60, 13), align("left"), identChannel("MOUSEFreqID"), , fontColour(0, 0, 0, 255), colour(255, 255, 255, 255)

</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d -+rtmidi=NULL --displays
</CsOptions>
<CsInstruments>

;sr is set by the host
sr = 44100
ksmps 	=  32
nchnls 	= 	2
0dbfs	=	1

giFFTSizes[]	fillarray	64,128,256,512,1024,2048,4096,8192

instr 1
kFrq = chnget:k("Frq")
aSig = oscili(1, kFrq)

iDispX init 0
iDispY init 430
iDispWidth init 365
iDispHeight init 170
iDispRange init 512

Sstring	sprintfk	"bounds(%d,%d,%d,%d), samplerange(0,%d)", iDispX, iDispY, iDispWidth, iDispHeight, iDispRange
chnset Sstring, "ampFFT" 

kNPeriods     chnget  "NPeriods"
kYzoom      chnget  "Yzoom"
kSmooth     chnget  "smooth"
kFFTIndex	chnget	"FFTSize"
kFFTSize	=		giFFTSizes[kFFTIndex-1]
kFFTSize	init	512
  
iprd init 20/sr

if changed(kNPeriods)==1 then 
    reinit	RESTART_DISP    
endif

RESTART_DISP:
inprds = i(kNPeriods)
display aSig, iprd, inprds
rireturn

if changed(kFFTSize)==1 then
  reinit	RESTART_FFT
endif
RESTART_FFT:
iTabSize	=	i(kFFTSize)
iampFFT		ftgen	1,0,iTabSize,2,0
rireturn 
/* FFT ATTRIBUTES */

ifftsize	=	iTabSize*2
ioverlap	=	ifftsize/4
iwinsize	=	ifftsize
iwintype	=	1

fSig	pvsanal	aSig*kYzoom, ifftsize, ioverlap, iwinsize, iwintype
fSig2	pvsblur fSig,kSmooth,5

if	metro(10)==1 then
  kflag	pvsftw fSig2, iampFFT
endif
 
if kflag==1 then
 	 chnset	"tablenumber(1)", "ampFFT"
endif

  
; Frequency pop-up
kMOUSE_X	chnget	"MOUSE_X"
kMOUSE_Y	chnget	"MOUSE_Y"
 if changed(kMOUSE_X,kMOUSE_Y)==1 then
 if kMOUSE_X>iDispX && kMOUSE_X<(iDispX+iDispWidth) && kMOUSE_Y>iDispY && kMOUSE_Y<(iDispY+iDispHeight) then
   kMOUSEFreq	=	((kMOUSE_X-iDispX)/iDispWidth) * (10900 * (2*iDispRange/kFFTSize)); calibration constant is about 10900
   Spos	sprintfk	"pos(%d,%d), text(%d Hz), visible(1)",limit:k(kMOUSE_X,iDispX,iDispX+iDispWidth-60),kMOUSE_Y-13,kMOUSEFreq ; subtract size of MOUSEFreqID
  		chnset		Spos,"MOUSEFreqID"
  else
   		chnset		"visible(0)","MOUSEFreqID"
  endif
 endif
 
endin

</CsInstruments>
<CsScore>
;causes Csound to run for about 7000 years...
f0 z
i 1 0 [3600*24*7]
</CsScore>

</CsoundSynthesizer>

I think you are right. Check this issue. I think this bug made its way into 6.16 :thinking:

p.s. I just checked the signaldisplay .csd from the widgets example and it’s working fine for me :thinking:

Thanks for the link, I’ll check. It is the FFT that fails not the time-domain.

The fft in the signaldisplay example works fine. Maybe we are talking about different examples?

Yes, I saw that. I can’t see why my example stopped working after some Cabbage evolution. Of course I’ll try to redo my homework, but I just can’t figure it out. Please let me know if you notice something in my example.

I’m going to take a look now…

Should it not be tableNumber(1) :thinking:

Great! Thanks! Would it be possible (or make sense) to include the Csound fix of the turnoff issue in the Cabbage beta installer? For my use case this is quite a bad bug, since I’m dynamically deciding when to turn instruments off. Maybe you have a suggestion for a workaround?

I don’t have a build that I can include. I think I might ask the devs to put out a minor release as this is a biggie…

Doesn’t seem to make a difference - just tried. Note that this works with older Cabbage.

Works fine for me:

2021-06-26 19.13.02

Good! Hmmm…

… and I just crashed Cabbage by changing FFT size…

One thing at a time, does tableNumber() work for you or not? Because if it is still not showing the FFT for you there is something wrong…

not showing FFT and the table size

I just reinstalled the entire latest package after deleting the previous installation. Still no FFT display and crashing when changing FFT Size.

I’m just downloading now…

Btw, can you send me the code you just tried?

It is the same as posted above.

So you didn’t change anything after I explained where the error was?