electro-music.com   Dedicated to experimental electro-acoustic
and electronic music
 
    Front Page  |  Articles  |  Radio
 |  Media  |  Forum  |  Links  |  Store
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 
Live streaming at radio.electro-music.com

  host / artist show at your time
<on air> faux pas quartet and friends Music From Last Thursday
Please visit the chat
 Forum index » DIY Hardware and Software » ChucK programming language
Why does this use so much CPU?
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [7 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
mrcold



Joined: Jun 18, 2009
Posts: 157
Location: USA
Audio files: 24

PostPosted: Fri Jun 19, 2009 11:08 am    Post subject: Why does this use so much CPU? Reply with quote  Mark this post and the followings unread

Why does this use so much cpu?
All was fine until I added the 'ch' function at the end.. when I did that the thing ate all of my cpu within about 10 seconds?

Have I done something wrong, or is this just not optimised correctly?

Code:
// bandlimited ugens (Blit, BlitSaw, BlitSquare)
Blit s => Pan2 p;
p.left => JCRev r1 => dac.left;
p.right => JCRev r2 => dac.right;

// initial settings
.5 => s.gain;
.1 => r1.mix;
.1 => r2.mix;

// an array
[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 ] @=> int hi[];

[ 0, 2, 4, 7, 9 ] @=> int hi2[];

// set the harmonic
5 => s.harmonics;

// spork the pan control
spork ~ dopan();

//sporkchords
spork ~ chords();

//spork ch
spork ~ ch();

// infinite time loop
while( true )
{
   32 => int i;
   Std.rand2( 0, 2 ) => int rand;
if( rand == 1 )
   {
//<<<"chrom">>>;
   while(  i > 0 )
      {      
   
      Std.mtof( 33 + Std.rand2(1,3) * 12 +
        hi[Std.rand2(0,hi.cap()-1)] ) => s.freq;
//mess with the rhythm
    Std.rand2(0,3) => int rh;
      if( rh == 0 )
         {
         240::ms => now;
         i - 4 => i;
         }
      else
         {
         120::ms => now;
         i - 2 => i;
         }
      }
   }
else
   {
//<<<"penta">>>;
   while( i > 0 )
      {
      Std.mtof( 33 + Std.rand2(0,3) * 12 +
        hi2[Std.rand2(0,hi2.cap()-1)] ) => s.freq;
       120::ms => now;
      i - 1 => i;
      }
   }   
}
// pan control
fun void dopan()
{
    float t;
    while( true )
    {
        .7 * Math.sin(t) => p.pan;
        .005 +=> t;
        10::ms => now;
    }
}

//chords
fun void chords()
{
TriOsc t1 => Gain g => Envelope e => dac;
TriOsc t2 => g => e => dac;
TriOsc t3 => g => e => dac;

.5 => g.gain;

[ 0, 2, 4, 7, 9 ] @=> int hi2[];



2000::ms => e.duration;

while( true )
{
    Std.mtof( 33 + Std.rand2(1,3) * 12 +
    hi2[Std.rand2(0,hi2.cap()-1)] ) => t1.freq;

    Std.mtof( 33 + Std.rand2(1,3) * 12 +
    hi2[Std.rand2(0,hi2.cap()-1)] ) => t2.freq;

    Std.mtof( 33 + Std.rand2(1,3) * 12 +
    hi2[Std.rand2(0,hi2.cap()-1)] ) => t3.freq;
   
   Std.rand2(0,3) => int chrand;
if( chrand != 3 )
{      
      .5 => g.gain;
      1920::ms => e.duration;
        //envelopstart
        e.keyOn();
        //wait
        1920::ms => now;
        //envelopstop
        e.keyOff();
        1920::ms => now;
}
else
{      
      1920::ms => e.duration;
        //envelopstart
        e.keyOn();
        //wait
        1920::ms => now;
        //envelopstop
        e.keyOff();
        now => now;
   .3 => g.gain;
}


}

}




fun void ch()
{
while( true )
{
Noise n => ADSR adsr => dac;
.4 => n.gain;
adsr.set(1::ms, 22::ms, .01, 23::ms);
adsr.keyOn();
80::ms => now;
adsr.keyOff();
400::ms => now;
}




}




keep in mind that I have only been learning chuck for 2 days... this is just a mutilated version of one of the basic examples Smile (I added some chords, a different scale array that plays randomly every now and then, and the beat)


THANKS


edit... I would also like any helpful comments about how I have put stuff together here...
Back to top
View user's profile Send private message
mrcold



Joined: Jun 18, 2009
Posts: 157
Location: USA
Audio files: 24

PostPosted: Fri Jun 19, 2009 11:23 am    Post subject: Reply with quote  Mark this post and the followings unread

... well I figured it out.

the problem is fixed my moving the Noise=>dac, and the adsr.set out of the while loop.

but thanks anyway!

Smile
Back to top
View user's profile Send private message
kijjaz



Joined: Sep 20, 2004
Posts: 760
Location: bangkok, thailand
Audio files: 4

PostPosted: Sat Jun 20, 2009 12:53 am    Post subject: Reply with quote  Mark this post and the followings unread

wow.. your patch is cute. i hope i can listen to more of your ChucK sound soon. keep posting heheh.
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
mrcold



Joined: Jun 18, 2009
Posts: 157
Location: USA
Audio files: 24

PostPosted: Sat Jun 20, 2009 7:29 am    Post subject: Reply with quote  Mark this post and the followings unread

Thanks Smile
I'm sure I'll need more help eventually
Back to top
View user's profile Send private message
mrcold



Joined: Jun 18, 2009
Posts: 157
Location: USA
Audio files: 24

PostPosted: Sat Jun 20, 2009 8:26 am    Post subject: Reply with quote  Mark this post and the followings unread

here is the finished version of this.. i cleaned it up a bit and added a pansy BD sound...

I would appreciate any suggestions or comments on it.

I realize that it is a bit simple and silly.. but whatever Smile


foo2.ck
 Description:

Download
 Filename:  foo2.ck
 Filesize:  2.56 KB
 Downloaded:  105 Time(s)

Back to top
View user's profile Send private message
Inventor



Joined: Oct 13, 2007
Posts: 5457
Location: San Antonio, Tx, USA
Audio files: 236

PostPosted: Mon Jun 22, 2009 5:58 pm    Post subject: Reply with quote  Mark this post and the followings unread

I really like this song, I will try to play it on the next ChucK Show.

Les

_________________
No matter how much society beats it out of me, I STILL want to make the world a better place. I am sick of the abuse yet I am powerless to stop it.
Back to top
View user's profile Send private message Send e-mail
mrcold



Joined: Jun 18, 2009
Posts: 157
Location: USA
Audio files: 24

PostPosted: Mon Jun 22, 2009 6:00 pm    Post subject: Reply with quote  Mark this post and the followings unread

word!

I am working on another one which is pretty much the same thing but with a breakbeat in it.. If I get it done I'll share it Smile
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 [7 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
Niio1

Please support our site. If you click through and buy from
our affiliate partners, we earn a small commission.


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