Author |
Message |
flies
Joined: May 20, 2008 Posts: 33 Location: NJ
|
Posted: Fri Nov 18, 2011 10:22 am Post subject:
baby's first granular synth Subject description: am noob - am I reaching too far too fast? |
 |
|
Hey,
I'm just starting with ChucK, and I'm interested in granular synthesis. In particular, I'm interested to learn how/whether chuck compartmentalizes synthesis and event scheduling. Let's say I want a new grain to be played every N seconds, where N is a random time between 5 and 10 seconds, and I want the grain to be a sine wave of random duration duration X, where X is randomly drawn from 10 to 15 seconds, and random pitch Y. Note that grains overlap.
In pseudocode:
Code: | while (1) {
waitTime = rand(5 seconds) + 5 seconds;
wait(waitTime);
durX = rand(10 seconds) + 5 seconds;
pitchY = rand(1000 Hz) + 100 Hz;
newGrain(pitchY, durX);
}
function newGrain(pitch, duration) {
output = sineWave(pitch, duration);
pushToAudioStream(output);
return;
} |
Is this easy? does the overlap make it much harder?
(my background: I am an experienced programmer and musician, with nearly 10 years experience in max/msp. I want a music environment where I can use actual code and not graphical programming - I've looked into superCollider but the syntax perplexes me, event processing in particular. I have about zero experience with ChucK itself, but lots of experience with computer music and with computer programming.) |
|
Back to top
|
|
 |
vrachnasormora

Joined: Mar 22, 2007 Posts: 42 Location: Preveza,Greece
|
Posted: Fri Nov 18, 2011 12:53 pm Post subject:
|
 |
|
Hi, I think what you're trying to prototype there is super easy for ChucK.One
possible implementation would be:
Code: | dur waitTime, durX;
float pitchY;
while ( true )
{
Std.rand2f(5., 10.)::second => waitTime;
waitTime => now;
Std.rand2f(10., 15.)::second => durX;
Std.rand2f(1000., 1100.) => pitchY;
spork~ newGrain( pitchY, durX );
}
function void newGrain( float pitch, dur duration )
{
SinOsc sineWave;
pitch => sineWave.freq;
0.3 => sineWave.gain;
sineWave => dac;
duration => now;
sineWave =< dac;
} |
Cheers,
Andreas |
|
Back to top
|
|
 |
flies
Joined: May 20, 2008 Posts: 33 Location: NJ
|
Posted: Fri Nov 18, 2011 3:53 pm Post subject:
|
 |
|
Awesome. this looks really promising. If I can get this going tonight, i'll be very happy. |
|
Back to top
|
|
 |
flies
Joined: May 20, 2008 Posts: 33 Location: NJ
|
Posted: Tue Nov 22, 2011 8:06 am Post subject:
|
 |
|
do you never have to remove the spork'd thread? |
|
Back to top
|
|
 |
vrachnasormora

Joined: Mar 22, 2007 Posts: 42 Location: Preveza,Greece
|
Posted: Tue Nov 22, 2011 8:52 am Post subject:
|
 |
|
You can get the id of the sporked thread:
Code: | ( spork~ newGrain( pitchY, durX ) ).id() => int my_id; |
then elsewhere removing it from the VM:
Code: | Machine.remove( my_id ); |
you may need to build an array for these id's in order not to always remove the last sporked thread |
|
Back to top
|
|
 |
flies
Joined: May 20, 2008 Posts: 33 Location: NJ
|
Posted: Wed Nov 30, 2011 2:46 pm Post subject:
|
 |
|
iinm, it looks like the is handling the garbage collection.
Thanks. |
|
Back to top
|
|
 |
|