electro-music.com   Dedicated to experimental electro-acoustic
and electronic music
 
    Front Page  |  Radio
 |  Media  |  Forum  |  Wiki  |  Links
Forum with support of Syndicator RSS
 FAQFAQ   CalendarCalendar   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   LinksLinks
 RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in  Chat RoomChat Room 
 Forum index » DIY Hardware and Software » ChucK programming language
baby's first granular synth
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [6 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
flies



Joined: May 20, 2008
Posts: 33
Location: NJ

PostPosted: 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?
Reply with quote  Mark this post and the followings unread

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
View user's profile Send private message
vrachnasormora



Joined: Mar 22, 2007
Posts: 42
Location: Preveza,Greece

PostPosted: Fri Nov 18, 2011 12:53 pm    Post subject: Reply with quote  Mark this post and the followings unread

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
View user's profile Send private message
flies



Joined: May 20, 2008
Posts: 33
Location: NJ

PostPosted: Fri Nov 18, 2011 3:53 pm    Post subject:   Reply with quote  Mark this post and the followings unread

Awesome. this looks really promising. If I can get this going tonight, i'll be very happy.
Back to top
View user's profile Send private message
flies



Joined: May 20, 2008
Posts: 33
Location: NJ

PostPosted: Tue Nov 22, 2011 8:06 am    Post subject: Reply with quote  Mark this post and the followings unread

do you never have to remove the spork'd thread?
Back to top
View user's profile Send private message
vrachnasormora



Joined: Mar 22, 2007
Posts: 42
Location: Preveza,Greece

PostPosted: Tue Nov 22, 2011 8:52 am    Post subject: Reply with quote  Mark this post and the followings unread

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
View user's profile Send private message
flies



Joined: May 20, 2008
Posts: 33
Location: NJ

PostPosted: Wed Nov 30, 2011 2:46 pm    Post subject: Reply with quote  Mark this post and the followings unread

iinm, it looks like the
Code:
sineWave  =< dac;
is handling the garbage collection.

Thanks.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [6 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
 Forum index » DIY Hardware and Software » ChucK programming language
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Forum with support of Syndicator RSS
Powered by phpBB © 2001, 2005 phpBB Group
Copyright © 2003 through 2009 by electro-music.com - Conditions Of Use