Cabbage Logo
Back to Cabbage Site

Gentable logarithmic scaling

Hello, I have a problem concerning the gentable widget. I’m working to create a graphic filter/EQ using the trfilter opcode. I’ve succeeded in getting the program to filter the sound so far with cutoff and octave-based slope controls, and in getting a gentable to display in real-time the filter slope. However, the current display is linear from 20hz to 20khz and I wish to scale it such that the spectrum is non-linear and the slope (octaves) is visually consistent across the frequency spectrum, similar to an EQ such as iZotope Neutron EQ.

<Cabbage>
form caption("Filter") size(300, 250), colour(100, 100, 100), pluginid("def1")
groupbox bounds(0, 150, 150, 100) colour(0, 0, 0, 0) outlinethickness(2)  linethickness(2)
groupbox bounds(150, 150, 150, 100) colour(0, 0, 0, 0) outlinethickness(2)  linethickness(2)

rslider bounds(10, 180, 70, 60), channel("cutoff"), range(20, 20000, 2000, 0.4, 0.01), text("Cutoff"), trackercolour(255, 255, 255, 255), outlinecolour(0, 0, 0, 50), textcolour(0, 0, 0, 255) 
rslider bounds(70, 180, 35, 60), channel("res"), range(0, 1, 1, 1, 0.01), text("Res"), trackercolour(255, 255, 255, 255), outlinecolour(0, 0, 0, 50), textcolour(0, 0, 0, 255) 
rslider bounds(105, 180, 35, 60), channel("slope"), range(0, 1, 0.25, 1, 0.01), text("Slope"), trackercolour(255, 255, 255, 255), outlinecolour(0, 0, 0, 50), textcolour(0, 0, 0, 255) 
rslider bounds(160, 180, 70, 60), channel("gain"), range(0, 1, 0.5, 1, 0.01), text("Gain"), trackercolour(255, 255, 255, 255), outlinecolour(0, 0, 0, 50), textcolour(0, 0, 0, 255) 
rslider bounds(220, 180, 70, 60), channel("mix"), range(0, 1, 1, 1, 0.01), text("Mix"), trackercolour(255, 255, 255, 255), outlinecolour(0, 0, 0, 50), textcolour(0, 0, 0, 255) 
gentable bounds(0, 0, 300, 150) identchannel("filterview") amprange(0.05, 2.0, 2.0, 0.0100) samplerange(20, 20000) tablenumber(2.0)  fill(0)  outlinethickness(2) tablecolour:0(255, 255, 255, 255)
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d -+rtmidi=NULL -M0 -m0d 
</CsOptions>
<CsInstruments>
; Initialize the global variables. 
ksmps = 32
nchnls = 2
0dbfs = 1
giFilter ftgen 2, 0, sr/2, 7, 0, 0, 0

instr 1
kCutoff chnget "cutoff"
kRes chnget "res"
kSlope chnget "slope"
kGain chnget "gain"
kMix chnget "mix"

if changed(kCutoff, kRes, kGain, kSlope) == 1 then
    event "i", 2, 0, 0, kCutoff, kRes, kSlope
endif

a1 vco2 0.2, 262 ;test signal
a2 vco2 0.2, 262 ;test signal
;a1 inch 1
;a2 inch 2

fs1l,fsi2l pvsifd	a1, 2048, 512, 1		    ; ifd analysis
fstl  partials fs1l, fsi2l, .003, 1, 3, 500	    ; partial tracking
fscll trfilter fstl, kMix, giFilter			    ; filtering using function table 1
aOut1 tradsyn fscll, 1, 1, 500, 1

fs1r,fsi2r pvsifd	a2, 2048, 512, 1		    ; ifd analysis
fstr  partials fs1r, fsi2r, .003, 1, 3, 500	    ; partial tracking
fsclr trfilter fstr, kMix, giFilter			    ; filtering using function table 1
aOut2 tradsyn fsclr, 1, 1, 500, 1

outs aOut1, aOut2
endin

instr 2
giFilter ftgen 2, 0, sr/2, 7, 1, p4, 1, p4*(p6*16), 0
chnset "tablenumber(2)", "filterview"
endin

</CsInstruments>
<CsScore>
f1 0 8192 10 1
;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>

Is there an opcode or other means of logarithmically scaling the x-axis of a gentable that I might be able to use?

The gentable just displays values from a table, you can edit these values any way you see fit. The table reading and writing opcodes are your best best I’d say :thinking: