Filtered Noise Etude Ugur Guney 44100 1 1 44100 1 1 true false false false true true true true -d false false true true true true -d false true 0 false filtered noise inbins init 64 iamp init p4 ifreq init p5 iminbin init p6 imaxbin init p7 iFFTsize init inbins*2 kgain init p8 kdecay init p9 ifnspectrum ftgen 0, 0, inbins, 7, 0, inbins, 0 ifnselectedbins ftgen 0, 0, inbins, 7, 0, inbins, 0 ktrig metro ifreq if (ktrig == 1) then ; at every iperiod kbin random iminbin, imaxbin kbin = int(kbin) ; select a random frequency bin -> kbin ;printk2 kbin tablew 1, kbin, ifnselectedbins ; and make its magnitude 1 endif k_index = 0 loopStart: kselected tablei k_index, ifnselectedbins if (kselected == 1) then kmag tablei k_index, ifnspectrum if(kmag < 0.1) then kmag = 0.1 tablew kmag, k_index, ifnspectrum elseif(kmag > 0.95) then tablew -1, k_index, ifnselectedbins endif tablew kmag*kgain, k_index, ifnspectrum elseif(kselected == -1) then kmag tablei k_index, ifnspectrum if(kmag < 0.1) then tablew 0, k_index, ifnselectedbins tablew 0, k_index, ifnspectrum else tablew kmag*kdecay, k_index, ifnspectrum endif endif loop_lt k_index, 1, inbins, loopStart ;vmult ifnspectrum, kdecay, inbins anoise noise iamp, 0 fnoise pvsanal anoise, iFFTsize, iFFTsize/4, iFFTsize, 0 ffiltered pvsmaska fnoise, ifnspectrum, 1 aout pvsynth ffiltered outs aout, aout filtered noise 2 This can not be used in real time. ginbins init 128 ; whole spectrum is divided in inbin parts gifnbinstate ftgen 0, 0, ginbins, 7, 0, ginbins, 0 ; this table includes the states of spectral bins ; state 0: waiting at zero magnitude ; state 1: raising ; state -1: decaying gifnspectrum ftgen 0, 0, ginbins, 7, 0, ginbins, 0 ; this table consists of actual spectral magnitude values of the filter iamp init p4 ; amplitude of the noise ifreq init p5 ; # of particles created in one second iminbin init p6 ; particles bin is selected randomly between minbin imaxbin init p7 ; and max bin iFFTsize init ginbins*2 kraise init p8 ; particle's raise time in seconds kdecay init p9 ; particle's decay time in seconds ktrig metro ifreq if (ktrig == 1) then ; at every iperiod kbin random iminbin, imaxbin kbin = int(kbin) ; select a random frequency bin -> kbin ;printk2 kbin kx table kbin, gifnbinstate if(kx == 0) then ; if it is in "waiting" state tablew 1, kbin, gifnbinstate ; change its state to "raising" endif endif kindex = 0 loopStart: kstate table kindex, gifnbinstate ; iterate on every bin's state kmag table kindex, gifnspectrum ; and its magnitude if (kstate == 1) then ; if the magnitude is raising if(kmag > 0.99) then ; and if it reached its aim tablew -1, kindex, gifnbinstate ; then start to decaying else kmag = kmag + 1 / (kraise * 44100) tablew kmag, kindex, gifnspectrum endif elseif(kstate == -1) then if(kmag < 0.01) then tablew 0, kindex, gifnbinstate tablew 0, kindex, gifnspectrum else kmag = kmag - 1 / (kdecay * 44100) tablew kmag, kindex, gifnspectrum endif endif loop_lt kindex, 1, ginbins, loopStart anoise noise iamp, 0 fnoise pvsanal anoise, iFFTsize, iFFTsize/4, iFFTsize, 0 ffiltered pvsmaska fnoise, gifnspectrum, 1 ffiltered pvsmaska ffiltered, gifnspectrum, 1 ffiltered pvsmaska ffiltered, gifnspectrum, 1 aout pvsynth ffiltered out aout filtered noise: engine ginbins init 64 ; whole spectrum is divided in "nbin" parts ; "engine" manipulates this "spectrum" table. ;it looks at "binstate", "raise time" and "decay time" tables and updates the spectrum gifnspectrum ftgen 0, 0, ginbins, 7, 0, ginbins, 0 ; this table consists of actual spectral magnitude values of the filter iFFTsize init ginbins*2 kraisetime init 0.05 ; particle's raise time in seconds kdecaytime init 0.5 ; particle's decay time in seconds iamp init 25000 kindex = 0 loopStart: kstate table kindex, gifnbinstate ; iterate on every bin's state kmagnitude table kindex, gifnspectrum ; take its magnitude kraisetime table kindex, gifraisetimes ; take its raise time kdecaytime table kindex, gifdecaytimes ; take its decay time if (kstate == 1) then ; if the bin is in "raising" state if(kmagnitude > 0.99) then ; and if it reached its aim (1) tablew -1, kindex, gifnbinstate ; then start to decaying else ; if it did not reach its aim yet kmagnitude = kmagnitude + 1 / (kraisetime * 44100) tablew kmagnitude, kindex, gifnspectrum ; raise the magnitude endif elseif(kstate == -1) then ; if the bin is in "decaying" state if(kmagnitude < 0.01) then ; and if it reached its aim (0) tablew 0, kindex, gifnbinstate ; then start waiting tablew 0, kindex, gifnspectrum else ; if it did not reach its aim yet kmagnitude = kmagnitude - 1 / (kdecaytime * 44100) ; decay the magnitude tablew kmagnitude, kindex, gifnspectrum endif endif loop_lt kindex, 1, ginbins, loopStart ; iterate on every bin's state anoise noise iamp, 0 ; white noise fnoise pvsanal anoise, iFFTsize, iFFTsize/4, iFFTsize, 0 ; take FFT of the white noise ffiltered pvsmaska fnoise, gifnspectrum, 1 ; mask it with the spectrum table ffiltered pvsmaska ffiltered, gifnspectrum, 1 ; namely multiply every FFT bin with the corresponding spectrum table value ffiltered pvsmaska ffiltered, gifnspectrum, 1 ; apply this masking 3 time for getting a more natural raise/decay mode than linear amplitude changes aout pvsynth ffiltered ; finally resynthesize the sound out aout filtered noise: particle creator ; "particle creator" instrument manipulates the tables below gifnbinstate ftgen 0, 0, ginbins, 7, 0, ginbins, 0 ; this table includes the states of spectral bins ; state 0: "waiting" at zero magnitude ; state 1: "raising" ; state -1: "decaying" gifraisetimes ftgen 0, 0, ginbins, 7, 0, ginbins, 0 gifdecaytimes ftgen 0, 0, ginbins, 7, 0, ginbins, 0 ifreq init p4 ; # of particles will be created in one second iminbin init p5 ; particle's bin is selected randomly between "minbin" imaxbin init p6 ; and "maxbin" iraisetime init p7 ; particle's "raise time" in seconds idecaytime init p8 ; particle's "decay time" in seconds ktrig metro ifreq if (ktrig == 1) then ; at every iperiod kbin random iminbin, imaxbin kbin = int(kbin) ; select a random frequency bin kx table kbin, gifnbinstate if(kx == 0) then ; if it is in "waiting" state tablew 1, kbin, gifnbinstate ; change its state to "raising" tablew iraisetime, kbin, gifraisetimes ; adjust its "raise time" tablew idecaytime, kbin, gifdecaytimes ; change its "decay time" endif endif false 0.0 1 Master 0.0 false false 2 Master 0.0 false false 3 Master 0.0 false false 4 Master 0.0 false false Master Master 0.0 false false ; "engine" must always on: ; i3 0 (end of score) ; particle generator's parameters. ; i4 (start time) (duration) (# of particles per second) (min bin) (max bin) (raise time) (decay time) ; "min bin" and "max bin" determines the bin interval in which a random one will be selected csound -Wdo devaudio -L stdin false false -1 -1 2.0 0.0 GenericScore -12566464 2 i2 0 4 10000 5 9 14 0.05 0.5 2.0 0.0 root -10066279 0 true 22 0 true 1.0 0 5 14.0 22.0 riff1 -12566464 0 i4 0 1 1.5 20 25 0.2 0.01 10.0 8.0 riff1 -12566464 0 i4 0 1 15 25 32 0.01 0.03 14.0 43.0 riff1 -12566464 0 i2 0 1 0.3 10 12 0.3 2 50.0 0.0 riff1 -12566464 0 i4 0 1 0.5 5 14 0.05 1.5 7.0 62.0 riff1 -12566464 0 i4 0 1 17 7 13 0.4 0.05 6.0 12.0 riff1 -12566464 0 i4 0 1 1 5 14 0.05 0.05 6.0 30.0 riff1 -12566464 0 i4 0 1 2 6 9 0.1 1.0 6.0 22.0 riff1 -12566464 0 i4 0 1 2 2 4 0.1 1.0 14.0 43.0 riff1 -12566464 0 i4 0 1 11 5 10 0.05 0.5 7.0 67.0 riff1 -12566464 0 i4 0 1 17 8 12 0.4 0.05 4.0 18.0 riff1 -12566464 0 i4 0 1 2 2 5 0.5 0.01 6.0 26.0 riff1 -12566464 0 i4 0 1 2.5 3 6 0.1 1.0 14.0 36.0 riff1 -12566464 0 i4 0 1 0.3 4 6 3 0.5 14.0 50.0 riff1 -12566464 0 i4 0 1 17 7 13 0.05 0.4 74.0 0.0 Engine -12566464 0 i3 0 1 true 0.0 73.954544 false