Cabbage Logo
Back to Cabbage Site

Continuous display of audio data

Hi!
I’d like to display the amplitude of my input signal in real-time as shown in this video at 00:16: https://youtu.be/aLdyFhaCbKA

As you can see the display is scrolling towards a direction and the input is written immediately, moving the index in which is saved sample-per-sample. That graph in the video have been made with Max Jitter/OpenGL object jit.gl.graph.

This topic have previously privately discussed with Rory.

Thank you very much!

Rory provided this code:

<Cabbage>
form caption("Untitled") size(400, 300), colour(58, 110, 182), pluginid("def1")

gentable bounds(2, 6, 393, 199), tablenumber(1), fill(0), identchannel("table1")
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d -+rtmidi=NULL -M0 -m0d 
</CsOptions>
<CsInstruments>
; Initialize the global variables. 
ksmps = 64
nchnls = 2
0dbfs = 1

instr 1
    a1 inch 1
    aRand randi 1, 200
    kSig downsamp aRand

    kIndex linseg 256, 10, 0, 0, 0
    tabw kSig, kIndex, 1

    kCnt = 256
    if metro(10) == 1 then
        if kIndex == 0 then
            while kCnt>0 do
                kSample tab kCnt-1, 1
                tabw kSample, kCnt, 1 
                kCnt-=1
            od
        endif
        chnset "tablenumber(1)", "table1"
    endif
endin

</CsInstruments>
<CsScore>
f1 0 256 7 0 256 0
;causes Csound to run for about 7000 years...
f0 z
;starts instrument 1 and runs it for a week
i1 0 [60*60*24*7] 
</CsScore>
</CsoundSynthesizer>

which works very close to the result I’d like to obtain.
It’s a little slow in drawing, so I’ve raised the metro to (50) and set the ksmps = 16.

The other problem is that the downsample opcode seems to cause the signal to not be written correctly. I tried to substitute the random function with my input “inch 1” but there are strange glitches: the correct peak is shown for an instant and erased a moment after.
For instance, tapping on my computer’s mic I should see a very high peak on the graph, but I don’t.
Also when tapping at my highest continuously to see when and what it is drawing it seems to pick the peaks very randomly, again for the downsample opcode probably.

Thank you again!

Ok, I can try to make some changes here. For now I was just curious to see if this was heading in the right direction! I would probably write a UDO so I can run ksmps as 1. I will try that for you later.

Awesome, very nice from you, thank you so much!

How about this one. I tested with live mic input and it seems to work ok better now, but perhaps still not quite good enough…

<Cabbage>
form caption("Scrolling waveform") size(400, 300), colour(58, 110, 182), guiresfresh(32), pluginid("def1")

gentable bounds(2, 6, 393, 199), tablenumber(1), fill(0), identchannel("table1")
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d -+rtmidi=NULL -M0 -m0d 
</CsOptions>
<CsInstruments>
; Initialize the global variables. 
ksmps = 64
nchnls = 2
0dbfs = 1


opcode ScrollTable, 0, aikiS
    setksmps 1
    aSig, iTable, kRate, iScrollPoint, SChannel xin
    kSig = aSig
    kIndex linseg ftlen(iTable), 5, iScrollPoint, 0, iScrollPoint
    tabw kSig, kIndex, 1
    STableString sprintf "tablenumber(%d)", iTable

    kCnt = ftlen(iTable)
    if metro(kRate) == 1 then
        if kIndex == iScrollPoint then
            while kCnt>iScrollPoint do
                kSample tab kCnt-1, 1
                tabw kSample, kCnt, 1 
                kCnt-=1
            od
        endif
        chnset STableString, SChannel
    endif
endop


instr 1
    a1 inch 1
                ;sig    table   update rate     scroll point    table channel
    ScrollTable a1,     1,      32,             64,             "table1"
endin

</CsInstruments>
<CsScore>
f1 0 256 7 0 256 0
;causes Csound to run for about 7000 years...
f0 z
;starts instrument 1 and runs it for a week
i1 0 [60*60*24*7] 
</CsScore>
</CsoundSynthesizer>

It seems better but still imprecise and the glitch is always there. It should work since you set the ksmps to 1…
Don’t know :confused:

What about this one. When I play it I don’t see any issues with peaks be misrepresented? Sorry, I don’t have a mic right now because I moved location! But I have a feeling that the update rates really aren’t high-res enough for what you want. Note that the peaks are those which Csound records directly into a table. If Cabbage misses some of these it’s due to the screen res or size of the widget. Can you try changeing the dimensions of the widgets to see if anything improves?

<Cabbage>
form caption("Scrolling waveform") size(400, 300), colour(58, 110, 182), guiresfresh(32), pluginid("def1")

gentable bounds(2, 6, 393, 199), tablenumber(1), fill(0), identchannel("table1")
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d -+rtmidi=NULL -M0 -m0d 
</CsOptions>
<CsInstruments>
; Initialize the global variables. 
ksmps = 64
nchnls = 2
0dbfs = 1


opcode ScrollTable, 0, aikiS
    setksmps 1
    aSig, iTable, kRate, iScrollPoint, SChannel xin
    kSig = aSig
    kIndex linseg ftlen(iTable), 5, iScrollPoint, 0, iScrollPoint
    tabw kSig, kIndex, 1
    STableString sprintf "tablenumber(%d)", iTable

    kCnt = ftlen(iTable)
    if metro(kRate) == 1 then
        if kIndex == iScrollPoint then
            while kCnt>iScrollPoint do
                kSample tab kCnt-1, 1
                tabw kSample, kCnt, 1 
                kCnt-=1
            od
        endif
        chnset STableString, SChannel
    endif
endop


instr 1
    a1 inch 1
    a1 = oscili(1, 200)*tab(phasor:a(1), 2, 1)
                ;sig    table   update rate     scroll point    table channel
    ScrollTable a1,     1,      32,             64,             "table1"
endin

</CsInstruments>
<CsScore>
f2 0 1024 7 0 256 1 [256*3] 0 
f1 0 256 7 0 256 0
;causes Csound to run for about 7000 years...
f0 z
;starts instrument 1 and runs it for a week
i1 0 [60*60*24*7] 
</CsScore>
</CsoundSynthesizer>

Hi,

Here is the code Rory provided with little tweaks to update the syntax and scroll from left to right with no margin. I’m sure it can be improved, please let me know if you see how it could be improved, but it’s already working well!

<Cabbage>
form caption("Scrolling waveform") size(400, 300), colour(58, 110, 182), guiMode("queue"), pluginid("def1") 

gentable bounds(2, 6, 393, 199), tableNumber(1), fill(0), channel("table1")
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d -+rtmidi=NULL -M0 -m0d 
</CsOptions>
<CsInstruments>
; Initialize the global variables. 
ksmps = 64
nchnls = 2
0dbfs = 1


opcode ScrollTable, 0, aikiS
    setksmps 1
    aSig, iTable, kRate, iScrollPoint, SChannel xin
    kSig = aSig
    kCnt = 0
    kIndex linseg 0, 8, ftlen(iTable), 0, ftlen(iTable)
 
    if metro(kRate) == 1 then
        tabw kSig, kIndex, 1
        if kIndex == ftlen(iTable) then
            while kCnt<ftlen(iTable) do
                kSample tab kCnt+1, 1
                tabw kSample, kCnt, 1 
                kCnt+=1
            od
        endif
    endif
    
endop

instr drawGentable
    cabbageSet      "table1", "tableNumber", 1
endin
instr 1
    a1 inch 1
    
    a1 = oscili(1, 200)*tab(phasor:a(1), 2, 1)
    ;a1 follow2 a1, 0.01, 0.01
    ScrollTable a1,     1,      32,             0,             "table1"
                ;sig    table   update rate     scroll point    table channel
    event "i", "drawGentable" , 0, 0.0008
    
    outs a1, a1
endin

</CsInstruments>
<CsScore>
f2 0 1024 7 0 256 1 [256*3] 0 
f1 0 256 7 0 256 0
;causes Csound to run for about 7000 years...
f0 z
;starts instrument 1 and runs it for a week
i1 0 [60*60*24*7] 
</CsScore>
</CsoundSynthesizer>

Ha, I’m looking forward to testing this. The last post was 5 years ago :joy: