Recursive granular synth

Hello,

I’m working on building my set of synths (turned into UDOs).
Right now, I’m trying to make a recursive granular synth (inspired by partikkel) but I just can’t make it work : I’m starting to think it is way more complicated than I thought !

I’m trying to turn a “two instr” synth into a single one (using recursion), before turning it into an UDO.
Here are the “two instr” version and the “single instr” one (which doesn’t work) :

csforum_recursiongranulation.csd (636 Bytes)
csforum_recursiongranulation_2.csd (686 Bytes)

(I made a very simplified version of the synth for this post so that it is understandable)

What I understand is that the envelop which was applied to each grain is now applied to the whole granular event (p3 → 32 - in my code). I just don’t know how to get the same result as with “two instr”.
Is it actually possible ? I thought about using nested UDOs but couldn’t figure that out.

Does anyone know how I could make that recursive granular synth work ? Using two instr is not an option for me, I don’t like it !
Thank you !

Perhaps I’m mistaken, but it appears you’re trying to modulate the amplitude using the aenv, is that correct? If so then no, at the moment your single instrument is using the envelope twice, once governed by the score and again by the internal trigger in the if statement.

If you’re trying to modulate the amplitude at a certain freq (cps) using the table as a window, you can simply use a phasor to run thru the index instead (at a-rate). Just place whatever frequency value you want in the phasor - I chose 3 to make it obvious, more of a tremolo effect.

<CsoundSynthesizer>
<CsOptions>
-odac
</CsOptions>
<CsInstruments>

sr = 48000
ksmps =	1
nchnls = 2
0dbfs =	1

gisiz = 16384
gicos ftgen 0, 0, gisiz, 11, 1
gienv ftgen 0, 0, gisiz, 19, 1, 1, 270, 1

// {{{ instr 1

instr 1
; run phasor at x cps
	andx = phasor(3)  * gisiz
	aenv = table(andx, gienv)
    iamp = p4
	ifrq = p5
	aout poscil3 iamp * aenv, ifrq, gicos, 0

	outs aout, aout	

endin

// }}}

</CsInstruments>
<CsScore>

i 1 0 32 0.25 110
e

</CsScore>
</CsoundSynthesizer>

Hi!
Thank you for your reply.
My aim is to make a granular synth with control over each grain (like partikkel, using arrays and another counter) : aenv is really just the grain window. I used poscil3 for the grain because I made a simplified version of my synth; but the grain should be a sample.

I haven’t tried your idea at the moment, maybe there is an answer to my problem in there and I don’t realize it yet. Thanks again !

hi jacques -

shouldn’t you write in your recursiongranulation_2.csd:
if p6 == 0 then
ktrig = 110

else
iamp = p4

outs aout, aout
endif
?

perhaps worth to try. best -

joachim

Worth the try it was. Spent weeks trying out insane methods. The correct solution is very often the simplest one indeed. :melting_face:
Thanks a lot !

All the best

Hi again. Yes, the example I posted gives control over each grain. Here is another simple example which uses a sample and randomizes the amp & freq of each grain at a-rate. This could be easily modified to use a directory of samples loaded as either arrays or ftables which could be chosen via the score or using a counter.

Try changing the kdens, grains per second, to 110 for example. Note that you can run the ksmps higher and only run necessary opcodes at a-rate which is probably more cpu efficient.

Of course if I’m somehow missing your intent I apologize.

<CsoundSynthesizer>
<CsOptions>
-odac
 -o gran.wav
</CsOptions>
<CsInstruments>

sr = 48000
ksmps = 32	
nchnls = 2
0dbfs  = 1

gisiz = 16384
gienv ftgen 0, 0, gisiz, 19, 1, 1, 270, 1
gicos ftgen 1, 0, gisiz, 11, 1
gifox ftgen 2, 0, 0, 1, "fox.wav", 0, 0, 0

seed 0

// {{{ instr 1

instr 1

    kdens = 10 ; grain density (grains per second) 
	andx  = phasor(kdens) * gisiz
	iamp  = p4
	aenv  = table:a(andx, gienv)
    arand = randomh:a(.5, 2, kdens) ; randomize grain amp and freq
	ifrq  = p5

	aout  = poscil3(iamp * aenv * arand, ifrq * arand * 2, p6, 0)     

	outs aout, aout	

endin

// }}}

</CsInstruments>
<CsScore>

i 1 0  8 0.35 220  1
i . 8 32  .45 .15  2 
e

</CsScore>
</CsoundSynthesizer>

1 Like

I’ll try it out :blush: Thanks a lot for your time