# Flickering!

**URL:** <https://forum.cabbageaudio.com/t/flickering/3683>\
**Category:** Csound Noobs\
**Created:** [15 April 2023 09:48 UTC](https://forum.cabbageaudio.com/t/flickering/3683 "2023-04-15T09:48:35Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![cinephos](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/cinephos/32/4698_2.png) [@cinephos](https://forum.cabbageaudio.com/u/cinephos)\
**Post date:** [15 April 2023 09:48 UTC](https://forum.cabbageaudio.com/t/flickering/3683/1 "2023-04-15T09:48:35Z")

</div>

I have customized the `FFTSpectrum.csd` example, removed all unnecessary commands and used `guiMode("queue")` successfully. I experience a strange flickering problem. The fft spikes on the display flicker! I suggest that the problem is related with csound internal triggers because it happens when signal’s amp and freq come from MIDI, for example

```
 aSig vco2 p5, p4

```

On the other hand, FFT spikes are steady when I set them up numerically in the orc section, for example

```
 aSig vco2 .7, 220

```

Here is a copy of all significant commands

```
<Cabbage>
form caption("FFT Spectrum"), size(610,570), colour( 50, 50, 50), pluginId("spec"), guiMode("queue")
gentable outlineThickness(1), bounds( 0, 0, 610,300), tableNumber(1), tablebackgroundColour("white"), tableGridColour(100,100,100,50), tableColour(0,0,200,200), channel("ampFFT"), ampRange(0,1,-1), outlineThickness(0), sampleRange(0, 512), zoom(-1) 
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d -+rtmidi=NULL -M0 --midi-key-cps=4 --midi-velocity-amp=5
</CsOptions>
<CsInstruments>
ksmps = 32
nchnls = 2
0dbfs = 1
;...
instr 1
;...
; signal generation
 aSig vco2 p5, p4
;...
 if metro(16)==1 then
  kflag pvsftw fSig2, iampFFT
 endif
 if kflag==1 then
  cabbageSet	1, "ampFFT", "tableNumber", 1	; update table display
 endif
;...
endin

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

```

---

<div class="post-metadata">

**Author:** ![rorywalsh](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/rorywalsh/32/165_2.png) [@rorywalsh](https://forum.cabbageaudio.com/u/rorywalsh)\
**Post date:** [15 April 2023 12:14 UTC](https://forum.cabbageaudio.com/t/flickering/3683/2 "2023-04-15T12:14:34Z")

</div>

Can you post a working example that illustrates the problem?

---

<div class="post-metadata">

**Author:** ![cinephos](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/cinephos/32/4698_2.png) [@cinephos](https://forum.cabbageaudio.com/u/cinephos)\
**Post date:** [15 April 2023 18:11 UTC](https://forum.cabbageaudio.com/t/flickering/3683/3 "2023-04-15T18:11:13Z")

</div>

Allow me to upload a short video for today demonstrating the problem.  
(a bit frustrated and rushing… the flickering part doesn’t last long. My ubuntu laptop crashed while recording twice…)

I’ll test some ideas before posting the code.  
ifreq init p5… etc, still produces flicker  
store values to a cabbage widget and get them from there is another idea for tomorrow.  
M.

---

<div class="post-metadata">

**Author:** ![cinephos](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/cinephos/32/4698_2.png) [@cinephos](https://forum.cabbageaudio.com/u/cinephos)\
**Post date:** [15 April 2023 21:09 UTC](https://forum.cabbageaudio.com/t/flickering/3683/4 "2023-04-15T21:09:55Z")

</div>

[test\_FFT\_solved.csd](https://forum.cabbageaudio.com/uploads/short-url/p7OiWdmuRZRaWz3ntnj9WRwvAks.csd) (3.1 KB) [test\_FFT.csd](https://forum.cabbageaudio.com/uploads/short-url/8qOvKTAjRK96xuiGd4YmgZsZp7o.csd) (3.1 KB)

I found a workaround. Can you explain it? Please? I’m afraid it is a Cabbage related issue.

`test_FFT.csd` flickers.  
`test_FFT_solved.csd` flickers not!  
Their difference is in the score!  
`i1 0 z` flickers!  
My solution was to add a dummy note `i1 0 2 220 .01` after which the keyboard notes’ (either from virtual keyboard or real MIDI keyboard) FFT analysis is displayed as expected.

(PS: Sounds are also audible. You have to turn the Audio gain rslider.)

---

<div class="post-metadata">

**Author:** ![rorywalsh](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/rorywalsh/32/165_2.png) [@rorywalsh](https://forum.cabbageaudio.com/u/rorywalsh)\
**Post date:** [16 April 2023 07:48 UTC](https://forum.cabbageaudio.com/t/flickering/3683/5 "2023-04-16T07:48:53Z")

</div>

I suspect the issue is that in test\_FFT.csd instrument 1 is always on, even if you are not playing any notes. So when you play a note, the two instances compete to display the spectrum. I believe this is the problem, although I’ve not had a chance to look over the code in much detail. I’ll be back to all things Cabbage tomorrow, I can take a deeper look then if you’ve not figure it out. 👍

---

<div class="post-metadata">

**Author:** ![cinephos](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/cinephos/32/4698_2.png) [@cinephos](https://forum.cabbageaudio.com/u/cinephos)\
**Post date:** [16 April 2023 08:31 UTC](https://forum.cabbageaudio.com/t/flickering/3683/6 "2023-04-16T08:31:24Z")

</div>

A score without an `i1` statement does not activate the instrument. I need an `i1` statement. I discovered that the score statement `i1 0 0 220 0` also works. The FFT is displayed correctly.  
I have no further experience to say when the program terminates after this command.  
It seems that it continues and expects a midi note. For how long, I don’t know.

---

<div class="post-metadata">

**Author:** ![rorywalsh](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/rorywalsh/32/165_2.png) [@rorywalsh](https://forum.cabbageaudio.com/u/rorywalsh)\
**Post date:** [16 April 2023 08:35 UTC](https://forum.cabbageaudio.com/t/flickering/3683/7 "2023-04-16T08:35:45Z")

</div>

> [@cinephos](#):
>
> A score without an `i1` statement does not activate the instrument.

It does, and it’s expected because the instrument is being triggered via MIDI. You can both hear the results, and see them in the output console. However, for some reason the FFT is not displaying. I haven’t had a chance to see why, but I have a feeling you have it figured out before I do 🙂

---

<div class="post-metadata">

**Author:** ![cinephos](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/cinephos/32/4698_2.png) [@cinephos](https://forum.cabbageaudio.com/u/cinephos)\
**Post date:** [16 April 2023 09:12 UTC](https://forum.cabbageaudio.com/t/flickering/3683/8 "2023-04-16T09:12:54Z")

</div>

The csound is activated, ok. This fft needs the instrument and this `cabbageSet` message to show something. But I would like to know when the gentable widget is activated. When the grid lines are drawn?  
`f0 z` is not enough to see the grid lines.  
My experiments showed that the instrument seems to be activated from the note on message till the note off + release time. This is the period that the mouse over routine works. Grid and spikes of the display remain after the instrument is idle.  
Then I tried to experiment with a command `i1 0.5 2 220 1` Well …( 🥁 🥁 🥁) … the mouse over works from t=0.5 to t=2+release time, but the FFT display is empty. No grid lines, not nothing. Not before the command, not during the command (it is executed, console says), nor after! 🤔 🤒

---

<div class="post-metadata">

**Author:** ![rorywalsh](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/rorywalsh/32/165_2.png) [@rorywalsh](https://forum.cabbageaudio.com/u/rorywalsh)\
**Post date:** [16 April 2023 11:26 UTC](https://forum.cabbageaudio.com/t/flickering/3683/9 "2023-04-16T11:26:55Z")

</div>

It might be best to put the fft display stuff into an instrument that is always on, and then pipe the audio to it using named channels.

---

<div class="post-metadata">

**Author:** ![cinephos](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/cinephos/32/4698_2.png) [@cinephos](https://forum.cabbageaudio.com/u/cinephos)\
**Post date:** [16 April 2023 18:01 UTC](https://forum.cabbageaudio.com/t/flickering/3683/10 "2023-04-16T18:01:15Z")

</div>

Do you mean  
connect alwayson outleta inleta…

---

<div class="post-metadata">

**Author:** ![rorywalsh](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/rorywalsh/32/165_2.png) [@rorywalsh](https://forum.cabbageaudio.com/u/rorywalsh)\
**Post date:** [16 April 2023 19:49 UTC](https://forum.cabbageaudio.com/t/flickering/3683/11 "2023-04-16T19:49:09Z")

</div>

No I mean start it in the score with a z or extremely long duration, and then send audio to it using chnset/chnget…

---

<div class="post-metadata">

**Author:** ![cinephos](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/cinephos/32/4698_2.png) [@cinephos](https://forum.cabbageaudio.com/u/cinephos)\
**Post date:** [17 April 2023 08:26 UTC](https://forum.cabbageaudio.com/t/flickering/3683/12 "2023-04-17T08:26:17Z")

</div>

This solution leads to a different problem.  
When FFT display is part of an instrument listening to the midi port, it seems that pvs opcodes stop working as soon as the noteoff message is received.

I tried an always on FFT display instrument. I was able to chnset and chnget the audio signal, but I could not control when to stop. The FFT display instead of freezing at the last (correct) pvs analysis, it continues to receive audio signal with undesirable effect.

I tried to control with the following code

```
 koff release
 if (koff!=1) then
  chnset aSig, "FFT" 
 endif

```

but it did not work. Not sure what can I do…

---

<div class="post-metadata">

**Author:** ![rorywalsh](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/rorywalsh/32/165_2.png) [@rorywalsh](https://forum.cabbageaudio.com/u/rorywalsh)\
**Post date:** [17 April 2023 09:24 UTC](https://forum.cabbageaudio.com/t/flickering/3683/13 "2023-04-17T09:24:51Z")

</div>

> [@cinephos](#):
>
> When FFT display is part of an instrument listening to the midi port, it seems that pvs opcodes stop working as soon as the noteoff message is received.

No, that’s not quite what I had in mind. I was thinking more along the lines of:

```
instr 1
   a1 oscili p5, p4
   outs a1, a1
   chnset a1, "synthOutput"
endin

instr 1000; //start in score to run for a long time..
   aSig chnget "synthOutput"
   //do FFT with this signal..
endin 

```

That should do the trick 👍

---

<div class="post-metadata">

**Author:** ![cinephos](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/cinephos/32/4698_2.png) [@cinephos](https://forum.cabbageaudio.com/u/cinephos)\
**Post date:** [17 April 2023 09:37 UTC](https://forum.cabbageaudio.com/t/flickering/3683/14 "2023-04-17T09:37:15Z")

</div>

This is what I did. But when noteoff message arrives, the fft continues.

When the FFT is inside the instrument, it goes like this:

This is the desired result, which I cannot get. That’s why I said, I cannot stop chnset optcode.

---

<div class="post-metadata">

**Author:** ![rorywalsh](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/rorywalsh/32/165_2.png) [@rorywalsh](https://forum.cabbageaudio.com/u/rorywalsh)\
**Post date:** [17 April 2023 09:40 UTC](https://forum.cabbageaudio.com/t/flickering/3683/15 "2023-04-17T09:40:11Z")

</div>

Ah, you need to use `chnclear` in your fft display instrument to clear the channel…

---

<div class="post-metadata">

**Author:** ![cinephos](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/cinephos/32/4698_2.png) [@cinephos](https://forum.cabbageaudio.com/u/cinephos)\
**Post date:** [17 April 2023 10:19 UTC](https://forum.cabbageaudio.com/t/flickering/3683/16 "2023-04-17T10:19:55Z")

</div>

Thank you!!! 😍  
I didn’t know that. (In fact, I learned tooo many things 👨‍🎓 by this conversation). It is time to stop this thread, and move on!

Now the FFT display fades out (because of the smoothing).  
`chnclear` works both ways:  
a) Either at the end of the FFT instrument as you suggested, or  
b) in the sending instrument, like this:

```csd
 koff release
 if (koff!=1) then
  chnset aSig, "FFT" 
 else
  chnclear "FFT"
 endif

```

The advantage of (a) is that the FFT works during the release time.
