Random selection
Date | 2016-12-04 18:05 |
From | Beinan Li |
Subject | Random selection |
Hello Csound, A noob question. I'd like to trigger sounds at controlled random moments in the following manner: 1) Hava a metro generate pulses; 2) Matching the pulses against an array of constant numbers and only allow those numbers pass; 3) Further filter the passing pulses with a probability gate. <code> gkcounter init 0 instr 1 ; Step 1) A metro repeatedly counting from 0 to 200; Seems to work. ktrig metro 1000/15 kmaxcount init 200 if ktrig==1 then gkcounter = (gkcounter+1)%kmaxcount endif endin instr 2 ; The pattern gate kprob init 0.5 kprimes[] fillarray 29, 37, 47, 67, 89, 113, 157, 197 ; use primes kIndx = 0 until kIndx == lenarray(kprimes) do if gkcounter == kprimes[kIndx] then ; Step 2) krnd random 0, 1 if krnd < kprob then ; Step 3) event "i", 3, 0, 1 ; randomly trigger a sound (instr3) endif kgoto PatternEnd endif kIndx += 1 od PatternEnd: endin </code> But once my Instrument 3 is on I got a fixed repeating pattern as if the Step 3) didn't work, i.e., all the matching prime pulses passed the "random" gate. I printk2'ed the krnd variable (the output of the random opcode) and didn't see a repeating pattern from a glimpse. With PD I did it with metro / sel / random / moses and that worked out fine. I then tried a few other random generators and ended up with the same result. I must have some fundamental misunderstanding about how the "random" or the timing system works, or am I simply using the wrong idiom for the task? I would appreciate it if I can borrow some sharp eyes or tips here. P.S. Now that we have a StackExchange site, are these sort of questions supposed to go there now? Let me know, please. Thanks, Beinan |