(tiny) Nifty Codez

I realize from looking through this site that I need to start posting more code (and resulting recordings.) Part of my motivation is that SC3 (now 3.4!) never ceases to amaze me with its possibilities. One can, with a very small amount of code, achieve some incredibly intricate, beautiful sounds. The below is one example.


{var func, ampFunc; func=LFNoise1.kr(LFNoise1.kr(1!2,0.005,0.02)!3,1000!3,1500!3);
ampFunc=LFNoise1.kr(LFNoise1.kr(1!2,0.4,0.5)!3,0.4!3,0.5!3);
FreeVerb.ar(SinOsc.ar(func,func%pi,ampFunc%1), 0.75,0.75);}.play;

The code all fits in one function ( {} ) and involves 6 UGens and a couple of variables. Basically, the LFNoise1 UGens are random line generators. I’ve nested them inside each other to add even more variability in how the randomness occurs, how often and how much the line moves within the given range. This are then duplicated several times for each parameter (using the ! operator) and applied to the sine-tone oscillator’s frequency, phase, and amplitude parameters. All is wrapped in a warm reverberant blanket of FreeVerb for that roomy effect. Note that the way I’m using the ! operator is sort of a hack and creates many redundant versions of the same integers. This can result in channel number mismatches and amplitudes of over 1. To solve this, the code can be simply modified with a Mix UGen that mixes the array of channels down to (in this case) 2 channels, and adding a multiplier of 0.5 ( ) * 0.5}… ) to keep the amplitudes below 1.


{var func, ampFunc; func=LFNoise1.kr(LFNoise1.kr(1!2,0.005,0.02)!3,1000!3,1500!3);
ampFunc=LFNoise1.kr(LFNoise1.kr(1!2,0.4,0.5)!3,0.4!3,0.5!3);
Mix(FreeVerb.ar(SinOsc.ar(func,func%pi,ampFunc%1), 0.75,0.75);)*0.5}.drawAndPlay;

Note the above uses an added method called drawAndPlay which graphs out the above code in GraphViz so one can visually see exactly what’s going on. The below png file (click it) shows what happens behind the scenes.

Here is a recording of the above code. Note: each time the code is run, the results are different, sometimes subtly, sometimes more noticeably.

The beauty of SC3 is that it is extremely customizable/flexible in terms of coding styles. The above code could be condensed even further, and made to fit in a tweet, for example, but for visual and pedagogical purposes I made it more visually self-explanitory.

I will hopefully post more small examples as the summer weeks pass by. Stay tuned, and stay cool.

\sP