Cabbage Logo
Back to Cabbage Site

Modulation per impulse

Hey, I’m trying to do something a little unusual and it’s not working, so I can’t move on until I figure it out.

I’m using dust to generate random impulses. On every individual impulse, I want to modulate it with a random cutoff frequency through a filter. Here’s what I have so far:

<CsoundSynthesizer>
<CsOptions>
-n -d 
</CsOptions>
<CsInstruments>

sr = 48000
ksmps = 32
nchnls = 2
0dbfs = 1
seed(0)

instr 1
    kAmp = 1
    kMinFreq = 5000
    kMaxFreq = 10000
    
    aImpulse dust kAmp, 10
    
    kImpulse = k(aImpulse)
    kTrig changed kImpulse
    
    kRandomFreq randomi kMinFreq, kMaxFreq, kTrig
    
    ; This part works better, but some impulses repeat with the same cutoff frequency
    ;if kImpulse > 0 then
	    kRandomFreq random kMinFreq, kMaxFreq
    ;endif

    ; debug output - not sure if this is the best way to approach debugging. 
    ; printk 0.01, kRandomFreq

    aFiltered moogladder aImpulse, kRandomFreq, 0.9
    
    out aFiltered, aFiltered
endin

</CsInstruments>
<CsScore>
i 1 0 5
</CsScore>
</CsoundSynthesizer>

During troubleshooting, I discovered that randomi doesn’t work with a control rate – I initially assumed that if I used kTrig as the kcps then it would result in a new random number being generated, allowing me to change the cutoff frequency for that impulse.

No doubt I’m doing this all wrong so I’d be grateful for any advice on how to push forward.

Thanks in advance!

What about updating the random frequency each time kTrig is 1?

Thanks for your reply. I did try this:

if kTrig == 1 then
    kRandomFreq random kMinFreq, kMaxFreq
endif

Although kTrig doesn’t seem to trigger. It does if I define a separate kImpulse dust, and even then it rarely changes cutoff frequency. I’m guessing it’s something to do with how I’m converting an audio rate into a control rate signal.

I’m wondering if I should use something other than dust (or integrating my own implementation of it for more granularity). I’d then be able to use whatever is generating the impulses as a control source for the filter.

I think downsampling in this case is perhaps not the best option as you’ll be bound to k-rate boundaries. How about simplifying it completely to this:

instr 1
    kCps = 20
    kAmp = 1
    aImpulse dust kAmp, kCps
    aFiltered moogladder aImpulse, abs(randi:k(1000, kCps)), 0.9
    out aFiltered, aFiltered
endin

You will probably miss some impulse, but perhaps it’s not too bad? Otherwise your suggestion sounds good. Generate the impulse yourself and you’ll be able to control things exactly how you like.